Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkmf: Add the extra option --with-verbose to enable verbose mode. #7863

Merged
merged 1 commit into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/mkmf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1965,14 +1965,14 @@ def mkintpath(path)

def configuration(srcdir)
mk = []
CONFIG['MKMF_VERBOSE'] ||= "0"
verbose = with_config('verbose') ? "1" : (CONFIG['MKMF_VERBOSE'] || "0")
vpath = $VPATH.dup
CONFIG["hdrdir"] ||= $hdrdir
mk << %{
SHELL = /bin/sh

# V=0 quiet, V=1 verbose. other values don't work.
V = #{CONFIG['MKMF_VERBOSE']}
V = #{verbose}
V0 = $(V:0=)
Q1 = $(V:1=)
Q = $(Q1:0=@)
Expand Down
7 changes: 5 additions & 2 deletions test/mkmf/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ def config_value(name)

include Base

def assert_separately(args, src, *rest, **options)
super(args + ["-r#{__FILE__}"], "extend TestMkmf::Base; setup\nEND{teardown}\n#{src}", *rest, **options)
def assert_separately(args, extra_args, src, *rest, **options)
super(args + ["-r#{__FILE__}"] + %w[- --] + extra_args,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this part, I wanted to write args + %w[-r#{__FILE__} - --] + extra_args. However, I saw the #{__FILE__} was not converted to the value. So, the ["-r#{__FILE__}"] + %w[- --] is a bit compromised way.

$ ruby -v
ruby 3.3.0dev (2023-05-25T12:45:21Z wip/mkmf-verbose-r.. cbeba2ed16) [x86_64-linux]

$ which irb
~/.local/ruby-cbeba2ed16/bin/irb

$ irb
irb(main):001:0> %w[-r#{__FILE__} - --]
=> ["-r\#{__FILE__}", "-", "--"]

irb(main):002:0> %[-r#{__FILE__} - --]
=> "-r(irb) - --"

"extend TestMkmf::Base; setup\nEND{teardown}\n#{src}",
*rest,
**options)
end
end
29 changes: 22 additions & 7 deletions test/mkmf/test_config.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
# frozen_string_literal: false
$extmk = true
require_relative 'base'

require 'test/unit'
require 'mkmf'

class TestMkmfConfig < Test::Unit::TestCase
class TestMkmfConfig < TestMkmf
def test_dir_config
bug8074 = '[Bug #8074]'
lib = RbConfig.expand(RbConfig::MAKEFILE_CONFIG["libdir"], "exec_prefix"=>"/test/foo")
assert_separately %w[-rmkmf - -- --with-foo-dir=/test/foo], %{
assert_separately([], %w[--with-foo-dir=/test/foo], <<-"end;")
assert_equal(%w[/test/foo/include #{lib}], dir_config("foo"), #{bug8074.dump})
}
end;
end

def test_with_config_with_arg_and_value
assert_separately([], %w[--with-foo=bar], <<-'end;')
assert_equal("bar", with_config("foo"))
end;
end

def test_with_config_with_arg_and_no_value
assert_separately([], %w[--with-foo], <<-'end;')
assert_equal(true, with_config("foo"))
end;
end

def test_with_config_without_arg
assert_separately([], %w[--without-foo], <<-'end;')
assert_equal(false, with_config("foo"))
end;
end
junaruga marked this conversation as resolved.
Show resolved Hide resolved
end
39 changes: 39 additions & 0 deletions test/mkmf/test_configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: false
require_relative 'base'

class TestMkmfConfiguration < TestMkmf
def test_verbose_with_rbconfig_verbose_disabled
makefile = mkmf do
self.class::CONFIG['MKMF_VERBOSE'] = "0"
init_mkmf(self.class::CONFIG)
configuration '.'
end
verbose = makefile.grep(/^V =/).first[/^V = (.)$/, 1]

assert_equal "0", verbose
end

def test_verbose_with_rbconfig_verbose_enabled
makefile = mkmf do
self.class::CONFIG['MKMF_VERBOSE'] = "1"
init_mkmf(self.class::CONFIG)
configuration '.'
end
verbose = makefile.grep(/^V =/).first[/^V = (.)$/, 1]

assert_equal "1", verbose
end

def test_verbose_with_arg
assert_separately([], %w[--with-verbose], <<-'end;')
makefile = mkmf do
self.class::CONFIG['MKMF_VERBOSE'] = "0"
init_mkmf(self.class::CONFIG)
configuration '.'
end
verbose = makefile.grep(/^V =/).first[/^V = (.)$/, 1]

assert_equal "1", verbose
end;
end
end
6 changes: 3 additions & 3 deletions test/mkmf/test_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ def test_valid_warnflags
end

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

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

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