From 031ac503f9ceca763abe77136ff5da01e5d0bed6 Mon Sep 17 00:00:00 2001 From: The Bundler Bot Date: Tue, 5 Dec 2017 06:07:14 +0000 Subject: [PATCH] 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 `
' ``` ### 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. --- lib/bundler/templates/Executable | 6 +++--- 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 9289debc262..4e35e586dba 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 388ee049d09..dcee234e152 100644 --- a/spec/runtime/executable_spec.rb +++ b/spec/runtime/executable_spec.rb @@ -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