summaryrefslogtreecommitdiff
path: root/lib/bundler/shared_helpers.rb
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-04-23 08:22:06 +0000
committerBundlerbot <bot@bundler.io>2019-04-23 08:22:06 +0000
commit9d733d92abe4e492f07027fc5928a5a1172d6b31 (patch)
tree6926e53453b3306d4356e527bdcb059c348f8571 /lib/bundler/shared_helpers.rb
parenta4a3cea1d458eeb38e04442e4616b44e7f3f407e (diff)
parent0dff2a9a26ac5afcb76c65a2939f9f72ca613af7 (diff)
downloadbundler-9d733d92abe4e492f07027fc5928a5a1172d6b31.tar.gz
Merge #7100
7100: Prefer `require_relative` for internal requires r=deivid-rodriguez a=deivid-rodriguez ### What was the end-user problem that led to this PR? The problem was that `bundler` seems to, in some very rare cases, leak to the copy of itself installed as a default gem. I have been able to reproduce this only for stuff that we have already fixed. For example: https://github.com/bundler/bundler/pull/6502. However, I have the gut feeling that this can still happen under some conditions, because sometimes we still get reports from people using bundler 2, and getting the error "You must user Bundler 2 or greater with this Gemfile". ### What was your diagnosis of the problem? My diagnosis was that somehow, due to the complicated LOAD_PATH manipulation bundler does, we may endup requiring bundler files in another copy of bundler. ### What is your fix for the problem, implemented in this PR? My fix is not really a fix, although it _might_ prevent the potential issue from happening. As @colby-swandale would say, we should fix the real culprit instead. However, I think using `require_relative` is a better practice anyways, because it makes it clear that you are requiring "internal" files and not files from some dependencies. And it should also be faster because it does not search the LOAD_PATH. And it skips the rubygems monkeypatches to `require`, which seems also good. ### Why did you choose this fix out of the possible options? I chose this fix because I think it's a good practice. Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
Diffstat (limited to 'lib/bundler/shared_helpers.rb')
-rw-r--r--lib/bundler/shared_helpers.rb34
1 files changed, 12 insertions, 22 deletions
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index 1b703c5cbc..73c6dc3097 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -1,15 +1,15 @@
# frozen_string_literal: true
-require "bundler/compatibility_guard"
+require_relative "compatibility_guard"
require "pathname"
require "rbconfig"
require "rubygems"
-require "bundler/version"
-require "bundler/constants"
-require "bundler/rubygems_integration"
-require "bundler/current_ruby"
+require_relative "version"
+require_relative "constants"
+require_relative "rubygems_integration"
+require_relative "current_ruby"
module Bundler
module SharedHelpers
@@ -132,7 +132,7 @@ module Bundler
def major_deprecation(major_version, message)
bundler_major_version = Bundler.bundler_major_version
if bundler_major_version > major_version
- require "bundler/errors"
+ require_relative "errors"
raise DeprecatedError, "[REMOVED] #{message}"
end
@@ -289,20 +289,10 @@ module Bundler
public :set_env
def set_bundle_variables
- begin
- exe_file = Bundler.rubygems.bin_path("bundler", "bundle", VERSION)
- unless File.exist?(exe_file)
- exe_file = File.expand_path("../../../exe/bundle", __FILE__)
- end
- Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", exe_file
- rescue Gem::GemNotFoundException
- exe_file = File.expand_path("../../../exe/bundle", __FILE__)
- # for Ruby core repository
- exe_file = File.expand_path("../../../../bin/bundle", __FILE__) unless File.exist?(exe_file)
- Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", exe_file
- end
-
- # Set BUNDLE_GEMFILE
+ exe_file = File.expand_path("../../../exe/bundle", __FILE__)
+ # for Ruby core repository
+ exe_file = File.expand_path("../../../../bin/bundle", __FILE__) unless File.exist?(exe_file)
+ Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", exe_file
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", find_gemfile(:order_matters).to_s
Bundler::SharedHelpers.set_env "BUNDLER_VERSION", Bundler::VERSION
end
@@ -351,9 +341,9 @@ module Bundler
end
def prints_major_deprecations?
- require "bundler"
+ require_relative "../bundler"
return false if Bundler.settings[:silence_deprecations]
- require "bundler/deprecate"
+ require_relative "deprecate"
return false if Bundler::Deprecate.skip
true
end