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 --standalone installation of default gems #4782

Merged
merged 5 commits into from Jul 30, 2021

Conversation

deivid-rodriguez
Copy link
Member

@deivid-rodriguez deivid-rodriguez commented Jul 25, 2021

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

Since recent versions, bundle install --standalone will fail if your Gemfile includes default gems.

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

Source replacement in Bundler::Definition is the process that decides whether sources from the lockfile can be used directly or whether sources from the Gemfile include changes over the lockfile and need to be considered instead.

This process was not happening correctly for rubygems sources, meaning that sometimes the chosen sources to pick up specs from were not correctly setup and failed to fetch some gems. We were workarounding the issue by "fixing" the incorrect sources at materialization time, but the workaround was not working for this particular case.

This PR fixes the root of the issue and allows us to remove all the workarounds at materialization time (which should also result in less unnecessary network activity).

Fixes #4760.

Make sure the following tasks are checked

These gems are built and installed to system directly as default gems.
There's no need to also build a remote repo.
TSort was released as a library so we can install it, and also other
gems that are loaded by the spec. Also, Ruby on Windows apparently loads
fiddle 1.0.6, so we need to also install that to make that not fail.
Rubygems source replacement was broken.
…mode

Since this mode is only enabled in frozen mode, it's fine to use the
lockfile and means we don't have to "prepare" the replacement for
materialization.
No need to fill up missing names from sources anymore since they should
now be properly set up correctly from the beginning.
@deivid-rodriguez deivid-rodriguez marked this pull request as ready for review July 29, 2021 09:15
@deivid-rodriguez deivid-rodriguez merged commit 719c249 into master Jul 30, 2021
@deivid-rodriguez deivid-rodriguez deleted the fix_standalone_default_gems branch July 30, 2021 07:39
deivid-rodriguez added a commit that referenced this pull request Jul 30, 2021
Fix `--standalone` installation of default gems

(cherry picked from commit 719c249)
deivid-rodriguez added a commit that referenced this pull request Jul 30, 2021
Fix `--standalone` installation of default gems

(cherry picked from commit 719c249)
koic added a commit to koic/rubocop that referenced this pull request Aug 2, 2021
This PR is a workaround for `undefined method `add_dependency_names' for nil:NilClass`
CI build error when using Bundler 2.2.25 on Windows.

```console
Failures:

  1) RuboCop::Lockfile#gems returns all the dependencies
     Failure/Error: @parser = lockfile ?
     Bundler::LockfileParser.new(lockfile) : nil

     NoMethodError:
       undefined method `add_dependency_names' for nil:NilClass
     # ./lib/rubocop/lockfile.rb:35:in `new'
     # ./lib/rubocop/lockfile.rb:35:in `parser'
     # ./lib/rubocop/lockfile.rb:17:in `gems'
     # ./spec/rubocop/lockfile_spec.rb:77:in `block (3 levels) in
       <top (required)>'
     # ./spec/rubocop/lockfile_spec.rb:79:in `block (3 levels) in
       <top (required)>'
  4) RuboCop::Lockfile#includes_gem? for an included dependency
     Failure/Error: @parser = lockfile ?
       Bundler::LockfileParser.new(lockfile) : nil

     NoMethodError:
       undefined method `add_dependency_names' for nil:NilClass
     # ./lib/rubocop/lockfile.rb:35:in `new'
     # ./lib/rubocop/lockfile.rb:35:in `parser'
     # ./lib/rubocop/lockfile.rb:17:in `gems'
     # ./lib/rubocop/lockfile.rb:25:in `includes_gem?'
     # ./spec/rubocop/lockfile_spec.rb:95:in `block (3 levels) in
       <top (required)>'
     # ./spec/rubocop/lockfile_spec.rb:100:in `block (4 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (4 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `chdir'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (3 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:7:in `block (2 levels) in
       <top (required)>'
     # tasks/spec_runner.rake:32:in `block in run_specs'
     # tasks/spec_runner.rake:44:in `with_encoding'
     # tasks/spec_runner.rake:28:in `run_specs'
     # tasks/spec_runner.rake:115:in `block in <top (required)>'

  5) RuboCop::Lockfile#dependencies returns all the dependencies
     Failure/Error: @parser = lockfile ?
     Bundler::LockfileParser.new(lockfile) : nil

     NoMethodError:
       undefined method `add_dependency_names' for nil:NilClass
     # ./lib/rubocop/lockfile.rb:35:in `new'
     # ./lib/rubocop/lockfile.rb:35:in `parser'
     # ./lib/rubocop/lockfile.rb:10:in `dependencies'
     # ./spec/rubocop/lockfile_spec.rb:59:in `block (3 levels) in
       <top (required)>'
     # ./spec/rubocop/lockfile_spec.rb:61:in `block (3 levels) in
       <top (required)>'
     # ./spec/rubocop/lockfile_spec.rb:66:in `block (3 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (4 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `chdir'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (3 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:7:in `block (2 levels) in
       <top (required)>'
     # tasks/spec_runner.rake:32:in `block in run_specs'
     # tasks/spec_runner.rake:44:in `with_encoding'
     # tasks/spec_runner.rake:28:in `run_specs'
     # tasks/spec_runner.rake:115:in `block in <top (required)>'

Finished in 4 minutes 9 seconds (files took 3.81 seconds to load)
16350 examples, 5 failures, 14 pending

Failed examples:

rspec ./spec/rubocop/lockfile_spec.rb:83 # RuboCop::Lockfile#gems
returns all the dependencies
rspec ./spec/rubocop/lockfile_spec.rb:112 #
RuboCop::Lockfile#includes_gem? for an excluded gem
rspec ./spec/rubocop/lockfile_spec.rb:106 #
RuboCop::Lockfile#includes_gem? for an included gem
rspec ./spec/rubocop/lockfile_spec.rb:100 #
RuboCop::Lockfile#includes_gem? for an included dependency
rspec ./spec/rubocop/lockfile_spec.rb:65 #
RuboCop::Lockfile#dependencies returns all the dependencies
```

https://github.com/rubocop/rubocop/runs/3211951622

It may be affected by the following Bundler's changes.

bundler/lib/bundler/lockfile_parser.rb:

```diff
        platform = platform ? Gem::Platform.new(platform) :
        Gem::Platform::RUBY
        @current_spec = LazySpecification.new(name, version, platform)
        @current_spec.source = @current_source
+       @current_source.add_dependency_names(name)

        @specs[@current_spec.identifier] = @current_spec
      elsif spaces.size == 6
```

rubygems/rubygems#4782
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.

Cannot do standalone install with builtin gems
2 participants