Skip to content

Commit edc5b3f

Browse files
Merge pull request #6490 from ntkme/remove-rubygems-path-in-rake-builder
Fix $LOAD_PATH in rake and ext_conf builder (cherry picked from commit 653ee82)
1 parent 6f3ee54 commit edc5b3f

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
@@ -55,6 +55,23 @@ def self.make(dest_path, results, make_dir = Dir.pwd, sitedir = nil, targets = [
5555
end
5656
end
5757

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

lib/rubygems/ext/ext_conf_builder.rb

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

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

2827
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
@@ -18,7 +18,7 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_di
1818
rake = rake.shellsplit
1919
else
2020
begin
21-
rake = [Gem.ruby, "-I#{File.expand_path("../..", __dir__)}", "-rrubygems", Gem.bin_path("rake", "rake")]
21+
rake = ruby << "-rrubygems" << Gem.bin_path("rake", "rake")
2222
rescue Gem::Exception
2323
rake = [Gem.default_exec_format % "rake"]
2424
end

0 commit comments

Comments
 (0)