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 force_ruby_platform: when the lockfile only locks the ruby platform #6936

Merged
merged 1 commit into from
Oct 15, 2023

Conversation

segiddins
Copy link
Member

@segiddins segiddins commented Sep 2, 2023

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

I was unable to force ruby platform for google-protobuf in the rubygems.org bundle

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

Respect force_ruby_platform: when materializing by transferring it over to the lazy spec from the gemfile dep

Make sure the following tasks are checked

@segiddins segiddins force-pushed the segiddins/force-ruby-platform-only-ruby branch from 6be8fea to 88c2630 Compare September 2, 2023 20:57
@segiddins
Copy link
Member Author

(I don't love this fix but I got really fed up after a few hours and figured it was worth getting something up that (a) had a failing spec and (b) fixed that one spec)

Copy link
Member

@martinemde martinemde left a comment

Choose a reason for hiding this comment

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

The fix itself makes sense to me, though I don't fully understand the implications from the change.

Comment on lines 203 to +205
target_platform = dep.force_ruby_platform ? Gem::Platform::RUBY : (platform || Bundler.local_platform)
matching_specs = GemHelpers.select_best_platform_match(specs_for_name, target_platform)
matching_specs.each {|s| s.force_ruby_platform = true } if dep.force_ruby_platform
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, maybe a little refactor could make this solution feel more elegant to you?

matching _specs =
  if dep.force_ruby_platform
    GemHelpers.force_ruby_platform(specs_for_name)
  else
    GemHelpers.select_best_platform_match(specs_for_name, platform || Bundler.local_platform)
  end

Then you don't need to iterate through matching_specs twice since it can be handled in GemHelpers more cleanly.

Copy link
Member Author

Choose a reason for hiding this comment

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

honestly, feels the same. matching specs should always be a very small array, so the double iteration doesn't feel that bad

@segiddins segiddins force-pushed the segiddins/force-ruby-platform-only-ruby branch from 88c2630 to 7c50064 Compare September 7, 2023 00:04
@segiddins segiddins marked this pull request as ready for review September 7, 2023 23:26
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.

Looks great, nice catch!

I only added a comment to simplify the spec to better illustrate the bug.

G

expect(the_bundle).to include_gems "depends_on_platform_specific 1.0.0 #{Bundler.local_platform}"
expect(the_bundle).to include_gems "platform_specific 1.0.0 #{Bundler.local_platform}"
Copy link
Member

Choose a reason for hiding this comment

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

This bug seems to happen when a platform specific variant is pre-installed, the Gemfile is using :force_ruby_platform => true, and the lockfile includes "RUBY" platform.

In this case, the locally installed platform specific variant will be selected, and unless we propagate the force_ruby_platform flag to it from the Gemfile, it will be happily picked as already installed, and used for materialization.

So, I believe transitive dependencies are unrelated to the fix, and I think the whole spec can be simplified to better illustrate this case like this:

it "reinstalls the ruby variant when a platform specific variant is already installed, the lockile has only RUBY platform, and :force_ruby_platform is used in the Gemfile" do
  lockfile <<-L
    GEM
      remote: #{file_uri_for(gem_repo4)}
      specs:
        platform_specific (1.0)

    PLATFORMS
      ruby

    DEPENDENCIES
      platform_specific

    BUNDLED WITH
       #{Bundler::VERSION}
  L

  system_gems "platform_specific-1.0-#{Gem::Platform.local}", :path => default_bundle_path

  install_gemfile <<-G, :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }, :artifice => "compact_index", :verbose => true
    source "#{file_uri_for(gem_repo4)}"

    gem "platform_specific", :force_ruby_platform => true
  G

  expect(the_bundle).to include_gems "platform_specific 1.0.0 RUBY"
end

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe just add that as a second spec, since we also want to test the transitive case, and the behavior could very well end up different with a different implementation

Copy link
Member

Choose a reason for hiding this comment

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

Sure, I just don't see it as related to this PR.

I'm also not sure which role dep_level_2 intends to play since it's in the lockfile but not in the gemfile. I guess it's testing replacing one dependency in the Gemfile with a subdependency of it? If we want to keep it, I'd at least clarify the wording.

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.

Approving this to clarify that my comment on the spec is definitely not blocking. This is a great fix!

@segiddins segiddins merged commit ed65279 into master Oct 15, 2023
92 checks passed
@segiddins segiddins deleted the segiddins/force-ruby-platform-only-ruby branch October 15, 2023 04:46
deivid-rodriguez pushed a commit that referenced this pull request Nov 8, 2023
…only-ruby

Fix force_ruby_platform: when the lockfile only locks the ruby platform

(cherry picked from commit ed65279)
deivid-rodriguez pushed a commit that referenced this pull request Nov 8, 2023
…only-ruby

Fix force_ruby_platform: when the lockfile only locks the ruby platform

(cherry picked from commit ed65279)
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

3 participants