diff options
-rw-r--r-- | lib/bundler.rb | 38 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 2 | ||||
-rw-r--r-- | spec/commands/clean_spec.rb | 39 | ||||
-rw-r--r-- | spec/runtime/with_unbundled_env_spec.rb | 88 |
4 files changed, 155 insertions, 12 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 1c6406807d..d500a57861 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -335,12 +335,46 @@ EOF with_env(unbundled_env) { yield } end + # Run subcommand with the environment present before Bundler was activated + def original_system(*args) + with_original_env { Kernel.system(*args) } + end + + # @deprecated Use `unbundled_system` instead def clean_system(*args) - with_clean_env { Kernel.system(*args) } + Bundler::SharedHelpers.major_deprecation( + 2, + "`Bundler.clean_system` has been deprecated in favor of `Bundler.unbundled_system`. " \ + "If you instead want to run the command in the environment before bundler was originally loaded, use `Bundler.original_system`" + ) + + with_env(unbundled_env) { Kernel.system(*args) } + end + + # Run subcommand in an environment with all bundler related variables removed + def unbundled_system(*args) + with_unbundled_env { Kernel.system(*args) } end + # Run a `Kernel.exec` to a subcommand with the environment present before Bundler was activated + def original_exec(*args) + with_original_env { Kernel.exec(*args) } + end + + # @deprecated Use `unbundled_exec` instead def clean_exec(*args) - with_clean_env { Kernel.exec(*args) } + Bundler::SharedHelpers.major_deprecation( + 2, + "`Bundler.clean_exec` has been deprecated in favor of `Bundler.unbundled_exec`. " \ + "If you instead want to exec to a command in the environment before bundler was originally loaded, use `Bundler.original_exec`" + ) + + with_env(unbundled_env) { Kernel.exec(*args) } + end + + # Run a `Kernel.exec` to a subcommand in an environment with all bundler related variables removed + def unbundled_exec(*args) + with_env(unbundled_env) { Kernel.exec(*args) } end def local_platform diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 762e7b3ec6..83945868f9 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -163,7 +163,7 @@ module Bundler gem_dirs = Dir["#{Gem.dir}/gems/*"] gem_files = Dir["#{Gem.dir}/cache/*.gem"] gemspec_files = Dir["#{Gem.dir}/specifications/*.gemspec"] - extension_dirs = Dir["#{Gem.dir}/extensions/*/*/*"] + extension_dirs = Dir["#{Gem.dir}/extensions/*/*/*"] + Dir["#{Gem.dir}/bundler/gems/extensions/*/*/*"] spec_gem_paths = [] # need to keep git sources around spec_git_paths = @definition.spec_git_paths diff --git a/spec/commands/clean_spec.rb b/spec/commands/clean_spec.rb index 6cd796f694..96599a965b 100644 --- a/spec/commands/clean_spec.rb +++ b/spec/commands/clean_spec.rb @@ -770,4 +770,43 @@ RSpec.describe "bundle clean" do expect(very_simple_binary_extensions_dir).not_to exist expect(simple_binary_extensions_dir).to exist end + + it "removes git extension directories", :ruby_repo do + build_git "very_simple_git_binary", &:add_c_extension + + revision = revision_for(lib_path("very_simple_git_binary-1.0")) + short_revision = revision[0..11] + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "thin" + gem "very_simple_git_binary", :git => "#{lib_path("very_simple_git_binary-1.0")}", :ref => "#{revision}" + G + + bundle! "install", forgotten_command_line_options(:path => "vendor/bundle") + + very_simple_binary_extensions_dir = + Pathname.glob("#{vendored_gems}/bundler/gems/extensions/*/*/very_simple_git_binary-1.0-#{short_revision}").first + + expect(very_simple_binary_extensions_dir).to exist + + gemfile <<-G + gem "very_simple_git_binary", :git => "#{lib_path("very_simple_git_binary-1.0")}", :ref => "#{revision}" + G + + bundle! "install" + bundle! :clean + expect(out).to include("Removing thin (1.0)") + expect(very_simple_binary_extensions_dir).to exist + + gemfile <<-G + G + + bundle! "install" + bundle! :clean + expect(out).to eq("Removing very_simple_git_binary-1.0 (#{short_revision})") + + expect(very_simple_binary_extensions_dir).not_to exist + end end diff --git a/spec/runtime/with_unbundled_env_spec.rb b/spec/runtime/with_unbundled_env_spec.rb index c47f2912c5..1ed853f467 100644 --- a/spec/runtime/with_unbundled_env_spec.rb +++ b/spec/runtime/with_unbundled_env_spec.rb @@ -188,20 +188,90 @@ RSpec.describe "Bundler.with_env helpers" do end end - describe "Bundler.clean_system", :bundler => "< 2" do + describe "Bundler.original_system" do + it "runs system inside with_original_env" do + code = 'exit Bundler.original_system(%(test "\$BUNDLE_FOO" = "bar"))' + lib = File.expand_path("../../lib", __dir__) + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + expect($?.exitstatus).to eq(0) + end + end + + describe "Bundler.clean_system" do it "runs system inside with_clean_env" do - Bundler.clean_system(%(echo 'if [ "$BUNDLE_PATH" = "" ]; then exit 42; else exit 1; fi' | /bin/sh)) - expect($?.exitstatus).to eq(42) + code = 'exit Bundler.clean_system(%(test "\$BUNDLE_FOO" = "bar"))' + lib = File.expand_path("../../lib", __dir__) + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + expect($?.exitstatus).to eq(1) + end + end + + describe "Bundler.unbundled_system" do + it "runs system inside with_unbundled_env" do + code = 'exit Bundler.clean_system(%(test "\$BUNDLE_FOO" = "bar"))' + lib = File.expand_path("../../lib", __dir__) + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + expect($?.exitstatus).to eq(1) end end - describe "Bundler.clean_exec", :bundler => "< 2" do + describe "Bundler.original_exec" do + let(:code) do + <<~RUBY + Process.fork do + exit Bundler.original_exec(%(test "\$BUNDLE_FOO" = "bar")) + end + + _, status = Process.wait2 + + exit(status.exitstatus) + RUBY + end + + it "runs exec inside with_original_env" do + lib = File.expand_path("../../lib", __dir__) + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + expect($?.exitstatus).to eq(0) + end + end + + describe "Bundler.clean_exec" do + let(:code) do + <<~RUBY + Process.fork do + exit Bundler.clean_exec(%(test "\$BUNDLE_FOO" = "bar")) + end + + _, status = Process.wait2 + + exit(status.exitstatus) + RUBY + end + it "runs exec inside with_clean_env" do - pid = Kernel.fork do - Bundler.clean_exec(%(echo 'if [ "$BUNDLE_PATH" = "" ]; then exit 42; else exit 1; fi' | /bin/sh)) - end - Process.wait(pid) - expect($?.exitstatus).to eq(42) + lib = File.expand_path("../../lib", __dir__) + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + expect($?.exitstatus).to eq(1) + end + end + + describe "Bundler.unbundled_exec" do + let(:code) do + <<~RUBY + Process.fork do + exit Bundler.unbundled_exec(%(test "\$BUNDLE_FOO" = "bar")) + end + + _, status = Process.wait2 + + exit(status.exitstatus) + RUBY + end + + it "runs exec inside with_clean_env" do + lib = File.expand_path("../../lib", __dir__) + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + expect($?.exitstatus).to eq(1) end end end |