brew/Library/Homebrew/cmd/upgrade.rb
Max Howell a13ff43886 Don't abort upgrade if one formula won't build
Also, unlink previous keg before installing to prevent issues when existing installed brews cause build problems for the newer installed brew.

If the build fails the active keg is relinked before aborting.

Fixes #10341.
2012-03-07 12:34:40 +00:00

72 lines
1.9 KiB
Ruby

require 'cmd/outdated'
require 'cmd/install'
class Fixnum
def plural_s
if self > 1 then "s" else "" end
end
end
module Homebrew extend self
def upgrade
Homebrew.perform_preinstall_checks
outdated = if ARGV.named.empty?
Homebrew.outdated_brews
else
ARGV.formulae.select do |f|
unless f.rack.exist? and not f.rack.children.empty?
onoe "#{f} not installed"
else
true
end
end
end
# 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.
outdated.map!{ |f| f.recursive_deps.reject{ |d| d.installed?} << f }
outdated.flatten!
outdated.uniq!
if outdated.length > 1
oh1 "Upgrading #{outdated.length} outdated package#{outdated.length.plural_s}, with result:"
puts outdated.map{ |f| "#{f.name} #{f.version}" } * ", "
end
outdated.each do |f|
upgrade_formula f
end
end
def upgrade_formula f
outdated_keg = Keg.new(f.linked_keg.realpath) rescue nil
installer = FormulaInstaller.new f
installer.show_header = false
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
installer.finish # includes link step
rescue CannotInstallFormulaError => e
onoe e
rescue BuildError => e
e.dump
puts
ensure
# restore previous installation state if build failed
outdated_keg.link if outdated_keg and not f.linked_keg.directory?
end
end