homebrew_bootsnap: various improvements.

- Add `HOMEBREW_NO_BOOTSNAP` as well as `HOMEBREW_BOOTSNAP`
- Guard the whole file rather than `raise` on inclusion.
- Use `HOMEBREW_CACHE` instead of `HOMEBREW_TEMP`
- Don't try to use Bootsnap with macOS portable ruby
This commit is contained in:
Mike McQuaid 2021-02-02 11:50:44 +00:00
parent a1c6d39792
commit 7912b1e043
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
2 changed files with 29 additions and 26 deletions

View File

@ -3,33 +3,37 @@
# TODO: make this `typed: true` when HOMEBREW_BOOTSNAP is enabled by
# default and/or we vendor bootsnap and the RBI file.
if !ENV["HOMEBREW_NO_BOOTSNAP"] &&
ENV["HOMEBREW_BOOTSNAP"] &&
# portable ruby doesn't play nice with bootsnap
!ENV["HOMEBREW_FORCE_VENDOR_RUBY"] &&
(!ENV["HOMEBREW_MACOS_VERSION"] || ENV["HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH"])
raise "Needs HOMEBREW_BOOTSNAP!" unless ENV["HOMEBREW_BOOTSNAP"]
require "rubygems"
require "rubygems"
begin
require "bootsnap"
rescue LoadError
raise if ENV["HOMEBREW_BOOTSNAP_RETRY"]
begin
require "bootsnap"
rescue LoadError
raise if ENV["HOMEBREW_BOOTSNAP_RETRY"]
Dir.chdir(HOMEBREW_LIBRARY_PATH) do
system "bundle", "install", "--standalone"
end
Dir.chdir(HOMEBREW_LIBRARY_PATH) do
system "bundle", "install", "--standalone"
ENV["HOMEBREW_BOOTSNAP_RETRY"] = "1"
exec ENV["HOMEBREW_BREW_FILE"], *ARGV
end
ENV["HOMEBREW_BOOTSNAP_RETRY"] = "1"
exec ENV["HOMEBREW_BREW_FILE"], *ARGV
ENV.delete("HOMEBREW_BOOTSNAP_RETRY")
cache = ENV["HOMEBREW_CACHE"] || ENV["HOMEBREW_DEFAULT_CACHE"]
# Can't use .blank? here because we haven't required active_support yet.
raise "Needs HOMEBREW_CACHE or HOMEBREW_DEFAULT_CACHE!" if cache.nil? || cache.empty? # rubocop:disable Rails/Blank
Bootsnap.setup(
cache_dir: cache,
load_path_cache: true,
compile_cache_iseq: true,
compile_cache_yaml: true,
)
end
ENV.delete("HOMEBREW_BOOTSNAP_RETRY")
tmp = ENV["HOMEBREW_TEMP"] || ENV["HOMEBREW_DEFAULT_TEMP"]
raise "Needs HOMEBREW_TEMP or HOMEBREW_DEFAULT_TEMP!" unless tmp
Bootsnap.setup(
cache_dir: "#{tmp}/homebrew-bootsnap",
development_mode: false, # TODO: use ENV["HOMEBREW_DEVELOPER"]?,
load_path_cache: true,
compile_cache_iseq: true,
compile_cache_yaml: true,
)

View File

@ -8,10 +8,9 @@ HOMEBREW_LIBRARY_PATH = Pathname(__dir__).realpath.freeze
$LOAD_PATH.push HOMEBREW_LIBRARY_PATH.to_s
require "vendor/bundle/bundler/setup"
require "homebrew_bootsnap"
if ENV["HOMEBREW_BOOTSNAP"]
require "homebrew_bootsnap"
else
unless defined?(Bootsnap)
$LOAD_PATH.select! { |d| Pathname(d).directory? }
$LOAD_PATH.uniq!
end