refactoring install

This commit is contained in:
thibhero 2025-06-08 12:34:24 -04:00
parent fd159ed32c
commit a5251b2fb6
2 changed files with 108 additions and 36 deletions

View File

@ -310,9 +310,7 @@ module Homebrew
Install.perform_preinstall_checks_once Install.perform_preinstall_checks_once
Install.check_cc_argv(args.cc) Install.check_cc_argv(args.cc)
Install.ask_formulae(installed_formulae, args: args) if args.ask? formulae_installer = Install.get_formulae_dependencies(
Install.install_formulae(
installed_formulae, installed_formulae,
installed_on_request: !args.as_dependency?, installed_on_request: !args.as_dependency?,
installed_as_dependency: args.as_dependency?, installed_as_dependency: args.as_dependency?,
@ -338,21 +336,71 @@ module Homebrew
skip_link: args.skip_link?, skip_link: args.skip_link?,
) )
Upgrade.check_installed_dependents( if args.ask?
installed_formulae, dependants = Upgrade.get_dependants(
flags: args.flags_only, installed_formulae,
installed_on_request: !args.as_dependency?, flags: args.flags_only,
force_bottle: args.force_bottle?, installed_on_request: !args.as_dependency?,
build_from_source_formulae: args.build_from_source_formulae, force_bottle: args.force_bottle?,
interactive: args.interactive?, build_from_source_formulae: args.build_from_source_formulae,
keep_tmp: args.keep_tmp?, interactive: args.interactive?,
debug_symbols: args.debug_symbols?, keep_tmp: args.keep_tmp?,
force: args.force?, debug_symbols: args.debug_symbols?,
debug: args.debug?, force: args.force?,
quiet: args.quiet?, debug: args.debug?,
verbose: args.verbose?, quiet: args.quiet?,
dry_run: args.dry_run?, verbose: args.verbose?,
) dry_run: args.dry_run?,
)
formulae_dependencies = formulae_installer.flat_map do |f|
[f.formula, f.compute_dependencies.flatten.filter do |c|
c.is_a? Dependency
end.flat_map(&:to_formula)]
end.flatten.uniq
formulae_dependencies.concat(dependants.upgradeable) if dependants
# Main block: if asking the user is enabled, show dependency and size information.
Install.ask_formulae(formulae_dependencies, args: args)
end
Upgrade.upgrade_formulae(formulae_installer,
dry_run: args.dry_run?,
verbose: args.verbose?)
unless args.ask?
dependants = Upgrade.get_dependants(
installed_formulae,
flags: args.flags_only,
dry_run: args.dry_run?,
ask: args.ask?,
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?,
)
end
if dependants
Upgrade.upgrade_dependents(
dependants, installed_formulae,
flags: args.flags_only,
dry_run: args.dry_run?,
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?
)
end
Cleanup.periodic_clean!(dry_run: args.dry_run?) Cleanup.periodic_clean!(dry_run: args.dry_run?)

View File

@ -232,7 +232,7 @@ module Homebrew
false false
end end
def install_formulae( def get_formulae_dependencies(
formulae_to_install, formulae_to_install,
installed_on_request: true, installed_on_request: true,
installed_as_dependency: false, installed_as_dependency: false,
@ -257,11 +257,11 @@ module Homebrew
skip_post_install: false, skip_post_install: false,
skip_link: false skip_link: false
) )
formula_installers = formulae_to_install.filter_map do |formula| formulae_to_install.filter_map do |formula|
Migrator.migrate_if_needed(formula, force:, dry_run:) Migrator.migrate_if_needed(formula, force:, dry_run:)
build_options = formula.build build_options = formula.build
formula_installer = FormulaInstaller.new( FormulaInstaller.new(
formula, formula,
options: build_options.used_options, options: build_options.used_options,
installed_on_request:, installed_on_request:,
@ -286,24 +286,36 @@ module Homebrew
skip_post_install:, skip_post_install:,
skip_link:, skip_link:,
) )
begin
unless dry_run
formula_installer.prelude
formula_installer.fetch
end
formula_installer
rescue CannotInstallFormulaError => e
ofail e.message
nil
rescue UnsatisfiedRequirements, DownloadError, ChecksumMismatchError => e
ofail "#{formula}: #{e}"
nil
end
end end
end
def install_formulae(
formula_installers,
installed_on_request: true,
installed_as_dependency: false,
build_bottle: false,
force_bottle: false,
bottle_arch: nil,
ignore_deps: false,
only_deps: false,
include_test_formulae: [],
build_from_source_formulae: [],
cc: nil,
git: false,
interactive: false,
keep_tmp: false,
debug_symbols: false,
force: false,
overwrite: false,
debug: false,
quiet: false,
verbose: false,
dry_run: false,
skip_post_install: false,
skip_link: false
)
if dry_run if dry_run
if (formulae_name_to_install = formulae_to_install.map(&:name)) if (formulae_name_to_install = formula_installers.map(&:name))
ohai "Would install #{Utils.pluralize("formula", formulae_name_to_install.count, ohai "Would install #{Utils.pluralize("formula", formulae_name_to_install.count,
plural: "e", include_count: true)}:" plural: "e", include_count: true)}:"
puts formulae_name_to_install.join(" ") puts formulae_name_to_install.join(" ")
@ -316,6 +328,18 @@ module Homebrew
end end
formula_installers.each do |fi| formula_installers.each do |fi|
begin
unless dry_run
fi.prelude
fi.fetch
end
rescue CannotInstallFormulaError => e
ofail e.message
next
rescue UnsatisfiedRequirements, DownloadError, ChecksumMismatchError => e
ofail "#{formula}: #{e}"
next
end
install_formula(fi) install_formula(fi)
Cleanup.install_formula_clean!(fi.formula) Cleanup.install_formula_clean!(fi.formula)
end end