Skip to content

Commit

Permalink
Merge pull request #6490 from ntkme/remove-rubygems-path-in-rake-builder
Browse files Browse the repository at this point in the history
Fix $LOAD_PATH in rake and ext_conf builder
  • Loading branch information
deivid-rodriguez authored Mar 20, 2023
2 parents f97de10 + 9db5e94 commit 653ee82
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
17 changes: 17 additions & 0 deletions lib/rubygems/ext/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ def self.make(dest_path, results, make_dir = Dir.pwd, sitedir = nil, targets = [
end
end

def self.ruby
require "shellwords"
# Gem.ruby is quoted if it contains whitespace
cmd = Gem.ruby.shellsplit

# This load_path is only needed when running rubygems test without a proper installation.
# Prepending it in a normal installation will cause problem with order of $LOAD_PATH.
# Therefore only add load_path if it is not present in the default $LOAD_PATH.
load_path = File.expand_path("../..", __dir__)
case load_path
when RbConfig::CONFIG["sitelibdir"], RbConfig::CONFIG["vendorlibdir"], RbConfig::CONFIG["rubylibdir"]
cmd
else
cmd << "-I#{load_path}"
end
end

def self.run(command, results, command_name = nil, dir = Dir.pwd, env = {})
verbose = Gem.configuration.really_verbose

Expand Down
3 changes: 1 addition & 2 deletions lib/rubygems/ext/ext_conf_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_di
destdir = ENV["DESTDIR"]

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

run(cmd, results, class_name, extension_dir) do |s, r|
Expand Down
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 = ruby << "-rrubygems" << Gem.bin_path("rake", "rake")
rescue Gem::Exception
rake = [Gem.default_exec_format % "rake"]
end
Expand Down

0 comments on commit 653ee82

Please sign in to comment.