Merge pull request #18547 from Homebrew/cask-formula-dep-preinstall

Perform preinstall checks when a formula is installed via a cask
This commit is contained in:
Mike McQuaid 2024-10-13 17:40:59 +01:00 committed by GitHub
commit d1e539cb84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 60 additions and 47 deletions

View File

@ -368,6 +368,7 @@ on_request: true)
force: false,
).install
else
Homebrew::Install.perform_preinstall_checks_once
fi = FormulaInstaller.new(
cask_or_formula,
**{

View File

@ -31,7 +31,7 @@ module Homebrew
sig { override.void }
def run
Install.perform_preinstall_checks(all_fatal: true)
Install.perform_preinstall_checks_once(all_fatal: true)
Install.perform_build_from_source_checks(all_fatal: true)
return unless (formula = args.named.to_resolved_formulae.first)

View File

@ -295,7 +295,8 @@ module Homebrew
return if formulae.any? && installed_formulae.empty?
Install.perform_preinstall_checks(cc: args.cc)
Install.perform_preinstall_checks_once
Install.check_cc_argv(args.cc)
Install.install_formulae(
installed_formulae,

View File

@ -126,7 +126,8 @@ module Homebrew
formulae = Homebrew::Attestation.sort_formulae_for_install(formulae) if Homebrew::Attestation.enabled?
Install.perform_preinstall_checks
unless formulae.empty?
Install.perform_preinstall_checks_once
formulae.each do |formula|
if formula.pinned?
@ -166,6 +167,7 @@ module Homebrew
quiet: args.quiet?,
verbose: args.verbose?,
)
end
if casks.any?
Cask::Reinstall.reinstall_casks(

View File

@ -154,8 +154,6 @@ module Homebrew
end
end
Install.perform_preinstall_checks
if formulae.blank?
outdated = Formula.installed.select do |f|
f.outdated?(fetch_head: args.fetch_HEAD?)
@ -212,6 +210,8 @@ module Homebrew
puts formulae_upgrades.join("\n")
end
Install.perform_preinstall_checks_once
Upgrade.upgrade_formulae(
formulae_to_install,
flags: args.flags_only,

View File

@ -30,11 +30,12 @@ module Homebrew
].freeze
private_constant :GCC_RUNTIME_LIBS
def self.perform_preinstall_checks(all_fatal: false, cc: nil)
generic_perform_preinstall_checks(all_fatal:, cc:)
def self.perform_preinstall_checks(all_fatal: false)
generic_perform_preinstall_checks(all_fatal:)
symlink_ld_so
setup_preferred_gcc_libs
end
private_class_method :perform_preinstall_checks
def self.global_post_install
generic_global_post_install

View File

@ -11,15 +11,24 @@ module Homebrew
# Helper module for performing (pre-)install checks.
module Install
class << self
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)
sig { params(all_fatal: T::Boolean).void }
def perform_preinstall_checks_once(all_fatal: false)
@perform_preinstall_checks_once ||= {}
@perform_preinstall_checks_once[all_fatal] ||= begin
perform_preinstall_checks(all_fatal:)
true
end
end
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
alias generic_perform_preinstall_checks perform_preinstall_checks
def perform_build_from_source_checks(all_fatal: false)
Diagnostic.checks(:fatal_build_from_source_checks)
@ -315,15 +324,14 @@ module Homebrew
private
def check_cc_argv(cc)
return unless cc
@checks ||= Diagnostic::Checks.new
opoo <<~EOS
You passed `--cc=#{cc}`.
#{@checks.please_create_pull_requests}
EOS
def perform_preinstall_checks(all_fatal: false)
check_prefix
check_cpu
attempt_directory_creation
Diagnostic.checks(:supported_configuration_checks, fatal: all_fatal)
Diagnostic.checks(:fatal_preinstall_checks)
end
alias generic_perform_preinstall_checks perform_preinstall_checks
def attempt_directory_creation
Keg.must_exist_directories.each do |dir|