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

Commit

Permalink
Merge #7052
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bundlerbot and deivid-rodriguez committed Mar 27, 2019
2 parents 6f39ea5 + 20dd665 commit df8b92f
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 11 deletions.
38 changes: 36 additions & 2 deletions lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,46 @@ def with_unbundled_env
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
Expand Down
88 changes: 79 additions & 9 deletions spec/runtime/with_unbundled_env_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,90 @@ def build_bundler_context
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

0 comments on commit df8b92f

Please sign in to comment.