Skip to content

Commit

Permalink
Improve Bootsnap behaviour
Browse files Browse the repository at this point in the history
- further refactor nested conditional to make it clearer
- allow running on Linux while still excluding Apple Silicon
- only warn on `bundle install` failures
  • Loading branch information
MikeMcQuaid committed Feb 25, 2021
1 parent 38be286 commit 60876ee
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 57 deletions.
28 changes: 13 additions & 15 deletions Library/Homebrew/homebrew_bootsnap.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
# typed: false
# frozen_string_literal: true

homebrew_bootsnap_enabled = !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"]) &&
# Apple Silicon doesn't play nice with bootsnap
(ENV["HOMEBREW_PROCESSOR"] == "Intel")

# we need some development tools to build bootsnap native code
development_tools_installed = if !homebrew_bootsnap_enabled
false
elsif RbConfig::CONFIG["host_os"].include? "darwin"
File.directory?("/Applications/Xcode.app") || File.directory?("/Library/Developer/CommandLineTools")
homebrew_bootsnap_enabled = !ENV["HOMEBREW_NO_BOOTSNAP"] && ENV["HOMEBREW_BOOTSNAP"]

# portable ruby doesn't play nice with bootsnap
# Can't use .exclude? here because we haven't required active_support yet.
homebrew_bootsnap_enabled &&= !ENV["HOMEBREW_RUBY_PATH"].to_s.include?("/vendor/portable-ruby/") # rubocop:disable Rails/NegateInclude

homebrew_bootsnap_enabled &&= if ENV["HOMEBREW_MACOS_VERSION"]
# Apple Silicon doesn't play nice with bootsnap
ENV["HOMEBREW_PROCESSOR"] == "Intel" &&
# we need some development tools to build bootsnap native code
(File.directory?("/Applications/Xcode.app") || File.directory?("/Library/Developer/CommandLineTools"))
else
File.executable?("/usr/bin/clang") || File.executable?("/usr/bin/gcc")
end

if homebrew_bootsnap_enabled && development_tools_installed
if homebrew_bootsnap_enabled
require "rubygems"

begin
require "bootsnap"
rescue LoadError
unless ENV["HOMEBREW_BOOTSNAP_RETRY"]
require "utils/gems"
Homebrew.install_bundler_gems!
Homebrew.install_bundler_gems!(only_warn_on_failure: true)

ENV["HOMEBREW_BOOTSNAP_RETRY"] = "1"
exec ENV["HOMEBREW_BREW_FILE"], *ARGV
Expand Down

0 comments on commit 60876ee

Please sign in to comment.