Skip to content

Commit

Permalink
[rubygems/rubygems] Fix regression when caching gems from secondary s…
Browse files Browse the repository at this point in the history
…ources

If `cache_all_platforms` setting is enabled, the secondary source was
no longer considering cached gems.

That means that if the remote secondary source has removed its gems,
then this was now resulting in an error while before the previously
cached gem from the source would still be used.

This commit restores previous behavior.

rubygems/rubygems@2d2cd00255
  • Loading branch information
deivid-rodriguez authored and matzbot committed May 16, 2024
1 parent 29a9ab0 commit 7857061
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/bundler/spec_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def materialize(deps)
def materialized_for_all_platforms
@specs.map do |s|
next s unless s.is_a?(LazySpecification)
s.source.cached!
s.source.remote!
spec = s.materialize_for_installation
raise GemNotFound, "Could not find #{s.full_name} in any of the sources" unless spec
Expand Down
60 changes: 60 additions & 0 deletions spec/bundler/commands/cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,66 @@
expect(the_bundle).to include_gems "rack 1.0.0"
end

it "uses cached gems for secondary sources when cache_all_platforms configured" do
build_repo4 do
build_gem "foo", "1.0.0" do |s|
s.platform = "x86_64-linux"
end

build_gem "foo", "1.0.0" do |s|
s.platform = "arm64-darwin"
end
end

gemfile <<~G
source "https://gems.repo2"
source "https://gems.repo4" do
gem "foo"
end
G

lockfile <<~L
GEM
remote: https://gems.repo2/
specs:
GEM
remote: https://gems.repo4/
specs:
foo (1.0.0-x86_64-linux)
foo (1.0.0-arm64-darwin)
PLATFORMS
arm64-darwin
ruby
x86_64-linux
DEPENDENCIES
foo
BUNDLED WITH
#{Bundler::VERSION}
L

simulate_platform "x86_64-linux" do
bundle "config set cache_all_platforms true"
bundle "config set path vendor/bundle"
bundle :cache, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }

build_repo4 do
# simulate removal of all remote gems
end

# delete compact index cache
FileUtils.rm_rf home(".bundle/cache/compact_index")

bundle "install", artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }

expect(the_bundle).to include_gems "foo 1.0.0 x86_64-linux"
end
end

it "does not reinstall already-installed gems" do
install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
Expand Down

0 comments on commit 7857061

Please sign in to comment.