Skip to content

Commit

Permalink
[rubygems/rubygems] Account for default gems not having remote when c…
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and matzbot committed Jul 2, 2022
1 parent 9101269 commit 7b78aba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/bundler/source/rubygems.rb
Expand Up @@ -153,13 +153,11 @@ def install(spec, options = {})
# 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?
Expand Down Expand Up @@ -242,7 +240,7 @@ def install(spec, options = {})
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)}"
Expand Down Expand Up @@ -462,6 +460,14 @@ def fetch_names(fetchers, dependency_names, index, override_dupes)
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

Expand Down
12 changes: 12 additions & 0 deletions spec/bundler/cache/gems_spec.rb
Expand Up @@ -118,6 +118,18 @@
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"
Expand Down

0 comments on commit 7b78aba

Please sign in to comment.