Skip to content

Commit

Permalink
mkmf.rb: avoid interference
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu authored and tmm1 committed Feb 9, 2015
1 parent 0416cd0 commit 1e6a7c4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
12 changes: 3 additions & 9 deletions lib/mkmf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,7 @@ def with_cppflags(flags)
end

def try_cppflags(flags)
with_cppflags(flags) do
try_header("int main() {return 0;}")
end
try_header(MAIN_DOES_NOTHING, flags)
end

def with_cflags(flags)
Expand All @@ -624,9 +622,7 @@ def with_cflags(flags)
end

def try_cflags(flags)
with_cflags(flags) do
try_compile("int main() {return 0;}")
end
try_compile(MAIN_DOES_NOTHING, flags)
end

def with_ldflags(flags)
Expand All @@ -638,9 +634,7 @@ def with_ldflags(flags)
end

def try_ldflags(flags)
with_ldflags(flags) do
try_link("int main() {return 0;}")
end
try_link(MAIN_DOES_NOTHING, flags)
end

def try_static_assert(expr, headers = nil, opt = "", &b)
Expand Down
12 changes: 11 additions & 1 deletion test/mkmf/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def write(s)
@buffer << s if @out
end
end
end

module TestMkmf::Base
attr_reader :stdout

def mkmflog(msg)
Expand Down Expand Up @@ -84,7 +86,7 @@ def setup
@tmpdir = Dir.mktmpdir
@curdir = Dir.pwd
@mkmfobj = Object.new
@stdout = Capture.new
@stdout = TestMkmf::Capture.new
Dir.chdir(@tmpdir)
@quiet, Logging.quiet = Logging.quiet, true
init_mkmf
Expand Down Expand Up @@ -127,3 +129,11 @@ def config_value(name)
nil
end
end

class TestMkmf
include TestMkmf::Base

def assert_separately(args, src, *rest)
super(args + ["-r#{__FILE__}"], "extend TestMkmf::Base; setup\n#{src}", *rest)
end
end
21 changes: 21 additions & 0 deletions test/mkmf/test_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,26 @@ def test_valid_warnflags
$warnflags = warnflags
$extmk = val
end

def test_try_ldflag_invalid_opt
assert_separately([], <<-'end;') #do
assert(!try_ldflags("----------"))
assert(have_devel?, TestMkmf::MKMFLOG)
end;
end

def test_try_cflag_invalid_opt
assert_separately([], <<-'end;') #do
assert(!try_cflags("----------"))
assert(have_devel?, TestMkmf::MKMFLOG)
end;
end

def test_try_cppflag_invalid_opt
assert_separately([], <<-'end;') #do
assert(!try_cppflags("----------"))
assert(have_devel?, TestMkmf::MKMFLOG)
end;
end
end
end

0 comments on commit 1e6a7c4

Please sign in to comment.