From 0f62f28b21c5ece35d26aaf6d822976ad8af1ee1 Mon Sep 17 00:00:00 2001 From: Paul Nikitochkin Date: Sat, 2 Dec 2017 18:04:41 +0200 Subject: [PATCH] Setup Gemfile path before loading bundler in order to use original Gemfile --- 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