From 69c87619bd7a69936c44cc0d323b11148400e894 Mon Sep 17 00:00:00 2001 From: David Rodriguez Date: Fri, 10 May 2024 16:14:26 +0200 Subject: [PATCH] [rubygems/rubygems] Avoid standard requires while loading shared helpers We should make sure Bundler does not trigger RubyGems require logic for gem activation until it had the chance to register its own monkeypatches to RubyGems. https://github.com/rubygems/rubygems/commit/fbd2ff86b9 --- lib/bundler/constants.rb | 2 ++ lib/bundler/rubygems_integration.rb | 6 ++---- lib/bundler/shared_helpers.rb | 10 ++++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/bundler/constants.rb b/lib/bundler/constants.rb index de9698b577..bcbd228b18 100644 --- a/lib/bundler/constants.rb +++ b/lib/bundler/constants.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "rbconfig" + module Bundler WINDOWS = RbConfig::CONFIG["host_os"] =~ /(msdos|mswin|djgpp|mingw)/ FREEBSD = RbConfig::CONFIG["host_os"].to_s.include?("bsd") diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 494030eab2..6980b32236 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -4,9 +4,7 @@ require "rubygems" unless defined?(Gem) module Bundler class RubygemsIntegration - require "monitor" - - EXT_LOCK = Monitor.new + autoload :Monitor, "monitor" def initialize @replaced_methods = {} @@ -173,7 +171,7 @@ module Bundler end def ext_lock - EXT_LOCK + @ext_lock ||= Monitor.new end def spec_from_gem(path) diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 78760e6fa4..28f0cdff19 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -1,15 +1,17 @@ # frozen_string_literal: true -require "pathname" -require "rbconfig" - require_relative "version" -require_relative "constants" require_relative "rubygems_integration" require_relative "current_ruby" module Bundler + autoload :WINDOWS, File.expand_path("constants", __dir__) + autoload :FREEBSD, File.expand_path("constants", __dir__) + autoload :NULL, File.expand_path("constants", __dir__) + module SharedHelpers + autoload :Pathname, "pathname" + def root gemfile = find_gemfile raise GemfileNotFound, "Could not locate Gemfile" unless gemfile