This repository has been archived by the owner on Apr 14, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Replace hardcoded gemfile path with methods to discover Gemfile for bundle binstub #6469
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,67 @@ | |
end | ||
end | ||
end | ||
|
||
context "when working with multiple gemfiles" do | ||
let(:bundle_binstub) { bundled_app("bin/bundle") } | ||
let(:load_bundle_exe) { "load Gem.bin_path(\"bundler\", \"bundle\")" } | ||
let(:output_bundle_gemfile) { "puts ENV[\"BUNDLE_GEMFILE\"]" } | ||
|
||
before do | ||
build_repo2 do | ||
build_gem "print_hello", "1.0" do |s| | ||
s.executables = "print_hello" | ||
s.bindir = "exe" | ||
s.write "exe/print_hello", <<-R | ||
puts "Hello!" | ||
R | ||
end | ||
build_gem "print_goodbye", "1.0" do |s| | ||
s.executables = "print_goodbye" | ||
s.bindir = "exe" | ||
s.write "exe/print_goodbye", <<-R | ||
puts "Goodbye." | ||
R | ||
end | ||
end | ||
|
||
bundle! "config --global path #{bundled_app}" | ||
bundle! "config --global bin #{bundled_app("bin")}" | ||
|
||
install_gemfile! <<-G | ||
source "file://#{gem_repo2}" | ||
G | ||
bundle! "binstubs bundler" | ||
end | ||
|
||
it "uses the correct Gemfile" do | ||
create_file "one/Gemfile", <<-G | ||
source "file://#{gem_repo2}" | ||
gem "print_hello" | ||
G | ||
create_file "two/Gemfile", <<-G | ||
source "file://#{gem_repo2}" | ||
gem "print_goodbye" | ||
G | ||
Dir.chdir("one") { bundle! "install" } | ||
Dir.chdir("two") { bundle! "install" } | ||
|
||
binstub = File.read(bundled_app("bin/bundle")) | ||
# Replace load statement with BUNDLE_GEMFILE puts | ||
binstub.gsub!(load_bundle_exe, output_bundle_gemfile) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we put these in the binstub for the gem, so that way we won't have to mess with the file we're supposed to be testing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 I don't believe so... I tried a few different ways, but |
||
File.open(bundle_binstub, "w") {|f| f.puts binstub } | ||
|
||
Dir.chdir("one") do | ||
sys_exec "#{bundled_app("bin/bundle")} exec print_hello" | ||
expect(out).to eq(bundled_app("one/Gemfile").to_s) | ||
end | ||
|
||
Dir.chdir("two") do | ||
sys_exec "#{bundled_app("bin/bundle")} exec print_goodbye" | ||
expect(out).to eq(bundled_app("two/Gemfile").to_s) | ||
end | ||
end | ||
end | ||
end | ||
|
||
it "installs binstubs from git gems" do | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this use the binstub directory instead of the current working directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be the current working directory. If a Gemfile is not found in that current directory it should continue searching upwards to find a Gemfile, similar to
SharedHelpers.find_gemfile
.The problem that this PR addresses is that when a bundler binstub is created and then used to install other gem executables, the bundler binstub currently stores the path of the Gemfile used in the last successful
bundle install
. Trying to runbundle exec
when bundling against multiple gemfiles could result in aGem::Exception
orLoadError
because bundler may not be using the correct Gemfile path.From #6162:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but this isn't
bundle exec foo
, this isbin/foo
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure I follow...
This particular template,
lib/bundler/templates/Executable.bundler
, sets up a special bundler binstub that ensures the correct version of bundler is activated (commit). Whenbundle exec foo
is run, this binstub is executed and loads a version of bundler.The bundler binstub sets
ENV['BUNDLE_GEMFILE']
, which is then passed along to bundler. At this point, ifENV['BUNDLE_GEMFILE']
is pointing to a gemfile that doesn't includefoo
, aGem::Exception
orLoadError
may be raised even ifbin/foo
exists.Not sure if this helps, but it may be easier to follow through this Bundler repro script for bundler issue 6154.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, but you quoted me documentation for
bundle exec
, and how it should find a gemfile. Shouldn't thebundle binstubs
binstubs always refer to the Gemfile they were generated with, even if executed from another directory?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you're saying... yes, I agree, except in the case of bundler itself (
bin/bundle
). The binstub for bundle shouldn't refer to the Gemfile that it was generated with as it runs into the previously mentioned issues.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only thing is that the other binstubs all use the same logic as the
bundle
binstubs when it comes to this, iircThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's okay if the non-bundler binstubs store the path of the gemfile that created them, but the act of using the bundler binstub to load another gem doesn't always work (
bin/bundle exec foo
).