Permalink
Browse files

Pass DESTDIR via command line to override what's in MAKEFLAGS.

This fixes an installation problem under a package building
environment where DESTDIR is specified in the (parent) command line.

Related bug reports:
- https://bugzilla.redhat.com/show_bug.cgi?id=921650
- ruby/ruby#327
  • Loading branch information...
1 parent 082c243 commit 75571d47a568ad95470604261083963794b86f1b @knu knu committed with drbrain Jun 23, 2013
@@ -23,26 +23,27 @@ def self.make(dest_path, results)
make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
end
- ['', ' install'].each do |target|
- cmd = "#{make_program}#{target}"
- results << cmd
- results << `#{cmd} #{redirector}`
-
- raise Gem::InstallError, "make#{target} failed:\n\n#{results}" unless
- $?.success?
+ ['', '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
def self.redirector
'2>&1'
end
- def self.run(command, results)
+ def self.run(command, results, command_name = nil)
results << command
results << `#{command} #{redirector}`
unless $?.success? then
- raise Gem::InstallError, "#{class_name} failed:\n\n#{results.join "\n"}"
+ raise Gem::InstallError, "#{command_name || class_name} failed:\n\n#{results.join "\n"}"
end
end
View
@@ -23,6 +23,7 @@
require 'pp'
require 'zlib'
require 'pathname'
+require 'shellwords'
Gem.load_yaml
require 'rubygems/mock_gem_ui'
@@ -94,6 +95,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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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

0 comments on commit 75571d4

Please sign in to comment.