Skip to content

Commit

Permalink
Use a global bundler cache by default
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Dec 22, 2023
1 parent c0d4244 commit 7173b8b
Show file tree
Hide file tree
Showing 13 changed files with 10 additions and 34 deletions.
1 change: 0 additions & 1 deletion bundler/lib/bundler/feature_flag.rb
Expand Up @@ -32,7 +32,6 @@ def self.settings_method(name, key, &default)
settings_flag(:cache_all) { bundler_3_mode? }
settings_flag(:default_install_uses_path) { bundler_3_mode? }
settings_flag(:forget_cli_options) { bundler_3_mode? }
settings_flag(:global_gem_cache) { bundler_3_mode? }
settings_flag(:path_relative_to_cwd) { bundler_3_mode? }
settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") }
settings_flag(:print_only_version_number) { bundler_3_mode? }
Expand Down
2 changes: 0 additions & 2 deletions bundler/lib/bundler/man/bundle-config.1
Expand Up @@ -141,8 +141,6 @@ The following is a list of all configuration keys and their purpose\. You can le
.IP "\(bu" 4
\fBgemfile\fR (\fBBUNDLE_GEMFILE\fR): The name of the file that bundler should use as the \fBGemfile\fR\. This location of this file also sets the root of the project, which is used to resolve relative paths in the \fBGemfile\fR, among other things\. By default, bundler will search up from the current working directory until it finds a \fBGemfile\fR\.
.IP "\(bu" 4
\fBglobal_gem_cache\fR (\fBBUNDLE_GLOBAL_GEM_CACHE\fR): Whether Bundler should cache all gems globally, rather than locally to the installing Ruby installation\.
.IP "\(bu" 4
\fBignore_funding_requests\fR (\fBBUNDLE_IGNORE_FUNDING_REQUESTS\fR): When set, no funding requests will be printed\.
.IP "\(bu" 4
\fBignore_messages\fR (\fBBUNDLE_IGNORE_MESSAGES\fR): When set, no post install messages will be printed\. To silence a single gem, use dot notation like \fBignore_messages\.httparty true\fR\.
Expand Down
3 changes: 0 additions & 3 deletions bundler/lib/bundler/man/bundle-config.1.ronn
Expand Up @@ -207,9 +207,6 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html).
relative paths in the `Gemfile`, among other things. By default, bundler
will search up from the current working directory until it finds a
`Gemfile`.
* `global_gem_cache` (`BUNDLE_GLOBAL_GEM_CACHE`):
Whether Bundler should cache all gems globally, rather than locally to the
installing Ruby installation.
* `ignore_funding_requests` (`BUNDLE_IGNORE_FUNDING_REQUESTS`):
When set, no funding requests will be printed.
* `ignore_messages` (`BUNDLE_IGNORE_MESSAGES`):
Expand Down
1 change: 0 additions & 1 deletion bundler/lib/bundler/settings.rb
Expand Up @@ -29,7 +29,6 @@ class Settings
gem.coc
gem.mit
git.allow_insecure
global_gem_cache
ignore_messages
init_gems_rb
inline
Expand Down
1 change: 0 additions & 1 deletion bundler/lib/bundler/source.rb
Expand Up @@ -77,7 +77,6 @@ def path?
end

