Skip to content

Commit

Permalink
Auto merge of rubygems#6201 - jetthoughts:binstub-use-gemfile-from-en…
Browse files Browse the repository at this point in the history
…v, r=indirect

Setup custom Gemfile path before loading bundler for binstubs

### What was the end-user problem that led to this PR?

While you have several gemfiles: `Gemfile` and `Gemfile.tools`.
and generates binstubs for gems from second gemfile: `BUNDLE_GEMFILE=Gemfile.tools bundle binstubs rubocop`
when you invoke those bin `bin/rubocop`
then you see error like:

```bash
/usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.16.0/lib/bundler/rubygems_integration.rb:458:in `block in replace_bin_path': can't find executable rubocop for gem rubocop. rubocop is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)
	from /usr/local/opt/rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.16.0/lib/bundler/rubygems_integration.rb:489:in `block in replace_bin_path'
	from bin/rubocop:21:in `<main>'
```

### What was your diagnosis of the problem?

When you have generated `bin/bundler` by rails or by `bundler` it has setup of `BUNDLE_GEMFILE` by default as `Gemfile` or by gemfile which has been setup on `bundle binstub bundler`.

So your binstub for rubocop could not change it.

### What is your fix for the problem, implemented in this PR?

I propose to use`BUNDLE_GEMFILE` from gem's binstub over bundler's binstub version

### Why did you choose this fix out of the possible options?

This was default behavior before rubygems#5878 introduced. Just added some fix to related PR.
  • Loading branch information
bundlerbot authored and hsbt committed Dec 11, 2017
1 parent a848576 commit 031ac50
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/bundler/templates/Executable
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
# this file is here to facilitate running it.
#

bundle_binstub = File.expand_path("../bundle", __FILE__)
load(bundle_binstub) if File.file?(bundle_binstub)

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../<%= relative_gemfile_path %>",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)
load(bundle_binstub) if File.file?(bundle_binstub)

require "rubygems"
require "bundler/setup"

Expand Down
29 changes: 29 additions & 0 deletions spec/runtime/executable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,33 @@

expect(bundled_app("bin/rackup").read).to_not eq("OMG")
end

it "use BUNDLE_GEMFILE gemfile for binstub" do
# context with bin/bunlder w/ default Gemfile
bundle! "binstubs bundler"

# generate other Gemfile with executable gem
build_repo2 do
build_gem("bindir") {|s| s.executables = "foo" }
end

create_file("OtherGemfile", <<-G)
source "file://#{gem_repo2}"
gem 'bindir'
G

# generate binstub for executable from non default Gemfile (other then bin/bundler version)
ENV["BUNDLE_GEMFILE"] = "OtherGemfile"
bundle "install"
bundle! "binstubs bindir"

# remove user settings
ENV["BUNDLE_GEMFILE"] = nil

# run binstub for non default Gemfile
gembin "foo"

expect(exitstatus).to eq(0) if exitstatus
expect(out).to eq("1.0")
end
end

0 comments on commit 031ac50

Please sign in to comment.