Skip to content

Commit 963cb65

Browse files
committed
Load "bundler/setup" in lib/rubygems.rb
Ruby interpreter loads some special gems at startup: did_you_mean, error_highlight, and syntax_suggest. These gems are loaded before `bundler/setup` is loaded by `RUBYOPT=-rbundler/setup`. So, the versions of the gems are not controllable by Gemfile. This change will `require "bundler/setup"` in rubygems.rb (i.e., before the special gems are loaded). Now `bundle exec` sets an environment variable `BUNDLER_SETUP`, and rubygems requires the variable if defined. See also: https://bugs.ruby-lang.org/issues/19089
1 parent 5eb1937 commit 963cb65

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

bundler/lib/bundler/environment_preserver.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class EnvironmentPreserver
77
BUNDLE_BIN_PATH
88
BUNDLE_GEMFILE
99
BUNDLER_VERSION
10+
BUNDLER_SETUP
1011
GEM_HOME
1112
GEM_PATH
1213
MANPATH

bundler/lib/bundler/shared_helpers.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ def set_bundle_variables
284284
Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", exe_file
285285
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", find_gemfile.to_s
286286
Bundler::SharedHelpers.set_env "BUNDLER_VERSION", Bundler::VERSION
287+
Bundler::SharedHelpers.set_env "BUNDLER_SETUP", File.expand_path("setup", __dir__)
287288
end
288289

289290
def set_path

bundler/spec/bundler/shared_helpers_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@
246246
end
247247
end
248248

249+
shared_examples_for "ENV['BUNDLER_SETUP'] gets set correctly" do
250+
it "ensures bundler/setup is set in ENV['BUNDLE_SETUP']" do
251+
subject.set_bundle_environment
252+
expect(ENV["BUNDLER_SETUP"]).to eq("#{source_lib_dir}/bundler/setup")
253+
end
254+
end
255+
249256
shared_examples_for "ENV['RUBYLIB'] gets set correctly" do
250257
let(:ruby_lib_path) { "stubbed_ruby_lib_dir" }
251258

lib/rubygems.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,3 +1348,5 @@ def default_gem_load_paths
13481348
require_relative "rubygems/core_ext/kernel_gem"
13491349
require_relative "rubygems/core_ext/kernel_require"
13501350
require_relative "rubygems/core_ext/kernel_warn"
1351+
1352+
require ENV["BUNDLER_SETUP"] if ENV["BUNDLER_SETUP"]

0 commit comments

Comments
 (0)