Skip to content

Commit 653ee82

Browse files
Merge pull request #6490 from ntkme/remove-rubygems-path-in-rake-builder
Fix $LOAD_PATH in rake and ext_conf builder
2 parents f97de10 + 9db5e94 commit 653ee82

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/rubygems/ext/builder.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ def self.make(dest_path, results, make_dir = Dir.pwd, sitedir = nil, targets = [
5454
end
5555
end
5656

57+
def self.ruby
58+
require "shellwords"
59+
# Gem.ruby is quoted if it contains whitespace
60+
cmd = Gem.ruby.shellsplit
61+
62+
# This load_path is only needed when running rubygems test without a proper installation.
63+
# Prepending it in a normal installation will cause problem with order of $LOAD_PATH.
64+
# Therefore only add load_path if it is not present in the default $LOAD_PATH.
65+
load_path = File.expand_path("../..", __dir__)
66+
case load_path
67+
when RbConfig::CONFIG["sitelibdir"], RbConfig::CONFIG["vendorlibdir"], RbConfig::CONFIG["rubylibdir"]
68+
cmd
69+
else
70+
cmd << "-I#{load_path}"
71+
end
72+
end
73+
5774
def self.run(command, results, command_name = nil, dir = Dir.pwd, env = {})
5875
verbose = Gem.configuration.really_verbose
5976

lib/rubygems/ext/ext_conf_builder.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_di
2222
destdir = ENV["DESTDIR"]
2323

2424
begin
25-
require "shellwords"
26-
cmd = Gem.ruby.shellsplit << "-I" << File.expand_path("../..", __dir__) << File.basename(extension)
25+
cmd = ruby << File.basename(extension)
2726
cmd.push(*args)
2827

2928
run(cmd, results, class_name, extension_dir) do |s, r|

lib/rubygems/ext/rake_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_di
1919
rake = rake.shellsplit
2020
else
2121
begin
22-
rake = [Gem.ruby, "-I#{File.expand_path("../..", __dir__)}", "-rrubygems", Gem.bin_path("rake", "rake")]
22+
rake = ruby << "-rrubygems" << Gem.bin_path("rake", "rake")
2323
rescue Gem::Exception
2424
rake = [Gem.default_exec_format % "rake"]
2525
end

0 commit comments

Comments
 (0)