Skip to content

Commit

Permalink
Allow support for BUNDLE_WITHOUT with spaces (#1083)
Browse files Browse the repository at this point in the history
In v218 we switched from configuring bundler via flags to env vars. It turns out that bundler supports defining an `--without` value with a space in it, but it does not support BUNDLE_WITHOUT with a space in it:

```
$ bundle install --without foo bar
$ bundle config | grep without -a1

without
Set for your local app (/private/tmp/40a4b42d7e884ebf62a1f85a3c5abd38/.bundle/config): [:foo, :bar]
```

But:

```
$ BUNDLE_WITHOUT="foo bar" bundle config | grep without -a1

without
Set via BUNDLE_WITHOUT: [:"foo bar"]
```

> Note in this example it is showing `:"foo bar"` as one group instead of two values.

To fix this, we can reproduce the bundler logic of replacing a space with a colon https://github.com/rubygems/rubygems/blob/ce27b98272d5c37ebf45b2b1b66894699ae47d58/bundler/lib/bundler/cli/install.rb#L151. 

Related ticket: https://heroku.support/924687
  • Loading branch information
schneems authored Oct 7, 2020
1 parent 6b27d65 commit 140fe67
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Main (unreleased)

* BUNDLE_WITHOUT now accommodates values with single spaces (https://github.com/heroku/heroku-buildpack-ruby/pull/1083)

## v219 (8/6/2020)

* Fix double installation of bundler on CI runs when no test script is specified (https://github.com/heroku/heroku-buildpack-ruby/pull/1073)
Expand Down
7 changes: 6 additions & 1 deletion lib/language_pack/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ def setup_language_pack_environment(ruby_layer_path:, gem_layer_path:, bundle_pa
ENV["PATH"] = paths.join(":")

ENV["BUNDLE_WITHOUT"] = env("BUNDLE_WITHOUT") || bundle_default_without
if ENV["BUNDLE_WITHOUT"].include?(' ')
ENV["BUNDLE_WITHOUT"] = ENV["BUNDLE_WITHOUT"].tr(' ', ':')

warn("Your BUNDLE_WITHOUT contains a space, we are converting it to a colon `:` BUNDLE_WITHOUT=#{ENV["BUNDLE_WITHOUT"]}", inline: true)
end
ENV["BUNDLE_PATH"] = bundle_path
ENV["BUNDLE_BIN"] = bundler_binstubs_path
ENV["BUNDLE_DEPLOYMENT"] = "1"
Expand Down Expand Up @@ -900,7 +905,7 @@ def build_bundler
end

bundle_command = String.new("")
bundle_command << "BUNDLE_WITHOUT=#{ENV["BUNDLE_WITHOUT"]} "
bundle_command << "BUNDLE_WITHOUT='#{ENV["BUNDLE_WITHOUT"]}' "
bundle_command << "BUNDLE_PATH=#{ENV["BUNDLE_PATH"]} "
bundle_command << "BUNDLE_BIN=#{ENV["BUNDLE_BIN"]} "
bundle_command << "BUNDLE_DEPLOYMENT=#{ENV["BUNDLE_DEPLOYMENT"]} " if ENV["BUNDLE_DEPLOYMENT"] # Unset on windows since we delete the Gemfile.lock
Expand Down
9 changes: 9 additions & 0 deletions spec/hatchet/bundler_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
require 'spec_helper'

describe "Bundler" do
it "can be configured with BUNDLE_WITHOUT env var with spaces in it" do
Hatchet::Runner.new("default_ruby", config: {"BUNDLE_WITHOUT" => "foo bar baz"}).tap do |app|
app.deploy do
expect(app.output).to match("BUNDLE_WITHOUT='foo:bar:baz'")
expect(app.output).to match("Your BUNDLE_WITHOUT contains a space")
end
end
end

it "deploys with version 2.x with Ruby 2.5" do
ruby_version = "2.5.7"
abi_version = ruby_version.dup
Expand Down

0 comments on commit 140fe67

Please sign in to comment.