diff options
author | Bundlerbot <bot@bundler.io> | 2019-03-27 03:37:00 +0000 |
---|---|---|
committer | Bundlerbot <bot@bundler.io> | 2019-03-27 03:37:00 +0000 |
commit | df8b92fa42efec18b0bd9cffa9dc6a6c7e99ee1c (patch) | |
tree | 810562294efc1bbd6da4f52843f7db1201c41ad4 | |
parent | 6f39ea5b15d61e5bdf7915bc94d66c31b1242d15 (diff) | |
parent | 20dd6657062c650505b81343e49febd9ad9461ee (diff) | |
download | bundler-df8b92fa42efec18b0bd9cffa9dc6a6c7e99ee1c.tar.gz |
Merge #7052
7052: Introduce `original_system`, `original_exec`, `unbundled_system`, and `unbundled_exec` r=indirect a=deivid-rodriguez
### What was the end-user problem that led to this PR?
The problem was that the `clean_system` and `clean_exec` would print deprecation messages, but there was not alternative for them.
### What was your diagnosis of the problem?
My diagnosis was that the helpers are using deprecated behavior and that we should provide non deprecated alternatives.
### What is your fix for the problem, implemented in this PR?
My fix is to introduce `original_system`, `original_exec`, `unbundled_system`, and `unbundled_exec` for consistency with the rest of the helpers, and deprecate `clean_system` and `clean_exec`.
### Why did you choose this fix out of the possible options?
I chose this fix because while maybe not super pretty names, they offer an alternative consistent with the other helpers.
Co-authored-by: David RodrÃguez <deivid.rodriguez@riseup.net>
-rw-r--r-- | lib/bundler.rb | 38 | ||||
-rw-r--r-- | spec/runtime/with_unbundled_env_spec.rb | 88 |
2 files changed, 115 insertions, 11 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/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 |