aboutsummaryrefslogtreecommitdiffstats
path: root/libexec/bundle
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2023-05-26 12:16:43 +0200
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-06-06 10:52:54 +0900
commit8819dc43238c1ce79e7b4528d1dee66c4616ee87 (patch)
treec46f7d46c23d4982ff8ba03e663b4427c14a3e66 /libexec/bundle
parent1f9e66836b71dd77aaef660628eb2455b4f28a3b (diff)
downloadruby-8819dc43238c1ce79e7b4528d1dee66c4616ee87.tar.gz
[rubygems/rubygems] Always rely on $LOAD_PATH when jumping from exe to lib
Normally, we use `require_relative` when requiring internal code. However, Bundler may also load external code (for example, bundler plugins), and when that external code loads Bundler itself, using `require_relative` without setting up the `$LOAD_PATH` may lead into double load errors. For example, when testing a Gemfile using plugins using our source code tree, I get the following: ``` ➜ plugins-dup ~/Code/rubygems/rubygems/bundler/exe/bundle Fetching gem metadata from https://rubygems.org/. Resolving dependencies... Using bundler 2.5.0.dev Installing extended_bundler-errors 0.3.3 /Users/deivid/.asdf/installs/ruby/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/version.rb:4: warning: already initialized constant Bundler::VERSION /Users/deivid/Code/rubygems/rubygems/bundler/lib/bundler/version.rb:4: warning: previous definition of VERSION was here /Users/deivid/.asdf/installs/ruby/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:5: warning: already initialized constant Bundler::Worker::POISON /Users/deivid/Code/rubygems/rubygems/bundler/lib/bundler/worker.rb:5: warning: previous definition of POISON was here /Users/deivid/.asdf/installs/ruby/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/vendor/fileutils/lib/fileutils.rb:183: warning: already initialized constant Bundler::FileUtils::VERSION /Users/deivid/Code/rubygems/rubygems/bundler/lib/bundler/vendor/fileutils/lib/fileutils.rb:183: warning: previous definition of VERSION was here /Users/deivid/.asdf/installs/ruby/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/vendor/fileutils/lib/fileutils.rb:2165: warning: already initialized constant Bundler::FileUtils::Entry_::S_IF_DOOR /Users/deivid/Code/rubygems/rubygems/bundler/lib/bundler/vendor/fileutils/lib/fileutils.rb:2165: warning: previous definition of S_IF_DOOR was here /Users/deivid/.asdf/installs/ruby/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/vendor/fileutils/lib/fileutils.rb:2461: warning: already initialized constant Bundler::FileUtils::Entry_::DIRECTORY_TERM /Users/deivid/Code/rubygems/rubygems/bundler/lib/bundler/vendor/fileutils/lib/fileutils.rb:2461: warning: previous definition of DIRECTORY_TERM was here /Users/deivid/.asdf/installs/ruby/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/vendor/fileutils/lib/fileutils.rb:2569: warning: already initialized constant Bundler::FileUtils::OPT_TABLE /Users/deivid/Code/rubygems/rubygems/bundler/lib/bundler/vendor/fileutils/lib/fileutils.rb:2569: warning: previous definition of OPT_TABLE was here /Users/deivid/.asdf/installs/ruby/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/vendor/fileutils/lib/fileutils.rb:2627: warning: already initialized constant Bundler::FileUtils::LOW_METHODS /Users/deivid/Code/rubygems/rubygems/bundler/lib/bundler/vendor/fileutils/lib/fileutils.rb:2627: warning: previous definition of LOW_METHODS was here /Users/deivid/.asdf/installs/ruby/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/vendor/fileutils/lib/fileutils.rb:2634: warning: already initialized constant Bundler::FileUtils::METHODS /Users/deivid/Code/rubygems/rubygems/bundler/lib/bundler/vendor/fileutils/lib/fileutils.rb:2634: warning: previous definition of METHODS was here Failed to install plugin `extended_bundler-errors`, due to Bundler::Plugin::MalformattedPlugin (ArgumentError: Trying to register Bundler::GemfileError for status code 4 but Bundler::GemfileError is already registered) ``` Changing this to always use `$LOAD_PATH` fixes the problem. https://github.com/rubygems/rubygems/commit/121a861c39
Diffstat (limited to 'libexec/bundle')
-rwxr-xr-xlibexec/bundle18
1 files changed, 5 insertions, 13 deletions
diff --git a/libexec/bundle b/libexec/bundle
index eaf2246bc0..90c62627f8 100755
--- a/libexec/bundle
+++ b/libexec/bundle
@@ -10,11 +10,11 @@ end
base_path = File.expand_path("../lib", __dir__)
if File.exist?(base_path)
- require_relative "../lib/bundler"
-else
- require "bundler"
+ $LOAD_PATH.unshift(base_path)
end
+require "bundler"
+
if Gem.rubygems_version < Gem::Version.new("3.2.3") && Gem.ruby_version < Gem::Version.new("2.7.a") && !ENV["BUNDLER_NO_OLD_RUBYGEMS_WARNING"]
Bundler.ui.warn \
"Your RubyGems version (#{Gem::VERSION}) has a bug that prevents " \
@@ -24,18 +24,10 @@ if Gem.rubygems_version < Gem::Version.new("3.2.3") && Gem.ruby_version < Gem::V
"and silence this warning by running `gem update --system 3.2.3`"
end
-if File.exist?(base_path)
- require_relative "../lib/bundler/friendly_errors"
-else
- require "bundler/friendly_errors"
-end
+require "bundler/friendly_errors"
Bundler.with_friendly_errors do
- if File.exist?(base_path)
- require_relative "../lib/bundler/cli"
- else
- require "bundler/cli"
- end
+ require "bundler/cli"
# Allow any command to use --help flag to show help for that command
help_flags = %w[--help -h]