Skip to content

Commit

Permalink
Merge pull request #18547 from Homebrew/cask-formula-dep-preinstall
Browse files Browse the repository at this point in the history
Perform preinstall checks when a formula is installed via a cask
  • Loading branch information
MikeMcQuaid authored Oct 13, 2024
2 parents 9fa2751 + 97866f8 commit d1e539c
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 48 deletions.
1 change: 1 addition & 0 deletions Library/Homebrew/cask/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
**{
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/gist-logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/cmd/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,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,
Expand Down
54 changes: 28 additions & 26 deletions Library/Homebrew/cmd/reinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions Library/Homebrew/extend/os/linux/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 24 additions & 16 deletions Library/Homebrew/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -315,15 +324,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|
Expand Down

0 comments on commit d1e539c

Please sign in to comment.