| 
									
										
										
										
											2011-08-23 23:30:52 +01:00
										 |  |  | require 'cmd/install' | 
					
						
							| 
									
										
										
										
											2013-07-15 23:47:03 -05:00
										 |  |  | require 'cmd/outdated' | 
					
						
							| 
									
										
										
										
											2011-08-23 23:30:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | class Fixnum | 
					
						
							|  |  |  |   def plural_s | 
					
						
							|  |  |  |     if self > 1 then "s" else "" end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Homebrew extend self | 
					
						
							|  |  |  |   def upgrade | 
					
						
							|  |  |  |     Homebrew.perform_preinstall_checks | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-19 19:45:18 -05:00
										 |  |  |     if ARGV.named.empty? | 
					
						
							|  |  |  |       outdated = Homebrew.outdated_brews | 
					
						
							| 
									
										
										
										
											2013-07-18 15:18:15 -05:00
										 |  |  |       exit 0 if outdated.empty? | 
					
						
							| 
									
										
										
										
											2011-08-23 23:30:52 +01:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2013-01-19 19:45:18 -05:00
										 |  |  |       outdated = ARGV.formulae.select do |f| | 
					
						
							| 
									
										
										
										
											2012-08-18 18:37:32 -05:00
										 |  |  |         if f.installed? | 
					
						
							|  |  |  |           onoe "#{f}-#{f.installed_version} already installed" | 
					
						
							| 
									
										
										
										
											2013-07-15 23:47:04 -05:00
										 |  |  |           false | 
					
						
							| 
									
										
										
										
											2013-05-18 22:09:15 -05:00
										 |  |  |         elsif not f.rack.directory? or f.rack.subdirs.empty? | 
					
						
							| 
									
										
										
										
											2012-03-07 11:17:36 +00:00
										 |  |  |           onoe "#{f} not installed" | 
					
						
							| 
									
										
										
										
											2013-07-15 23:47:04 -05:00
										 |  |  |           false | 
					
						
							| 
									
										
										
										
											2012-03-07 11:17:36 +00:00
										 |  |  |         else | 
					
						
							|  |  |  |           true | 
					
						
							|  |  |  |         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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-15 23:47:02 -05:00
										 |  |  |     oh1 "Upgrading #{outdated.length} outdated package#{outdated.length.plural_s}, with result:" | 
					
						
							|  |  |  |     puts outdated.map{ |f| "#{f.name} #{f.version}" } * ", " | 
					
						
							| 
									
										
										
										
											2013-05-18 22:09:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-15 23:47:03 -05:00
										 |  |  |     unless upgrade_pinned? || pinned.empty? | 
					
						
							| 
									
										
										
										
											2013-05-18 22:11:19 -05:00
										 |  |  |       oh1 "Not upgrading #{pinned.length} pinned package#{pinned.length.plural_s}:" | 
					
						
							| 
									
										
										
										
											2013-03-11 16:41:08 +01:00
										 |  |  |       puts pinned.map{ |f| "#{f.name} #{f.version}" } * ", " | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-08-23 23:30:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-18 22:09:15 -05:00
										 |  |  |     outdated.each { |f| upgrade_formula(f) } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def upgrade_pinned? | 
					
						
							|  |  |  |     not ARGV.named.empty? | 
					
						
							| 
									
										
										
										
											2011-08-23 23:30:52 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-03-07 11:17:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def upgrade_formula f | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:31 -06:00
										 |  |  |     tab = Tab.for_formula(f) | 
					
						
							| 
									
										
										
										
											2013-05-24 10:33:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Inject options from a previous install into the formula's | 
					
						
							|  |  |  |     # BuildOptions object. TODO clean this up. | 
					
						
							|  |  |  |     f.build.args += tab.used_options | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-07 11:17:36 +00:00
										 |  |  |     outdated_keg = Keg.new(f.linked_keg.realpath) rescue nil | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:27 -06:00
										 |  |  |     installer = FormulaInstaller.new(f) | 
					
						
							|  |  |  |     installer.tab = tab | 
					
						
							| 
									
										
										
										
											2012-03-07 11:17:36 +00:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2012-03-07 13:48:04 +00:00
										 |  |  |     installer.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 | 
					
						
							| 
									
										
										
										
											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 |