Permalink
Browse files

Add workaround for .time dependency by mkmf.rb introduced since Ruby …

…2.0.0

GitHub: fix #411

Ruby: fix [Bug #7698] [ruby-core:51437]

mkmf.rb on Ruby 2.0.0 introduces .time dependency to support "make -j".
See Ruby's [Bug #6904]: https://bugs.ruby-lang.org/issues/6904

With this change, installing *.rb tasks are always ran even if source
rb and destination rb are the same file. RubyGems uses the same
directory for source directory and install directory. So this behavior
causes a RubyGems problem. GNU install reports an error for the same
source and destination file. BSD install also reports an error for it
but doesn't report any error by specifying destination as directory.
Makefile generated by mkmf.rb uses destination directory not
destination file.

Prepare:

  % cd /tmp
  % touch x

GNU install (Debian GNU/Linux):

  % install x x
  install: 'x' and 'x' are the same file
  % install x ./
  install: 'x' and './x' are the same file

BSD install (FreeBSD):

  % install x x
  install: x and x are the same file
  % install x ./
  % echo $?
  0

This workaround doesn't causes any problems with Ruby 1.9 and 1.8
because mkmf.rb on Ruby 1.9 and 1.8 don't use .time.
  • Loading branch information...
kou committed Jan 17, 2013
1 parent 7e880b1 commit a7cd1be541f2194fc8c1436d86bc05eb3a94500d
Showing with 28 additions and 0 deletions.
  1. +1 −0 lib/rubygems/ext/builder.rb
  2. +27 −0 test/rubygems/test_gem_installer.rb
@@ -19,6 +19,7 @@ def self.make(dest_path, results)
mf = Gem.read_binary 'Makefile'
mf = mf.gsub(/^RUBYARCHDIR\s*=\s*\$[^$]*/, "RUBYARCHDIR = #{dest_path}")
mf = mf.gsub(/^RUBYLIBDIR\s*=\s*\$[^$]*/, "RUBYLIBDIR = #{dest_path}")
+ mf = mf.gsub(/\s*\S+\.time$/, "")
File.open('Makefile', 'wb') {|f| f.print mf}
@@ -964,6 +964,33 @@ def test_install_with_message
assert_match %r|I am a shiny gem!|, @ui.output
end
+ def test_install_extension_and_script
+ @spec.extensions << "extconf.rb"
+ write_file File.join(@tempdir, "extconf.rb") do |io|
+ io.write <<-RUBY
+ require "mkmf"
+ create_makefile("#{@spec.name}")
+ RUBY
+ end
+
+ rb = File.join("lib", "#{@spec.name}.rb")
+ @spec.files += [rb]
+ write_file File.join(@tempdir, rb) do |io|
+ io.write <<-RUBY
+ # #{@spec.name}.rb
+ RUBY
+ end
+
+ assert !File.exist?(File.join(@spec.gem_dir, rb))
+ use_ui @ui do
+ path = Gem::Package.build @spec
+
+ @installer = Gem::Installer.new path
+ @installer.install
+ end
+ assert File.exist?(File.join(@spec.gem_dir, rb))
+ end
+
def test_installation_satisfies_dependency_eh
quick_spec 'a'

0 comments on commit a7cd1be

Please sign in to comment.