Skip to content

Fix bundler rubygems binstub not properly looking for bundler#2426

Merged
2 commits merged intoruby:masterfrom
deivid-rodriguez:fix_binstubs_finding_bundler
Nov 13, 2018
Merged

Fix bundler rubygems binstub not properly looking for bundler#2426
2 commits merged intoruby:masterfrom
deivid-rodriguez:fix_binstubs_finding_bundler

Conversation

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

@deivid-rodriguez deivid-rodriguez commented Oct 5, 2018

Description:

The problem is that when running a rubygems bundler binstub with a lock file locked to a non-installed bundler version, one would get the cryptic error message:

can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

where one tends to think... What? How is it not found if I just run it?!

Partially closes rubygems/bundler#6595. Now the message is way more clear, but I guess it'd be better to actually run the command. Not sure if that's possible from a rubygems binstub, though.

Tasks:

  • Describe the problem / feature
  • Write tests
  • Write Delete code to solve the problem
  • Get code review from coworkers / friends

I will abide by the code of conduct.

@segiddins
Copy link
Copy Markdown
Contributor

How is this fixing the issue?

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

Because when you run the spec with this patch applied you get what you want, but when run without the patch you don't... 🤣.

Seriously, I'm not sure. I'll comment over the code and throw some guesses.

@without_filtering = false

def self.without_filtering
without_filtering, @without_filtering = true, @without_filtering
Copy link
Copy Markdown
Contributor Author

@deivid-rodriguez deivid-rodriguez Oct 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I have no idea what this filtering intends to do, but I think the problem is that here the assignment is inverted (it should be without_filtering, @without_filtering = @without_filtering, true). That means that once the instance variable is set to true, it's never switched back. Since this variable is used further below in the bundler_version_with_reason method to prevent the method from returning an useful message, that's what it ends up happening.

So, I think this could also be fixed by inverting the assignment but I wonder what we're trying to achieve with all this untested code... 🤷‍♂️.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 yeah I think that sounds right

@deivid-rodriguez deivid-rodriguez force-pushed the fix_binstubs_finding_bundler branch from 6db1bf2 to 6f32146 Compare October 6, 2018 12:38
@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

I managed to write a spec for this! 👍

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

Also, I think this fix might mean that bundler 2 should require rubygems 2.7.8 or higher?

@deivid-rodriguez deivid-rodriguez force-pushed the fix_binstubs_finding_bundler branch from 6f32146 to 11b0171 Compare October 21, 2018 18:31
@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

I rebased this PR and also correct a typo, and a test description.

@deivid-rodriguez deivid-rodriguez force-pushed the fix_binstubs_finding_bundler branch from 11b0171 to d2b3827 Compare November 11, 2018 16:21
@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

I think this is important for the bundler + rubygems integration. Any more thoughts / reviews?

@deivid-rodriguez deivid-rodriguez force-pushed the fix_binstubs_finding_bundler branch from d2b3827 to fa9c3b6 Compare November 12, 2018 00:00
@hsbt
Copy link
Copy Markdown
Member

hsbt commented Nov 13, 2018

@bundlerbot r+

ghost pushed a commit that referenced this pull request Nov 13, 2018
2426: Fix bundler rubygems binstub not properly looking for bundler r=hsbt a=deivid-rodriguez

# Description:

The problem is that when running a rubygems bundler binstub with a lock file locked to a non-installed bundler version, one would get the cryptic error message:

```
can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
```

where one tends to think... What? How is it not found if I just run it?!

Partially closes rubygems/bundler#6595. Now the message is way more clear, but I guess it'd be better to actually run the command. Not sure if that's possible from a rubygems binstub, though.

# Tasks:

- [x] Describe the problem / feature
- [x] Write tests
- [x] ~Write~ Delete 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).


Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
@ghost
Copy link
Copy Markdown

ghost commented Nov 13, 2018

Build succeeded

