| 
									
										
										
										
											2019-01-03 16:23:44 +00:00
										 |  |  | #:  * `upgrade` [<install-options>] [`--fetch-HEAD`] [`--ignore-pinned`] [`--display-times`] [<formulae>]: | 
					
						
							| 
									
										
										
										
											2017-12-30 21:23:33 +00:00
										 |  |  | #:    Upgrade outdated, unpinned brews (with existing install options). | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #: | 
					
						
							|  |  |  | #:    Options for the `install` command are also valid here. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											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
										 |  |  | #: | 
					
						
							| 
									
										
										
										
											2018-03-16 20:31:20 +00:00
										 |  |  | #:    If `--ignore-pinned` is passed, set a 0 exit code even if pinned formulae | 
					
						
							|  |  |  | #:    are not upgraded. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2018-06-20 00:54:14 -04:00
										 |  |  | #:    If `--display-times` is passed, install times for each formula are printed | 
					
						
							|  |  |  | #:    at the end of the run. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2018-03-10 11:54:10 +00:00
										 |  |  | #:    If <formulae> are given, upgrade only the specified brews (unless they | 
					
						
							|  |  |  | #:    are pinned; see `pin`, `unpin`). | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-05 23:19:18 -04:00
										 |  |  | require "install" | 
					
						
							| 
									
										
										
										
											2018-09-12 19:28:02 +00:00
										 |  |  | require "reinstall" | 
					
						
							| 
									
										
										
										
											2018-06-05 23:19:18 -04:00
										 |  |  | require "formula_installer" | 
					
						
							| 
									
										
										
										
											2016-07-29 20:31:32 -06:00
										 |  |  | require "development_tools" | 
					
						
							| 
									
										
										
										
											2018-06-20 02:10:54 -04:00
										 |  |  | require "messages" | 
					
						
							| 
									
										
										
										
											2019-01-03 16:23:44 +00:00
										 |  |  | require "cleanup" | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2019-01-03 16:23:44 +00:00
										 |  |  |     # TODO: deprecate for next minor release. | 
					
						
							|  |  |  |     if ARGV.include?("--cleanup") | 
					
						
							|  |  |  |       ENV["HOMEBREW_INSTALL_CLEANUP"] = "1" | 
					
						
							| 
									
										
										
										
											2019-01-08 19:13:46 +00:00
										 |  |  |       odeprecated("'brew upgrade --cleanup'", "'HOMEBREW_INSTALL_CLEANUP'") | 
					
						
							| 
									
										
										
										
											2019-01-03 16:23:44 +00:00
										 |  |  |     elsif ENV["HOMEBREW_UPGRADE_CLEANUP"] | 
					
						
							|  |  |  |       ENV["HOMEBREW_INSTALL_CLEANUP"] = "1" | 
					
						
							| 
									
										
										
										
											2019-01-08 19:13:46 +00:00
										 |  |  |       odeprecated("'HOMEBREW_UPGRADE_CLEANUP'", "'HOMEBREW_INSTALL_CLEANUP'") | 
					
						
							| 
									
										
										
										
											2019-01-03 16:23:44 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-06 11:07:24 +01:00
										 |  |  |     FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? | 
					
						
							| 
									
										
										
										
											2015-06-29 14:09:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-05 23:19:18 -04:00
										 |  |  |     Install.perform_preinstall_checks | 
					
						
							| 
									
										
										
										
											2011-08-23 23:30:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-05 09:31:17 +00:00
										 |  |  |     pinned = outdated.select(&:pinned?) | 
					
						
							|  |  |  |     outdated -= pinned | 
					
						
							| 
									
										
										
										
											2016-09-15 16:01:18 +01:00
										 |  |  |     formulae_to_install = outdated.map(&:latest_formula) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-16 20:31:20 +00:00
										 |  |  |     if !pinned.empty? && !ARGV.include?("--ignore-pinned") | 
					
						
							| 
									
										
										
										
											2018-09-17 20:11:11 +02:00
										 |  |  |       ofail "Not upgrading #{pinned.count} pinned #{"package".pluralize(pinned.count)}:" | 
					
						
							| 
									
										
										
										
											2018-03-16 20:31:20 +00:00
										 |  |  |       puts pinned.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", " | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 16:01:18 +01:00
										 |  |  |     if formulae_to_install.empty? | 
					
						
							| 
									
										
										
										
											2016-09-10 10:24:57 +01:00
										 |  |  |       oh1 "No packages to upgrade" | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2018-09-17 20:11:11 +02:00
										 |  |  |       oh1 "Upgrading #{formulae_to_install.count} outdated #{"package".pluralize(formulae_to_install.count)}:" | 
					
						
							| 
									
										
										
										
											2018-03-30 15:00:45 +01:00
										 |  |  |       formulae_upgrades = formulae_to_install.map do |f| | 
					
						
							|  |  |  |         if f.optlinked? | 
					
						
							|  |  |  |           "#{f.full_specified_name} #{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}" | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           "#{f.full_specified_name} #{f.pkg_version}" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       puts formulae_upgrades.join(", ") | 
					
						
							| 
									
										
										
										
											2014-01-25 06:30:46 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-05-18 22:09:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-12 19:28:02 +00:00
										 |  |  |     upgrade_formulae(formulae_to_install) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     check_dependents(formulae_to_install) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Homebrew.messages.display_messages | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def upgrade_formulae(formulae_to_install) | 
					
						
							|  |  |  |     return if formulae_to_install.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-18 21:42:43 -04:00
										 |  |  |     # Sort keg-only before non-keg-only formulae to avoid any needless conflicts | 
					
						
							|  |  |  |     # with outdated, non-keg-only versions of formulae being upgraded. | 
					
						
							| 
									
										
										
										
											2017-03-17 08:31:49 -07:00
										 |  |  |     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) | 
					
						
							| 
									
										
										
										
											2018-01-08 14:38:10 +00:00
										 |  |  |       begin | 
					
						
							|  |  |  |         upgrade_formula(f) | 
					
						
							| 
									
										
										
										
											2019-01-03 16:23:44 +00:00
										 |  |  |         Cleanup.install_formula_clean!(f) | 
					
						
							| 
									
										
										
										
											2018-01-08 14:38:10 +00:00
										 |  |  |       rescue UnsatisfiedRequirements => e | 
					
						
							| 
									
										
										
										
											2018-01-09 09:07:37 +00:00
										 |  |  |         Homebrew.failed = true | 
					
						
							| 
									
										
										
										
											2018-01-08 14:38:10 +00:00
										 |  |  |         onoe "#{f}: #{e}" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-10-06 23:14:12 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-05-18 22:09:15 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-02 20:04:03 +00:00
										 |  |  |     build_options = BuildOptions.new(Options.create(ARGV.flags_only), f.options) | 
					
						
							|  |  |  |     options = build_options.used_options | 
					
						
							|  |  |  |     options |= f.build.used_options | 
					
						
							|  |  |  |     options &= f.options | 
					
						
							| 
									
										
										
										
											2017-12-02 17:14:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 10:11:00 -05:00
										 |  |  |     fi = FormulaInstaller.new(f) | 
					
						
							| 
									
										
										
										
											2017-12-02 20:04:03 +00:00
										 |  |  |     fi.options = options | 
					
						
							| 
									
										
										
										
											2019-01-14 16:47:07 +00:00
										 |  |  |     fi.build_bottle = ARGV.build_bottle? || (!f.bottle_defined? && f.build.bottle?) | 
					
						
							| 
									
										
										
										
											2017-01-09 21:09:46 +00:00
										 |  |  |     fi.installed_on_request = !ARGV.named.empty? | 
					
						
							| 
									
										
										
										
											2018-01-10 16:43:21 +00: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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-09 11:31:51 +09:00
										 |  |  |     oh1 "Upgrading #{Formatter.identifier(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-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. | 
					
						
							| 
									
										
										
										
											2018-03-06 09:36:49 +00:00
										 |  |  |     nil | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2018-09-12 19:28:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def upgradable_dependents(kegs, formulae) | 
					
						
							|  |  |  |     formulae_to_upgrade = Set.new | 
					
						
							|  |  |  |     formulae_pinned = Set.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     formulae.each do |formula| | 
					
						
							|  |  |  |       descendants = Set.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       dependents = kegs.select do |keg| | 
					
						
							|  |  |  |         keg.runtime_dependencies | 
					
						
							|  |  |  |            .any? { |d| d["full_name"] == formula.full_name } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       next if dependents.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       dependent_formulae = dependents.map(&:to_formula) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       dependent_formulae.each do |f| | 
					
						
							|  |  |  |         next if formulae_to_upgrade.include?(f) | 
					
						
							|  |  |  |         next if formulae_pinned.include?(f) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if f.outdated?(fetch_head: ARGV.fetch_head?) | 
					
						
							|  |  |  |           if f.pinned? | 
					
						
							|  |  |  |             formulae_pinned << f | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             formulae_to_upgrade << f | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         descendants << f | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       upgradable_descendants, pinned_descendants = upgradable_dependents(kegs, descendants) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       formulae_to_upgrade.merge upgradable_descendants | 
					
						
							|  |  |  |       formulae_pinned.merge pinned_descendants | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [formulae_to_upgrade, formulae_pinned] | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def broken_dependents(kegs, formulae) | 
					
						
							|  |  |  |     formulae_to_reinstall = Set.new | 
					
						
							|  |  |  |     formulae_pinned_and_outdated = Set.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     CacheStoreDatabase.use(:linkage) do |db| | 
					
						
							|  |  |  |       formulae.each do |formula| | 
					
						
							|  |  |  |         descendants = Set.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dependents = kegs.select do |keg| | 
					
						
							|  |  |  |           keg.runtime_dependencies | 
					
						
							|  |  |  |              .any? { |d| d["full_name"] == formula.full_name } | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         next if dependents.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dependents.each do |keg| | 
					
						
							|  |  |  |           f = keg.to_formula | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           next if formulae_to_reinstall.include?(f) | 
					
						
							|  |  |  |           next if formulae_pinned_and_outdated.include?(f) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           checker = LinkageChecker.new(keg, cache_db: db) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           if checker.broken_library_linkage? | 
					
						
							|  |  |  |             if f.outdated?(fetch_head: ARGV.fetch_head?) | 
					
						
							|  |  |  |               # Outdated formulae = pinned formulae (see function above) | 
					
						
							|  |  |  |               formulae_pinned_and_outdated << f | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |               formulae_to_reinstall << f | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           descendants << f | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         descendants_to_reinstall, descendants_pinned = broken_dependents(kegs, descendants) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         formulae_to_reinstall.merge descendants_to_reinstall | 
					
						
							|  |  |  |         formulae_pinned_and_outdated.merge descendants_pinned | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [formulae_to_reinstall, formulae_pinned_and_outdated] | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # @private | 
					
						
							|  |  |  |   def depends_on(a, b) | 
					
						
							|  |  |  |     if a.opt_or_installed_prefix_keg | 
					
						
							|  |  |  |         .runtime_dependencies | 
					
						
							|  |  |  |         .any? { |d| d["full_name"] == b.full_name } | 
					
						
							|  |  |  |       1
 | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       a <=> b | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # @private | 
					
						
							|  |  |  |   def formulae_with_runtime_dependencies | 
					
						
							|  |  |  |     Formula.installed | 
					
						
							|  |  |  |            .map(&:opt_or_installed_prefix_keg) | 
					
						
							|  |  |  |            .reject(&:nil?) | 
					
						
							|  |  |  |            .reject { |f| f.runtime_dependencies.to_a.empty? } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def check_dependents(formulae) | 
					
						
							|  |  |  |     return if formulae.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # First find all the outdated dependents. | 
					
						
							|  |  |  |     kegs = formulae_with_runtime_dependencies | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return if kegs.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     oh1 "Checking dependents for outdated formulae" if ARGV.verbose? | 
					
						
							|  |  |  |     upgradable, pinned = upgradable_dependents(kegs, formulae).map(&:to_a) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     upgradable.sort! { |a, b| depends_on(a, b) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pinned.sort! { |a, b| depends_on(a, b) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Print the pinned dependents. | 
					
						
							|  |  |  |     unless pinned.empty? | 
					
						
							| 
									
										
										
										
											2018-09-17 20:11:11 +02:00
										 |  |  |       ohai "Not upgrading #{pinned.count} pinned #{"dependent".pluralize(pinned.count)}:" | 
					
						
							| 
									
										
										
										
											2018-09-12 19:28:02 +00:00
										 |  |  |       puts pinned.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", " | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Print the upgradable dependents. | 
					
						
							|  |  |  |     if upgradable.empty? | 
					
						
							|  |  |  |       ohai "No dependents to upgrade" if ARGV.verbose? | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2018-09-17 20:11:11 +02:00
										 |  |  |       ohai "Upgrading #{upgradable.count} #{"dependent".pluralize(upgradable.count)}:" | 
					
						
							| 
									
										
										
										
											2018-09-12 19:28:02 +00:00
										 |  |  |       formulae_upgrades = upgradable.map do |f| | 
					
						
							|  |  |  |         if f.optlinked? | 
					
						
							|  |  |  |           "#{f.full_specified_name} #{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}" | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           "#{f.full_specified_name} #{f.pkg_version}" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       puts formulae_upgrades.join(", ") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     upgrade_formulae(upgradable) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Assess the dependents tree again. | 
					
						
							|  |  |  |     kegs = formulae_with_runtime_dependencies | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     oh1 "Checking dependents for broken library links" if ARGV.verbose? | 
					
						
							|  |  |  |     reinstallable, pinned = broken_dependents(kegs, formulae).map(&:to_a) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     reinstallable.sort! { |a, b| depends_on(a, b) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pinned.sort! { |a, b| depends_on(a, b) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Print the pinned dependents. | 
					
						
							|  |  |  |     unless pinned.empty? | 
					
						
							| 
									
										
										
										
											2018-09-17 20:11:11 +02:00
										 |  |  |       onoe "Not reinstalling #{pinned.count} broken and outdated, but pinned #{"dependent".pluralize(pinned.count)}:" | 
					
						
							| 
									
										
										
										
											2018-09-12 19:28:02 +00:00
										 |  |  |       $stderr.puts pinned.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", " | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Print the broken dependents. | 
					
						
							|  |  |  |     if reinstallable.empty? | 
					
						
							|  |  |  |       ohai "No broken dependents to reinstall" if ARGV.verbose? | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2018-09-17 20:11:11 +02:00
										 |  |  |       ohai "Reinstalling #{reinstallable.count} broken #{"dependent".pluralize(reinstallable.count)} from source:" | 
					
						
							| 
									
										
										
										
											2018-09-12 19:28:02 +00:00
										 |  |  |       puts reinstallable.map(&:full_specified_name).join(", ") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     reinstallable.each do |f| | 
					
						
							|  |  |  |       begin | 
					
						
							|  |  |  |         reinstall_formula(f, build_from_source: true) | 
					
						
							|  |  |  |       rescue FormulaInstallationAlreadyAttemptedError | 
					
						
							|  |  |  |         # We already attempted to reinstall f as part of the dependency tree of | 
					
						
							|  |  |  |         # another formula. In that case, don't generate an error, just move on. | 
					
						
							|  |  |  |         nil | 
					
						
							|  |  |  |       rescue CannotInstallFormulaError => e | 
					
						
							|  |  |  |         ofail e | 
					
						
							|  |  |  |       rescue BuildError => e | 
					
						
							|  |  |  |         e.dump | 
					
						
							|  |  |  |         puts | 
					
						
							|  |  |  |         Homebrew.failed = true | 
					
						
							|  |  |  |       rescue DownloadError => e | 
					
						
							|  |  |  |         ofail e | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-23 23:30:52 +01:00
										 |  |  | end |