Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bundler/inline not properly installing gems with extensions when used more than once #6306

Merged

Conversation

tbates-redarc
Copy link
Contributor

@tbates-redarc tbates-redarc commented Jan 25, 2023

What was the end-user or developer problem that led to this PR?

The following test script fails on Windows (RubyInstaller) with Ruby 3.1 and Ruby 2.6 using Bundler 2.4.5:

require 'bundler/inline'
gemfile(true) do
  source 'http://rubygems.org'
  gem 'bundler'
end
gemfile(true) do
  source 'http://rubygems.org'
  gem 'racc'
end
The output is as follows:
Resolving dependencies...
Using bundler 2.4.5
Fetching gem metadata from http://rubygems.org/.
Resolving dependencies...
Using bundler 2.4.5
Installing racc 1.6.2 with native extensions
C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/installer/parallel_installer.rb:189:in `handle_error': Gem::Ext::BuildError: ERROR: Failed to build gem native extension. (Bundler::InstallError)

    current directory: C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/racc-1.6.2/ext/racc/cparse
C:/Ruby31-x64/bin/ruby.exe -I C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0 extconf.rb
C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/definition.rb:35:in `build': C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/racc-1.6.2/ext/racc/cparse/Gemfile not found (Bundler::GemfileNotFound)
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler.rb:216:in `definition'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler.rb:164:in `setup'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/setup.rb:20:in `block in <top (required)>'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/ui/shell.rb:159:in `with_level'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/ui/shell.rb:111:in `silence'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/setup.rb:20:in `<top (required)>'
        from <internal:C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/rubygems.rb:1360:in `<top (required)>'
        from <internal:gem_prelude>:2:in `require'
        from <internal:gem_prelude>:2:in `<internal:gem_prelude>'

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/racc-1.6.2 for inspection.
Results logged to C:/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/racc-1.6.2/gem_make.out

  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:102:in `run'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:28:in `build'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:171:in `build_extension'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:205:in `block in build_extensions'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:202:in `each'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/rubygems/ext/builder.rb:202:in `build_extensions'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/rubygems/installer.rb:843:in `build_extensions'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/rubygems_gem_installer.rb:72:in `build_extensions'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/rubygems_gem_installer.rb:28:in `install'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/source/rubygems.rb:200:in `install'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/installer/gem_installer.rb:54:in `install'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/installer/parallel_installer.rb:155:in `do_install'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/installer/parallel_installer.rb:146:in `block in worker_pool'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/worker.rb:62:in `apply_func'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/worker.rb:57:in `block in process_queue'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/worker.rb:54:in `loop'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/worker.rb:54:in `process_queue'
  C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/worker.rb:90:in `block (2 levels) in create_threads'

An error occurred while installing racc (1.6.2), and Bundler cannot continue.

In Gemfile:
  racc
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/installer/parallel_installer.rb:96:in `call'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/installer/parallel_installer.rb:67:in `call'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/installer.rb:244:in `install_in_parallel'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/installer.rb:201:in `install'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/installer.rb:89:in `block in run'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/process_lock.rb:12:in `block in lock'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/process_lock.rb:9:in `open'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/process_lock.rb:9:in `lock'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/installer.rb:71:in `run'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/installer.rb:23:in `install'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/inline.rb:58:in `block (2 levels) in gemfile'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/settings.rb:131:in `temporary'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/inline.rb:57:in `block in gemfile'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/settings.rb:131:in `temporary'
        from C:/Ruby31-x64/lib/ruby/site_ruby/3.1.0/bundler/inline.rb:51:in `gemfile'
        from test.rb:9:in `<main>'

What is your fix for the problem, implemented in this PR?

Wrapping the body of the gemfile method in Bundler.with_unbundled_env fixed it.

Make sure the following tasks are checked

@deivid-rodriguez
Copy link
Member

deivid-rodriguez commented Jan 25, 2023

I tend to recall setting BUNDLE_GEMFILE to the empty string instead of nil was an intentional choice to avoid Bundler's default mechanism to infer the Gemfile automatically when BUNDLE_GEMFILE not set. It would be good to double check git/issue history for the whole story.

Also, you may want to add a CI job that runs on Ruby 2.6 on Windows to get this to reproduce. You can look at .github/workflows/install-rubygems.yml for inspiration.

@tbates-redarc
Copy link
Contributor Author

tbates-redarc commented Jan 30, 2023

You're right, it was in rubygems/bundler#7537. Reverted the changes to the BUNDLE_GEMFILE test.

The issue is reproducible on Ruby 3.1 so I have added a test for it but not changed the workflow.

@deivid-rodriguez deivid-rodriguez changed the title Fix issue with extensions not compiling properly using inline gemfile Fix bundler/inline not properly installing gems with extensions when used more than once Jan 30, 2023
Copy link
Member

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

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

Thanks so much for your improvements to bundler/inline 😍

@deivid-rodriguez deivid-rodriguez merged commit 1168071 into rubygems:master Jan 30, 2023
@tbates-redarc tbates-redarc deleted the inline-extension-fix branch January 30, 2023 23:58
deivid-rodriguez added a commit that referenced this pull request Jan 31, 2023
Fix `bundler/inline` not properly installing gems with extensions when used more than once

(cherry picked from commit 1168071)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants