Invalidate Bootsnap cache on Gemfile.lock changes

This commit is contained in:
Bo Anderson 2024-09-04 02:35:40 +01:00
parent 0b3d78aa0f
commit 99ce3094e9
No known key found for this signature in database
9 changed files with 36 additions and 15 deletions

View File

@ -278,6 +278,7 @@ Sorbet/StrictSigil:
- "Taps/**/*"
- "/**/{Formula,Casks}/**/*.rb"
- "**/{Formula,Casks}/**/*.rb"
- "Homebrew/{standalone,startup}/*.rb" # These are loaded before sorbet-runtime
- "Homebrew/test/**/*.rb"
Sorbet/TrueSigil:

View File

@ -295,6 +295,7 @@ module Homebrew
cleanup_cache
cleanup_empty_api_source_directories
cleanup_bootsnap
cleanup_logs
cleanup_lockfiles
cleanup_python_site_packages
@ -314,7 +315,6 @@ module Homebrew
return if periodic
cleanup_portable_ruby
cleanup_bootsnap
else
args.each do |arg|
formula = begin
@ -528,9 +528,11 @@ module Homebrew
def cleanup_bootsnap
bootsnap = cache/"bootsnap"
return unless bootsnap.exist?
return unless bootsnap.directory?
cleanup_path(bootsnap) { bootsnap.rmtree }
bootsnap.each_child do |subdir|
cleanup_path(subdir) { subdir.rmtree } if subdir.basename.to_s != Homebrew.bootsnap_key
end
end
def cleanup_cache_db(rack = nil)

View File

@ -362,11 +362,4 @@ homebrew-vendor-install() {
lock "vendor-install ${VENDOR_NAME}"
fetch
install
# Bootsnap needs cleaned up on a new Ruby version.
# It's cleaned up by every `brew cleanup` run anyway so not a big deal to do it here, too.
if [[ "${VENDOR_NAME}" == "ruby" ]]
then
rm -rf "${HOMEBREW_CACHE}/bootsnap"
fi
}

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:disable Sorbet/StrictSigil
# typed: true
# frozen_string_literal: true
# This file is included before any other files. It intentionally has typing disabled and has minimal use of `require`.

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: true
# frozen_string_literal: true
require "sorbet-runtime"

View File

@ -1,16 +1,36 @@
# typed: strict
# typed: true
# frozen_string_literal: true
homebrew_bootsnap_enabled = HOMEBREW_USING_PORTABLE_RUBY &&
ENV["HOMEBREW_NO_BOOTSNAP"].nil? &&
!ENV["HOMEBREW_BOOTSNAP"].nil?
module Homebrew
def self.bootsnap_key
@bootsnap_key ||= begin
require "digest/sha2"
checksum = Digest::SHA256.new
begin
checksum.file(HOMEBREW_LIBRARY_PATH/"Gemfile.lock")
rescue SystemCallError
# If it's inaccessible, let's just assume it's empty.
end
checksum << user_gem_groups.join(",")
"#{RUBY_VERSION}-#{checksum}"
end
end
end
if homebrew_bootsnap_enabled
require "bootsnap"
cache = ENV.fetch("HOMEBREW_CACHE", nil) || ENV.fetch("HOMEBREW_DEFAULT_CACHE", nil)
raise "Needs HOMEBREW_CACHE or HOMEBREW_DEFAULT_CACHE!" if cache.nil? || cache.empty?
cache = File.join(cache, "bootsnap", Homebrew.bootsnap_key)
# We never do `require "vendor/bundle/ruby/..."` or `require "vendor/portable-ruby/..."`,
# so let's slim the cache a bit by excluding them.
# Note that gems within `bundle/ruby` will still be cached - these are when directory walking down from above.

View File

@ -1,5 +1,10 @@
# typed: strict
module Homebrew
sig { returns(String) }
def self.bootsnap_key; end
end
module Bootsnap
sig {
params(

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: true
# frozen_string_literal: true
raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" unless ENV["HOMEBREW_BREW_FILE"]

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: true
# frozen_string_literal: true
RUBY_PATH = Pathname.new(RbConfig.ruby).freeze