rubygems / bundler

Manage your Ruby application's gem dependencies
https://bundler.io
MIT License
4.88k stars 1.99k forks source link

2.1.0+ breaks bundler/inline #7536

Closed cheald closed 4 years ago

cheald commented 4 years ago

bundle -v Bundler version 2.1.3

require "bundler/inline"
gemfile do
  source "https://rubygems.org"
  gem "capistrano", require: false
end

require "capistrano/all"

Results in "Could not locate Gemfile":

 Traceback (most recent call last):
        27: from cap.rb:7:in `<main>'
        26: from cap.rb:7:in `require'
        25: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/capistrano-3.11.2/lib/capistrano/all.rb:2:in `<top (required)>'
        24: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/capistrano-3.11.2/lib/capistrano/all.rb:2:in `require'
        23: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit.rb:29:in `<top (required)>'
        22: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit.rb:29:in `require_relative'
        21: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/all.rb:37:in `<top (required)>'
        20: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/all.rb:37:in `require_relative'
        19: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/netssh.rb:4:in `<top (required)>'
        18: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/netssh.rb:4:in `require'
        17: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh.rb:11:in `<top (required)>'
        16: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh.rb:11:in `require'
        15: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh/transport/session.rb:6:in `<top (required)>'
        14: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh/transport/session.rb:6:in `require'
        13: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh/transport/algorithms.rb:1:in `<top (required)>'
        12: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh/transport/algorithms.rb:1:in `require'
        11: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh/buffer.rb:5:in `<top (required)>'
        10: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh/buffer.rb:5:in `require'
         9: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh/authentication/ed25519_loader.rb:1:in `<top (required)>'
         8: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh/authentication/ed25519_loader.rb:2:in `<module:Net>'
         7: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh/authentication/ed25519_loader.rb:3:in `<module:SSH>'
         6: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh/authentication/ed25519_loader.rb:7:in `<module:Authentication>'
         5: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh/authentication/ed25519_loader.rb:10:in `<module:ED25519Loader>'
         4: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh/authentication/ed25519_loader.rb:10:in `require'
         3: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/net-ssh-5.2.0/lib/net/ssh/authentication/ed25519.rb:1:in `<top (required)>'
         2: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.1.3/lib/bundler/rubygems_integration.rb:333:in `block (2 levels) in replace_gem'
         1: from .rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.1.3/lib/bundler.rb:434:in `default_gemfile'
.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.1.3/lib/bundler/shared_helpers.rb:21:in `default_gemfile': Could not locate Gemfile (Bundler::GemfileNotFound)

This works fine under Bundler 2.0.1 and earlier.

cheald commented 4 years ago

It seems likely that it's related to this change: https://github.com/bundler/bundler/pull/7418/files

Under Bundler 2.0.1, ENV["BUNDLE_GEMFILE"] after requiring bundler/inline is "Gemfile". Under 2.1.3 is it nil. Manually setting ENV["BUNDLE_GEMFILE"] = "Gemfile" causes it to work again.

It is worth noting that in my case, there is no file named Gemfile in the directory we're executing in, or any parent directory.

~/projects/isolate  ll
.rw-rw-r--  chris  chris  169 B  Thu Jan  2 09:28:49 2020    cap.rb
~/projects/isolate  ruby cap.rb
~/projects/isolate  echo $?
0
~/projects/isolate  cat cap.rb
require "bundler/inline"
gemfile do
  source "https://rubygems.org"
  gem "capistrano", require: false
end

ENV["BUNDLE_GEMFILE"] = "Gemfile"

require "capistrano/all"
cheald commented 4 years ago

https://github.com/bundler/bundler/blob/master/lib/bundler/shared_helpers.rb#L229-L233

It appears that when ENV["BUNDLE_GEMFILE"] is nil, bundler attempts to actually find files on disk matching the default filenames. When it is given, Bundler doesn't perform any existence check. Because bundler 2.1.0+ "restores" a nil BUNDLE_GEMFILE, we end up doing a file check for gems.rb and Gemfile, which don't exist because...we're using an inline gemfile.

My intuition here is that we want to restore BUNDLE_GEMFILE only in the case that it previously had a value. Otherwise, we want to leave it set to something so that we don't attempt to go find files that probably aren't there.

deivid-rodriguez commented 4 years ago

That makes sense @cheald. Let me try fix this.

deivid-rodriguez commented 4 years ago

Can you try out #7537?

cheald commented 4 years ago

That seems to have done the trick.