summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2024-06-28 16:12:29 +0200
committerGitHub <noreply@github.com>2024-06-28 10:12:29 -0400
commit98c923ff4bbeeb4a8f9f63ea2695a38471da42c2 (patch)
tree46dcbbfb81eec22b88efa8d46a0de99d81247813 /lib
parent1652c194c849468659baa566a2422a308d6eac0c (diff)
Synchronize Bundler & RubyGems (#11071)
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler/self_manager.rb19
-rw-r--r--lib/bundler/vendored_net_http.rb23
2 files changed, 34 insertions, 8 deletions
diff --git a/lib/bundler/self_manager.rb b/lib/bundler/self_manager.rb
index 3cef0197c0..ea7c014f3c 100644
--- a/lib/bundler/self_manager.rb
+++ b/lib/bundler/self_manager.rb
@@ -70,8 +70,23 @@ module Bundler
configured_gem_home = ENV["GEM_HOME"]
configured_gem_path = ENV["GEM_PATH"]
- cmd = [$PROGRAM_NAME, *ARGV]
- cmd.unshift(Gem.ruby) unless File.executable?($PROGRAM_NAME)
+ # Bundler specs need some stuff to be required before Bundler starts
+ # running, for example, for faking the compact index API. However, these
+ # flags are lost when we reexec to a different version of Bundler. In the
+ # future, we may be able to properly reconstruct the original Ruby
+ # invocation (see https://bugs.ruby-lang.org/issues/6648), but for now
+ # there's no way to do it, so we need to be explicit about how to re-exec.
+ # This may be a feature end users request at some point, but maybe by that
+ # time, we have builtin tools to do. So for now, we use an undocumented
+ # ENV variable only for our specs.
+ bundler_spec_original_cmd = ENV["BUNDLER_SPEC_ORIGINAL_CMD"]
+ if bundler_spec_original_cmd
+ require "shellwords"
+ cmd = [*Shellwords.shellsplit(bundler_spec_original_cmd), *ARGV]
+ else
+ cmd = [$PROGRAM_NAME, *ARGV]
+ cmd.unshift(Gem.ruby) unless File.executable?($PROGRAM_NAME)
+ end
Bundler.with_original_env do
Kernel.exec(
diff --git a/lib/bundler/vendored_net_http.rb b/lib/bundler/vendored_net_http.rb
index 0dcabaa7d7..8ff2ccd1fe 100644
--- a/lib/bundler/vendored_net_http.rb
+++ b/lib/bundler/vendored_net_http.rb
@@ -1,12 +1,23 @@
# frozen_string_literal: true
-begin
- require "rubygems/vendored_net_http"
-rescue LoadError
+# This defined? guard can be removed once RubyGems 3.4 support is dropped.
+#
+# Bundler specs load this code from `spec/support/vendored_net_http.rb` to avoid
+# activating the Bundler gem too early. Without this guard, we get redefinition
+# warnings once Bundler is actually activated and
+# `lib/bundler/vendored_net_http.rb` is required. This is not an issue in
+# RubyGems versions including `rubygems/vendored_net_http` since `require` takes
+# care of avoiding the double load.
+#
+unless defined?(Gem::Net)
begin
- require "rubygems/net/http"
+ require "rubygems/vendored_net_http"
rescue LoadError
- require "net/http"
- Gem::Net = Net
+ begin
+ require "rubygems/net/http"
+ rescue LoadError
+ require "net/http"
+ Gem::Net = Net
+ end
end
end