Skip to content

[Bug #21723] Let force_activate() succeed when Gemfile contains path:#15373

Merged
hsbt merged 4 commits intoruby:masterfrom
osyoyu:fix-binding-irb-fail
Jan 15, 2026
Merged

[Bug #21723] Let force_activate() succeed when Gemfile contains path:#15373
hsbt merged 4 commits intoruby:masterfrom
osyoyu:fix-binding-irb-fail

Conversation

@osyoyu
Copy link
Copy Markdown
Contributor

@osyoyu osyoyu commented Dec 2, 2025

This patch fixes a problem where binding.irb (= force_activate('irb')) fails under bundle exec when the Gemfile does not contain irb and does contain a gem which is (1) not installed in GEM_HOME (2) sourced using path:/git:.

The original approach constructing a temporary definition fails since it does not set the equalivent of path:/git:.

Always reconstructing a definition from a Gemfile and applying lockfile constraints should be a more robust approach.

[Bug #21723]

…vate()

This patch fixes a problem where `binding.irb` (= force_activate('irb'))
fails under `bundle exec` when the Gemfile does not contain `irb` and
does contain a gem which is (1) not installed in GEM_HOME (2) sourced
using `path:`/`git:`.

The original approach constructing a temporary definition fails since
it does not set the equalivent of `path:`/`git:`.

Always reconstructing a definition from a Gemfile and applying lockfile
constraints should be a more robust approach.

[Bug #21723]
@hsbt
Copy link
Copy Markdown
Member

hsbt commented Dec 4, 2025

Is this working with bundler/inline? Bundler.default_gemfile will raise Bundler::GemfileNotFound under the bundler/inline.

I confirmed that with this change and https://github.com/ruby/ruby/blob/master/spec/bundled_gems_spec.rb#L366. You can run that with make bundled_gems_spec-run.

@osyoyu
Copy link
Copy Markdown
Contributor Author

osyoyu commented Dec 4, 2025

Nice catch -- this indeed doesn't work. But that isn't this patch's fault, the same error reproduces on master.

@osyoyu
Copy link
Copy Markdown
Contributor Author

osyoyu commented Dec 4, 2025

% ruby -v -rbundler/inline -e 'gemfile {}; binding.irb'
ruby 4.0.0dev (2025-12-04T09:08:23Z master 8099e9d2d1) +PRISM [x86_64-linux]
last_commit=[DOC] Fix a macro name
-e:1: warning: irb used to be loaded from the standard library, but is not part of the default gems since Ruby 4.0.0.
You can add irb to your Gemfile or gemspec to fix this error.
/home/osyoyu/.rbenv/versions/master/lib/ruby/4.0.0+0/bundler/shared_helpers.rb:21:in 'Bundler::SharedHelpers#default_gemfile': Could not locate Gemfile (Bundler::GemfileNotFound)
        from /home/osyoyu/.rbenv/versions/master/lib/ruby/4.0.0+0/bundler/shared_helpers.rb:29:in 'Bundler::SharedHelpers#default_lockfile'
        from /home/osyoyu/.rbenv/versions/master/lib/ruby/4.0.0+0/bundler/shared_helpers.rb:304:in 'Bundler::SharedHelpers#set_bundle_variables'
        from /home/osyoyu/.rbenv/versions/master/lib/ruby/4.0.0+0/bundler/shared_helpers.rb:79:in 'Bundler::SharedHelpers#set_bundle_environment'
        from /home/osyoyu/.rbenv/versions/master/lib/ruby/4.0.0+0/bundler/runtime.rb:20:in 'Bundler::Runtime#setup'
        from /home/osyoyu/.rbenv/versions/master/lib/ruby/4.0.0+0/bundled_gems.rb:224:in 'Gem::BUNDLED_GEMS.force_activate'
        from -e:1:in 'Binding#irb'
        from -e:1:in '<main>'
/home/osyoyu/.rbenv/versions/master/lib/ruby/4.0.0+0/bundled_gems.rb:60:in 'Kernel.require': cannot load such file -- irb (LoadError)
Did you mean?  erb
        from /home/osyoyu/.rbenv/versions/master/lib/ruby/4.0.0+0/bundled_gems.rb:60:in 'block (2 levels) in Kernel#replace_require'
        from -e:1:in 'Binding#irb'
        from -e:1:in '<main>'

@hsbt
Copy link
Copy Markdown
Member

hsbt commented Dec 4, 2025

I didn't say about binding.irb. This change lead to fail with make bundled_gems_spec-run.

❯ make bundled_gems_spec-run
generating known_errors.inc
generating encdb.h
generating enc.mk
known_errors.inc unchanged
encdb.h unchanged
making enc
making srcs under enc
generating transdb.h
transdb.h unchanged
making trans
generating makefiles ext/configure-ext.mk
making encs
ext/configure-ext.mk updated
generating makefile exts.mk
exts.mk unchanged
generating known_errors.inc
known_errors.inc unchanged

Randomized with seed 5903
...............F..

Failures:

  1) bundled_gems.rb .force_activate without bundle environment warns about installation requirement
     Failure/Error: raise GemfileNotFound, "Could not locate Gemfile" unless gemfile

     Bundler::GemfileNotFound:
       Could not locate Gemfile
     # ./lib/bundler.rb:448:in 'Bundler.default_lockfile'
     # ./lib/bundled_gems.rb:208:in 'Gem::BUNDLED_GEMS.force_activate'
     # ./spec/bundled_gems_spec.rb:399:in 'block (4 levels) in <top (required)>'
     # ./spec/bundled_gems_spec.rb:39:in 'block (4 levels) in <top (required)>'
     # ./spec/bundled_gems_spec.rb:39:in 'block (3 levels) in <top (required)>'
     # ./spec/bundler/support/helpers.rb:358:in 'block in Spec::Helpers#with_gem_path_as'
     # ./spec/bundler/support/helpers.rb:372:in 'Spec::Helpers#without_env_side_effects'
     # ./spec/bundler/support/helpers.rb:353:in 'Spec::Helpers#with_gem_path_as'
     # ./spec/bundled_gems_spec.rb:38:in 'block (2 levels) in <top (required)>'
     # ./lib/rubygems.rb:303:in 'Kernel#load'
     # ./lib/rubygems.rb:303:in 'Gem.activate_and_load_bin_path'

Finished in 10.68 seconds (files took 0.77813 seconds to load)
18 examples, 1 failure

Failed examples:

rspec ./spec/bundled_gems_spec.rb:397 # bundled_gems.rb .force_activate without bundle environment warns about installation requirement

Randomized with seed 5903

make: *** [uncommon.mk:1598: bundled_gems_spec-run] Error 1

Bundler::Runtime#setup requires a real existing lockfile (see
Bundler::SharedHelpers#default_lockfile).
@osyoyu
Copy link
Copy Markdown
Contributor Author

osyoyu commented Dec 4, 2025

Understood. We have two problems:

  • My original patch broke make bundled_gems_spec-run
  • binding.irb doesn't work under bundler/inline, regardless of this pull request / my patch

7c1fc06 shall fix both.

@osyoyu
Copy link
Copy Markdown
Contributor Author

osyoyu commented Dec 9, 2025

@hsbt Can you re-run the tests and check this again? I believe the failing tests are unrelated to this patch.

@kou
Copy link
Copy Markdown
Member

kou commented Dec 9, 2025

Done.

@hsbt
Copy link
Copy Markdown
Member

hsbt commented Jan 15, 2026

@osyoyu Sorry to my late review. I confirmed your code is working with:

  1. with Gemfile
  2. with Gemfile and lockfile
  3. with bundler/inline

I added simple test for bundle/inline at 4ad76e1.

I will merge this after passing CI.

@hsbt hsbt enabled auto-merge (rebase) January 15, 2026 07:01
@hsbt hsbt merged commit 2d79cc9 into ruby:master Jan 15, 2026
93 checks passed
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.

3 participants