Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Feature-flag the postit trampoline, disabled by default
Browse files Browse the repository at this point in the history
Set ENV["BUNDLE_ENABLE_TRAMPOLINE"] to enable it
  • Loading branch information
segiddins committed Jul 27, 2016
1 parent 6904ac6 commit a2fc99e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 47 deletions.
97 changes: 50 additions & 47 deletions lib/bundler/postit_trampoline.rb
@@ -1,62 +1,65 @@
# frozen_string_literal: true
if ENV["BUNDLE_ENABLE_TRAMPOLINE"]

module BundlerVendoredPostIt; end
require "bundler/vendor/postit/lib/postit"
require "rubygems"
module BundlerVendoredPostIt; end
require "bundler/vendor/postit/lib/postit"
require "rubygems"

environment = BundlerVendoredPostIt::PostIt::Environment.new([])
version = Gem::Requirement.new(environment.bundler_version)
environment = BundlerVendoredPostIt::PostIt::Environment.new([])
version = Gem::Requirement.new(environment.bundler_version)

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)
installer.install!
rescue => e
abort <<-EOS.strip
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)
installer.install!
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
end

if deleted_spec = Gem.loaded_specs.delete("bundler")
deleted_spec.full_require_paths.each {|path| $:.delete(path) }
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
$:.delete(File.expand_path("../..", __FILE__))
begin
gem "bundler", version
rescue LoadError
$:.unshift(File.expand_path("../..", __FILE__))
end
end
gem "bundler", version
else
begin
gem "bundler", version
rescue LoadError
$:.unshift(File.expand_path("../..", __FILE__))

running_version = begin
require "bundler/version"
Bundler::VERSION
rescue LoadError, NameError
nil
end
end

running_version = begin
require "bundler/version"
Bundler::VERSION
rescue LoadError, NameError
nil
end

if Gem::Requirement.new(">= 1.13.pre".dup).satisfied_by?(Gem::Version.new(running_version))
ENV["BUNDLE_POSTIT_TRAMPOLINING_VERSION"] = installed_version.to_s
elsif ARGV.empty? || ARGV.any? {|a| %w(install i).include? a }
puts <<-WARN.strip

if Gem::Requirement.new(">= 1.13.pre".dup).satisfied_by?(Gem::Version.new(running_version))
ENV["BUNDLE_POSTIT_TRAMPOLINING_VERSION"] = installed_version.to_s
elsif 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
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

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 # unless ENV["BUNDLE_ENABLE_TRAMPOLINE"]
1 change: 1 addition & 0 deletions spec/other/trampoline_spec.rb
Expand Up @@ -4,6 +4,7 @@
describe "bundler version trampolining" do
before do
ENV["BUNDLE_DISABLE_POSTIT"] = nil
ENV["BUNDLE_ENABLE_TRAMPOLINE"] = "true"
FileUtils.rm_rf(system_gem_path)
FileUtils.cp_r(base_system_gems, system_gem_path)
end
Expand Down

0 comments on commit a2fc99e

Please sign in to comment.