def extension_cache_path(spec)
return unless Bundler.feature_flag.global_gem_cache?
return unless source_slug = extension_cache_slug(spec)
Bundler.user_cache.join(
"extensions", Gem::Platform.local.to_s, Bundler.ruby_scope,
Expand Down
6 changes: 1 addition & 5 deletions bundler/lib/bundler/source/git.rb
Expand Up @@ -227,11 +227,7 @@ def load_spec_files
# across different projects, this cache will be shared.
# When using local git repos, this is set to the local repo.
def cache_path
@cache_path ||= if Bundler.feature_flag.global_gem_cache?
Bundler.user_cache
else
Bundler.bundle_path.join("cache", "bundler")
end.join("git", git_scope)
@cache_path ||= Bundler.user_cache.join("git", git_scope)
end

def app_cache_dirname
Expand Down
1 change: 0 additions & 1 deletion bundler/lib/bundler/source/rubygems.rb
Expand Up @@ -500,7 +500,6 @@ def download_gem(spec, download_cache_path, previous_spec = nil)
# @return [Pathname] The global cache path.
#
def download_cache_path(spec)
return unless Bundler.feature_flag.global_gem_cache?
return unless remote = spec.remote
return unless cache_slug = remote.cache_slug

Expand Down
2 changes: 1 addition & 1 deletion bundler/spec/commands/clean_spec.rb
Expand Up @@ -151,7 +151,7 @@ def should_not_have_gems(*gems)
bundle :clean

digest = Digest(:SHA1).hexdigest(git_path.to_s)
cache_path = Bundler::VERSION.start_with?("2.") ? vendored_gems("cache/bundler/git/foo-1.0-#{digest}") : home(".bundle/cache/git/foo-1.0-#{digest}")
cache_path = home(".bundle/cache/git/foo-1.0-#{digest}")
expect(cache_path).to exist
end

Expand Down
7 changes: 2 additions & 5 deletions bundler/spec/install/gemfile/git_spec.rb
Expand Up @@ -26,8 +26,8 @@
expect(out).to eq("WIN")
end

it "caches the git repo", bundler: "< 3" do
expect(Dir["#{default_bundle_path}/cache/bundler/git/foo-1.0-*"]).to have_attributes size: 1
it "caches the git repo" do
expect(Dir["#{default_cache_path}/git/foo-1.0-*"]).to have_attributes size: 1
end

it "does not write to cache on bundler/setup" do
Expand All @@ -39,7 +39,6 @@

it "caches the git repo globally and properly uses the cached repo on the next invocation" do
simulate_new_machine
bundle "config set global_gem_cache true"
bundle :install
expect(Dir["#{home}/.bundle/cache/git/foo-1.0-*"]).to have_attributes size: 1

Expand Down Expand Up @@ -334,8 +333,6 @@
it "does not download random non-head refs" do
sys_exec("git update-ref -m \"Bundler Spec!\" refs/bundler/1 main~1", dir: lib_path("foo-1.0"))

bundle "config set global_gem_cache true"

install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
git "#{lib_path("foo-1.0")}" do
Expand Down
6 changes: 4 additions & 2 deletions bundler/spec/install/gemfile/sources_spec.rb
Expand Up @@ -351,17 +351,19 @@
rack_checksum = "c0ffee11" * 8
bundle :install, artifice: "compact_index", env: { "BUNDLER_SPEC_RACK_CHECKSUM" => rack_checksum }, raise_on_error: false

gem_path = default_cache_path.dirname.join("cache", "gems", "gem.repo2.443.0c6866cb34f3fc6d95f4fcfa60e6c430", "rack-1.0.0.gem")

expect(err).to eq(<<~E.strip)
[DEPRECATED] Your Gemfile contains multiple global sources. Using `source` more than once without a block is a security risk, and may result in installing unexpected gems. To resolve this warning, use a block to indicate which gems should come from the secondary source.
Bundler found mismatched checksums. This is a potential security risk.
rack (1.0.0) sha256=#{rack_checksum}
from the API at https://gem.repo2/
and the API at https://gem.repo1/
#{checksum_to_lock(gem_repo2, "rack", "1.0.0")}
from the gem at #{default_bundle_path("cache", "rack-1.0.0.gem")}
from the gem at #{gem_path}
If you trust the API at https://gem.repo2/, to resolve this issue you can:
1. remove the gem at #{default_bundle_path("cache", "rack-1.0.0.gem")}
1. remove the gem at #{gem_path}
2. run `bundle install`
To ignore checksum security warnings, disable checksum validation with
Expand Down
6 changes: 1 addition & 5 deletions bundler/spec/install/gems/compact_index_spec.rb
Expand Up @@ -996,11 +996,7 @@ def start
gem "rack"
G

gem_path = if Bundler.feature_flag.global_gem_cache?
default_cache_path.dirname.join("cache", "gems", "localgemserver.test.80.dd34752a738ee965a2a4298dc16db6c5", "rack-1.0.0.gem")
else
default_cache_path.dirname.join("rack-1.0.0.gem")
end
gem_path = default_cache_path.dirname.join("cache", "gems", "localgemserver.test.80.dd34752a738ee965a2a4298dc16db6c5", "rack-1.0.0.gem")

expect(exitstatus).to eq(37)
expect(err).to eq <<~E.strip
Expand Down
2 changes: 0 additions & 2 deletions bundler/spec/install/global_cache_spec.rb
@@ -1,8 +1,6 @@
# frozen_string_literal: true

RSpec.describe "global gem caching" do
before { bundle "config set global_gem_cache true" }

describe "using the cross-application user cache" do
let(:source) { "http://localgemserver.test" }
let(:source2) { "http://gemserver.example.org" }
Expand Down
6 changes: 1 addition & 5 deletions bundler/spec/support/path.rb
Expand Up @@ -121,11 +121,7 @@ def default_bundle_path(*path)
end

def default_cache_path(*path)
if Bundler.feature_flag.global_gem_cache?
home(".bundle/cache", *path)
else
default_bundle_path("cache/bundler", *path)
end
home(".bundle/cache", *path)
end

def bundled_app(*path)
Expand Down

0 comments on commit 7173b8b

Please sign in to comment.