| 
									
										
										
										
											2016-08-06 17:08:35 +03:00
										 |  |  | #:  * `upgrade` [<install-options>] [`--cleanup`] [`--fetch-HEAD`] [<formulae>]: | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #:    Upgrade outdated, unpinned brews. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    Options for the `install` command are also valid here. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--cleanup` is specified then remove previously installed <formula> version(s). | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2016-08-11 09:28:29 +02:00
										 |  |  | #:    If `--fetch-HEAD` is passed, fetch the upstream repository to detect if | 
					
						
							|  |  |  | #:    the HEAD installation of the formula is outdated. Otherwise, the | 
					
						
							|  |  |  | #:    repository's HEAD will be checked for updates when a new stable or devel | 
					
						
							|  |  |  | #:    version has been released. | 
					
						
							| 
									
										
										
										
											2016-08-06 17:08:35 +03:00
										 |  |  | #: | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #:    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" | 
					
						
							| 
									
										
										
										
											2016-07-29 20:31:32 -06:00
										 |  |  | require "development_tools" | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-23 23:30:52 +01:00
										 |  |  |   def upgrade | 
					
						
							| 
									
										
										
										
											2016-07-06 11:07:24 +01:00
										 |  |  |     FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? | 
					
						
							| 
									
										
										
										
											2015-06-29 14:09:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-23 23:30:52 +01:00
										 |  |  |     Homebrew.perform_preinstall_checks | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-01 15:11:52 +01:00
										 |  |  |     if ARGV.include?("--all") | 
					
						
							|  |  |  |       opoo <<-EOS.undent
 | 
					
						
							|  |  |  |         We decided to not change the behaviour of `brew upgrade` so | 
					
						
							|  |  |  |         `brew upgrade --all` is equivalent to `brew upgrade` without any other | 
					
						
							|  |  |  |         arguments (so the `--all` is a no-op and can be removed). | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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| | 
					
						
							| 
									
										
										
										
											2016-09-17 15:32:44 +01:00
										 |  |  |         f.outdated?(fetch_head: ARGV.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| | 
					
						
							| 
									
										
										
										
											2016-09-17 15:32:44 +01:00
										 |  |  |         f.outdated?(fetch_head: ARGV.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? | 
					
						
							| 
									
										
										
										
											2016-09-15 16:01:18 +01:00
										 |  |  |           onoe "#{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 | 
					
						
							| 
									
										
										
										
											2016-09-15 16:01:18 +01:00
										 |  |  |           onoe "#{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 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 16:01:18 +01:00
										 |  |  |     formulae_to_install = outdated.map(&:latest_formula) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if formulae_to_install.empty? | 
					
						
							| 
									
										
										
										
											2016-09-10 10:24:57 +01:00
										 |  |  |       oh1 "No packages to upgrade" | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2017-03-11 11:33:12 +01:00
										 |  |  |       oh1 "Upgrading #{Formatter.pluralize(formulae_to_install.length, "outdated package")}, with result:" | 
					
						
							| 
									
										
										
										
											2016-09-15 16:01:18 +01:00
										 |  |  |       puts formulae_to_install.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", " | 
					
						
							| 
									
										
										
										
											2014-01-25 06:30:46 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-05-18 22:09:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-15 23:47:03 -05:00
										 |  |  |     unless upgrade_pinned? || pinned.empty? | 
					
						
							| 
									
										
										
										
											2017-03-11 11:33:12 +01:00
										 |  |  |       oh1 "Not upgrading #{Formatter.pluralize(pinned.length, "pinned package")}:" | 
					
						
							| 
									
										
										
										
											2016-09-15 16:01:18 +01:00
										 |  |  |       puts pinned.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", " | 
					
						
							| 
									
										
										
										
											2013-03-11 16:41:08 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-08-23 23:30:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-17 08:31:49 -07:00
										 |  |  |     # Sort keg_only before non-keg_only formulae to avoid any needless conflicts | 
					
						
							|  |  |  |     # with outdated, non-keg_only versions of formulae being upgraded. | 
					
						
							|  |  |  |     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) | 
					
						
							| 
									
										
										
										
											2015-10-06 23:14:12 +05:30
										 |  |  |       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) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 10:11:00 -05:00
										 |  |  |     fi = FormulaInstaller.new(f) | 
					
						
							| 
									
										
										
										
											2017-01-09 21:09:46 +00:00
										 |  |  |     fi.options  = f.build.used_options | 
					
						
							|  |  |  |     fi.options &= f.options | 
					
						
							|  |  |  |     fi.build_bottle = ARGV.build_bottle? || (!f.bottled? && f.build.build_bottle?) | 
					
						
							|  |  |  |     fi.installed_on_request = !ARGV.named.empty? | 
					
						
							| 
									
										
										
										
											2017-07-30 21:44:43 +01:00
										 |  |  |     fi.link_keg             = keg_was_linked if keg_had_linked_opt | 
					
						
							| 
									
										
										
										
											2017-01-09 21:09:46 +00:00
										 |  |  |     if tab | 
					
						
							|  |  |  |       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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-10 13:07:03 +00:00
										 |  |  |     oh1 "Upgrading #{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-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 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2011-08-23 23:30:52 +01:00
										 |  |  | end |