@ghost ghost merged commit fa9c3b6 into ruby:master Nov 13, 2018
@deivid-rodriguez deivid-rodriguez deleted the fix_binstubs_finding_bundler branch November 13, 2018 11:50
@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

Thanks! 😃

matzbot pushed a commit to ruby/ruby that referenced this pull request Nov 21, 2018
  * Enable Style/MethodDefParentheses in Rubocop
    ruby/rubygems#2478
  * Enable Style/MultilineIfThen in Rubocop
    ruby/rubygems#2479
  * Fix required_ruby_version with prereleases and improve error message
    ruby/rubygems#2344
  * Fix bundler rubygems binstub not properly looking for bundler
    ruby/rubygems#2426

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
ioquatix pushed a commit to ioquatix/ruby that referenced this pull request Nov 22, 2018
  * Enable Style/MethodDefParentheses in Rubocop
    ruby/rubygems#2478
  * Enable Style/MultilineIfThen in Rubocop
    ruby/rubygems#2479
  * Fix required_ruby_version with prereleases and improve error message
    ruby/rubygems#2344
  * Fix bundler rubygems binstub not properly looking for bundler
    ruby/rubygems#2426

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
@hsbt hsbt added this to the 2.7.9 milestone Dec 5, 2018
bannable pushed a commit to bannable/ruby that referenced this pull request Dec 10, 2018
  * Enable Style/MethodDefParentheses in Rubocop
    ruby/rubygems#2478
  * Enable Style/MultilineIfThen in Rubocop
    ruby/rubygems#2479
  * Fix required_ruby_version with prereleases and improve error message
    ruby/rubygems#2344
  * Fix bundler rubygems binstub not properly looking for bundler
    ruby/rubygems#2426

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
schneems added a commit to heroku/heroku-buildpack-ruby that referenced this pull request Feb 6, 2019
## Problem 1

Bundler 2.x cannot be used with a Gemfile.lock that specifies bundler 1.x:

```
BUNDLED WITH
   1.16.4
```

If you try, then Bundler 2.x will look for an installed bundler 1.x version and try to use it. If no such version exists on the system then an error is thrown:


```
can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
```


- ruby/rubygems#2426
- ruby/rubygems#2515


## Problem 2

Likewise a version of bundler 1.x cannot be used on a project where a `BUNDLED WITH` specifies 2.x:


```
$ bundle -v
1.17.3
$ cat Gemfile.lock | grep -A 1 BUNDLED WITH
BUNDLED WITH
  2.0.1
$ bundle
Traceback (most recent call last):
	2: from /Users/rschneeman/.gem/ruby/2.6.0/bin/bundle:23:in `<main>'
	1: from /Users/rschneeman/.rubies/ruby-2.6.0/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
/Users/rschneeman/.rubies/ruby-2.6.0/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.0.0) required by your /private/tmp/default_ruby/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.0.0`
```

This is due to a bug in Rubygems 3.x ruby/rubygems#2592


## Proposed Solution

This PR implements a solution where we have a different "blessed" version of bundler for each major version. 

The way this is implemented is to read in a Gemfile.lock and to read in the `BUNDLED WITH` value. Then the major version is pulled out and converted into a "blessed" version.

This allows for multiple major versions of bundler to be used on Heroku without sacrificing stability.
hsbt pushed a commit that referenced this pull request Mar 6, 2019
2426: Fix bundler rubygems binstub not properly looking for bundler r=hsbt a=deivid-rodriguez

# Description:

The problem is that when running a rubygems bundler binstub with a lock file locked to a non-installed bundler version, one would get the cryptic error message:

```
can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
```

where one tends to think... What? How is it not found if I just run it?!

Partially closes rubygems/bundler#6595. Now the message is way more clear, but I guess it'd be better to actually run the command. Not sure if that's possible from a rubygems binstub, though.

# Tasks:

- [x] Describe the problem / feature
- [x] Write tests
- [x] ~Write~ Delete 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).


Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
(cherry picked from commit 9b1c44a)
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bundler 1 crashes on gemfiles generated using bundler 2

4 participants