diff options
author | The Bundler Bot <bot@bundler.io> | 2017-12-05 06:07:14 +0000 |
---|---|---|
committer | SHIBATA Hiroshi <hsbt@ruby-lang.org> | 2017-12-11 20:42:18 +0900 |
commit | 031ac503f9ceca763abe77136ff5da01e5d0bed6 (patch) | |
tree | 7219bc6b70e3d903d5db92dc15d77a5f5d09e8fc | |
parent | a8485767d3dcf531fc9b0f1c84dcd55cd402ee4b (diff) | |
download | bundler-031ac503f9ceca763abe77136ff5da01e5d0bed6.tar.gz |
Auto merge of #6201 - jetthoughts:binstub-use-gemfile-from-env, 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 #5878 introduced. Just added some fix to related PR.
-rwxr-xr-x | lib/bundler/templates/Executable | 6 | ||||
-rw-r--r-- | spec/runtime/executable_spec.rb | 29 |
2 files changed, 32 insertions, 3 deletions
diff --git a/lib/bundler/templates/Executable b/lib/bundler/templates/Executable index 9289debc26..4e35e586db 100755 --- a/lib/bundler/templates/Executable +++ b/lib/bundler/templates/Executable @@ -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" diff --git a/spec/runtime/executable_spec.rb b/spec/runtime/executable_spec.rb index 388ee049d0..dcee234e15 100644 --- a/spec/runtime/executable_spec.rb +++ b/spec/runtime/executable_spec.rb @@ -158,4 +158,33 @@ RSpec.describe "Running bin/* commands" do 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 |