2016-04-08 16:28:43 +02:00
|
|
|
#: * `upgrade` [<install-options>] [`--cleanup`] [<formulae>]:
|
|
|
|
#: Upgrade outdated, unpinned brews.
|
|
|
|
#:
|
|
|
|
#: Options for the `install` command are also valid here.
|
|
|
|
#:
|
|
|
|
#: If `--cleanup` is specified then remove previously installed <formula> version(s).
|
|
|
|
#:
|
|
|
|
#: If <formulae> are given, upgrade only the specified brews (but do so even
|
|
|
|
#: if they are pinned; see `pin`, `unpin`).
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
require "cmd/install"
|
2015-12-29 12:57:48 +01:00
|
|
|
require "cleanup"
|
2011-08-23 23:30:52 +01:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2011-08-23 23:30:52 +01:00
|
|
|
def upgrade
|
2015-07-26 16:49:16 -04:00
|
|
|
FormulaInstaller.prevent_build_flags unless MacOS.has_apple_developer_tools?
|
2015-06-29 14:09:57 -04:00
|
|
|
|
2011-08-23 23:30:52 +01:00
|
|
|
Homebrew.perform_preinstall_checks
|
|
|
|
|
2015-06-04 11:24:32 +01:00
|
|
|
if ARGV.named.empty?
|
2015-11-27 15:11:00 +00:00
|
|
|
outdated = Formula.installed.select(&:outdated?)
|
2013-07-18 15:18:15 -05:00
|
|
|
exit 0 if outdated.empty?
|
2015-04-26 19:38:50 +01:00
|
|
|
elsif ARGV.named.any?
|
2015-11-27 15:11:00 +00:00
|
|
|
outdated = ARGV.resolved_formulae.select(&:outdated?)
|
2015-01-03 17:59:40 -05:00
|
|
|
|
2015-05-17 21:16:07 +08:00
|
|
|
(ARGV.resolved_formulae - outdated).each do |f|
|
2015-11-29 15:37:06 +08:00
|
|
|
versions = f.installed_kegs.map { |keg| keg.version }
|
|
|
|
if versions.any?
|
|
|
|
version = versions.max
|
2015-05-27 21:23:45 +08:00
|
|
|
onoe "#{f.full_name} #{version} already installed"
|
2012-03-07 11:17:36 +00:00
|
|
|
else
|
2015-05-27 21:23:45 +08:00
|
|
|
onoe "#{f.full_name} not installed"
|
2012-03-07 11:17:36 +00:00
|
|
|
end
|
2011-09-02 09:55:37 +01:00
|
|
|
end
|
2013-01-19 19:45:18 -05:00
|
|
|
exit 1 if outdated.empty?
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|
|
|
|
|
2013-05-18 22:09:15 -05:00
|
|
|
unless upgrade_pinned?
|
|
|
|
pinned = outdated.select(&:pinned?)
|
2013-03-11 16:41:08 +01:00
|
|
|
outdated -= pinned
|
|
|
|
end
|
|
|
|
|
2014-01-25 06:30:46 +01:00
|
|
|
unless outdated.empty?
|
2014-05-26 11:19:00 -07:00
|
|
|
oh1 "Upgrading #{outdated.length} outdated package#{plural(outdated.length)}, with result:"
|
2015-08-03 13:09:07 +01:00
|
|
|
puts outdated.map { |f| "#{f.full_name} #{f.pkg_version}" } * ", "
|
2014-01-25 06:30:46 +01:00
|
|
|
else
|
|
|
|
oh1 "No packages to upgrade"
|
|
|
|
end
|
2013-05-18 22:09:15 -05:00
|
|
|
|
2013-07-15 23:47:03 -05:00
|
|
|
unless upgrade_pinned? || pinned.empty?
|
2014-05-26 11:19:00 -07:00
|
|
|
oh1 "Not upgrading #{pinned.length} pinned package#{plural(pinned.length)}:"
|
2015-08-03 13:09:07 +01:00
|
|
|
puts pinned.map { |f| "#{f.full_name} #{f.pkg_version}" } * ", "
|
2013-03-11 16:41:08 +01:00
|
|
|
end
|
2011-08-23 23:30:52 +01:00
|
|
|
|
2015-10-06 23:14:12 +05:30
|
|
|
outdated.each do |f|
|
|
|
|
upgrade_formula(f)
|
2015-12-29 12:57:48 +01:00
|
|
|
next unless ARGV.include?("--cleanup")
|
|
|
|
next unless f.installed?
|
|
|
|
Homebrew::Cleanup.cleanup_formula f
|
2015-10-06 23:14:12 +05:30
|
|
|
end
|
2013-05-18 22:09:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def upgrade_pinned?
|
2015-08-03 13:09:07 +01:00
|
|
|
!ARGV.named.empty?
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|
2012-03-07 11:17:36 +00:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def upgrade_formula(f)
|
2014-04-05 12:17:19 -05:00
|
|
|
outdated_keg = Keg.new(f.linked_keg.resolved_path) if f.linked_keg.directory?
|
2014-08-15 16:56:13 -06:00
|
|
|
tab = Tab.for_formula(f)
|
2012-03-07 11:17:36 +00:00
|
|
|
|
2014-03-13 10:11:00 -05:00
|
|
|
fi = FormulaInstaller.new(f)
|
2014-08-15 16:56:13 -06:00
|
|
|
fi.options = tab.used_options
|
2015-03-24 12:11:40 +00:00
|
|
|
fi.build_bottle = ARGV.build_bottle? || (!f.bottled? && tab.build_bottle?)
|
2014-03-13 10:11:00 -05:00
|
|
|
fi.build_from_source = ARGV.build_from_source?
|
|
|
|
fi.verbose = ARGV.verbose?
|
2014-11-03 21:36:01 -06:00
|
|
|
fi.quieter = ARGV.quieter?
|
2014-03-13 10:11:00 -05:00
|
|
|
fi.debug = ARGV.debug?
|
|
|
|
fi.prelude
|
2012-03-07 11:17:36 +00:00
|
|
|
|
2015-05-27 21:23:45 +08:00
|
|
|
oh1 "Upgrading #{f.full_name}"
|
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!
|
|
|
|
outdated_keg.unlink if outdated_keg
|
|
|
|
|
2014-03-13 10:11:00 -05:00
|
|
|
fi.install
|
|
|
|
fi.finish
|
2013-03-11 16:41:08 +01:00
|
|
|
|
|
|
|
# If the formula was pinned, and we were force-upgrading it, unpin and
|
|
|
|
# pin it again to get a symlink pointing to the correct keg.
|
|
|
|
if f.pinned?
|
|
|
|
f.unpin
|
|
|
|
f.pin
|
|
|
|
end
|
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.
|
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
|
2015-08-03 13:09:07 +01:00
|
|
|
outdated_keg.link if outdated_keg && !f.installed? rescue nil
|
2012-03-07 11:17:36 +00:00
|
|
|
end
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|