-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Add a special bundler binstub that ensures the correct version is activated #5878
Conversation
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 like the approach, both to make the binstub load the correct version of Bundler even if the app changes from 1 to 2, and in the way the other binstubs are able to incorporate that check. 👍
How do you feel about shipping this binstub, or something very close to it, as the default RubyGems bundle
?
File.expand_path case File.basename(gemfile) | ||
when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile) | ||
else "#{gemfile}.lock" | ||
end |
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.
Can you use a variable so the case statement body isn't indented?
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.
Sure, this was lifted directly from postit 👍🏻
I actually have something different in mind for RubyGems, which will handle requiring Bundler/setup as well |
@indirect I believe this should work now, and I've made sure to run the file through rubocop |
88c1af9
to
ad7fbf2
Compare
Wow, green within a day! That's like a new record for me |
@indirect r? |
Awesome. @bundlerbot r+ |
📌 Commit ad7fbf2 has been approved by |
Add a special bundler binstub that ensures the correct version is activated ### What was the end-user problem that led to this PR? Closes #5876. > Once Bundler 2 ships, each application will depend on a 1.x or 2.x version of Bundler. We want to make sure that the user always has an _easy_ and _convenient_ way to activate the version of Bundler their app is depending upon. ### What was your diagnosis of the problem? > One way to ensure that the application will always get the version of Bundler that it needs is with an application-and-bundler-version specific binstub. Let's make it so that bundle binstubs bundler will generate a binstub for the correct version of Bundler, and simply running bin/bundle will always provide the correct version of Bundler. ### What is your fix for the problem, implemented in this PR? My fix implements a `bundle` binstub when `bundle binstubs bundler` is run ### Why did you choose this fix out of the possible options? I chose this fix because it allows us to dynamically select the correct Bundler version (with appropriate overrides, such as `$BUNDLER_VERSION` and `bundle update --bundler`), both when invoking `bin/bundle`, and also when invoking other bundler-generated binstubs.
☀️ Test successful - status-travis |
Ensure that an appropriate version of Bundler is always activated # Description: Closes #1974. This ensures that the `bundle` binstub, along with anything running `require "bundler/setup"` will respect, in order: 1. `ENV["BUNDLER_VERSION"]` 2. `bundle update --bundler` 3. The bundler version in the nearest `Gemfile.lock` See rubygems/bundler#5876 for further context, and rubygems/bundler#5878 for a related change to Bundler. # Tasks: - [x] Describe the problem / feature - [x] Write tests - [x] Write code to solve the problem - [ ] Get code review from coworkers / friends I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).
…irect 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.
…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.
What was the end-user problem that led to this PR?
Closes #5876.
We want to make sure that the user always has an easy and convenient way to activate the version of Bundler their app is depending upon.
What was your diagnosis of the problem?
What is your fix for the problem, implemented in this PR?
My fix implements a
bundle
binstub whenbundle binstubs bundler
is runWhy did you choose this fix out of the possible options?
I chose this fix because it allows us to dynamically select the correct Bundler version (with appropriate overrides, such as
$BUNDLER_VERSION
andbundle update --bundler
), both when invokingbin/bundle
, and also when invoking other bundler-generated binstubs.