From 62768527ed109b771acba7759319bfc35436a064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Wed, 15 Mar 2023 20:52:46 -0700 Subject: [PATCH 1/4] Make sure native extensions are loaded correctly in rake builder --- lib/rubygems/ext/rake_builder.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/rubygems/ext/rake_builder.rb b/lib/rubygems/ext/rake_builder.rb index 282285b97029..9a3f8ca65e8f 100644 --- a/lib/rubygems/ext/rake_builder.rb +++ b/lib/rubygems/ext/rake_builder.rb @@ -18,8 +18,20 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_di require "shellwords" rake = rake.shellsplit else + # This is only needed when running rubygems test without a proper installation. + # Prepending it in a normal installation can cause problem with order of $LOAD_PATH. + # Therefore only add rubygems_load_path if it is not present in the default $LOAD_PATH. + rubygems_load_path = File.expand_path("../..", __dir__) + load_path = + case rubygems_load_path + when RbConfig::CONFIG["sitelibdir"], RbConfig::CONFIG["vendorlibdir"], RbConfig::CONFIG["rubylibdir"] + [] + else + ["-I#{rubygems_load_path}"] + end + begin - rake = [Gem.ruby, "-I#{File.expand_path("../..", __dir__)}", "-rrubygems", Gem.bin_path("rake", "rake")] + rake = [Gem.ruby, *load_path, "-rrubygems", Gem.bin_path("rake", "rake")] rescue Gem::Exception rake = [Gem.default_exec_format % "rake"] end From d095b477e9f030b5f9461bdbcf3747ba90efb881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Thu, 16 Mar 2023 18:09:45 -0700 Subject: [PATCH 2/4] Make sure native extensions are loaded correctly in ext_conf builder --- lib/rubygems/ext/ext_conf_builder.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb index cabafaed05a7..f8fed2a8bfca 100644 --- a/lib/rubygems/ext/ext_conf_builder.rb +++ b/lib/rubygems/ext/ext_conf_builder.rb @@ -21,9 +21,23 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_di destdir = ENV["DESTDIR"] + # This is only needed when running rubygems test without a proper installation. + # Prepending it in a normal installation can cause problem with order of $LOAD_PATH. + # Therefore only add rubygems_load_path if it is not present in the default $LOAD_PATH. + rubygems_load_path = File.expand_path("../..", __dir__) + load_path = + case rubygems_load_path + when RbConfig::CONFIG["sitelibdir"], RbConfig::CONFIG["vendorlibdir"], RbConfig::CONFIG["rubylibdir"] + [] + else + ["-I#{rubygems_load_path}"] + end + begin require "shellwords" - cmd = Gem.ruby.shellsplit << "-I" << File.expand_path("../..", __dir__) << File.basename(extension) + cmd = Gem.ruby.shellsplit + cmd.push(*load_path) + cmd << File.basename(extension) cmd.push(*args) run(cmd, results, class_name, extension_dir) do |s, r| From e82ed20f866930321ab11606e3489ec61d5d9ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Fri, 17 Mar 2023 09:16:03 -0700 Subject: [PATCH 3/4] Move duplicated logic to parent class --- lib/rubygems/ext/builder.rb | 13 +++++++++++++ lib/rubygems/ext/ext_conf_builder.rb | 14 +------------- lib/rubygems/ext/rake_builder.rb | 14 +------------- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/lib/rubygems/ext/builder.rb b/lib/rubygems/ext/builder.rb index b52ba0d5dd61..adb118133d4a 100644 --- a/lib/rubygems/ext/builder.rb +++ b/lib/rubygems/ext/builder.rb @@ -54,6 +54,19 @@ def self.make(dest_path, results, make_dir = Dir.pwd, sitedir = nil, targets = [ end end + def self.rubygems_load_path + # 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"] + [] + else + ["-I#{load_path}"] + end + end + def self.run(command, results, command_name = nil, dir = Dir.pwd, env = {}) verbose = Gem.configuration.really_verbose diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb index f8fed2a8bfca..22e740fde8bb 100644 --- a/lib/rubygems/ext/ext_conf_builder.rb +++ b/lib/rubygems/ext/ext_conf_builder.rb @@ -21,22 +21,10 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_di destdir = ENV["DESTDIR"] - # This is only needed when running rubygems test without a proper installation. - # Prepending it in a normal installation can cause problem with order of $LOAD_PATH. - # Therefore only add rubygems_load_path if it is not present in the default $LOAD_PATH. - rubygems_load_path = File.expand_path("../..", __dir__) - load_path = - case rubygems_load_path - when RbConfig::CONFIG["sitelibdir"], RbConfig::CONFIG["vendorlibdir"], RbConfig::CONFIG["rubylibdir"] - [] - else - ["-I#{rubygems_load_path}"] - end - begin require "shellwords" cmd = Gem.ruby.shellsplit - cmd.push(*load_path) + cmd.push(*rubygems_load_path) cmd << File.basename(extension) cmd.push(*args) diff --git a/lib/rubygems/ext/rake_builder.rb b/lib/rubygems/ext/rake_builder.rb index 9a3f8ca65e8f..ce5c10e505e4 100644 --- a/lib/rubygems/ext/rake_builder.rb +++ b/lib/rubygems/ext/rake_builder.rb @@ -18,20 +18,8 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_di require "shellwords" rake = rake.shellsplit else - # This is only needed when running rubygems test without a proper installation. - # Prepending it in a normal installation can cause problem with order of $LOAD_PATH. - # Therefore only add rubygems_load_path if it is not present in the default $LOAD_PATH. - rubygems_load_path = File.expand_path("../..", __dir__) - load_path = - case rubygems_load_path - when RbConfig::CONFIG["sitelibdir"], RbConfig::CONFIG["vendorlibdir"], RbConfig::CONFIG["rubylibdir"] - [] - else - ["-I#{rubygems_load_path}"] - end - begin - rake = [Gem.ruby, *load_path, "-rrubygems", Gem.bin_path("rake", "rake")] + rake = [Gem.ruby, *rubygems_load_path, "-rrubygems", Gem.bin_path("rake", "rake")] rescue Gem::Exception rake = [Gem.default_exec_format % "rake"] end From 9db5e947689d33b6b8ea5b9f6fba736f09e8c62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Fri, 17 Mar 2023 09:48:52 -0700 Subject: [PATCH 4/4] Refactor and fix usage of Gem.ruby --- lib/rubygems/ext/builder.rb | 10 +++++++--- lib/rubygems/ext/ext_conf_builder.rb | 5 +---- lib/rubygems/ext/rake_builder.rb | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/rubygems/ext/builder.rb b/lib/rubygems/ext/builder.rb index adb118133d4a..3ac6d34d1389 100644 --- a/lib/rubygems/ext/builder.rb +++ b/lib/rubygems/ext/builder.rb @@ -54,16 +54,20 @@ def self.make(dest_path, results, make_dir = Dir.pwd, sitedir = nil, targets = [ end end - def self.rubygems_load_path + 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 - ["-I#{load_path}"] + cmd << "-I#{load_path}" end end diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb index 22e740fde8bb..7efd4a06b701 100644 --- a/lib/rubygems/ext/ext_conf_builder.rb +++ b/lib/rubygems/ext/ext_conf_builder.rb @@ -22,10 +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 - cmd.push(*rubygems_load_path) - cmd << File.basename(extension) + cmd = ruby << File.basename(extension) cmd.push(*args) run(cmd, results, class_name, extension_dir) do |s, r| diff --git a/lib/rubygems/ext/rake_builder.rb b/lib/rubygems/ext/rake_builder.rb index ce5c10e505e4..8fa14f21282c 100644 --- a/lib/rubygems/ext/rake_builder.rb +++ b/lib/rubygems/ext/rake_builder.rb @@ -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, *rubygems_load_path, "-rrubygems", Gem.bin_path("rake", "rake")] + rake = ruby << "-rrubygems" << Gem.bin_path("rake", "rake") rescue Gem::Exception rake = [Gem.default_exec_format % "rake"] end