2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-05 23:19:18 -04:00
|
|
|
require "install"
|
2018-09-12 19:28:02 +00:00
|
|
|
require "reinstall"
|
2018-06-05 23:19:18 -04:00
|
|
|
require "formula_installer"
|
2016-07-29 20:31:32 -06:00
|
|
|
require "development_tools"
|
2018-06-20 02:10:54 -04:00
|
|
|
require "messages"
|
2019-01-03 16:23:44 +00:00
|
|
|
require "cleanup"
|
2019-04-17 18:25:08 +09:00
|
|
|
require "cli/parser"
|
2011-08-23 23:30:52 +01:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2019-01-29 19:52:06 +05:30
|
|
|
def upgrade_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
2019-08-06 14:17:17 -04:00
|
|
|
`upgrade` [<options>] [<formula>]
|
2019-01-29 19:52:06 +05:30
|
|
|
|
2019-08-20 00:04:14 -04:00
|
|
|
Upgrade outdated, unpinned formulae using the same options they were originally
|
|
|
|
installed with, plus any appended brew formula options. If <formula> are specified,
|
|
|
|
upgrade only the given <formula> kegs (unless they are pinned; see `pin`, `unpin`).
|
2019-01-29 19:52:06 +05:30
|
|
|
|
2019-08-20 00:04:14 -04:00
|
|
|
Unless `HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for the
|
2019-08-06 13:23:19 -04:00
|
|
|
upgraded formulae or, every 30 days, for all formulae.
|
2019-01-29 19:52:06 +05:30
|
|
|
EOS
|
2019-01-29 19:25:13 +00:00
|
|
|
switch :debug,
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "If brewing fails, open an interactive debugging session with access to IRB "\
|
2019-08-06 14:22:24 -04:00
|
|
|
"or a shell inside the temporary build directory."
|
2019-01-29 19:25:13 +00:00
|
|
|
switch "-s", "--build-from-source",
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "Compile <formula> from source even if a bottle is available."
|
2019-01-29 19:25:13 +00:00
|
|
|
switch "--force-bottle",
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "Install from a bottle if it exists for the current or newest version of "\
|
|
|
|
"macOS, even if it would not normally be used for installation."
|
2019-01-29 19:52:06 +05:30
|
|
|
switch "--fetch-HEAD",
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "Fetch the upstream repository to detect if the HEAD installation of the "\
|
2019-08-20 00:04:14 -04:00
|
|
|
"formula is outdated. Otherwise, the repository's HEAD will only be checked for "\
|
2019-04-30 08:44:35 +01:00
|
|
|
"updates when a new stable or development version has been released."
|
2019-01-29 19:52:06 +05:30
|
|
|
switch "--ignore-pinned",
|
2019-08-20 00:04:14 -04:00
|
|
|
description: "Set a successful exit status even if pinned formulae are not upgraded."
|
2019-01-29 19:25:13 +00:00
|
|
|
switch "--keep-tmp",
|
2019-08-20 00:04:14 -04:00
|
|
|
description: "Retain the temporary files created during installation."
|
2019-01-29 19:25:13 +00:00
|
|
|
switch :force,
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "Install without checking for previously installed keg-only or "\
|
|
|
|
"non-migrated versions."
|
2019-01-29 19:25:13 +00:00
|
|
|
switch :verbose,
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "Print the verification and postinstall steps."
|
2019-01-29 19:52:06 +05:30
|
|
|
switch "--display-times",
|
2019-07-28 11:12:32 +01:00
|
|
|
env: :display_install_times,
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "Print install times for each formula at the end of the run."
|
2019-08-21 12:42:09 -04:00
|
|
|
switch "-n", "--dry-run",
|
2019-07-26 22:55:16 -07:00
|
|
|
description: "Show what would be upgraded, but do not actually upgrade anything."
|
2019-01-29 19:39:41 +00:00
|
|
|
conflicts "--build-from-source", "--force-bottle"
|
2019-01-29 19:25:13 +00:00
|
|
|
formula_options
|
2019-01-29 19:52:06 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-23 23:30:52 +01:00
|
|
|
def upgrade
|
2019-02-04 08:38:24 +01:00
|
|
|
upgrade_args.parse
|
|
|
|
|
2016-07-06 11:07:24 +01:00
|
|
|
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
|
2015-06-29 14:09:57 -04:00
|
|
|
|
2018-06-05 23:19:18 -04:00
|
|
|
Install.perform_preinstall_checks
|
2011-08-23 23:30:52 +01:00
|
|
|
|
2015-06-04 11:24:32 +01:00
|
|
|
if ARGV.named.empty?
|
2016-07-22 12:47:47 +03:00
|
|
|
outdated = Formula.installed.select do |f|
|
2019-01-29 19:52:06 +05:30
|
|
|
f.outdated?(fetch_head: args.fetch_HEAD?)
|
2016-07-22 12:47:47 +03:00
|
|
|
end
|
|
|
|
|
2013-07-18 15:18:15 -05:00
|
|
|
exit 0 if outdated.empty?
|
2016-08-05 22:01:32 +08:00
|
|
|
else
|
2016-07-22 12:47:47 +03:00
|
|
|
outdated = ARGV.resolved_formulae.select do |f|
|
2019-01-29 19:52:06 +05:30
|
|
|
f.outdated?(fetch_head: args.fetch_HEAD?)
|
2016-07-22 12:47:47 +03:00
|
|
|
end
|
2015-01-03 17:59:40 -05:00
|
|
|
|
2015-05-17 21:16:07 +08:00
|
|
|
(ARGV.resolved_formulae - outdated).each do |f|
|
2016-09-10 10:24:57 +01:00
|
|
|
versions = f.installed_kegs.map(&:version)
|
2016-08-05 22:01:32 +08:00
|
|
|
if versions.empty?
|
2019-11-12 16:18:54 -08:00
|
|
|
ofail "#{f.full_specified_name} not installed"
|
2016-08-05 22:01:32 +08:00
|
|
|
else
|
2015-11-29 15:37:06 +08:00
|
|
|
version = versions.max
|
2019-11-12 16:18:54 -08:00
|
|
|
opoo "#{f.full_specified_name} #{version} already installed"
|
2012-03-07 11:17:36 +00:00
|
|
|
end
|
2011-09-02 09:55:37 +01:00
|
|
|
end
|
2019-11-12 16:18:54 -08:00
|
|
|
exit
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|
|
|
|
|
2018-02-05 09:31:17 +00:00
|
|
|
pinned = outdated.select(&:pinned?)
|
|
|
|
outdated -= pinned
|
2016-09-15 16:01:18 +01:00
|
|
|
formulae_to_install = outdated.map(&:latest_formula)
|
|
|
|
|
2019-01-29 19:52:06 +05:30
|
|
|
if !pinned.empty? && !args.ignore_pinned?
|
2018-09-17 20:11:11 +02:00
|
|
|
ofail "Not upgrading #{pinned.count} pinned #{"package".pluralize(pinned.count)}:"
|
2018-03-16 20:31:20 +00:00
|
|
|
puts pinned.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", "
|
|
|
|
end
|
|
|
|
|
2016-09-15 16:01:18 +01:00
|
|
|
if formulae_to_install.empty?
|
2016-09-10 10:24:57 +01:00
|
|
|
oh1 "No packages to upgrade"
|
|
|
|
else
|
2019-07-28 14:50:59 +01:00
|
|
|
verb = args.dry_run? ? "Would upgrade" : "Upgrading"
|
|
|
|
oh1 "#{verb} #{formulae_to_install.count} outdated #{"package".pluralize(formulae_to_install.count)}:"
|
2018-03-30 15:00:45 +01:00
|
|
|
formulae_upgrades = formulae_to_install.map do |f|
|
|
|
|
if f.optlinked?
|
|
|
|
"#{f.full_specified_name} #{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}"
|
|
|
|
else
|
|
|
|
"#{f.full_specified_name} #{f.pkg_version}"
|
|
|
|
end
|
|
|
|
end
|
2019-09-09 12:03:19 +02:00
|
|
|
puts formulae_upgrades.join("\n")
|
2014-01-25 06:30:46 +01:00
|
|
|
end
|
2019-07-28 14:50:59 +01:00
|
|
|
return if args.dry_run?
|
2013-05-18 22:09:15 -05:00
|
|
|
|
2018-09-12 19:28:02 +00:00
|
|
|
upgrade_formulae(formulae_to_install)
|
|
|
|
|
|
|
|
check_dependents(formulae_to_install)
|
|
|
|
|
|
|
|
Homebrew.messages.display_messages
|
|
|
|
end
|
|
|
|
|
|
|
|
def upgrade_formulae(formulae_to_install)
|
|
|
|
return if formulae_to_install.empty?
|
|
|
|
|
2018-10-18 21:42:43 -04:00
|
|
|
# Sort keg-only before non-keg-only formulae to avoid any needless conflicts
|
|
|
|
# with outdated, non-keg-only versions of formulae being upgraded.
|
2017-03-17 08:31:49 -07:00
|
|
|
formulae_to_install.sort! do |a, b|
|
|
|
|
if !a.keg_only? && b.keg_only?
|
|
|
|
1
|
|
|
|
elsif a.keg_only? && !b.keg_only?
|
|
|
|
-1
|
|
|
|
else
|
|
|
|
0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-15 16:01:18 +01:00
|
|
|
formulae_to_install.each do |f|
|
2017-03-29 11:25:37 +01:00
|
|
|
Migrator.migrate_if_needed(f)
|
2018-01-08 14:38:10 +00:00
|
|
|
begin
|
|
|
|
upgrade_formula(f)
|
2019-01-03 16:23:44 +00:00
|
|
|
Cleanup.install_formula_clean!(f)
|
2018-01-08 14:38:10 +00:00
|
|
|
rescue UnsatisfiedRequirements => e
|
2018-01-09 09:07:37 +00:00
|
|
|
Homebrew.failed = true
|
2018-01-08 14:38:10 +00:00
|
|
|
onoe "#{f}: #{e}"
|
|
|
|
end
|
2015-10-06 23:14:12 +05:30
|
|
|
end
|
2013-05-18 22:09:15 -05:00
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def upgrade_formula(f)
|
2017-07-30 21:44:43 +01:00
|
|
|
if f.opt_prefix.directory?
|
|
|
|
keg = Keg.new(f.opt_prefix.resolved_path)
|
|
|
|
keg_had_linked_opt = true
|
|
|
|
keg_was_linked = keg.linked?
|
|
|
|
end
|
|
|
|
|
2016-09-15 16:01:18 +01:00
|
|
|
formulae_maybe_with_kegs = [f] + f.old_installed_formulae
|
2016-09-19 16:04:32 +01:00
|
|
|
outdated_kegs = formulae_maybe_with_kegs
|
|
|
|
.map(&:linked_keg)
|
|
|
|
.select(&:directory?)
|
|
|
|
.map { |k| Keg.new(k.resolved_path) }
|
2017-07-28 17:47:10 +01:00
|
|
|
linked_kegs = outdated_kegs.select(&:linked?)
|
2012-03-07 11:17:36 +00:00
|
|
|
|
2017-01-09 21:09:46 +00:00
|
|
|
if f.opt_prefix.directory?
|
|
|
|
keg = Keg.new(f.opt_prefix.resolved_path)
|
|
|
|
tab = Tab.for_keg(keg)
|
|
|
|
end
|
|
|
|
|
2019-09-23 12:36:45 +05:30
|
|
|
build_options = BuildOptions.new(Options.create(Homebrew.args.flags_only), f.options)
|
2017-12-02 20:04:03 +00:00
|
|
|
options = build_options.used_options
|
|
|
|
options |= f.build.used_options
|
|
|
|
options &= f.options
|
2017-12-02 17:14:46 +00:00
|
|
|
|
2014-03-13 10:11:00 -05:00
|
|
|
fi = FormulaInstaller.new(f)
|
2017-12-02 20:04:03 +00:00
|
|
|
fi.options = options
|
2019-04-25 14:01:50 -07:00
|
|
|
fi.build_bottle = args.build_bottle?
|
2017-01-09 21:09:46 +00:00
|
|
|
fi.installed_on_request = !ARGV.named.empty?
|
2018-01-10 16:43:21 +00:00
|
|
|
fi.link_keg ||= keg_was_linked if keg_had_linked_opt
|
2017-01-09 21:09:46 +00:00
|
|
|
if tab
|
2019-04-25 14:01:50 -07:00
|
|
|
fi.build_bottle ||= tab.built_bottle?
|
2017-01-09 21:09:46 +00:00
|
|
|
fi.installed_as_dependency = tab.installed_as_dependency
|
2017-01-18 16:10:28 +00:00
|
|
|
fi.installed_on_request ||= tab.installed_on_request
|
2017-01-09 21:09:46 +00:00
|
|
|
end
|
2014-03-13 10:11:00 -05:00
|
|
|
fi.prelude
|
2012-03-07 11:17:36 +00:00
|
|
|
|
2018-02-09 11:31:51 +09:00
|
|
|
oh1 "Upgrading #{Formatter.identifier(f.full_specified_name)} #{fi.options.to_a.join " "}"
|
2012-03-07 11:17:36 +00:00
|
|
|
|
|
|
|
# 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!
|
2016-09-15 16:01:18 +01:00
|
|
|
outdated_kegs.each(&:unlink)
|
2012-03-07 11:17:36 +00:00
|
|
|
|
2014-03-13 10:11:00 -05:00
|
|
|
fi.install
|
|
|
|
fi.finish
|
2013-01-08 19:54:32 -06:00
|
|
|
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.
|
2018-03-06 09:36:49 +00:00
|
|
|
nil
|
2012-03-07 11:17:36 +00:00
|
|
|
rescue CannotInstallFormulaError => e
|
2012-04-30 14:08:59 +10:00
|
|
|
ofail e
|
2012-03-07 11:17:36 +00:00
|
|
|
rescue BuildError => e
|
|
|
|
e.dump
|
|
|
|
puts
|
2012-03-15 10:57:34 +13:00
|
|
|
Homebrew.failed = true
|
2014-02-18 15:08:03 -05:00
|
|
|
rescue DownloadError => e
|
|
|
|
ofail e
|
2012-03-07 11:17:36 +00:00
|
|
|
ensure
|
|
|
|
# restore previous installation state if build failed
|
2016-09-10 10:24:57 +01:00
|
|
|
begin
|
2017-07-28 17:47:10 +01:00
|
|
|
linked_kegs.each(&:link) unless f.installed?
|
2016-09-10 10:24:57 +01:00
|
|
|
rescue
|
|
|
|
nil
|
|
|
|
end
|
2012-03-07 11:17:36 +00:00
|
|
|
end
|
2018-09-12 19:28:02 +00:00
|
|
|
|
|
|
|
# @private
|
|
|
|
def depends_on(a, b)
|
|
|
|
if a.opt_or_installed_prefix_keg
|
|
|
|
.runtime_dependencies
|
|
|
|
.any? { |d| d["full_name"] == b.full_name }
|
|
|
|
1
|
|
|
|
else
|
|
|
|
a <=> b
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-05 20:35:49 +00:00
|
|
|
def check_dependents(formulae_to_install)
|
|
|
|
return if formulae_to_install.empty?
|
2018-09-12 19:28:02 +00:00
|
|
|
|
2019-11-06 11:38:17 +00:00
|
|
|
oh1 "Checking for dependents of upgraded formulae..."
|
2019-11-05 20:35:49 +00:00
|
|
|
dependents =
|
|
|
|
formulae_to_install.flat_map(&:runtime_installed_formula_dependents)
|
2019-11-06 11:38:17 +00:00
|
|
|
if dependents.blank?
|
|
|
|
ohai "No dependents found!"
|
|
|
|
return
|
|
|
|
end
|
2019-11-05 20:35:49 +00:00
|
|
|
|
|
|
|
upgradeable_dependents = dependents.select(&:outdated?)
|
|
|
|
.sort { |a, b| depends_on(a, b) }
|
|
|
|
pinned_dependents = dependents.select(&:pinned?)
|
|
|
|
.sort { |a, b| depends_on(a, b) }
|
|
|
|
|
|
|
|
if pinned_dependents.present?
|
|
|
|
plural = "dependent".pluralize(pinned_dependents.count)
|
|
|
|
ohai "Not upgrading #{pinned_dependents.count} pinned #{plural}:"
|
|
|
|
puts pinned_dependents.map do |f|
|
|
|
|
"#{f.full_specified_name} #{f.pkg_version}"
|
|
|
|
end.join(", ")
|
2018-09-12 19:28:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Print the upgradable dependents.
|
2019-11-05 20:35:49 +00:00
|
|
|
if upgradeable_dependents.blank?
|
2019-11-06 11:38:17 +00:00
|
|
|
ohai "No outdated dependents to upgrade!"
|
2018-09-12 19:28:02 +00:00
|
|
|
else
|
2019-11-05 20:35:49 +00:00
|
|
|
plural = "dependent".pluralize(upgradeable_dependents.count)
|
2019-11-07 22:58:02 +07:00
|
|
|
ohai "Upgrading #{upgradeable_dependents.count} #{plural}:"
|
2019-11-05 20:35:49 +00:00
|
|
|
formulae_upgrades = upgradeable_dependents.map do |f|
|
|
|
|
name = f.full_specified_name
|
2018-09-12 19:28:02 +00:00
|
|
|
if f.optlinked?
|
2019-11-05 20:35:49 +00:00
|
|
|
"#{name} #{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}"
|
2018-09-12 19:28:02 +00:00
|
|
|
else
|
2019-11-05 20:35:49 +00:00
|
|
|
"#{name} #{f.pkg_version}"
|
2018-09-12 19:28:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
puts formulae_upgrades.join(", ")
|
|
|
|
end
|
|
|
|
|
2019-11-05 20:35:49 +00:00
|
|
|
upgrade_formulae(upgradeable_dependents)
|
2018-09-12 19:28:02 +00:00
|
|
|
|
2019-11-05 20:35:49 +00:00
|
|
|
# Assess the dependents tree again now we've upgraded.
|
2019-11-06 11:38:17 +00:00
|
|
|
oh1 "Checking for dependents' broken linkage from upgraded formulae..."
|
2019-11-05 20:35:49 +00:00
|
|
|
broken_dependents = CacheStoreDatabase.use(:linkage) do |db|
|
|
|
|
formulae_to_install.flat_map(&:runtime_installed_formula_dependents)
|
2019-11-11 10:08:08 +00:00
|
|
|
.select do |f|
|
|
|
|
keg = f.opt_or_installed_prefix_keg
|
|
|
|
next unless keg
|
|
|
|
|
2019-11-05 20:35:49 +00:00
|
|
|
LinkageChecker.new(keg, cache_db: db)
|
|
|
|
.broken_library_linkage?
|
2019-11-11 10:08:08 +00:00
|
|
|
end.compact
|
2019-11-05 20:35:49 +00:00
|
|
|
end
|
2019-11-06 11:38:17 +00:00
|
|
|
if broken_dependents.blank?
|
|
|
|
ohai "No broken dependents found!"
|
|
|
|
return
|
|
|
|
end
|
2018-09-12 19:28:02 +00:00
|
|
|
|
2019-11-05 20:35:49 +00:00
|
|
|
reinstallable_broken_dependents =
|
|
|
|
broken_dependents.select(&:outdated?)
|
|
|
|
.sort { |a, b| depends_on(a, b) }
|
|
|
|
pinned_broken_dependents =
|
|
|
|
broken_dependents.select(&:pinned?)
|
|
|
|
.sort { |a, b| depends_on(a, b) }
|
2018-09-12 19:28:02 +00:00
|
|
|
|
|
|
|
# Print the pinned dependents.
|
2019-11-05 20:35:49 +00:00
|
|
|
if pinned_broken_dependents.present?
|
|
|
|
count = pinned_broken_dependents.count
|
|
|
|
plural = "dependent".pluralize(pinned_broken_dependents.count)
|
|
|
|
onoe "Not reinstalling #{count} broken and outdated, but pinned #{plural}:"
|
|
|
|
$stderr.puts pinned_broken_dependents.map do |f|
|
|
|
|
"#{f.full_specified_name} #{f.pkg_version}"
|
|
|
|
end.join(", ")
|
2018-09-12 19:28:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Print the broken dependents.
|
2019-11-06 11:38:17 +00:00
|
|
|
if reinstallable_broken_dependents.blank?
|
|
|
|
ohai "No broken dependents to reinstall!"
|
2018-09-12 19:28:02 +00:00
|
|
|
else
|
2019-11-05 20:35:49 +00:00
|
|
|
count = reinstallable_broken_dependents.count
|
|
|
|
plural = "dependent".pluralize(reinstallable_broken_dependents.count)
|
|
|
|
ohai "Reinstalling #{count} broken #{plural} from source:"
|
|
|
|
puts reinstallable_broken_dependents.map(&:full_specified_name)
|
|
|
|
.join(", ")
|
2018-09-12 19:28:02 +00:00
|
|
|
end
|
|
|
|
|
2019-11-05 20:35:49 +00:00
|
|
|
reinstallable_broken_dependents.each do |f|
|
2019-10-13 10:03:26 +01:00
|
|
|
reinstall_formula(f, build_from_source: true)
|
|
|
|
rescue FormulaInstallationAlreadyAttemptedError
|
|
|
|
# We already attempted to reinstall f as part of the dependency tree of
|
|
|
|
# another formula. In that case, don't generate an error, just move on.
|
|
|
|
nil
|
|
|
|
rescue CannotInstallFormulaError => e
|
|
|
|
ofail e
|
|
|
|
rescue BuildError => e
|
|
|
|
e.dump
|
|
|
|
puts
|
|
|
|
Homebrew.failed = true
|
|
|
|
rescue DownloadError => e
|
|
|
|
ofail e
|
2018-09-12 19:28:02 +00:00
|
|
|
end
|
|
|
|
end
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|