thoughtbot / appraisal

A Ruby library for testing your library against different versions of dependencies.
https://thoughtbot.com
MIT License
1.25k stars 107 forks source link

Could not find bundler 2.0.01 #152

Closed marten closed 5 years ago

marten commented 5 years ago

I'm running into a strange issue on our CI system. Bundler 2.0.1 is installed, it's also what's used if you check bundle version but the command to install Appraisal's gemfiles fails saying that it can't find bundler v2.0.1 (full error below).

I'm at a loss as to what this could be. It might not be Appraisal's fault, but I figured I'd try posting this here first, maybe someone has seen this before?

$ gem list
bigdecimal (default: 1.3.2)
bundler (2.0.1, default: 1.17.3)
did_you_mean (1.1.0)
io-console (default: 0.4.6)
json (default: 2.0.4)
minitest (5.10.1)
net-telnet (0.1.1)
openssl (default: 2.0.9)
power_assert (0.4.1)
psych (default: 2.2.2)
rake (12.0.0)
rdoc (default: 5.0.0)
rubygems-update (3.0.3)
test-unit (3.2.3)
xmlrpc (0.2.1)
$ bundle --version
Bundler version 2.0.1
$ bundle exec bundle version
Bundler version 2.0.1 (2019-01-04 commit d7ad2192f)
$ bundle exec appraisal install
>> bundle check --gemfile='/builds/roqua/quby_engine/gemfiles/rails50.gemfile' || bundle install --gemfile='/builds/roqua/quby_engine/gemfiles/rails50.gemfile'
/usr/local/lib/ruby/site_ruby/2.4.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.0.1) required by `$BUNDLER_VERSION`. (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.1`
    from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems.rb:302:in `activate_bin_path'
    from /usr/local/bundle/bin/bundle:23:in `<main>'
/usr/local/lib/ruby/site_ruby/2.4.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.0.1) required by `$BUNDLER_VERSION`. (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.1`
    from /usr/local/lib/ruby/site_ruby/2.4.0/rubygems.rb:302:in `activate_bin_path'
    from /usr/local/bundle/bin/bundle:23:in `<main>'
luong-komorebi commented 5 years ago

After digging appraisal source code as well as other resources, allow me to describe what is happening.

  1. For the context, please read https://github.com/bundler/bundler/issues/6882. TL;DR: Bundler 2. is having compatability issue with old bundle 1. . If your gemfile has been bundle with Bundle 2.x in the Gemfile.lock, then you can't use bundle install with bundler < 2., for example bundle v1.17.3
  2. The recommended way to fix this is:
    gem update --system # this update Ruby gems
    gem install bundle # to install the latest version of bundle 

    after this bundle install should be successful.

  3. Why is it not working for appraisal? In appraisal source code, every command, for example bundle exec appraisal make me a god will go through a bunch of processing. Essentially, if the command has no bundle exec, it will be appended bundle exec -> the above example would turn into bundle exec make me a god and executed in the code by Kernel.system(bundle exec make me a god). Now let's say make me a god have a compatibility problem with bundler that we already fixed above, it should be working right? The answer is no. Because here: https://github.com/thoughtbot/appraisal/blob/c4af85912d26bd4a730d739c44a5070b6de4bd4b/lib/appraisal/command.rb#L69-L74

In these lines, an important ENV is reset. It is RUBYOPT. I wont go into details what this ENV do and why the chose to reset it, but:

$ bundle exec irb
irb(main):003:0> `gem list bundle`
=> "bundler (2.0.1)\n"
irb(main):007:0> ENV['RUBYOPT'] = nil
=> nil
irb(main):008:0> `gem list bundle`
=> "bundler (default: 1.17.3)\n"

and then our commands will stop working.

The solution right now in my opinion is to rollback to using the old version of bundler or ignore appraisals' gemfiles' gemfile.lock in your code. After all, this problem is from the bundler team, not Appraisal so fixing this here does not make sense to me.

marten commented 5 years ago

I'm so sorry I didn't get around to saying how awesome this reply is sooner. Thanks so much for this above and beyond investigation, especially when the fix, as you explain, belongs in Bundler rather than Appraisal. 🥇