diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 7200f54a9c..a50934b315 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -153,13 +153,11 @@ module Bundler # Check for this spec from other sources uris = [spec.remote, *remotes_for_spec(spec)].map(&:anonymized_uri).uniq Installer.ambiguous_gems << [spec.name, *uris] if uris.length > 1 - - path = fetch_gem(spec, options[:previous_spec]) - else - path = cached_gem(spec) - raise GemNotFound, "Could not find #{spec.file_name} for installation" unless path end + path = fetch_gem_if_possible(spec, options[:previous_spec]) + raise GemNotFound, "Could not find #{spec.file_name} for installation" unless path + return if Bundler.settings[:no_install] if requires_sudo? @@ -242,7 +240,7 @@ module Bundler end def cache(spec, custom_path = nil) - cached_path = Bundler.settings[:cache_all_platforms] ? fetch_gem(spec) : cached_gem(spec) + cached_path = Bundler.settings[:cache_all_platforms] ? fetch_gem_if_possible(spec) : cached_gem(spec) raise GemNotFound, "Missing gem file '#{spec.file_name}'." unless cached_path return if File.dirname(cached_path) == Bundler.app_cache.to_s Bundler.ui.info " * #{File.basename(cached_path)}" @@ -462,6 +460,14 @@ module Bundler end end + def fetch_gem_if_possible(spec, previous_spec = nil) + if spec.remote + fetch_gem(spec, previous_spec) + else + cached_gem(spec) + end + end + def fetch_gem(spec, previous_spec = nil) spec.fetch_platform diff --git a/spec/bundler/cache/gems_spec.rb b/spec/bundler/cache/gems_spec.rb index a8382a5d8c..63c00eba01 100644 --- a/spec/bundler/cache/gems_spec.rb +++ b/spec/bundler/cache/gems_spec.rb @@ -118,6 +118,18 @@ RSpec.describe "bundle cache" do expect(bundled_app("vendor/cache/json-#{default_json_version}.gem")).to exist end + it "caches builtin gems when cache_all_platforms is set" do + gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + gem "json" + G + + bundle "config set cache_all_platforms true" + + bundle :cache + expect(bundled_app("vendor/cache/json-#{default_json_version}.gem")).to exist + end + it "doesn't make remote request after caching the gem" do build_gem "builtin_gem_2", "1.0.2", :path => bundled_app("vendor/cache") do |s| s.summary = "This builtin_gem is bundled with Ruby"