diff options
-rw-r--r-- | Rakefile | 8 | ||||
-rw-r--r-- | doc/development/SETUP.md | 4 | ||||
-rwxr-xr-x | exe/bundle | 5 | ||||
-rw-r--r-- | lib/bundler/cli.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/install.rb | 16 | ||||
-rw-r--r-- | lib/bundler/postit_trampoline.rb | 73 | ||||
-rw-r--r-- | lib/bundler/setup.rb | 10 | ||||
-rw-r--r-- | lib/bundler/vendor/postit/lib/postit.rb | 15 | ||||
-rw-r--r-- | lib/bundler/vendor/postit/lib/postit/environment.rb | 44 | ||||
-rw-r--r-- | lib/bundler/vendor/postit/lib/postit/installer.rb | 28 | ||||
-rw-r--r-- | lib/bundler/vendor/postit/lib/postit/parser.rb | 21 | ||||
-rw-r--r-- | lib/bundler/vendor/postit/lib/postit/setup.rb | 12 | ||||
-rw-r--r-- | lib/bundler/vendor/postit/lib/postit/version.rb | 3 | ||||
-rw-r--r-- | man/bundle.ronn | 18 | ||||
-rw-r--r-- | spec/commands/install_spec.rb | 21 | ||||
-rw-r--r-- | spec/other/trampoline_spec.rb | 193 | ||||
-rw-r--r-- | spec/support/helpers.rb | 1 |
17 files changed, 5 insertions, 469 deletions
@@ -328,13 +328,6 @@ begin lib.vendor_lib = "lib/bundler/vendor/thor" end - Automatiek::RakeTask.new("postit") do |lib| - lib.download = { :github => "https://github.com/bundler/postit" } - lib.namespace = "PostIt" - lib.prefix = "BundlerVendoredPostIt" - lib.vendor_lib = "lib/bundler/vendor/postit" - end - Automatiek::RakeTask.new("net-http-persistent") do |lib| lib.download = { :github => "https://github.com/drbrain/net-http-persistent" } lib.namespace = "Net::HTTP::Persistent" @@ -355,7 +348,6 @@ rescue LoadError namespace :vendor do task(:molinillo) { abort "Install the automatiek gem to be able to vendor gems." } task(:thor) { abort "Install the automatiek gem to be able to vendor gems." } - task(:postit) { abort "Install the automatiek gem to be able to vendor gems." } task("net-http-persistent") { abort "Install the automatiek gem to be able to vendor gems." } end end diff --git a/doc/development/SETUP.md b/doc/development/SETUP.md index 2011651252..d4ec555fef 100644 --- a/doc/development/SETUP.md +++ b/doc/development/SETUP.md @@ -20,9 +20,7 @@ Bundler doesn't use a Gemfile to list development dependencies, because when we 4. Set up a shell alias to run Bundler from your clone, e.g. a Bash alias: - `$ alias dbundle='BUNDLE_TRAMPOLINE_DISABLE=1 ruby -I /path/to/bundler/lib /path/to/bundler/exe/bundle'` - - The `BUNDLE_TRAMPOLINE_DISABLE` environment variable ensures that the version of Bundler in `/path/to/bundler/lib` will be used. Without that environment setting, Bundler will automatically download, install, and run the version of Bundler listed in `Gemfile.lock`. With that set up, you can test changes you've made to Bundler by running `dbundle`, without interfering with the regular `bundle` command. + `$ alias dbundle='ruby -I /path/to/bundler/lib /path/to/bundler/exe/bundle'` ## Debugging with `pry` diff --git a/exe/bundle b/exe/bundle index d73e9984c9..aaf773745d 100755 --- a/exe/bundle +++ b/exe/bundle @@ -7,11 +7,6 @@ Signal.trap("INT") do exit 1 end -update = "update".start_with?(ARGV.first || " ") && ARGV.find {|a| a.start_with?("--bundler") } -update &&= update =~ /--bundler(?:=(.+))?/ && $1 || "> 0.a" -ENV["BUNDLER_VERSION"] = update if update -require "bundler/postit_trampoline" - require "bundler" # Check if an older version of bundler is installed $LOAD_PATH.each do |path| diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 58a7ce491a..c09b14433a 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -619,7 +619,7 @@ module Bundler end def print_command - return unless ENV["BUNDLE_POSTIT_TRAMPOLINING_VERSION"] || Bundler.ui.debug? + return unless Bundler.ui.debug? _, _, config = @_initializer current_command = config[:current_command] command_name = current_command.name diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index c110f516fc..0592385e23 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -13,8 +13,6 @@ module Bundler warn_if_root - warn_if_outdated - [:with, :without].each do |option| if options[option] options[option] = options[option].join(":").tr(" ", ":").split(":") @@ -116,20 +114,6 @@ module Bundler "application for all non-root users on this machine.", :wrap => true end - def warn_if_outdated - return if ENV["BUNDLE_POSTIT_TRAMPOLINING_VERSION"].nil? - installed_version = Gem::Version.new(ENV["BUNDLE_POSTIT_TRAMPOLINING_VERSION"].dup) - running_version = Gem::Version.new(Bundler::VERSION) - return if Gem::Requirement.new(installed_version).satisfied_by?(running_version) - if Bundler.settings[:warned_version].nil? || running_version > Gem::Version.new(Bundler.settings[:warned_version]) - Bundler.settings[:warned_version] = running_version - Bundler.ui.warn "You're running Bundler #{installed_version} but this " \ - "project uses #{running_version}. To update, run `bundle update " \ - "--bundler`. You won't see this message again unless you upgrade " \ - "to a newer version of Bundler.", :wrap => true - end - end - def dependencies_count_for(definition) count = definition.dependencies.count "#{count} Gemfile #{count == 1 ? "dependency" : "dependencies"}" diff --git a/lib/bundler/postit_trampoline.rb b/lib/bundler/postit_trampoline.rb deleted file mode 100644 index 576ce2a274..0000000000 --- a/lib/bundler/postit_trampoline.rb +++ /dev/null @@ -1,73 +0,0 @@ -# frozen_string_literal: true - -module BundlerVendoredPostIt; end -require "bundler/vendor/postit/lib/postit" -require "rubygems" - -environment = BundlerVendoredPostIt::PostIt::Environment.new([]) -version = Gem::Requirement.new(environment.bundler_version) -if version.requirements.size == 1 && version.requirements.first.first == "=" # version.exact? - if version.requirements.first.last.segments.first >= 2 - ENV["BUNDLE_TRAMPOLINE_FORCE"] = "true" - end -end - -if ENV["BUNDLE_TRAMPOLINE_FORCE"] && !ENV["BUNDLE_TRAMPOLINE_DISABLE"] - installed_version = - if defined?(Bundler::VERSION) - Bundler::VERSION - else - File.read(File.expand_path("../version.rb", __FILE__)) =~ /VERSION = "(.+)"/ - $1 - end - installed_version &&= Gem::Version.new(installed_version) - - if !version.satisfied_by?(installed_version) - begin - installer = BundlerVendoredPostIt::PostIt::Installer.new(version) - unless installer.installed? - warn "Installing locked Bundler version #{version.to_s.gsub("= ", "")}..." - installer.install! - end - rescue => e - abort <<-EOS.strip -Installing the inferred bundler version (#{version}) failed. -If you'd like to update to the current bundler version (#{installed_version}) in this project, run `bundle update --bundler`. -The error was: #{e} - EOS - end - - if deleted_spec = Gem.loaded_specs.delete("bundler") - deleted_spec.full_require_paths.each {|path| $:.delete(path) } - else - $:.delete(File.expand_path("../..", __FILE__)) - end - gem "bundler", version - else - begin - gem "bundler", version - rescue LoadError - $:.unshift(File.expand_path("../..", __FILE__)) - end - end - - running_version = begin - require "bundler/version" - Bundler::VERSION - rescue LoadError, NameError - nil - end - - ENV["BUNDLE_POSTIT_TRAMPOLINING_VERSION"] = installed_version.to_s - - if !Gem::Requirement.new(">= 1.13.pre".dup).satisfied_by?(Gem::Version.new(running_version)) && (ARGV.empty? || ARGV.any? {|a| %w[install i].include? a }) - puts <<-WARN.strip -You're running Bundler #{installed_version} but this project uses #{running_version}. To update, run `bundle update --bundler`. - WARN - end - - if !Gem::Version.correct?(running_version.to_s) || !version.satisfied_by?(Gem::Version.create(running_version)) - abort "The running bundler (#{running_version}) does not match the required `#{version}`" - end - -end # if ENV["BUNDLE_TRAMPOLINE_FORCE"] && !ENV["BUNDLE_TRAMPOLINE_DISABLE"] diff --git a/lib/bundler/setup.rb b/lib/bundler/setup.rb index eb816b9988..9aae6478cd 100644 --- a/lib/bundler/setup.rb +++ b/lib/bundler/setup.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "bundler/postit_trampoline" require "bundler/shared_helpers" if Bundler::SharedHelpers.in_bundle? @@ -20,12 +19,9 @@ if Bundler::SharedHelpers.in_bundle? Bundler.setup end - unless ENV["BUNDLE_POSTIT_TRAMPOLINING_VERSION"] - # Add bundler to the load path after disabling system gems - # This is guaranteed to be done already if we've trampolined - bundler_lib = File.expand_path("../..", __FILE__) - $LOAD_PATH.unshift(bundler_lib) unless $LOAD_PATH.include?(bundler_lib) - end + # Add bundler to the load path after disabling system gems + bundler_lib = File.expand_path("../..", __FILE__) + $LOAD_PATH.unshift(bundler_lib) unless $LOAD_PATH.include?(bundler_lib) Bundler.ui = nil end diff --git a/lib/bundler/vendor/postit/lib/postit.rb b/lib/bundler/vendor/postit/lib/postit.rb deleted file mode 100644 index e07dfccac4..0000000000 --- a/lib/bundler/vendor/postit/lib/postit.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'bundler/vendor/postit/lib/postit/environment' -require 'bundler/vendor/postit/lib/postit/installer' -require 'bundler/vendor/postit/lib/postit/parser' -require 'bundler/vendor/postit/lib/postit/version' -require 'rubygems' - -module BundlerVendoredPostIt::PostIt - def self.setup - load File.expand_path('../postit/setup.rb', __FILE__) - end - - def self.bundler_version - defined?(Bundler::VERSION) && Bundler::VERSION - end -end diff --git a/lib/bundler/vendor/postit/lib/postit/environment.rb b/lib/bundler/vendor/postit/lib/postit/environment.rb deleted file mode 100644 index 0c27f2cd69..0000000000 --- a/lib/bundler/vendor/postit/lib/postit/environment.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'bundler/vendor/postit/lib/postit/parser' - -module BundlerVendoredPostIt::PostIt - class Environment - def initialize(argv) - @argv = argv - end - - def env_var_version - ENV['BUNDLER_VERSION'] - end - - def cli_arg_version - return unless str = @argv.first - str = str.dup.force_encoding('BINARY') if str.respond_to?(:force_encoding) - if Gem::Version.correct?(str) - @argv.shift - str - end - end - - def gemfile - ENV['BUNDLE_GEMFILE'] || 'Gemfile' - end - - def lockfile - File.expand_path case File.basename(gemfile) - when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile) - else "#{gemfile}.lock" - end - end - - def lockfile_version - BundlerVendoredPostIt::PostIt::Parser.new(lockfile).parse - end - - def bundler_version - @bundler_version ||= begin - env_var_version || cli_arg_version || - lockfile_version || "#{Gem::Requirement.default}.a" - end - end - end -end diff --git a/lib/bundler/vendor/postit/lib/postit/installer.rb b/lib/bundler/vendor/postit/lib/postit/installer.rb deleted file mode 100644 index 5fa34b6938..0000000000 --- a/lib/bundler/vendor/postit/lib/postit/installer.rb +++ /dev/null @@ -1,28 +0,0 @@ -module BundlerVendoredPostIt::PostIt - class Installer - def initialize(bundler_version) - @bundler_version = bundler_version - end - - def installed? - if Gem::Specification.respond_to?(:find_by_name) - !Gem::Specification.find_by_name('bundler', @bundler_version).nil? - else - requirement = Gem::Requirement.new(@bundler_version) - Gem.source_index.gems.values.any? do |s| - s.name == 'bundler' && requirement.satisfied_by?(s.version) - end - end - rescue LoadError - false - end - - def install! - return if installed? - require 'rubygems/dependency_installer' - installer = Gem::DependencyInstaller.new - installer.install('bundler', @bundler_version) - installer.installed_gems - end - end -end diff --git a/lib/bundler/vendor/postit/lib/postit/parser.rb b/lib/bundler/vendor/postit/lib/postit/parser.rb deleted file mode 100644 index 7b2eb72ff1..0000000000 --- a/lib/bundler/vendor/postit/lib/postit/parser.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rubygems' - -module BundlerVendoredPostIt::PostIt - class Parser - def initialize(file) - @file = file - end - - BUNDLED_WITH = - /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ - - def parse - return unless lockfile = File.file?(@file) && File.read(@file) - if lockfile =~ BUNDLED_WITH - Regexp.last_match(1) - else - '< 1.10' - end - end - end -end diff --git a/lib/bundler/vendor/postit/lib/postit/setup.rb b/lib/bundler/vendor/postit/lib/postit/setup.rb deleted file mode 100644 index 2580e7b7b8..0000000000 --- a/lib/bundler/vendor/postit/lib/postit/setup.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'bundler/vendor/postit/lib/postit/environment' -require 'bundler/vendor/postit/lib/postit/installer' - -environment = BundlerVendoredPostIt::PostIt::Environment.new(ARGV) -version = environment.bundler_version - -installer = BundlerVendoredPostIt::PostIt::Installer.new(version) -installer.install! - -gem 'bundler', version - -require 'bundler/version' diff --git a/lib/bundler/vendor/postit/lib/postit/version.rb b/lib/bundler/vendor/postit/lib/postit/version.rb deleted file mode 100644 index b54175254d..0000000000 --- a/lib/bundler/vendor/postit/lib/postit/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module BundlerVendoredPostIt::PostIt - VERSION = '0.2.0'.freeze -end diff --git a/man/bundle.ronn b/man/bundle.ronn index 9e42e046a7..c0726c9dcd 100644 --- a/man/bundle.ronn +++ b/man/bundle.ronn @@ -97,24 +97,6 @@ When running a command that isn't listed in PRIMARY COMMANDS or UTILITIES, Bundler will try to find an executable on your path named `bundler-<command>` and execute it, passing down any extra arguments to it. -## BUNDLER TRAMPOLINING - -Bundler includes a feature called trampolining, designed to allow a single -developer to work on multiple projects, each on different Bundler versions. -The trampoline will infer the correct version of Bundler to use for each project -and load that version instead of the version directly invoked (which is almost -always the newest version installed locally). - -Bundler by default will use the Bundler version in the current directory to -determine the version to trampoline to, reading from the `BUNDLED WITH` section. -However, if the `BUNDLER_VERSION` environment variable is set, that version will -override the lockfile inference and can be used in directories without a -lockfile. - -Until the target version is Bundler 2 or later, `BUNDLE_TRAMPOLINE_FORCE` must -be set for the trampoline to be used. Additionally, `BUNDLE_TRAMPOLINE_DISABLE` can -be set to completely disable the trampoline. - ## OBSOLETE These commands are obsolete and should no longer be used diff --git a/spec/commands/install_spec.rb b/spec/commands/install_spec.rb index 4ca8330d02..3b339e5147 100644 --- a/spec/commands/install_spec.rb +++ b/spec/commands/install_spec.rb @@ -484,25 +484,4 @@ RSpec.describe "bundle install with gem sources" do "setting them for authentication.") end end - - describe "warns user if Bundler is outdated" do - it "warns only once and is > 1.13.0.rc.1" do - gemfile <<-G - source "file://#{gem_repo1}" - G - - bundle :install, :env => { "BUNDLE_POSTIT_TRAMPOLINING_VERSION" => "999" } - expect(out).to include("You're running Bundler 999 but this project uses #{Bundler::VERSION}.") - - bundle :install, :env => { "BUNDLE_POSTIT_TRAMPOLINING_VERSION" => "999" } - expect(out).not_to include("You're running Bundler 999 but this project uses #{Bundler::VERSION}.") - end - - it "should not print warning if versions match" do - bundle :init - bundle :install, :env => { "BUNDLE_POSTIT_TRAMPOLINING_VERSION" => Bundler::VERSION } - expect(out).to start_with("Running `bundle install --no-color` with bundler #{Bundler::VERSION}\nThe Gemfile specifies no dependencies") - expect(out).not_to include("You're running Bundler #{Bundler::VERSION} but this project uses #{Bundler::VERSION}.") - end - end end diff --git a/spec/other/trampoline_spec.rb b/spec/other/trampoline_spec.rb deleted file mode 100644 index 0ac9ee06a8..0000000000 --- a/spec/other/trampoline_spec.rb +++ /dev/null @@ -1,193 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe "bundler version trampolining" do - before do - ENV["BUNDLE_TRAMPOLINE_DISABLE"] = nil - ENV["BUNDLE_TRAMPOLINE_FORCE"] = "true" - FileUtils.rm_rf(system_gem_path) - FileUtils.cp_r(base_system_gems, system_gem_path) - end - - context "version guessing" do - shared_examples_for "guesses" do |version| - it "guesses the correct bundler version" do - bundle! "--version" - expect(out).to eq("Bundler version #{version}") - - if bundled_app("Gemfile").file? - bundle! "exec ruby -e 'puts Bundler::VERSION'" - expect(out).to eq(version) - end - end - end - - context "with a lockfile" do - before do - install_gemfile "" - lockfile lockfile.sub(Bundler::VERSION, "1.12.0") - end - - include_examples "guesses", "1.12.0" - end - - context "with BUNDLER_VERSION" do - before do - ENV["BUNDLER_VERSION"] = "1.12.0" - end - - context "with a lockfile" do - before { install_gemfile "" } - include_examples "guesses", "1.12.0" - end - - context "without a lockfile" do - include_examples "guesses", "1.12.0" - end - end - - context "with no hints" do - include_examples "guesses", Bundler::VERSION - end - - context "with a gemfile and no lockfile" do - before do - gemfile "" - end - - include_examples "guesses", Bundler::VERSION - end - end - - context "without BUNDLE_TRAMPOLINE_FORCE" do - before { ENV["BUNDLE_TRAMPOLINE_FORCE"] = nil } - - context "when the version is >= 2" do - let(:version) { "2.7182818285" } - before do - simulate_bundler_version version do - install_gemfile! "" - end - end - - it "trampolines automatically", :realworld => true do - bundle "--version" - expect(err).to include("Installing locked Bundler version #{version}...") - end - end - end - - context "installing missing bundler versions", :realworld => true do - before do - ENV["BUNDLER_VERSION"] = "1.12.3" - if Bundler::RubygemsIntegration.provides?("< 2.6.4") - # necessary since we intall with 2.6.4 but the specs can run against - # older versions that match againt the "gem" invocation - %w[bundle bundler].each do |exe| - system_gem_path.join("bin", exe).open("a") do |f| - f << %(\ngem "bundler", ">= 0.a"\n) - end - end - end - end - - it "guesses & installs the correct bundler version" do - expect(system_gem_path.join("gems", "bundler-1.12.3")).not_to exist - bundle! "--version" - expect(out).to eq("Bundler version 1.12.3") - expect(system_gem_path.join("gems", "bundler-1.12.3")).to exist - end - - it "fails gracefully when installing the bundler fails" do - ENV["BUNDLER_VERSION"] = "9999" - bundle "--version" - expect(err).to start_with(<<-E.strip) -Installing locked Bundler version 9999... -Installing the inferred bundler version (= 9999) failed. -If you'd like to update to the current bundler version (#{Bundler::VERSION}) in this project, run `bundle update --bundler`. -The error was: - E - end - - it "displays installing message before install is started" do - expect(system_gem_path.join("gems", "bundler-1.12.3")).not_to exist - bundle! "--version" - expect(err).to include("Installing locked Bundler version #{ENV["BUNDLER_VERSION"]}...") - end - - it "doesn't display installing message if locked version is installed" do - expect(system_gem_path.join("gems", "bundler-1.12.3")).not_to exist - bundle! "--version" - expect(system_gem_path.join("gems", "bundler-1.12.3")).to exist - bundle! "--version" - expect(err).not_to include("Installing locked Bundler version = #{ENV["BUNDLER_VERSION"]}...") - end - end - - context "bundle update --bundler" do - before do - simulate_bundler_version("1.11.1") do - install_gemfile "" - end - end - - it "updates to the specified version" do - # HACK: since no released bundler version actually supports this feature! - bundle "update --bundler=1.12.0" - expect(out).to include("Unknown switches '--bundler=1.12.0'") - end - - it "updates to the specified (running) version" do - # HACK: since no released bundler version actually supports this feature! - bundle! "update --bundler=#{Bundler::VERSION}" - bundle! "--version" - expect(out).to eq("Bundler version #{Bundler::VERSION}") - end - - it "updates to the running version" do - # HACK: since no released bundler version actually supports this feature! - bundle! "update --bundler" - bundle! "--version" - expect(out).to eq("Bundler version #{Bundler::VERSION}") - end - end - - context "-rbundler/setup" do - before do - simulate_bundler_version("1.12.0") do - install_gemfile "" - end - end - - it "uses the locked version" do - ruby! <<-R - require "bundler/setup" - puts Bundler::VERSION - R - expect(err).to be_empty - expect(out).to include("1.12.0") - end - end - - context "warnings" do - before do - simulate_bundler_version("1.12.0") do - install_gemfile "" - end - end - - it "warns user if Bundler is outdated and is < 1.13.0.rc.1" do - ENV["BUNDLER_VERSION"] = "1.12.0" - bundle! "install" - expect(out).to include(<<-WARN.strip) -You're running Bundler #{Bundler::VERSION} but this project uses #{ENV["BUNDLER_VERSION"]}. To update, run `bundle update --bundler`. - WARN - end - end - - context "with --verbose" do - it "prints the running command" do - bundle! "config", :verbose => true, :env => { "BUNDLE_POSTIT_TRAMPOLINING_VERSION" => Bundler::VERSION } - expect(out).to start_with("Running `bundle config --verbose` with bundler #{Bundler::VERSION}") - end - end -end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index ffad652fc0..d961ad0886 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -12,7 +12,6 @@ module Spec end FileUtils.mkdir_p(home) FileUtils.mkdir_p(tmpdir) - ENV["BUNDLE_TRAMPOLINE_DISABLE"] = "1" Bundler.reset! Bundler.ui = nil Bundler.ui # force it to initialize |