rubygems / rubygems

Library packaging and distribution for Ruby.
https://rubygems.org/
Other
3.64k stars 1.74k forks source link

Bundler::Definition#specs_for after reset fails for native gems #6626

Open akostadinov opened 1 year ago

akostadinov commented 1 year ago

Describe the problem as clearly as you can

Hi, I'm not completely sure that I'm doing the right thing. I'm hitting an issue with license_finder which boiled down to a different behavior after Bundler was reset as part of license_finder logic.

        ::Bundler.reset!
        ::Bundler.configure

So after the reset, Bundler can't find native gems anymore when PLATFORM in Gemfile.lock is ruby. While it could find them prior.

Traceback (most recent call last):
    2: from bad.rb:5:in `<main>'
    1: from /opt/rh/rh-ruby27/root/usr/local/share/gems/gems/bundler-2.4.12/lib/bundler/definition.rb:256:in `specs_for'
/opt/rh/rh-ruby27/root/usr/local/share/gems/gems/bundler-2.4.12/lib/bundler/definition.rb:524:in `materialize': Could not find nokogiri-1.13.10, mini_portile2-2.8.1 in locally installed gems (Bundler::GemNotFound)

Now I'm not sure whether license_finder does the right thing here. If there is a better way to do that, please advise!

See below for a minimal reproducer.

Did you try upgrading rubygems & bundler?

yes

Post steps to reproduce the problem

I crafted a minimal project to easily reproduce the issue with simple copy/paste steps in the readme: https://github.com/akostadinov/bundler-native-platform-issue

What were you expecting to happen?

I expect that Bundler will behave the same after reset as it behaved before reset.

What actually happened?

Could not find gem, see error above.

If not included with the output of your command, run bundle env and paste the output below

Environment

Bundler       2.4.10
  Platforms   ruby, x86_64-linux
Ruby          3.2.2p53 (2023-03-30 revision e51014f9c05aa65cbf203442d37fef7c12390015) [x86_64-linux]
  Full Path   /home/avalon/.asdf/installs/ruby/3.2.2/bin/ruby
  Config Dir  /home/avalon/.asdf/installs/ruby/3.2.2/etc
RubyGems      3.4.10
  Gem Home    /home/avalon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0
  Gem Path    /home/avalon/.gem/ruby/3.2.0:/home/avalon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0
  User Home   /home/avalon
  User Path   /home/avalon/.gem/ruby/3.2.0
  Bin Dir     /home/avalon/.asdf/installs/ruby/3.2.2/bin
Tools         
  Git         2.39.2
  RVM         not installed
  rbenv       not installed
  chruby      not installed

Bundler Build Metadata

Built At          2023-03-27
Git SHA           7ffdec80d0
Released Version  true

Bundler settings

build.eventmachine
  Set for the current user (/home/avalon/.bundle/config): "--with-cppflags=-I/usr/include/openssl/"
deployment
  Set for your local app (/home/avalon/ws/repos/bundler-native-platform-issue/.bundle/config): true

Gemfile

Gemfile

# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem "nokogiri", '1.13.10'

Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    mini_portile2 (2.8.1)
    nokogiri (1.13.10)
      mini_portile2 (~> 2.8.0)
      racc (~> 1.4)
    racc (1.6.2)

PLATFORMS
  ruby

DEPENDENCIES
  nokogiri (= 1.13.10)

BUNDLED WITH
   2.4.10
Paradiselife1984 commented 1 year ago

"cURL" https://learning.postman.com/docs/getting-started/importing-and-exporting-data/#:~:text=can%20also%20paste-,cURL,-commands%20into%20a paradiselife813@gmail.com

Details

Paradiselife1984 commented 1 year ago

@akostadinov https://github.com/rubygems/rubygems/issues/6626#issuecomment-1518697689

akostadinov commented 1 year ago

@Paradiselife1984 , sorry, I don't understand what to do with that link.

simi commented 1 year ago

Hello @akostadinov ! Thanks to your detailed "reproducer" I was able to reproduce your problem. But I'm not sure there is anything wrong on Bundler side. Do you know why ::Bundler.reset! is called? It resets all already loaded specs in RubyGems and that is the reason for your failure.

deivid-rodriguez commented 1 year ago

Since there was no further feedback here, I will close this issue. Feel free to reopen or comment more if still interested.

akostadinov commented 1 year ago

@simi , @deivid-rodriguez , missed this somehow. license_finder I assume tries to remove anything pre-xisting so it is able to get only data for the inspected project. i.e. tries to make sure there is no stale data before starting.

What would be a proper way to do so if not by resetting?

deivid-rodriguez commented 1 year ago

I didn't look into this properly, just realized that there had been no further feedback. I'll reopen then.

tikhomirov commented 1 year ago

JFYI removing bundle config commands from the build script (so bundler config is not created) can be a workaround for this problem (see this if statement)