From 97866f8adf256ce50cb26a2f976236cbdfbdd6d9 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Fri, 11 Oct 2024 16:49:01 +0100 Subject: [PATCH] Perform preinstall checks when a formula is installed via a cask --- Library/Homebrew/cask/installer.rb | 1 + Library/Homebrew/cmd/gist-logs.rb | 2 +- Library/Homebrew/cmd/install.rb | 3 +- Library/Homebrew/cmd/reinstall.rb | 54 +++++++++++---------- Library/Homebrew/cmd/upgrade.rb | 4 +- Library/Homebrew/extend/os/linux/install.rb | 5 +- Library/Homebrew/install.rb | 40 +++++++++------ 7 files changed, 61 insertions(+), 48 deletions(-) diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 66bd4412c0b81..0874fceb32a4a 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -368,6 +368,7 @@ def satisfy_cask_and_formula_dependencies force: false, ).install else + Homebrew::Install.perform_preinstall_checks_once fi = FormulaInstaller.new( cask_or_formula, **{ diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index 25407fa07ab94..54d7e3e3fc881 100644 --- a/Library/Homebrew/cmd/gist-logs.rb +++ b/Library/Homebrew/cmd/gist-logs.rb @@ -31,7 +31,7 @@ class GistLogs < AbstractCommand 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) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index fe9ac9869e7ad..ff0d81d73a77f 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -294,7 +294,8 @@ def run 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, diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 953e25adbdfbf..bacf33beaac90 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -126,16 +126,35 @@ def run formulae = Homebrew::Attestation.sort_formulae_for_install(formulae) if Homebrew::Attestation.enabled? - Install.perform_preinstall_checks - - formulae.each do |formula| - if formula.pinned? - onoe "#{formula.full_name} is pinned. You must unpin it to reinstall." - next + unless formulae.empty? + Install.perform_preinstall_checks_once + + formulae.each do |formula| + if formula.pinned? + onoe "#{formula.full_name} is pinned. You must unpin it to reinstall." + next + end + Migrator.migrate_if_needed(formula, force: args.force?) + Homebrew::Reinstall.reinstall_formula( + formula, + flags: args.flags_only, + installed_on_request: args.named.present?, + force_bottle: args.force_bottle?, + build_from_source_formulae: args.build_from_source_formulae, + interactive: args.interactive?, + keep_tmp: args.keep_tmp?, + debug_symbols: args.debug_symbols?, + force: args.force?, + debug: args.debug?, + quiet: args.quiet?, + verbose: args.verbose?, + git: args.git?, + ) + Cleanup.install_formula_clean!(formula) end - Migrator.migrate_if_needed(formula, force: args.force?) - Homebrew::Reinstall.reinstall_formula( - formula, + + Upgrade.check_installed_dependents( + formulae, flags: args.flags_only, installed_on_request: args.named.present?, force_bottle: args.force_bottle?, @@ -147,26 +166,9 @@ def run debug: args.debug?, quiet: args.quiet?, verbose: args.verbose?, - git: args.git?, ) - Cleanup.install_formula_clean!(formula) end - Upgrade.check_installed_dependents( - formulae, - flags: args.flags_only, - installed_on_request: args.named.present?, - force_bottle: args.force_bottle?, - build_from_source_formulae: args.build_from_source_formulae, - interactive: args.interactive?, - keep_tmp: args.keep_tmp?, - debug_symbols: args.debug_symbols?, - force: args.force?, - debug: args.debug?, - quiet: args.quiet?, - verbose: args.verbose?, - ) - if casks.any? Cask::Reinstall.reinstall_casks( *casks, diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index c2dfb656f9bb9..80a6a019a7012 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -154,8 +154,6 @@ def upgrade_outdated_formulae(formulae) 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 @@ def upgrade_outdated_formulae(formulae) puts formulae_upgrades.join("\n") end + Install.perform_preinstall_checks_once + Upgrade.upgrade_formulae( formulae_to_install, flags: args.flags_only, diff --git a/Library/Homebrew/extend/os/linux/install.rb b/Library/Homebrew/extend/os/linux/install.rb index ab4a4901466bd..0fc3cd16dcc49 100644 --- a/Library/Homebrew/extend/os/linux/install.rb +++ b/Library/Homebrew/extend/os/linux/install.rb @@ -30,11 +30,12 @@ module Install ].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 diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 34849222f1d8b..892761212d475 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -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) @@ -314,15 +323,14 @@ def print_dry_run_dependencies(formula, dependencies) 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|