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,14 +3,17 @@
# TODO: make this `typed: true` when HOMEBREW_BOOTSNAP is enabled by # TODO: make this `typed: true` when HOMEBREW_BOOTSNAP is enabled by
# default and/or we vendor bootsnap and the RBI file. # 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
begin
require "bootsnap" require "bootsnap"
rescue LoadError rescue LoadError
raise if ENV["HOMEBREW_BOOTSNAP_RETRY"] raise if ENV["HOMEBREW_BOOTSNAP_RETRY"]
Dir.chdir(HOMEBREW_LIBRARY_PATH) do Dir.chdir(HOMEBREW_LIBRARY_PATH) do
@ -19,17 +22,18 @@ rescue LoadError
ENV["HOMEBREW_BOOTSNAP_RETRY"] = "1" ENV["HOMEBREW_BOOTSNAP_RETRY"] = "1"
exec ENV["HOMEBREW_BREW_FILE"], *ARGV exec ENV["HOMEBREW_BREW_FILE"], *ARGV
end end
ENV.delete("HOMEBREW_BOOTSNAP_RETRY") ENV.delete("HOMEBREW_BOOTSNAP_RETRY")
tmp = ENV["HOMEBREW_TEMP"] || ENV["HOMEBREW_DEFAULT_TEMP"] cache = ENV["HOMEBREW_CACHE"] || ENV["HOMEBREW_DEFAULT_CACHE"]
raise "Needs HOMEBREW_TEMP or HOMEBREW_DEFAULT_TEMP!" unless tmp # 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( Bootsnap.setup(
cache_dir: "#{tmp}/homebrew-bootsnap", cache_dir: cache,
development_mode: false, # TODO: use ENV["HOMEBREW_DEVELOPER"]?,
load_path_cache: true, load_path_cache: true,
compile_cache_iseq: true, compile_cache_iseq: true,
compile_cache_yaml: true, compile_cache_yaml: true,
) )
end

View File

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