From f9cb39e61499e51cfdd0670a95de584b9e5f29c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 3 Aug 2019 12:22:36 +0200 Subject: [PATCH 1/9] Remove a bunch of unneeded rubygems requires --- spec/runtime/setup_spec.rb | 17 ----------------- spec/support/artifice/endpoint.rb | 1 - spec/support/hax.rb | 2 -- 3 files changed, 20 deletions(-) diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 65cb006eddc..c24e951a4fb 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -12,7 +12,6 @@ G ruby <<-RUBY - require 'rubygems' require 'bundler' Bundler.setup @@ -35,7 +34,6 @@ it "doesn't make all groups available" do ruby <<-RUBY - require 'rubygems' require 'bundler' Bundler.setup(:default) @@ -51,7 +49,6 @@ it "accepts string for group name" do ruby <<-RUBY - require 'rubygems' require 'bundler' Bundler.setup(:default, 'test') @@ -64,7 +61,6 @@ it "leaves all groups available if they were already" do ruby <<-RUBY - require 'rubygems' require 'bundler' Bundler.setup Bundler.setup(:default) @@ -78,7 +74,6 @@ it "leaves :default available if setup is called twice" do ruby <<-RUBY - require 'rubygems' require 'bundler' Bundler.setup(:default) Bundler.setup(:default, :test) @@ -127,7 +122,6 @@ def clean_load_path(lp) ENV["RUBYLIB"] = "rubylib_dir" ruby <<-RUBY - require 'rubygems' require 'bundler' Bundler.setup puts $LOAD_PATH @@ -150,7 +144,6 @@ def clean_load_path(lp) G ruby! <<-RUBY - require 'rubygems' require 'bundler' Bundler.setup puts $LOAD_PATH @@ -179,7 +172,6 @@ def clean_load_path(lp) G ruby! <<-RUBY - require 'rubygems' require 'bundler/setup' puts $LOAD_PATH RUBY @@ -201,7 +193,6 @@ def clean_load_path(lp) G ruby <<-R - require 'rubygems' require 'bundler' begin @@ -222,7 +213,6 @@ def clean_load_path(lp) G ruby <<-R - require 'rubygems' require 'bundler' Bundler.setup @@ -246,7 +236,6 @@ def clean_load_path(lp) G ruby <<-R - require 'rubygems' require 'bundler' Bundler.setup @@ -300,7 +289,6 @@ def clean_load_path(lp) ENV["BUNDLE_GEMFILE"] = "Gemfile" ruby <<-R - require 'rubygems' require 'bundler' begin @@ -456,7 +444,6 @@ def clean_load_path(lp) break_git! ruby <<-R - require 'rubygems' require 'bundler' begin @@ -478,7 +465,6 @@ def clean_load_path(lp) break_git! ruby <<-R - require "rubygems" require "bundler" begin @@ -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 @@ -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) diff --git a/spec/support/artifice/endpoint.rb b/spec/support/artifice/endpoint.rb index d9e9e0ae0a5..0176059e877 100644 --- a/spec/support/artifice/endpoint.rb +++ b/spec/support/artifice/endpoint.rb @@ -44,7 +44,6 @@ def call!(*) def dependencies_for(gem_names, gem_repo = GEM_REPO) return [] if gem_names.nil? || gem_names.empty? - require "rubygems" require "bundler" Bundler::Deprecate.skip_during do all_specs = %w[specs.4.8 prerelease_specs.4.8].map do |filename| diff --git a/spec/support/hax.rb b/spec/support/hax.rb index 4f8d9b89ec7..5e6acdc783e 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) From fb587b9ebbcf82cb0a65bb333236ca09103a89b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 2 Aug 2019 13:23:20 +0200 Subject: [PATCH 2/9] Last relative requires --- lib/bundler/plugin.rb | 10 +++++----- .../net-http-persistent/lib/net/http/persistent.rb | 6 +++--- .../lib/net/http/persistent/pool.rb | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) 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' From e4cbb91b7df00d497870b6741ce72e8a393a2185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 2 Aug 2019 14:08:28 +0200 Subject: [PATCH 3/9] Require relatively from exe/ when possible --- exe/bundle | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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] From 789dd1864f534876a1078af22985a544716302dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 16 Aug 2019 17:51:18 +0200 Subject: [PATCH 4/9] Fix spec using the deprecated `bundle config` mode --- spec/commands/exec_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index c68a9c4f430..303dbb243a0 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -843,7 +843,7 @@ def bin_path(a,b,c) source "#{file_uri_for(gem_repo1)}" gem "rack" G - bundle "config path vendor/bundler" + bundle "config set path vendor/bundler" bundle! :install, :system_bundler => true end From a3d72a34aba89df3951fc629096b66b73bc56f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 16 Aug 2019 17:54:12 +0200 Subject: [PATCH 5/9] Don't use system bundler on this spec If we use system bundler, when booting the "outermost" bundler process, bundler will save the path to the system bundler in BUNDLE_BIN_PATH, and use it again when booting the "innermost" bundler process (`bundle exec echo foo`). That means that second process will use the system bundler path again. However, we have `-rsupport/hax` in RUBYOPT, so that file will load from the local copy of bundler, and that file will load `bundler/version` from the project (not from system), because -Ilib is in the LOAD_PATH. That will end up causing redefinition errors because the same constant will be loaded from two different locations. In general, this is expected behavior, normally you will wrap the process with `Bundler.with_original_env` to reset the environment. However, the easiest fix here is to not use system bundler, because it's not really necessary and thus doesn't help the readability of the spec. --- spec/commands/exec_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index 303dbb243a0..ec75b9eb0dd 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -837,14 +837,12 @@ def bin_path(a,b,c) context "nested bundle exec" do context "when bundle in a local path" do before do - system_gems :bundler - gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "rack" G bundle "config set path vendor/bundler" - bundle! :install, :system_bundler => true + 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 From ac655ffeda6433ce16f0013801c19ec361ce20a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 23 Jul 2019 18:44:21 +0200 Subject: [PATCH 6/9] Remove unnecessary rubygems monkeypatch Instead, make sure we always load the local copy of bundler during specs, and never end up using the default copy. --- spec/commands/pristine_spec.rb | 3 +- spec/install/gemfile/groups_spec.rb | 2 +- spec/realworld/double_check_spec.rb | 4 +- spec/runtime/inline_spec.rb | 6 +-- spec/runtime/load_spec.rb | 2 +- spec/runtime/require_spec.rb | 2 +- spec/runtime/setup_spec.rb | 58 ++++++++++++------------- spec/runtime/with_unbundled_env_spec.rb | 12 ++--- spec/support/artifice/endpoint.rb | 2 +- spec/support/hax.rb | 3 +- spec/support/helpers.rb | 2 +- 11 files changed, 48 insertions(+), 48 deletions(-) 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/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 c24e951a4fb..9fa6e1bf9bb 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -12,7 +12,7 @@ G ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup require 'rack' @@ -34,7 +34,7 @@ it "doesn't make all groups available" do ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup(:default) begin @@ -49,7 +49,7 @@ it "accepts string for group name" do ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup(:default, 'test') require 'rack' @@ -61,7 +61,7 @@ it "leaves all groups available if they were already" do ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup Bundler.setup(:default) @@ -74,7 +74,7 @@ it "leaves :default available if setup is called twice" do ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup(:default) Bundler.setup(:default, :test) @@ -91,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' @@ -122,7 +122,7 @@ def clean_load_path(lp) ENV["RUBYLIB"] = "rubylib_dir" ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup puts $LOAD_PATH RUBY @@ -144,7 +144,7 @@ def clean_load_path(lp) G ruby! <<-RUBY - require 'bundler' + require '#{lib}/bundler' Bundler.setup puts $LOAD_PATH RUBY @@ -172,7 +172,7 @@ def clean_load_path(lp) G ruby! <<-RUBY - require 'bundler/setup' + require '#{lib}/bundler/setup' puts $LOAD_PATH RUBY @@ -193,7 +193,7 @@ def clean_load_path(lp) G ruby <<-R - require 'bundler' + require '#{lib}/bundler' begin Bundler.setup @@ -213,7 +213,7 @@ def clean_load_path(lp) G ruby <<-R - require 'bundler' + require '#{lib}/bundler' Bundler.setup R @@ -236,7 +236,7 @@ def clean_load_path(lp) G ruby <<-R - require 'bundler' + require '#{lib}/bundler' Bundler.setup R @@ -289,7 +289,7 @@ def clean_load_path(lp) ENV["BUNDLE_GEMFILE"] = "Gemfile" ruby <<-R - require 'bundler' + require '#{lib}/bundler' begin Bundler.setup @@ -444,7 +444,7 @@ def clean_load_path(lp) break_git! ruby <<-R - require 'bundler' + require '#{lib}/bundler' begin Bundler.setup @@ -465,7 +465,7 @@ def clean_load_path(lp) break_git! ruby <<-R - require "bundler" + require "#{lib}/bundler" begin Bundler.setup @@ -774,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 @@ -1028,7 +1028,7 @@ def clean_load_path(lp) bundle "install" ruby <<-RUBY - require 'bundler' + require '#{lib}/bundler' def Bundler.require(path) raise "LOSE" end @@ -1083,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 @@ -1091,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) @@ -1101,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 @@ -1148,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 @@ -1164,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 @@ -1173,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 @@ -1186,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" @@ -1240,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 @@ -1315,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 @@ -1330,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 @@ -1346,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 0176059e877..966681f8d8e 100644 --- a/spec/support/artifice/endpoint.rb +++ b/spec/support/artifice/endpoint.rb @@ -44,7 +44,7 @@ def call!(*) def dependencies_for(gem_names, gem_repo = GEM_REPO) return [] if gem_names.nil? || gem_names.empty? - 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 5e6acdc783e..c8f78a34a1d 100644 --- a/spec/support/hax.rb +++ b/spec/support/hax.rb @@ -11,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..f069911f653 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 From 6b0dc20bcec10d26a1105765de068e115b33a45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 8 Aug 2019 10:28:53 +0200 Subject: [PATCH 7/9] Comment the changes being applied to vendored lib --- Rakefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index b2a630090e7..d5ea04beb42 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" } From d366cbfe5d9b7559399284bc913d24116e37ce40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 16 Aug 2019 17:45:00 +0200 Subject: [PATCH 8/9] No need to activate the `fileutils` default gem The version we're vendoring actually relaxed this restriction back to 2.3.0+, so we can always use the vendored version. --- lib/bundler/vendored_fileutils.rb | 7 +------ spec/bundler/bundler_spec.rb | 2 +- spec/bundler/settings_spec.rb | 4 ++-- spec/support/helpers.rb | 8 -------- 4 files changed, 4 insertions(+), 17 deletions(-) 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 = <= "2.4" - ::Bundler::FileUtils - else - ::FileUtils - end - end end end From 8ef571ed4e443e066cc17c01de753953ff205c04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 17 Aug 2019 13:39:56 +0200 Subject: [PATCH 9/9] Remove unnecessary require --- spec/plugins/source/example_spec.rb | 1 - 1 file changed, 1 deletion(-) 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