Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/rubygems/ext/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ def self.make(dest_path, results)
make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
end

['', ' install'].each do |target|
cmd = "#{make_program}#{target}"
run(cmd, results, "make#{target}")
['', 'install'].each do |target|
# Pass DESTDIR via command line to override what's in MAKEFLAGS
cmd = [
make_program,
'"DESTDIR=%s"' % ENV['DESTDIR'],
target
].join(' ').rstrip
run(cmd, results, "make #{target}".rstrip)
end
end

Expand Down
58 changes: 58 additions & 0 deletions lib/rubygems/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
require 'pp'
require 'zlib'
require 'pathname'
require 'shellwords'
Gem.load_yaml

require 'rubygems/mock_gem_ui'
Expand Down Expand Up @@ -106,6 +107,63 @@ def refute_path_exists path, msg = nil
refute File.exist?(path), msg
end

def scan_make_command_lines(output)
output.scan(/^#{Regexp.escape make_command}(?:[[:blank:]].*)?$/)
end

def parse_make_command_line(line)
command, *args = line.shellsplit

targets = []
macros = {}

args.each do |arg|
case arg
when /\A(\w+)=/
macros[$1] = $'
else
targets << arg
end
end

targets << '' if targets.empty?

{
:command => command,
:targets => targets,
:macros => macros,
}
end

def assert_contains_make_command(target, output, msg = nil)
if output.match(/\n/)
msg = message(msg) {
'Expected output containing make command "%s": %s' % [
('%s %s' % [make_command, target]).rstrip,
output.inspect
]
}
else
msg = message(msg) {
'Expected make command "%s": %s' % [
('%s %s' % [make_command, target]).rstrip,
output.inspect
]
}
end

assert scan_make_command_lines(output).any? { |line|
make = parse_make_command_line(line)

if make[:targets].include?(target)
yield make, line if block_given?
true
else
false
end
}, msg
end

include Gem::DefaultUserInteraction

undef_method :default_test if instance_methods.include? 'default_test' or
Expand Down
8 changes: 4 additions & 4 deletions test/rubygems/test_gem_ext_cmake_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def test_self_build
assert_match \
%r%^cmake \. -DCMAKE_INSTALL_PREFIX=#{Regexp.escape @dest_path}%, output
assert_match %r%#{Regexp.escape @ext}%, output
assert_match %r%^#{Regexp.escape make_command}$%, output
assert_match %r%^#{Regexp.escape make_command} install$%, output
assert_contains_make_command '', output
assert_contains_make_command 'install', output
assert_match %r%test\.txt%, output
end

Expand Down Expand Up @@ -82,8 +82,8 @@ def test_self_build_has_makefile

output = output.join "\n"

assert_match %r%^#{make_command}%, output
assert_match %r%^#{make_command} install%, output
assert_contains_make_command '', output
assert_contains_make_command 'install', output
end

end
Expand Down
8 changes: 4 additions & 4 deletions test/rubygems/test_gem_ext_configure_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def test_self_build

assert_equal "sh ./configure --prefix=#{@dest_path}", output.shift
assert_equal "", output.shift
assert_equal make_command, output.shift
assert_contains_make_command '', output.shift
assert_match(/^ok$/m, output.shift)
assert_equal make_command + " install", output.shift
assert_contains_make_command 'install', output.shift
assert_match(/^ok$/m, output.shift)
end

Expand Down Expand Up @@ -76,8 +76,8 @@ def test_self_build_has_makefile
Gem::Ext::ConfigureBuilder.build nil, nil, @dest_path, output
end

assert_equal make_command, output[0]
assert_equal "#{make_command} install", output[2]
assert_contains_make_command '', output[0]
assert_contains_make_command 'install', output[2]
end

end
Expand Down
20 changes: 7 additions & 13 deletions test/rubygems/test_gem_ext_ext_conf_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@ def test_class_build

assert_match(/^#{Gem.ruby} extconf.rb/, output[0])
assert_equal "creating Makefile\n", output[1]
case RUBY_PLATFORM
when /mswin/ then
assert_equal "nmake", output[2]
assert_equal "nmake install", output[4]
else
assert_equal "make", output[2]
assert_equal "make install", output[4]
end
assert_contains_make_command '', output[2]
assert_contains_make_command 'install', output[4]
end

def test_class_build_rbconfig_make_prog
Expand All @@ -56,8 +50,8 @@ def test_class_build_rbconfig_make_prog
end

assert_equal "creating Makefile\n", output[1]
assert_equal make_command, output[2]
assert_equal "#{make_command} install", output[4]
assert_contains_make_command '', output[2]
assert_contains_make_command 'install', output[4]
ensure
RbConfig::CONFIG['configure_args'] = configure_args
end
Expand All @@ -80,7 +74,7 @@ def test_class_build_env_make
end

assert_equal "creating Makefile\n", output[1]
assert_equal "anothermake", output[2]
assert_contains_make_command '', output[2]
ensure
RbConfig::CONFIG['configure_args'] = configure_args
ENV['make'] = env_make
Expand Down Expand Up @@ -132,8 +126,8 @@ def test_class_make
Gem::Ext::ExtConfBuilder.make @ext, output
end

assert_equal make_command, output[0]
assert_equal "#{make_command} install", output[2]
assert_contains_make_command '', output[0]
assert_contains_make_command 'install', output[2]
end

def test_class_make_no_Makefile
Expand Down