diff --git a/Rakefile b/Rakefile index 3399f4dd25b..6655af7d8d4 100644 --- a/Rakefile +++ b/Rakefile @@ -312,7 +312,9 @@ else # This will be automated once https://github.com/segiddins/automatiek/pull/3 # is included in `automatiek` and we start using the new API for vendoring # subdependencies. - + # Besides that, we currently cherry-pick changes to use `require_relative` + # internally instead of regular `require`. They are pending review at + # https://github.com/drbrain/net-http-persistent/pull/106 desc "Vendor a specific version of net-http-persistent" Automatiek::RakeTask.new("net-http-persistent") do |lib| lib.download = { :github => "https://github.com/drbrain/net-http-persistent" } diff --git a/exe/bundle b/exe/bundle index aaf773745d3..b3b1b691d81 100755 --- a/exe/bundle +++ b/exe/bundle @@ -7,7 +7,14 @@ Signal.trap("INT") do exit 1 end -require "bundler" +base_path = File.expand_path("../lib", __dir__) + +if File.exist?(base_path) + require_relative "../lib/bundler" +else + require "bundler" +end + # Check if an older version of bundler is installed $LOAD_PATH.each do |path| next unless path =~ %r{/bundler-0\.(\d+)} && $1.to_i < 9 @@ -18,9 +25,18 @@ $LOAD_PATH.each do |path| abort(err) end -require "bundler/friendly_errors" +if File.exist?(base_path) + require_relative "../lib/bundler/friendly_errors" +else + require "bundler/friendly_errors" +end + Bundler.with_friendly_errors do - require "bundler/cli" + if File.exist?(base_path) + require_relative "../lib/bundler/cli" + else + require "bundler/cli" + end # Allow any command to use --help flag to show help for that command help_flags = %w[--help -h] diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index ffb3ee98830..f4dd435df46 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -4,11 +4,11 @@ module Bundler module Plugin - autoload :DSL, "bundler/plugin/dsl" - autoload :Events, "bundler/plugin/events" - autoload :Index, "bundler/plugin/index" - autoload :Installer, "bundler/plugin/installer" - autoload :SourceList, "bundler/plugin/source_list" + autoload :DSL, File.expand_path("plugin/dsl", __dir__) + autoload :Events, File.expand_path("plugin/events", __dir__) + autoload :Index, File.expand_path("plugin/index", __dir__) + autoload :Installer, File.expand_path("plugin/installer", __dir__) + autoload :SourceList, File.expand_path("plugin/source_list", __dir__) class MalformattedPlugin < PluginError; end class UndefinedCommandError < PluginError; end diff --git a/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb b/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb index f3382465a78..327cb0f8c28 100644 --- a/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +++ b/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb @@ -1,7 +1,7 @@ require 'net/http' require 'uri' require 'cgi' # for escaping -require 'bundler/vendor/connection_pool/lib/connection_pool' +require_relative '../../../../connection_pool/lib/connection_pool' begin require 'net/http/pipeline' @@ -1197,6 +1197,6 @@ def verify_callback= callback end -require 'bundler/vendor/net-http-persistent/lib/net/http/persistent/connection' -require 'bundler/vendor/net-http-persistent/lib/net/http/persistent/pool' +require_relative 'persistent/connection' +require_relative 'persistent/pool' diff --git a/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb b/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb index fb1816de835..9dfa6ffdb11 100644 --- a/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb +++ b/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb @@ -49,5 +49,5 @@ def shutdown end end -require 'bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi' +require_relative 'timed_stack_multi' diff --git a/lib/bundler/vendored_fileutils.rb b/lib/bundler/vendored_fileutils.rb index 4b71759224e..1be1138ce25 100644 --- a/lib/bundler/vendored_fileutils.rb +++ b/lib/bundler/vendored_fileutils.rb @@ -1,9 +1,4 @@ # frozen_string_literal: true module Bundler; end -if RUBY_VERSION >= "2.4" - require_relative "vendor/fileutils/lib/fileutils" -else - # the version we vendor is 2.4+ - require "fileutils" -end +require_relative "vendor/fileutils/lib/fileutils" diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index 8a4ce729edd..3cae67c52a9 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -176,7 +176,7 @@ let(:bundler_ui) { Bundler.ui } it "should raise a friendly error" do allow(File).to receive(:exist?).and_return(true) - allow(bundler_fileutils).to receive(:remove_entry_secure).and_raise(ArgumentError) + allow(::Bundler::FileUtils).to receive(:remove_entry_secure).and_raise(ArgumentError) allow(File).to receive(:world_writable?).and_return(true) message = < true + bundle "config set path vendor/bundler" + bundle! :install end it "correctly shells out", :ruby_repo do @@ -854,7 +852,7 @@ def bin_path(a,b,c) puts `bundle exec echo foo` RB file.chmod(0o777) - bundle! "exec #{file}", :system_bundler => true + bundle! "exec #{file}" expect(out).to eq("foo") end end diff --git a/spec/commands/pristine_spec.rb b/spec/commands/pristine_spec.rb index 252bef6d0d9..aa5c2213d1f 100644 --- a/spec/commands/pristine_spec.rb +++ b/spec/commands/pristine_spec.rb @@ -42,8 +42,7 @@ expect(changes_txt).to_not be_file end - it "does not delete the bundler gem", :rubygems => ">= 2.6.2" do - ENV["BUNDLER_SPEC_KEEP_DEFAULT_BUNDLER_GEM"] = "true" + it "does not delete the bundler gem" do system_gems :bundler bundle! "install" bundle! "pristine", :system_bundler => true diff --git a/spec/install/gemfile/groups_spec.rb b/spec/install/gemfile/groups_spec.rb index b38e8b43d5e..93798ef62e5 100644 --- a/spec/install/gemfile/groups_spec.rb +++ b/spec/install/gemfile/groups_spec.rb @@ -333,7 +333,7 @@ G ruby <<-R - require "bundler" + require "#{lib}/bundler" Bundler.setup :default Bundler.require :default puts RACK diff --git a/spec/plugins/source/example_spec.rb b/spec/plugins/source/example_spec.rb index 7bc8fb0f29b..1ef7c2134df 100644 --- a/spec/plugins/source/example_spec.rb +++ b/spec/plugins/source/example_spec.rb @@ -6,7 +6,6 @@ build_repo2 do build_plugin "bundler-source-mpath" do |s| s.write "plugins.rb", <<-RUBY - require "bundler/vendored_fileutils" require "bundler-source-mpath" class MPath < Bundler::Plugin::API diff --git a/spec/realworld/double_check_spec.rb b/spec/realworld/double_check_spec.rb index 07593ac4931..323e0d57358 100644 --- a/spec/realworld/double_check_spec.rb +++ b/spec/realworld/double_check_spec.rb @@ -25,9 +25,9 @@ RUBY cmd = <<-RUBY - require "bundler" + require "#{lib}/bundler" require #{File.expand_path("../../support/artifice/vcr.rb", __FILE__).dump} - require "bundler/inline" + require "#{lib}/bundler/inline" gemfile(true) do source "https://rubygems.org" gem "rails", path: "." diff --git a/spec/runtime/inline_spec.rb b/spec/runtime/inline_spec.rb index 6168c0c1973..c3d632d75de 100644 --- a/spec/runtime/inline_spec.rb +++ b/spec/runtime/inline_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "bundler/inline#gemfile" do def script(code, options = {}) - requires = ["bundler/inline"] + requires = ["#{lib}/bundler/inline"] requires.unshift File.expand_path("../../support/artifice/" + options.delete(:artifice) + ".rb", __FILE__) if options.key?(:artifice) requires = requires.map {|r| "require '#{r}'" }.join("\n") @out = ruby("#{requires}\n\n" + code, options) @@ -96,7 +96,7 @@ def script(code, options = {}) it "lets me use my own ui object" do script <<-RUBY, :artifice => "endpoint" - require 'bundler' + require '#{lib}/bundler' class MyBundlerUI < Bundler::UI::Silent def confirm(msg, newline = nil) puts "CONFIRMED!" @@ -140,7 +140,7 @@ def confirm(msg, newline = nil) it "does not mutate the option argument" do script <<-RUBY - require 'bundler' + require '#{lib}/bundler' options = { :ui => Bundler::UI::Shell.new } gemfile(false, options) do path "#{lib_path}" do diff --git a/spec/runtime/load_spec.rb b/spec/runtime/load_spec.rb index 80ad6927690..b7dc509f6f7 100644 --- a/spec/runtime/load_spec.rb +++ b/spec/runtime/load_spec.rb @@ -80,7 +80,7 @@ G ruby! <<-RUBY - require "bundler" + require "#{lib}/bundler" Bundler.setup :default Bundler.require :default puts RACK diff --git a/spec/runtime/require_spec.rb b/spec/runtime/require_spec.rb index 016fc14dfec..7874a86c32a 100644 --- a/spec/runtime/require_spec.rb +++ b/spec/runtime/require_spec.rb @@ -193,7 +193,7 @@ G cmd = <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.require RUBY ruby(cmd) diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 65cb006eddc..9fa6e1bf9bb 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -12,8 +12,7 @@ G ruby <<-RUBY - require 'rubygems' - require 'bundler' + require '#{lib}/bundler' Bundler.setup require 'rack' @@ -35,8 +34,7 @@ it "doesn't make all groups available" do ruby <<-RUBY - require 'rubygems' - require 'bundler' + require '#{lib}/bundler' Bundler.setup(:default) begin @@ -51,8 +49,7 @@ it "accepts string for group name" do ruby <<-RUBY - require 'rubygems' - require 'bundler' + require '#{lib}/bundler' Bundler.setup(:default, 'test') require 'rack' @@ -64,8 +61,7 @@ it "leaves all groups available if they were already" do ruby <<-RUBY - require 'rubygems' - require 'bundler' + require '#{lib}/bundler' Bundler.setup Bundler.setup(:default) @@ -78,8 +74,7 @@ it "leaves :default available if setup is called twice" do ruby <<-RUBY - require 'rubygems' - require 'bundler' + require '#{lib}/bundler' Bundler.setup(:default) Bundler.setup(:default, :test) @@ -96,7 +91,7 @@ it "handles multiple non-additive invocations" do ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup(:default, :test) Bundler.setup(:default) require 'rack' @@ -127,8 +122,7 @@ def clean_load_path(lp) ENV["RUBYLIB"] = "rubylib_dir" ruby <<-RUBY - require 'rubygems' - require 'bundler' + require '#{lib}/bundler' Bundler.setup puts $LOAD_PATH RUBY @@ -150,8 +144,7 @@ def clean_load_path(lp) G ruby! <<-RUBY - require 'rubygems' - require 'bundler' + require '#{lib}/bundler' Bundler.setup puts $LOAD_PATH RUBY @@ -179,8 +172,7 @@ def clean_load_path(lp) G ruby! <<-RUBY - require 'rubygems' - require 'bundler/setup' + require '#{lib}/bundler/setup' puts $LOAD_PATH RUBY @@ -201,8 +193,7 @@ def clean_load_path(lp) G ruby <<-R - require 'rubygems' - require 'bundler' + require '#{lib}/bundler' begin Bundler.setup @@ -222,8 +213,7 @@ def clean_load_path(lp) G ruby <<-R - require 'rubygems' - require 'bundler' + require '#{lib}/bundler' Bundler.setup R @@ -246,8 +236,7 @@ def clean_load_path(lp) G ruby <<-R - require 'rubygems' - require 'bundler' + require '#{lib}/bundler' Bundler.setup R @@ -300,8 +289,7 @@ def clean_load_path(lp) ENV["BUNDLE_GEMFILE"] = "Gemfile" ruby <<-R - require 'rubygems' - require 'bundler' + require '#{lib}/bundler' begin Bundler.setup @@ -456,8 +444,7 @@ def clean_load_path(lp) break_git! ruby <<-R - require 'rubygems' - require 'bundler' + require '#{lib}/bundler' begin Bundler.setup @@ -478,8 +465,7 @@ def clean_load_path(lp) break_git! ruby <<-R - require "rubygems" - require "bundler" + require "#{lib}/bundler" begin Bundler.setup @@ -788,7 +774,7 @@ def clean_load_path(lp) s.class.send(:define_method, :build_extensions) { nil } end - require 'bundler' + require '#{lib}/bundler' gem '#{gem_name}' puts $LOAD_PATH.count {|path| path =~ /#{gem_name}/} >= 2 @@ -937,8 +923,6 @@ def clean_load_path(lp) it "does not pull in system gems" do run <<-R - require 'rubygems' - begin; require 'rack' rescue LoadError @@ -1044,7 +1028,7 @@ def clean_load_path(lp) bundle "install" ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' def Bundler.require(path) raise "LOSE" end @@ -1099,7 +1083,7 @@ def lock_with(bundler_version = nil) context "is not present" do it "does not change the lock" do lockfile lock_with(nil) - ruby "require 'bundler/setup'" + ruby "require '#{lib}/bundler/setup'" lockfile_should_be lock_with(nil) end end @@ -1107,7 +1091,7 @@ def lock_with(bundler_version = nil) context "is newer" do it "does not change the lock or warn" do lockfile lock_with(Bundler::VERSION.succ) - ruby "require 'bundler/setup'" + ruby "require '#{lib}/bundler/setup'" expect(out).to eq("") expect(err).to eq("") lockfile_should_be lock_with(Bundler::VERSION.succ) @@ -1117,7 +1101,7 @@ def lock_with(bundler_version = nil) context "is older" do it "does not change the lock" do lockfile lock_with("1.10.1") - ruby "require 'bundler/setup'" + ruby "require '#{lib}/bundler/setup'" lockfile_should_be lock_with("1.10.1") end end @@ -1164,14 +1148,14 @@ def lock_with(ruby_version = nil) context "is not present" do it "does not change the lock" do - expect { ruby! "require 'bundler/setup'" }.not_to change { lockfile } + expect { ruby! "require '#{lib}/bundler/setup'" }.not_to change { lockfile } end end context "is newer" do let(:ruby_version) { "5.5.5" } it "does not change the lock or warn" do - expect { ruby! "require 'bundler/setup'" }.not_to change { lockfile } + expect { ruby! "require '#{lib}/bundler/setup'" }.not_to change { lockfile } expect(out).to eq("") expect(err).to eq("") end @@ -1180,7 +1164,7 @@ def lock_with(ruby_version = nil) context "is older" do let(:ruby_version) { "1.0.0" } it "does not change the lock" do - expect { ruby! "require 'bundler/setup'" }.not_to change { lockfile } + expect { ruby! "require '#{lib}/bundler/setup'" }.not_to change { lockfile } end end end @@ -1189,7 +1173,7 @@ def lock_with(ruby_version = nil) it "does not load Psych" do gemfile "" ruby <<-RUBY - require 'bundler/setup' + require '#{lib}/bundler/setup' puts defined?(Psych::VERSION) ? Psych::VERSION : "undefined" require 'psych' puts Psych::VERSION @@ -1202,7 +1186,7 @@ def lock_with(ruby_version = nil) it "does not load openssl" do install_gemfile! "" ruby! <<-RUBY - require "bundler/setup" + require "#{lib}/bundler/setup" puts defined?(OpenSSL) || "undefined" require "openssl" puts defined?(OpenSSL) || "undefined" @@ -1221,7 +1205,6 @@ def lock_with(ruby_version = nil) let(:activation_warning_hack) { strip_whitespace(<<-RUBY) } require #{spec_dir.join("support/hax").to_s.dump} - require "rubygems" if Gem::Specification.instance_methods.map(&:to_sym).include?(:activate) Gem::Specification.send(:alias_method, :bundler_spec_activate, :activate) @@ -1257,7 +1240,7 @@ def lock_with(ruby_version = nil) it "activates no gems with -rbundler/setup" do install_gemfile! "" - ruby! code, :env => { :RUBYOPT => activation_warning_hack_rubyopt + " -rbundler/setup" } + ruby! code, :env => { :RUBYOPT => activation_warning_hack_rubyopt + " -r#{lib}/bundler/setup" } expect(out).to eq("{}") end @@ -1332,7 +1315,7 @@ def lock_with(ruby_version = nil) G ruby! <<-RUBY - require "bundler/setup" + require "#{lib}/bundler/setup" Object.new.gem "rack" puts Gem.loaded_specs["rack"].full_name RUBY @@ -1347,7 +1330,7 @@ def lock_with(ruby_version = nil) G ruby <<-RUBY - require "bundler/setup" + require "#{lib}/bundler/setup" Object.new.gem "rack" puts "FAIL" RUBY @@ -1363,7 +1346,7 @@ def lock_with(ruby_version = nil) G ruby <<-RUBY - require "bundler/setup" + require "#{lib}/bundler/setup" Object.new.require "rack" puts "FAIL" RUBY diff --git a/spec/runtime/with_unbundled_env_spec.rb b/spec/runtime/with_unbundled_env_spec.rb index 30e85180430..62a9e408813 100644 --- a/spec/runtime/with_unbundled_env_spec.rb +++ b/spec/runtime/with_unbundled_env_spec.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true RSpec.describe "Bundler.with_env helpers" do - def bundle_exec_ruby!(code) - build_bundler_context - bundle! "exec '#{Gem.ruby}' -e #{code}" + def bundle_exec_ruby!(code, options = {}) + build_bundler_context options + bundle! "exec '#{Gem.ruby}' -e #{code}", options end - def build_bundler_context + def build_bundler_context(options = {}) bundle "config set path vendor/bundle" gemfile "" - bundle "install" + bundle "install", options end describe "Bundler.original_env" do @@ -75,7 +75,7 @@ def build_bundler_context it "should remove '-rbundler/setup' from RUBYOPT" do code = "print #{modified_env}['RUBYOPT']" ENV["RUBYOPT"] = "-W2 -rbundler/setup #{ENV["RUBYOPT"]}" - bundle_exec_ruby! code.dump + bundle_exec_ruby! code.dump, :env => { "BUNDLER_SPEC_DISABLE_DEFAULT_BUNDLER_GEM" => "true" } expect(last_command.stdboth).not_to include("-rbundler/setup") end diff --git a/spec/support/artifice/endpoint.rb b/spec/support/artifice/endpoint.rb index d9e9e0ae0a5..966681f8d8e 100644 --- a/spec/support/artifice/endpoint.rb +++ b/spec/support/artifice/endpoint.rb @@ -44,8 +44,7 @@ def call!(*) def dependencies_for(gem_names, gem_repo = GEM_REPO) return [] if gem_names.nil? || gem_names.empty? - require "rubygems" - require "bundler" + require "#{Spec::Path.lib}/bundler" Bundler::Deprecate.skip_during do all_specs = %w[specs.4.8 prerelease_specs.4.8].map do |filename| Marshal.load(File.open(gem_repo.join(filename)).read) diff --git a/spec/support/hax.rb b/spec/support/hax.rb index 4f8d9b89ec7..c8f78a34a1d 100644 --- a/spec/support/hax.rb +++ b/spec/support/hax.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "rubygems" - module Gem if version = ENV["BUNDLER_SPEC_RUBYGEMS_VERSION"] remove_const(:VERSION) if const_defined?(:VERSION) @@ -13,7 +11,8 @@ class Platform end @platforms = [Gem::Platform::RUBY, Gem::Platform.local] - if defined?(@path_to_default_spec_map) && !ENV["BUNDLER_SPEC_KEEP_DEFAULT_BUNDLER_GEM"] + # We only need this hack for rubygems versions without the BundlerVersionFinder + if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") || ENV["BUNDLER_SPEC_DISABLE_DEFAULT_BUNDLER_GEM"] @path_to_default_spec_map.delete_if do |_path, spec| spec.name == "bundler" end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 9cd468dfa13..0c05789946c 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -77,7 +77,7 @@ def in_app_root_custom(root, &blk) def run(cmd, *args) opts = args.last.is_a?(Hash) ? args.pop : {} groups = args.map(&:inspect).join(", ") - setup = "require 'bundler' ; Bundler.setup(#{groups})\n" + setup = "require '#{lib}/bundler' ; Bundler.setup(#{groups})\n" ruby(setup + cmd, opts) end bang :run @@ -593,13 +593,5 @@ def find_unused_port end port end - - def bundler_fileutils - if RUBY_VERSION >= "2.4" - ::Bundler::FileUtils - else - ::FileUtils - end - end end end