2020-10-10 14:16:11 +02:00
|
|
|
# typed: true
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-05 23:19:18 -04:00
|
|
|
require "diagnostic"
|
|
|
|
require "fileutils"
|
|
|
|
require "hardware"
|
|
|
|
require "development_tools"
|
|
|
|
|
|
|
|
module Homebrew
|
2020-08-17 18:39:55 +02:00
|
|
|
# Helper module for performing (pre-)install checks.
|
|
|
|
#
|
|
|
|
# @api private
|
2018-06-05 23:19:18 -04:00
|
|
|
module Install
|
2020-07-27 11:37:07 +02:00
|
|
|
module_function
|
|
|
|
|
2020-08-17 18:39:55 +02:00
|
|
|
def perform_preinstall_checks(all_fatal: false, cc: nil)
|
2020-11-12 17:06:47 +00:00
|
|
|
check_prefix
|
2020-08-17 18:39:55 +02:00
|
|
|
check_cpu
|
|
|
|
attempt_directory_creation
|
|
|
|
check_cc_argv(cc)
|
2020-09-11 12:05:22 +01:00
|
|
|
Diagnostic.checks(:supported_configuration_checks, fatal: all_fatal)
|
|
|
|
Diagnostic.checks(:fatal_preinstall_checks)
|
2020-08-17 18:39:55 +02:00
|
|
|
end
|
|
|
|
alias generic_perform_preinstall_checks perform_preinstall_checks
|
|
|
|
module_function :generic_perform_preinstall_checks
|
|
|
|
|
|
|
|
def perform_build_from_source_checks(all_fatal: false)
|
2020-09-11 12:05:22 +01:00
|
|
|
Diagnostic.checks(:fatal_build_from_source_checks)
|
|
|
|
Diagnostic.checks(:build_from_source_checks, fatal: all_fatal)
|
2020-08-17 18:39:55 +02:00
|
|
|
end
|
|
|
|
|
2020-11-12 17:06:47 +00:00
|
|
|
def check_prefix
|
2020-12-22 08:41:49 +00:00
|
|
|
if (Hardware::CPU.intel? || Hardware::CPU.in_rosetta2?) &&
|
|
|
|
HOMEBREW_PREFIX.to_s == HOMEBREW_MACOS_ARM_DEFAULT_PREFIX
|
|
|
|
configuration = if Hardware::CPU.in_rosetta2?
|
|
|
|
"under Rosetta 2"
|
2020-12-22 11:28:45 +00:00
|
|
|
else
|
|
|
|
"on Intel processor"
|
2020-12-22 08:41:49 +00:00
|
|
|
end
|
|
|
|
odie "Cannot install in Homebrew #{configuration} in ARM default prefix (#{HOMEBREW_PREFIX})!"
|
2020-11-12 18:58:03 +00:00
|
|
|
elsif Hardware::CPU.arm? && HOMEBREW_PREFIX.to_s == HOMEBREW_DEFAULT_PREFIX
|
2020-11-12 19:14:46 +00:00
|
|
|
odie <<~EOS
|
|
|
|
Cannot install in Homebrew on ARM processor in Intel default prefix (#{HOMEBREW_PREFIX})!
|
|
|
|
Please create a new installation in #{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX} using one of the
|
|
|
|
"Alternative Installs" from:
|
|
|
|
#{Formatter.url("https://docs.brew.sh/Installation")}
|
|
|
|
You can migrate your previously installed formula list with:
|
|
|
|
brew bundle dump
|
|
|
|
EOS
|
2020-11-12 17:06:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-08 19:13:46 +00:00
|
|
|
def check_cpu
|
2020-11-12 17:06:47 +00:00
|
|
|
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
|
2018-06-05 23:19:18 -04:00
|
|
|
end
|
2020-08-17 18:39:55 +02:00
|
|
|
private_class_method :check_cpu
|
2018-06-05 23:19:18 -04:00
|
|
|
|
2018-09-06 18:38:43 +01:00
|
|
|
def attempt_directory_creation
|
2018-09-25 22:03:29 +01:00
|
|
|
Keg::MUST_EXIST_DIRECTORIES.each do |dir|
|
2019-10-13 10:03:26 +01:00
|
|
|
FileUtils.mkdir_p(dir) unless dir.exist?
|
2019-09-17 11:06:48 +02:00
|
|
|
|
2019-10-13 10:03:26 +01:00
|
|
|
# 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
|
2018-06-05 23:19:18 -04:00
|
|
|
end
|
|
|
|
end
|
2020-08-17 18:39:55 +02:00
|
|
|
private_class_method :attempt_directory_creation
|
2018-06-05 23:19:18 -04:00
|
|
|
|
2020-07-27 11:37:07 +02:00
|
|
|
def check_cc_argv(cc)
|
|
|
|
return unless cc
|
2019-01-21 19:23:31 +00:00
|
|
|
|
|
|
|
@checks ||= Diagnostic::Checks.new
|
|
|
|
opoo <<~EOS
|
2020-07-25 21:33:48 +02:00
|
|
|
You passed `--cc=#{cc}`.
|
2019-01-21 19:23:31 +00:00
|
|
|
#{@checks.please_create_pull_requests}
|
|
|
|
EOS
|
2018-09-06 18:38:43 +01:00
|
|
|
end
|
2020-08-17 18:39:55 +02:00
|
|
|
private_class_method :check_cc_argv
|
2018-06-05 23:19:18 -04:00
|
|
|
end
|
|
|
|
end
|
2018-09-28 14:01:09 -07:00
|
|
|
|
|
|
|
require "extend/os/install"
|