Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade: fetch all formulae before installing #11940

Merged
merged 3 commits into from
Aug 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 26 additions & 15 deletions Library/Homebrew/upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def upgrade_formulae(
end
end

formulae_to_install.each do |formula|
formula_installers = formulae_to_install.map do |formula|
Migrator.migrate_if_needed(formula, force: force)
begin
upgrade_formula(
fi = create_and_fetch_formula_installer(
formula,
flags: flags,
installed_on_request: installed_on_request,
Expand All @@ -57,10 +57,17 @@ def upgrade_formulae(
quiet: quiet,
verbose: verbose,
)
Cleanup.install_formula_clean!(formula)
rescue UnsatisfiedRequirements => e
fi.fetch
fi
rescue UnsatisfiedRequirements, DownloadError => e
ofail "#{formula}: #{e}"
nil
end
end.compact

formula_installers.each do |fi|
upgrade_formula(fi, verbose: verbose)
Cleanup.install_formula_clean!(fi.formula)
end
end

Expand All @@ -82,7 +89,7 @@ def print_upgrade_message(formula, fi_options)
EOS
end

def upgrade_formula(
def create_and_fetch_formula_installer(
formula,
flags:,
installed_on_request: false,
Expand All @@ -101,9 +108,6 @@ def upgrade_formula(
keg_was_linked = keg.linked?
end

kegs = outdated_kegs(formula)
linked_kegs = kegs.select(&:linked?)

if formula.opt_prefix.directory?
keg = Keg.new(formula.opt_prefix.resolved_path)
tab = Tab.for_keg(keg)
Expand All @@ -114,7 +118,7 @@ def upgrade_formula(
options |= formula.build.used_options
options &= formula.options

fi = FormulaInstaller.new(
FormulaInstaller.new(
formula,
**{
options: options,
Expand All @@ -132,24 +136,31 @@ def upgrade_formula(
verbose: verbose,
}.compact,
)
end
private_class_method :create_and_fetch_formula_installer

def upgrade_formula(formula_installer, verbose: false)
formula = formula_installer.formula

kegs = outdated_kegs(formula)
linked_kegs = kegs.select(&:linked?)

print_upgrade_message(formula, fi.options)
print_upgrade_message(formula, formula_installer.options)

fi.prelude
fi.fetch
formula_installer.prelude

# first we unlink the currently active keg for this formula otherwise it is
# possible for the existing build to interfere with the build we are about to
# do! Seriously, it happens!
kegs.each(&:unlink)

fi.install
fi.finish
formula_installer.install
formula_installer.finish
rescue FormulaInstallationAlreadyAttemptedError
# We already attempted to upgrade f as part of the dependency tree of
# another formula. In that case, don't generate an error, just move on.
nil
rescue CannotInstallFormulaError, DownloadError => e
rescue CannotInstallFormulaError => e
ofail e
rescue BuildError => e
e.dump(verbose: verbose)
Expand Down