Skip to content

Commit

Permalink
Fix incorrect path to rubygems being passed to rake builder
Browse files Browse the repository at this point in the history
We were passing an incorrect folder, and one which has a `openssl.rb`
file inside. So this file was shadowing the require of the "real openssl".

This `-I` parameter is not really needed in real life I believe, since there can
be at most one rubygems installation at a given ruby installation. I think the
idea of this parameter is that our tests never leak to the "system rubygems",
because when testing there are two copies of rubygems involved (the one being
tested, and the one from the ruby we're running).

I'm not sure using this `-I` parameter here is a good idea, so since I'm not
sure I'm just keeping things as they are for now and fixing the bug.
  • Loading branch information
deivid-rodriguez committed Dec 16, 2020
1 parent 352a1f5 commit 189f658
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rubygems/ext/rake_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_di
rake = rake.shellsplit
else
begin
rake = [Gem.ruby, "-I#{File.expand_path("..", __dir__)}", "-rrubygems", Gem.bin_path('rake', 'rake')]
rake = [Gem.ruby, "-I#{File.expand_path("../..", __dir__)}", "-rrubygems", Gem.bin_path('rake', 'rake')]
rescue Gem::Exception
rake = [Gem.default_exec_format % 'rake']
end
Expand Down
25 changes: 25 additions & 0 deletions test/rubygems/test_gem_ext_rake_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,31 @@ def test_class_build_with_args
end
end

def test_class_no_openssl_override
create_temp_mkrf_file('task :default')

rake = util_spec 'rake' do |s|
s.executables = %w[rake]
s.files = %w[bin/rake]
end

output = []

write_file File.join(@tempdir, 'bin', 'rake') do |fp|
fp.puts "#!/usr/bin/ruby"
fp.puts "require 'openssl'; puts OpenSSL"
end

install_gem rake

Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', @dest_path, output, [''], nil, @ext

output = output.join "\n"

assert_match "OpenSSL", output
assert_match %r{^#{Regexp.escape Gem.ruby} mkrf_conf\.rb}, output
end

def test_class_build_no_mkrf_passes_args
output = []

Expand Down

0 comments on commit 189f658

Please sign in to comment.