Project

General

Profile

Actions

Feature #17883

closed

Load bundler/setup earlier to make `bundle exec ruby -r` respect Gemfile

Added by mame (Yusuke Endoh) almost 3 years ago. Updated almost 3 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:104004]

Description

To reproduce the issue, prepare a Gemfile and run bundle install --path=vendor/bundle.

$ cat Gemfile
source "https://rubygems.org"
gem "activesupport"

$ bundle install --path=vendor/bundle

Kernel#require respects the Gemfile correctly.

$ bundle exec ruby -e 'require "active_support"'

However, bundle exec ruby -ractive_support -e '' does not.

$ bundle exec ruby -ractive_support -e ''
<internal:/home/mame/work/ruby/local/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- active_support (LoadError)
        from <internal:/home/mame/work/ruby/local/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'

We can work around the issue by explicitly passing -rbundler/setup before -ractive_support, but this is very confusing to me. The same issue was discussed in StackOverflow: https://stackoverflow.com/questions/59623068/correct-way-to-combine-bundle-exec-and-ruby-r


Here is my analysis. bundle exec sets RUBYOPT=-rbundler/setup which replaces Kernel#require with bundler's own definition. -e 'require "active_support"' correctly triggers bundler's definition. However, -ractive_support is evaluated before RUBYOPT=-rbundler/setup is evaluated, so it triggers rubygems' require definition which does not know vendor/bundle directory.

This is caused by the interpretation order of RUBYOPT and command-line arguments.

$ RUBYOPT=-r./a ruby -r./b -e ''
:b
:a

For compatibility, I don't think that changing the order is a good idea. IMO, it would be good for ruby interpreter to provide Bundler something special, because Bundler is now bundled with Ruby.

My naive idea is to make the interpreter load ENV["BUNDLE_BIN_PATH"] + "../../lib/bundler/setup" before any other -r options if BUNDLE_BIN_PATH is defined. Or another new dedicated environment variable that bundle exec sets may work (for example, RUBY_BUNDLER_SETUP or something).

@deivid (David Rodríguez) @nobu (Nobuyoshi Nakada) What do you think?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0