Permalink
Browse files

Fix extension building on Ruby 1.9.3 and mingw

Supplying DESTDIR on mingw causes link errors due to reasons I don't
understand (see the related bug).  Now, on 1.9.3, DESTDIR is not
supplied to the make command which prevents the bug.  Ruby 2.0.0 behaves
as before.

Fixes #594, see also duplicate bug #599
  • Loading branch information...
1 parent f3f99fc commit 9667d4580856edd09c28a4cef032e1cc735ad910 @drbrain drbrain committed Jul 19, 2013
Showing with 62 additions and 1 deletion.
  1. +1 −0 Manifest.txt
  2. +3 −1 lib/rubygems/ext/builder.rb
  3. +58 −0 test/rubygems/test_gem_ext_builder.rb
View
@@ -164,6 +164,7 @@ test/rubygems/test_gem_dependency.rb
test/rubygems/test_gem_dependency_installer.rb
test/rubygems/test_gem_dependency_list.rb
test/rubygems/test_gem_doc_manager.rb
+test/rubygems/test_gem_ext_builder.rb
test/rubygems/test_gem_ext_configure_builder.rb
test/rubygems/test_gem_ext_ext_conf_builder.rb
test/rubygems/test_gem_ext_rake_builder.rb
@@ -23,11 +23,13 @@ def self.make(dest_path, results)
make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
end
+ destdir = '"DESTDIR=%s"' % ENV['DESTDIR'] if RUBY_VERSION > '2.0'
+
['', 'install'].each do |target|
# Pass DESTDIR via command line to override what's in MAKEFLAGS
cmd = [
make_program,
- '"DESTDIR=%s"' % ENV['DESTDIR'],
+ destdir,
target
].join(' ').rstrip
run(cmd, results, "make #{target}".rstrip)
@@ -0,0 +1,58 @@
+require 'rubygems/test_case'
+require 'rubygems/ext'
+
+class TestGemExtBuilder < Gem::TestCase
+
+ def setup
+ super
+
+ @ext = File.join @tempdir, 'ext'
+ @dest_path = File.join @tempdir, 'prefix'
+
+ FileUtils.mkdir_p @ext
+ FileUtils.mkdir_p @dest_path
+
+ @orig_DESTDIR = ENV['DESTDIR']
+ end
+
+ def teardown
+ ENV['DESTDIR'] = @orig_DESTDIR
+
+ super
+ end
+
+ def test_class_make
+ ENV['DESTDIR'] = 'destination'
+ results = []
+
+ Dir.chdir @ext do
+ open 'Makefile', 'w' do |io|
+ io.puts <<-MAKEFILE
+all:
+\t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}"
+
+install:
+\t@#{Gem.ruby} -e "puts %Q{install: \#{ENV['DESTDIR']}}"
+ MAKEFILE
+ end
+
+ Gem::Ext::Builder.make @dest_path, results
+ end
+
+ results = results.join "\n"
+
+
+ if RUBY_VERSION > '2.0' then
+ assert_match %r%"DESTDIR=#{ENV['DESTDIR']}"$%, results
+ assert_match %r%"DESTDIR=#{ENV['DESTDIR']}" install$%, results
+ else
+ refute_match %r%"DESTDIR=#{ENV['DESTDIR']}"$%, results
+ refute_match %r%"DESTDIR=#{ENV['DESTDIR']}" install$%, results
+ end
+
+ assert_match %r%^all: destination$%, results
+ assert_match %r%^install: destination$%, results
+ end
+
+end
+

0 comments on commit 9667d45

Please sign in to comment.