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, force: false,
).install ).install
else else
Homebrew::Install.perform_preinstall_checks_once
fi = FormulaInstaller.new( fi = FormulaInstaller.new(
cask_or_formula, cask_or_formula,
**{ **{

View File

@ -31,7 +31,7 @@ module Homebrew
sig { override.void } sig { override.void }
def run 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) Install.perform_build_from_source_checks(all_fatal: true)
return unless (formula = args.named.to_resolved_formulae.first) return unless (formula = args.named.to_resolved_formulae.first)

View File

@ -295,7 +295,8 @@ module Homebrew
return if formulae.any? && installed_formulae.empty? 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( Install.install_formulae(
installed_formulae, installed_formulae,

View File

@ -126,7 +126,8 @@ module Homebrew
formulae = Homebrew::Attestation.sort_formulae_for_install(formulae) if Homebrew::Attestation.enabled? 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| formulae.each do |formula|
if formula.pinned? if formula.pinned?
@ -166,6 +167,7 @@ module Homebrew
quiet: args.quiet?, quiet: args.quiet?,
verbose: args.verbose?, verbose: args.verbose?,
) )
end
if casks.any? if casks.any?
Cask::Reinstall.reinstall_casks( Cask::Reinstall.reinstall_casks(

View File

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

View File

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

View File

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