From 127e56ebbb82df82d2e1a0acbd1dd32e1c2e28dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 20 Oct 2020 13:48:51 +0200 Subject: [PATCH] Make sure git gems are properly cached When using the `cache_all` setting, git gems are also cached. Also, when using `--all-platforms`, gems for all platforms should be cached. Since `git` gems supporting multiple platforms usually provide a single gemspec, we need to special case that, otherwise the versions of the git gems for platforms different than the running one wouldn't be found because the gemspec would've been evaluated only for the current platform. --- bundler/lib/bundler/lazy_specification.rb | 6 +++- .../install/gemfile/specific_platform_spec.rb | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/bundler/lib/bundler/lazy_specification.rb b/bundler/lib/bundler/lazy_specification.rb index 546b8d9b098f..279d00afa743 100644 --- a/bundler/lib/bundler/lazy_specification.rb +++ b/bundler/lib/bundler/lazy_specification.rb @@ -79,7 +79,11 @@ def __materialize__ @specification = if source.is_a?(Source::Gemspec) && source.gemspec.name == name source.gemspec.tap {|s| s.source = source } else - search_object = Bundler.feature_flag.specific_platform? || Bundler.settings[:force_ruby_platform] ? self : Dependency.new(name, version) + search_object = if source.is_a?(Source::Path) + Dependency.new(name, version) + else + Bundler.feature_flag.specific_platform? || Bundler.settings[:force_ruby_platform] ? self : Dependency.new(name, version) + end platform_object = Gem::Platform.new(platform) candidates = source.specs.search(search_object) same_platform_candidates = candidates.select do |spec| diff --git a/bundler/spec/install/gemfile/specific_platform_spec.rb b/bundler/spec/install/gemfile/specific_platform_spec.rb index 6b29407f23bd..44991ef982d2 100644 --- a/bundler/spec/install/gemfile/specific_platform_spec.rb +++ b/bundler/spec/install/gemfile/specific_platform_spec.rb @@ -33,6 +33,41 @@ to all(exist) end + it "caches multiplatform git gems with a single gemspec when --all-platforms is passed" do + git = build_git "pg_array_parser", "1.0" + + gemfile <<-G + gem "pg_array_parser", :git => "#{lib_path("pg_array_parser-1.0")}" + G + + lockfile <<-L + GIT + remote: #{lib_path("pg_array_parser-1.0")} + revision: #{git.ref_for("master")} + specs: + pg_array_parser (1.0-java) + pg_array_parser (1.0) + + GEM + specs: + + PLATFORMS + java + #{lockfile_platforms} + + DEPENDENCIES + pg_array_parser! + + BUNDLED WITH + #{Bundler::VERSION} + L + + bundle "config set --local cache_all true" + bundle "cache --all-platforms" + + expect(err).to be_empty + end + it "uses the platform-specific gem with extra dependencies" do setup_multiplatform_gem_with_different_dependencies_per_platform install_gemfile <<-G