diff options
author | The Bundler Bot <bot@bundler.io> | 2017-03-15 17:58:22 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2017-03-15 17:58:22 +0000 |
commit | 2e127e90873299f24517b5bec6d9890c452ae7cb (patch) | |
tree | 853957f20f4e3e8914adbb250c1f1929f1f8901f | |
parent | 34817df09450dcbe721454d3d802b2adabddf627 (diff) | |
parent | a58bda0f3f9f5446b658c8682d265f569524b70c (diff) | |
download | bundler-2e127e90873299f24517b5bec6d9890c452ae7cb.tar.gz |
Auto merge of #5504 - bundler:seg-double-bundle-exec, r=indirect
[CLI] Dont reset every time the CLI is initialized
Fixes #5500
- [x] Tests
-rw-r--r-- | lib/bundler.rb | 10 | ||||
-rw-r--r-- | lib/bundler/cli.rb | 6 | ||||
-rw-r--r-- | spec/commands/exec_spec.rb | 72 | ||||
-rw-r--r-- | spec/support/helpers.rb | 8 |
4 files changed, 74 insertions, 22 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 914bdb3762..63a9f5784c 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -442,6 +442,12 @@ EOF end def reset! + reset_paths! + Plugin.reset! + reset_rubygems! + end + + def reset_paths! @root = nil @settings = nil @definition = nil @@ -451,9 +457,9 @@ EOF @bundle_path = nil @bin_path = nil @user_home = nil + end - Plugin.reset! - + def reset_rubygems! return unless defined?(@rubygems) && @rubygems rubygems.undo_replacements rubygems.reset diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index d5054e8054..78ce355ff5 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -23,10 +23,12 @@ module Bundler def initialize(*args) super - Bundler.reset! custom_gemfile = options[:gemfile] || Bundler.settings[:gemfile] - ENV["BUNDLE_GEMFILE"] = File.expand_path(custom_gemfile) if custom_gemfile && !custom_gemfile.empty? + if custom_gemfile && !custom_gemfile.empty? + ENV["BUNDLE_GEMFILE"] = File.expand_path(custom_gemfile) + Bundler.reset_paths! + end Bundler.settings[:retry] = options[:retry] if options[:retry] diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index bf20ec7d9a..3c5f2ca1dd 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -646,23 +646,65 @@ __FILE__: #{path.to_s.inspect} context "nested bundle exec" do let(:system_gems_to_install) { super() << :bundler } - before do - gemfile <<-G - source "file://#{gem_repo1}" - gem "rack" - G - bundle :install, :system_bundler => true, :path => "vendor/bundler" + + context "with shared gems disabled" do + before do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + bundle :install, :system_bundler => true, :path => "vendor/bundler" + end + + it "overrides disable_shared_gems so bundler can be found" do + file = bundled_app("file_that_bundle_execs.rb") + create_file(file, <<-RB) + #!#{Gem.ruby} + puts `bundle exec echo foo` + RB + file.chmod(0o777) + bundle! "exec #{file}", :system_bundler => true + expect(out).to eq("foo") + end end - it "overrides disable_shared_gems so bundler can be found" do - file = bundled_app("file_that_bundle_execs.rb") - create_file(file, <<-RB) - #!#{Gem.ruby} - puts `bundle exec echo foo` - RB - file.chmod(0o777) - bundle! "exec #{file}", :system_bundler => true - expect(out).to eq("foo") + context "with a system gem that shadows a default gem" do + let(:openssl_version) { "2.0.3" } + let(:expected) { ruby "gem 'openssl', '< 999999'; require 'openssl'; puts OpenSSL::VERSION", :artifice => nil } + + it "only leaves the default gem in the stdlib available" do + skip "openssl isn't a default gem" if expected.empty? + + install_gemfile! "" # must happen before installing the broken system gem + + build_repo4 do + build_gem "openssl", openssl_version do |s| + s.write("lib/openssl.rb", <<-RB) + raise "custom openssl should not be loaded, it's not in the gemfile!" + RB + end + end + + system_gems(:bundler, "openssl-#{openssl_version}", :gem_repo => gem_repo4) + + file = bundled_app("require_openssl.rb") + create_file(file, <<-RB) + #!/usr/bin/env ruby + require "openssl" + puts OpenSSL::VERSION + RB + file.chmod(0o777) + + aggregate_failures do + expect(bundle!("exec #{file}", :system_bundler => true, :artifice => nil)).to eq(expected) + expect(bundle!("exec bundle exec #{file}", :system_bundler => true, :artifice => nil)).to eq(expected) + expect(bundle!("exec ruby #{file}", :system_bundler => true, :artifice => nil)).to eq(expected) + end + + # sanity check that we get the newer, custom version without bundler + sys_exec(file.to_s) + expect(err).to include("custom openssl should not be loaded") + end end end end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 8095331b0a..1b2769ebf8 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -2,8 +2,8 @@ module Spec module Helpers def reset! - Dir["#{tmp}/{gems/*,*}"].each do |dir| - next if %w(base remote1 gems rubygems).include?(File.basename(dir)) + Dir.glob("#{tmp}/{gems/*,*}", File::FNM_DOTMATCH).each do |dir| + next if %w(base remote1 gems rubygems . ..).include?(File.basename(dir)) if ENV["BUNDLER_SUDO_TESTS"] `sudo rm -rf "#{dir}"` else @@ -245,12 +245,14 @@ module Spec end def install_gems(*gems) + options = gems.last.is_a?(Hash) ? gems.pop : {} + gem_repo = options.fetch(:gem_repo) { gem_repo1 } gems.each do |g| path = if g == :bundler Dir.chdir(root) { gem_command! :build, "#{root}/bundler.gemspec" } bundler_path = root + "bundler-#{Bundler::VERSION}.gem" else - "#{gem_repo1}/gems/#{g}.gem" + "#{gem_repo}/gems/#{g}.gem" end raise "OMG `#{path}` does not exist!" unless File.exist?(path) |