Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Add a special bundler binstub that ensures the correct version is activated #5878

Merged
merged 5 commits into from
Jul 24, 2017

Conversation

segiddins
Copy link
Member

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.

Copy link
Member

@indirect indirect left a 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
Copy link
Member

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?

Copy link
Member Author

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 👍🏻

@segiddins
Copy link
Member Author

I actually have something different in mind for RubyGems, which will handle requiring Bundler/setup as well

@segiddins
Copy link
Member Author

@indirect I believe this should work now, and I've made sure to run the file through rubocop

@segiddins segiddins force-pushed the seg-bundler-binstubs branch from 88c1af9 to ad7fbf2 Compare July 21, 2017 14:37
@segiddins
Copy link
Member Author

Wow, green within a day! That's like a new record for me

@segiddins
Copy link
Member Author

@indirect r?

@indirect
Copy link
Member

Awesome. @bundlerbot r+

@bundlerbot
Copy link
Collaborator

📌 Commit ad7fbf2 has been approved by indirect

@bundlerbot
Copy link
Collaborator

⌛ Testing commit ad7fbf2 with merge 631231d...

bundlerbot added a commit that referenced this pull request Jul 24, 2017
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.
@bundlerbot
Copy link
Collaborator

☀️ Test successful - status-travis
Approved by: indirect
Pushing 631231d to master...

@bundlerbot bundlerbot merged commit ad7fbf2 into master Jul 24, 2017
@segiddins segiddins deleted the seg-bundler-binstubs branch July 24, 2017 22:47
bundlerbot added a commit to rubygems/rubygems that referenced this pull request Aug 27, 2017
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).
bundlerbot added a commit that referenced this pull request Dec 5, 2017
…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.
hsbt pushed a commit to hsbt/bundler that referenced this pull request Dec 11, 2017
…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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Special-case binstubs bundler for the app's bundler version
3 participants