summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-11-11 17:56:17 +0000
committerDavid Rodríguez <deivid.rodriguez@riseup.net>2019-11-11 23:17:21 +0100
commit4195b12cde389f8f21dec69e27742bdfac7c644b (patch)
tree9d576051efda7b09d1ce98de9bc519f67901be71
parentdb79526704d76fc69027f94332a811387cf483e2 (diff)
downloadbundler-4195b12cde389f8f21dec69e27742bdfac7c644b.tar.gz
Merge #7435
7435: Fix RGV env variable specified as a path r=deivid-rodriguez a=deivid-rodriguez ### What was the end-user problem that led to this PR? The problem was that using `RGV` (the environment variable we use to select the proper rubygems version to test bundler against) with a path was not quite working. Setting `RGV` to a path (`RGV=..`) is used in the rubygems repo to test the vendored copy of bundler (that lives at `bundler/` inside that repo) against the checked out copy of the repository. ### What was your diagnosis of the problem? My diagnosis was that the previous approach to switch the `rubygems` version, namely, reexec'ing with `--disable-gems` and explicitly requiring our "version switching code" was not quite working because nested subprocesses would end up "leaking" to the system copy of `rubygems` again. ### What is your fix for the problem, implemented in this PR? My fix is to use `RUBYOPT` to configure the path to the rubygems copy that should be used, since I found that even the `require "rubygems"` present's in [ruby's `gem_prelude.rb`](https://github.com/ruby/ruby/blob/c5eb24349a4535948514fe765c3ddb0628d81004/gem_prelude.rb#L1) respects the `-I` option in the `RUBYOPT` env variable. ### Why did you choose this fix out of the possible options? I chose this fix because it's simpler and works better. Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net> (cherry picked from commit 09e21f1e59c1e182361b56bd0796b47ae0fd8d86)
-rw-r--r--spec/install/gemfile/git_spec.rb3
-rw-r--r--spec/install/gemfile/path_spec.rb3
-rw-r--r--spec/rubygems/rubygems.rb9
-rw-r--r--spec/spec_helper.rb2
-rw-r--r--spec/support/helpers.rb3
-rw-r--r--spec/support/path.rb2
-rw-r--r--spec/support/rubygems.rb7
-rw-r--r--spec/support/rubygems_ext.rb2
-rw-r--r--spec/support/rubygems_version_manager.rb2
9 files changed, 14 insertions, 19 deletions
diff --git a/spec/install/gemfile/git_spec.rb b/spec/install/gemfile/git_spec.rb
index 08789820d8..00f8e96625 100644
--- a/spec/install/gemfile/git_spec.rb
+++ b/spec/install/gemfile/git_spec.rb
@@ -1056,7 +1056,6 @@ RSpec.describe "bundle install with git sources" do
File.open(lib_path("install_hooks.rb"), "w") do |h|
h.write <<-H
- require '#{spec_dir}/support/rubygems'
Gem.pre_install_hooks << lambda do |inst|
STDERR.puts "Ran pre-install hook: \#{inst.spec.full_name}"
end
@@ -1076,7 +1075,6 @@ RSpec.describe "bundle install with git sources" do
File.open(lib_path("install_hooks.rb"), "w") do |h|
h.write <<-H
- require '#{spec_dir}/support/rubygems'
Gem.post_install_hooks << lambda do |inst|
STDERR.puts "Ran post-install hook: \#{inst.spec.full_name}"
end
@@ -1096,7 +1094,6 @@ RSpec.describe "bundle install with git sources" do
File.open(lib_path("install_hooks.rb"), "w") do |h|
h.write <<-H
- require '#{spec_dir}/support/rubygems'
Gem.pre_install_hooks << lambda do |inst|
false
end
diff --git a/spec/install/gemfile/path_spec.rb b/spec/install/gemfile/path_spec.rb
index 5261e18bbe..786b767354 100644
--- a/spec/install/gemfile/path_spec.rb
+++ b/spec/install/gemfile/path_spec.rb
@@ -672,7 +672,6 @@ RSpec.describe "bundle install with explicit source paths" do
File.open(lib_path("install_hooks.rb"), "w") do |h|
h.write <<-H
- require '#{spec_dir}/support/rubygems'
Gem.pre_install_hooks << lambda do |inst|
STDERR.puts "Ran pre-install hook: \#{inst.spec.full_name}"
end
@@ -692,7 +691,6 @@ RSpec.describe "bundle install with explicit source paths" do
File.open(lib_path("install_hooks.rb"), "w") do |h|
h.write <<-H
- require '#{spec_dir}/support/rubygems'
Gem.post_install_hooks << lambda do |inst|
STDERR.puts "Ran post-install hook: \#{inst.spec.full_name}"
end
@@ -712,7 +710,6 @@ RSpec.describe "bundle install with explicit source paths" do
File.open(lib_path("install_hooks.rb"), "w") do |h|
h.write <<-H
- require '#{spec_dir}/support/rubygems'
Gem.pre_install_hooks << lambda do |inst|
false
end
diff --git a/spec/rubygems/rubygems.rb b/spec/rubygems/rubygems.rb
new file mode 100644
index 0000000000..6fa63013bf
--- /dev/null
+++ b/spec/rubygems/rubygems.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+require_relative "../support/rubygems_version_manager"
+
+RubygemsVersionManager.new(ENV["RGV"]).switch
+
+$:.delete("#{Spec::Path.spec_dir}/rubygems")
+
+require "rubygems"
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index ba21d22fbd..9702ab71f5 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -82,7 +82,7 @@ RSpec.configure do |config|
config.before :suite do
require_relative "support/rubygems_ext"
Spec::Rubygems.setup
- ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -r#{Spec::Path.spec_dir}/support/hax.rb"
+ ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -I#{Spec::Path.spec_dir}/rubygems -r#{Spec::Path.spec_dir}/support/hax.rb"
ENV["BUNDLE_SPEC_RUN"] = "true"
ENV["BUNDLE_USER_CONFIG"] = ENV["BUNDLE_USER_CACHE"] = ENV["BUNDLE_USER_PLUGIN"] = nil
ENV["GEMRC"] = nil
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 8bf76bba89..911f734d8b 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -110,7 +110,6 @@ module Spec
env["PATH"].gsub!("#{Path.root}/exe", "") if env["PATH"] && system_bundler
requires = options.delete(:requires) || []
- requires << "support/rubygems"
requires << "support/hax"
artifice = options.delete(:artifice) do
@@ -144,7 +143,7 @@ module Spec
end
end.join
- cmd = "#{sudo} #{Gem.ruby} --disable-gems #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}"
+ cmd = "#{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}"
sys_exec(cmd, env) {|i, o, thr| yield i, o, thr if block_given? }
end
bang :bundle
diff --git a/spec/support/path.rb b/spec/support/path.rb
index b957e24abe..cc5aebb01b 100644
--- a/spec/support/path.rb
+++ b/spec/support/path.rb
@@ -22,7 +22,7 @@ module Spec
end
def gem_bin
- @gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "#{Gem.ruby} --disable-gems -r#{spec_dir}/support/rubygems -S gem --backtrace"
+ @gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "#{Gem.ruby} -I#{spec_dir}/rubygems -S gem --backtrace"
end
def spec_dir
diff --git a/spec/support/rubygems.rb b/spec/support/rubygems.rb
deleted file mode 100644
index e60f9a928e..0000000000
--- a/spec/support/rubygems.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-# frozen_string_literal: true
-
-require_relative "rubygems_version_manager"
-
-RubygemsVersionManager.new(ENV["RGV"]).switch
-
-require "rubygems"
diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb
index 8c5dff880b..d237897b67 100644
--- a/spec/support/rubygems_ext.rb
+++ b/spec/support/rubygems_ext.rb
@@ -39,7 +39,7 @@ module Spec
end
def gem_load(gem_name, bin_container)
- require_relative "rubygems"
+ require_relative "../rubygems/rubygems"
gem_load_and_activate(gem_name, bin_container)
end
diff --git a/spec/support/rubygems_version_manager.rb b/spec/support/rubygems_version_manager.rb
index 31f7cc4b08..356d391c08 100644
--- a/spec/support/rubygems_version_manager.rb
+++ b/spec/support/rubygems_version_manager.rb
@@ -56,7 +56,7 @@ private
end
def rubygems_unrequire_needed?
- defined?(Gem) && Gem::VERSION != target_gem_version
+ defined?(Gem::VERSION) && Gem::VERSION != target_gem_version
end
def local_copy_switch_needed?