Skip to content

Commit 1e6a7c4

Browse files
nobutmm1
authored andcommitted
mkmf.rb: avoid interference
* lib/mkmf.rb (try_cppflags, try_cflags, try_ldflags): get rid of interference by modifying global variables in have_devel? method. [ruby-core:67962] [Bug ruby#10821] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49482 b2dd03c8-39d4-4d8f-98ff-823fe69b080e Conflicts: ChangeLog
1 parent 0416cd0 commit 1e6a7c4

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

lib/mkmf.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,7 @@ def with_cppflags(flags)
610610
end
611611

612612
def try_cppflags(flags)
613-
with_cppflags(flags) do
614-
try_header("int main() {return 0;}")
615-
end
613+
try_header(MAIN_DOES_NOTHING, flags)
616614
end
617615

618616
def with_cflags(flags)
@@ -624,9 +622,7 @@ def with_cflags(flags)
624622
end
625623

626624
def try_cflags(flags)
627-
with_cflags(flags) do
628-
try_compile("int main() {return 0;}")
629-
end
625+
try_compile(MAIN_DOES_NOTHING, flags)
630626
end
631627

632628
def with_ldflags(flags)
@@ -638,9 +634,7 @@ def with_ldflags(flags)
638634
end
639635

640636
def try_ldflags(flags)
641-
with_ldflags(flags) do
642-
try_link("int main() {return 0;}")
643-
end
637+
try_link(MAIN_DOES_NOTHING, flags)
644638
end
645639

646640
def try_static_assert(expr, headers = nil, opt = "", &b)

test/mkmf/base.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def write(s)
4949
@buffer << s if @out
5050
end
5151
end
52+
end
5253

54+
module TestMkmf::Base
5355
attr_reader :stdout
5456

5557
def mkmflog(msg)
@@ -84,7 +86,7 @@ def setup
8486
@tmpdir = Dir.mktmpdir
8587
@curdir = Dir.pwd
8688
@mkmfobj = Object.new
87-
@stdout = Capture.new
89+
@stdout = TestMkmf::Capture.new
8890
Dir.chdir(@tmpdir)
8991
@quiet, Logging.quiet = Logging.quiet, true
9092
init_mkmf
@@ -127,3 +129,11 @@ def config_value(name)
127129
nil
128130
end
129131
end
132+
133+
class TestMkmf
134+
include TestMkmf::Base
135+
136+
def assert_separately(args, src, *rest)
137+
super(args + ["-r#{__FILE__}"], "extend TestMkmf::Base; setup\n#{src}", *rest)
138+
end
139+
end

test/mkmf/test_flags.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,26 @@ def test_valid_warnflags
3131
$warnflags = warnflags
3232
$extmk = val
3333
end
34+
35+
def test_try_ldflag_invalid_opt
36+
assert_separately([], <<-'end;') #do
37+
assert(!try_ldflags("----------"))
38+
assert(have_devel?, TestMkmf::MKMFLOG)
39+
end;
40+
end
41+
42+
def test_try_cflag_invalid_opt
43+
assert_separately([], <<-'end;') #do
44+
assert(!try_cflags("----------"))
45+
assert(have_devel?, TestMkmf::MKMFLOG)
46+
end;
47+
end
48+
49+
def test_try_cppflag_invalid_opt
50+
assert_separately([], <<-'end;') #do
51+
assert(!try_cppflags("----------"))
52+
assert(have_devel?, TestMkmf::MKMFLOG)
53+
end;
54+
end
3455
end
3556
end

0 commit comments

Comments
 (0)