brew/Library/Homebrew/install.rb
Mike McQuaid 5afff3f3aa
Handle macOS Homebrew on ARM
- Output `brew doctor` and `brew install` messages noting this configuration is (currently) unsupported and encourage use of Rosetta instead
- Output Rosetta 2 usage in `brew config` on ARM (whether in Rosetta 2 or not)
- Check the architecture of (newly installed) dependencies and ensure they are using the correct architecture.
- Don't allow installing macOS Intel Homebrew in macOS ARM Homebrew default prefix (and vice versa
- Actually write out the architecture of dependencies to the tab rather than generating and throwing them away
- Set and document the expected default prefix for macOS Intel Homebrew, macOS ARM Homebrew (`/opt/homebrew`) and Homebrew on Linux

While we're here:
- Don't say Big Sur is a prerelease version but still make it clear we
  don't support it (yet).
- Don't reference non-existent IRC channel
2020-11-12 17:06:47 +00:00

85 lines
2.5 KiB
Ruby

# typed: true
# frozen_string_literal: true
require "diagnostic"
require "fileutils"
require "hardware"
require "development_tools"
module Homebrew
# Helper module for performing (pre-)install checks.
#
# @api private
module Install
module_function
def perform_preinstall_checks(all_fatal: false, cc: nil)
check_prefix
check_cpu
attempt_directory_creation
check_cc_argv(cc)
Diagnostic.checks(:supported_configuration_checks, fatal: all_fatal)
Diagnostic.checks(:fatal_preinstall_checks)
end
alias generic_perform_preinstall_checks perform_preinstall_checks
module_function :generic_perform_preinstall_checks
def perform_build_from_source_checks(all_fatal: false)
Diagnostic.checks(:fatal_build_from_source_checks)
Diagnostic.checks(:build_from_source_checks, fatal: all_fatal)
end
def check_prefix
if Hardware::CPU.intel? && HOMEBREW_PREFIX == HOMEBREW_MACOS_ARM_DEFAULT_PREFIX
odie "Cannot install in Homebrew on Intel processor in ARM default prefix (#{HOMEBREW_PREFIX})!"
elsif Hardware::CPU.arm? && HOMEBREW_PREFIX == HOMEBREW_DEFAULT_PREFIX
odie "Cannot install in Homebrew on ARM processor in Intel default prefix (#{HOMEBREW_PREFIX})!"
end
end
def check_cpu
return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
# Handled by check_for_unsupported_arch in extend/os/mac/diagnostic.rb
return if Hardware::CPU.arm?
return unless Hardware::CPU.ppc?
odie <<~EOS
Sorry, Homebrew does not support your computer's CPU architecture!
For PowerPC Mac (PPC32/PPC64BE) support, see:
#{Formatter.url("https://github.com/mistydemeo/tigerbrew")}
EOS
end
private_class_method :check_cpu
def attempt_directory_creation
Keg::MUST_EXIST_DIRECTORIES.each do |dir|
FileUtils.mkdir_p(dir) unless dir.exist?
# Create these files to ensure that these directories aren't removed
# by the Catalina installer.
# (https://github.com/Homebrew/brew/issues/6263)
keep_file = dir/".keepme"
FileUtils.touch(keep_file) unless keep_file.exist?
rescue
nil
end
end
private_class_method :attempt_directory_creation
def check_cc_argv(cc)
return unless cc
@checks ||= Diagnostic::Checks.new
opoo <<~EOS
You passed `--cc=#{cc}`.
#{@checks.please_create_pull_requests}
EOS
end
private_class_method :check_cc_argv
end
end
require "extend/os/install"