2011-08-23 23:30:52 +01:00
|
|
|
require 'cmd/install'
|
|
|
|
|
|
|
|
class Fixnum
|
|
|
|
def plural_s
|
|
|
|
if self > 1 then "s" else "" end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Homebrew extend self
|
|
|
|
def upgrade
|
2012-03-07 12:50:15 +00:00
|
|
|
if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero?
|
|
|
|
# note we only abort if Homebrew is *not* installed as sudo and the user
|
|
|
|
# calls brew as root. The fix is to chown brew to root.
|
|
|
|
abort "Cowardly refusing to `sudo brew upgrade'"
|
|
|
|
end
|
|
|
|
|
2011-08-23 23:30:52 +01:00
|
|
|
Homebrew.perform_preinstall_checks
|
|
|
|
|
|
|
|
outdated = if ARGV.named.empty?
|
2012-07-10 22:09:31 -05:00
|
|
|
require 'cmd/outdated'
|
2011-08-23 23:30:52 +01:00
|
|
|
Homebrew.outdated_brews
|
|
|
|
else
|
2012-03-07 11:17:36 +00:00
|
|
|
ARGV.formulae.select do |f|
|
2012-08-18 18:37:32 -05:00
|
|
|
if f.installed?
|
|
|
|
onoe "#{f}-#{f.installed_version} already installed"
|
|
|
|
elsif not f.rack.exist? or f.rack.children.empty?
|
2012-03-07 11:17:36 +00:00
|
|
|
onoe "#{f} not installed"
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
2011-09-02 09:55:37 +01:00
|
|
|
end
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|
|
|
|
|
2012-08-18 18:13:01 -05:00
|
|
|
# Expand the outdated list to include outdated dependencies then sort and
|
|
|
|
# reduce such that dependencies are installed first and installation is not
|
|
|
|
# attempted twice. Sorting is implicit the way `recursive_deps` returns
|
|
|
|
# root dependencies at the head of the list and `uniq` keeps the first
|
|
|
|
# element it encounters and discards the rest.
|
|
|
|
ARGV.filter_for_dependencies do
|
|
|
|
outdated.map!{ |f| f.recursive_deps.reject{ |d| d.installed? } << f }
|
2012-06-25 09:20:18 -08:00
|
|
|
outdated.flatten!
|
|
|
|
outdated.uniq!
|
2012-08-18 18:13:01 -05:00
|
|
|
end unless ARGV.ignore_deps?
|
2011-09-11 13:16:01 -07:00
|
|
|
|
2011-08-24 17:33:28 -07:00
|
|
|
if outdated.length > 1
|
2011-08-25 18:02:36 -07:00
|
|
|
oh1 "Upgrading #{outdated.length} outdated package#{outdated.length.plural_s}, with result:"
|
2011-09-11 13:06:05 -07:00
|
|
|
puts outdated.map{ |f| "#{f.name} #{f.version}" } * ", "
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|
|
|
|
|
2011-09-11 13:06:05 -07:00
|
|
|
outdated.each do |f|
|
2012-03-07 11:17:36 +00:00
|
|
|
upgrade_formula f
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|
|
|
|
end
|
2012-03-07 11:17:36 +00:00
|
|
|
|
|
|
|
def upgrade_formula f
|
2012-12-18 14:59:12 -08:00
|
|
|
# Generate using `for_keg` since the formula object points to a newer version
|
|
|
|
# that doesn't exist yet. Use `opt_prefix` to guard against keg-only installs.
|
|
|
|
# Also, guard against old installs that may not have an `opt_prefix` symlink.
|
|
|
|
tab = (f.opt_prefix.exist? ? Tab.for_keg(f.opt_prefix) : Tab.dummy_tab(f))
|
2012-03-07 11:17:36 +00:00
|
|
|
outdated_keg = Keg.new(f.linked_keg.realpath) rescue nil
|
|
|
|
|
2012-03-23 13:05:08 -05:00
|
|
|
installer = FormulaInstaller.new(f, tab)
|
2012-03-07 11:17:36 +00:00
|
|
|
installer.show_header = false
|
2012-12-18 14:59:12 -08:00
|
|
|
installer.install_bottle = (install_bottle?(f) and tab.used_options.empty?)
|
2012-03-07 11:17:36 +00:00
|
|
|
|
|
|
|
oh1 "Upgrading #{f.name}"
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
installer.install
|
|
|
|
installer.caveats
|
2012-03-07 13:48:04 +00:00
|
|
|
installer.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.
|
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
|
2012-03-07 11:17:36 +00:00
|
|
|
ensure
|
|
|
|
# restore previous installation state if build failed
|
2012-03-07 13:48:04 +00:00
|
|
|
outdated_keg.link if outdated_keg and not f.installed? rescue nil
|
2012-03-07 11:17:36 +00:00
|
|
|
end
|
|
|
|
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|