| 
									
										
										
										
											2023-03-06 09:49:53 -08:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-31 20:10:08 -05: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" | 
					
						
							| 
									
										
										
										
											2020-07-25 21:33:48 +02:00
										 |  |  | require "install" | 
					
						
							| 
									
										
										
										
											2018-09-12 19:28:02 +00:00
										 |  |  | require "reinstall" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2019-01-03 16:23:44 +00:00
										 |  |  | require "cleanup" | 
					
						
							| 
									
										
										
										
											2020-06-30 13:22:21 -04:00
										 |  |  | require "cask/utils" | 
					
						
							|  |  |  | require "cask/macos" | 
					
						
							| 
									
										
										
										
											2023-04-10 22:07:06 +09:00
										 |  |  | require "cask/reinstall" | 
					
						
							| 
									
										
										
										
											2020-07-02 12:53:52 +01:00
										 |  |  | require "upgrade" | 
					
						
							| 
									
										
										
										
											2021-08-06 02:30:44 -04:00
										 |  |  | require "api" | 
					
						
							| 
									
										
										
										
											2013-02-17 13:23:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |   def self.reinstall_args | 
					
						
							| 
									
										
										
										
											2018-11-07 22:17:36 +05:30
										 |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2020-09-28 01:33:29 +02:00
										 |  |  |         Uninstall and then reinstall a <formula> or <cask> using the same options it was | 
					
						
							|  |  |  |         originally installed with, plus any appended options specific to a <formula>. | 
					
						
							| 
									
										
										
										
											2019-02-03 09:34:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-25 09:10:59 +00:00
										 |  |  |         Unless `HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK` is set, `brew upgrade` or `brew reinstall` will be run for | 
					
						
							|  |  |  |         outdated dependents and dependents with broken linkage, respectively. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |         Unless `HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for the | 
					
						
							| 
									
										
										
										
											2019-08-06 13:23:19 -04:00
										 |  |  |         reinstalled formulae or, every 30 days, for all formulae. | 
					
						
							| 
									
										
										
										
											2018-11-07 22:17:36 +05:30
										 |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  |       switch "-d", "--debug", | 
					
						
							| 
									
										
										
										
											2020-10-08 11:18:24 +02:00
										 |  |  |              description: "If brewing fails, open an interactive debugging session with access to IRB " \ | 
					
						
							| 
									
										
										
										
											2019-08-06 14:22:24 -04:00
										 |  |  |                           "or a shell inside the temporary build directory." | 
					
						
							| 
									
										
										
										
											2020-07-27 03:59:52 +02:00
										 |  |  |       switch "-f", "--force", | 
					
						
							| 
									
										
										
										
											2020-10-08 11:18:24 +02:00
										 |  |  |              description: "Install without checking for previously installed keg-only or " \ | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |                           "non-migrated versions." | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  |       switch "-v", "--verbose", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Print the verification and postinstall steps." | 
					
						
							| 
									
										
										
										
											2020-10-08 11:18:24 +02:00
										 |  |  |       [ | 
					
						
							|  |  |  |         [:switch, "--formula", "--formulae", { description: "Treat all named arguments as formulae." }], | 
					
						
							|  |  |  |         [:switch, "-s", "--build-from-source", { | 
					
						
							|  |  |  |           description: "Compile <formula> from source even if a bottle is available.", | 
					
						
							|  |  |  |         }], | 
					
						
							|  |  |  |         [:switch, "-i", "--interactive", { | 
					
						
							|  |  |  |           description: "Download and patch <formula>, then open a shell. This allows the user to " \ | 
					
						
							| 
									
										
										
										
											2020-11-12 10:40:41 -05:00
										 |  |  |                        "run `./configure --help` and otherwise determine how to turn the software " \ | 
					
						
							|  |  |  |                        "package into a Homebrew package.", | 
					
						
							| 
									
										
										
										
											2020-10-08 11:18:24 +02:00
										 |  |  |         }], | 
					
						
							|  |  |  |         [:switch, "--force-bottle", { | 
					
						
							|  |  |  |           description: "Install from a bottle if it exists for the current or newest version of " \ | 
					
						
							|  |  |  |                        "macOS, even if it would not normally be used for installation.", | 
					
						
							|  |  |  |         }], | 
					
						
							|  |  |  |         [:switch, "--keep-tmp", { | 
					
						
							|  |  |  |           description: "Retain the temporary files created during installation.", | 
					
						
							|  |  |  |         }], | 
					
						
							| 
									
										
										
										
											2022-07-26 12:15:53 +01:00
										 |  |  |         [:switch, "--debug-symbols", { | 
					
						
							|  |  |  |           depends_on:  "--build-from-source", | 
					
						
							| 
									
										
										
										
											2023-02-10 23:15:40 -05:00
										 |  |  |           description: "Generate debug symbols on build. Source will be retained in a cache directory.", | 
					
						
							| 
									
										
										
										
											2022-07-26 12:15:53 +01:00
										 |  |  |         }], | 
					
						
							| 
									
										
										
										
											2020-10-08 11:18:24 +02:00
										 |  |  |         [:switch, "--display-times", { | 
					
						
							|  |  |  |           env:         :display_install_times, | 
					
						
							|  |  |  |           description: "Print install times for each formula at the end of the run.", | 
					
						
							|  |  |  |         }], | 
					
						
							| 
									
										
										
										
											2021-06-09 16:26:09 -07:00
										 |  |  |         [:switch, "-g", "--git", { | 
					
						
							|  |  |  |           description: "Create a Git repository, useful for creating patches to the software.", | 
					
						
							|  |  |  |         }], | 
					
						
							| 
									
										
										
										
											2022-10-08 01:08:15 +01:00
										 |  |  |       ].each do |args| | 
					
						
							|  |  |  |         options = args.pop | 
					
						
							|  |  |  |         send(*args, **options) | 
					
						
							|  |  |  |         conflicts "--cask", args.last | 
					
						
							| 
									
										
										
										
											2020-09-28 02:10:17 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-10-03 02:45:32 +02:00
										 |  |  |       formula_options | 
					
						
							| 
									
										
										
										
											2020-10-08 11:18:24 +02:00
										 |  |  |       [ | 
					
						
							|  |  |  |         [:switch, "--cask", "--casks", { description: "Treat all named arguments as casks." }], | 
					
						
							| 
									
										
										
										
											2023-04-19 21:30:42 +09:00
										 |  |  |         [:switch, "--[no-]binaries", { | 
					
						
							|  |  |  |           description: "Disable/enable linking of helper executables (default: enabled).", | 
					
						
							|  |  |  |           env:         :cask_opts_binaries, | 
					
						
							|  |  |  |         }], | 
					
						
							|  |  |  |         [:switch, "--require-sha",  { | 
					
						
							|  |  |  |           description: "Require all casks to have a checksum.", | 
					
						
							|  |  |  |           env:         :cask_opts_require_sha, | 
					
						
							|  |  |  |         }], | 
					
						
							|  |  |  |         [:switch, "--[no-]quarantine", { | 
					
						
							|  |  |  |           description: "Disable/enable quarantining of downloads (default: enabled).", | 
					
						
							|  |  |  |           env:         :cask_opts_quarantine, | 
					
						
							|  |  |  |         }], | 
					
						
							|  |  |  |         [:switch, "--adopt", { | 
					
						
							|  |  |  |           description: "Adopt existing artifacts in the destination that are identical to those being installed. " \ | 
					
						
							|  |  |  |                        "Cannot be combined with --force.", | 
					
						
							|  |  |  |         }], | 
					
						
							|  |  |  |         [:switch, "--skip-cask-deps", { | 
					
						
							|  |  |  |           description: "Skip installing cask dependencies.", | 
					
						
							|  |  |  |         }], | 
					
						
							|  |  |  |         [:switch, "--zap", { | 
					
						
							|  |  |  |           description: "For use with `brew reinstall --cask`. Remove all files associated with a cask. " \ | 
					
						
							|  |  |  |                        "*May remove files which are shared between applications.*", | 
					
						
							|  |  |  |         }], | 
					
						
							| 
									
										
										
										
											2022-10-08 01:08:15 +01:00
										 |  |  |       ].each do |args| | 
					
						
							|  |  |  |         options = args.pop | 
					
						
							|  |  |  |         send(*args, **options) | 
					
						
							|  |  |  |         conflicts "--formula", args.last | 
					
						
							| 
									
										
										
										
											2020-09-28 02:10:17 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-10-03 02:45:32 +02:00
										 |  |  |       cask_options | 
					
						
							| 
									
										
										
										
											2020-09-28 02:10:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-08 11:18:24 +02:00
										 |  |  |       conflicts "--build-from-source", "--force-bottle" | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       named_args [:formula, :cask], min: 1
 | 
					
						
							| 
									
										
										
										
											2018-11-07 22:17:36 +05:30
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-17 10:37:59 -07:00
										 |  |  |   def self.reinstall | 
					
						
							| 
									
										
										
										
											2020-07-25 03:48:33 +02:00
										 |  |  |     args = reinstall_args.parse | 
					
						
							| 
									
										
										
										
											2018-11-07 22:17:36 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-29 20:40:26 +09:00
										 |  |  |     formulae, casks = args.named.to_formulae_and_casks(method: :resolve) | 
					
						
							| 
									
										
										
										
											2020-09-28 02:10:17 +02:00
										 |  |  |                           .partition { |o| o.is_a?(Formula) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-17 14:33:53 +00:00
										 |  |  |     if args.build_from_source? | 
					
						
							|  |  |  |       unless DevelopmentTools.installed? | 
					
						
							|  |  |  |         raise BuildFlagsError.new(["--build-from-source"], bottled: formulae.all?(&:bottled?)) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       unless Homebrew::EnvConfig.developer? | 
					
						
							|  |  |  |         opoo "building from source is not supported!" | 
					
						
							|  |  |  |         puts "You're on your own. Failures are expected so don't create any issues, please!" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2021-03-22 16:11:27 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Install.perform_preinstall_checks | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-18 14:46:48 +00:00
										 |  |  |     formulae.each do |formula| | 
					
						
							|  |  |  |       if formula.pinned? | 
					
						
							|  |  |  |         onoe "#{formula.full_name} is pinned. You must unpin it to reinstall." | 
					
						
							| 
									
										
										
										
											2016-09-05 22:40:08 +03:00
										 |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2021-03-18 14:46:48 +00:00
										 |  |  |       Migrator.migrate_if_needed(formula, force: args.force?) | 
					
						
							|  |  |  |       reinstall_formula( | 
					
						
							|  |  |  |         formula, | 
					
						
							|  |  |  |         flags:                      args.flags_only, | 
					
						
							|  |  |  |         installed_on_request:       args.named.present?, | 
					
						
							|  |  |  |         force_bottle:               args.force_bottle?, | 
					
						
							|  |  |  |         build_from_source_formulae: args.build_from_source_formulae, | 
					
						
							|  |  |  |         interactive:                args.interactive?, | 
					
						
							|  |  |  |         keep_tmp:                   args.keep_tmp?, | 
					
						
							| 
									
										
										
										
											2022-07-26 12:15:53 +01:00
										 |  |  |         debug_symbols:              args.debug_symbols?, | 
					
						
							| 
									
										
										
										
											2021-03-18 14:46:48 +00:00
										 |  |  |         force:                      args.force?, | 
					
						
							|  |  |  |         debug:                      args.debug?, | 
					
						
							|  |  |  |         quiet:                      args.quiet?, | 
					
						
							|  |  |  |         verbose:                    args.verbose?, | 
					
						
							| 
									
										
										
										
											2021-06-09 16:26:09 -07:00
										 |  |  |         git:                        args.git?, | 
					
						
							| 
									
										
										
										
											2021-03-18 14:46:48 +00:00
										 |  |  |       ) | 
					
						
							|  |  |  |       Cleanup.install_formula_clean!(formula) | 
					
						
							| 
									
										
										
										
											2016-09-05 22:40:08 +03:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-07-02 12:53:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-18 14:46:48 +00:00
										 |  |  |     Upgrade.check_installed_dependents( | 
					
						
							|  |  |  |       formulae, | 
					
						
							|  |  |  |       flags:                      args.flags_only, | 
					
						
							|  |  |  |       installed_on_request:       args.named.present?, | 
					
						
							|  |  |  |       force_bottle:               args.force_bottle?, | 
					
						
							|  |  |  |       build_from_source_formulae: args.build_from_source_formulae, | 
					
						
							|  |  |  |       interactive:                args.interactive?, | 
					
						
							|  |  |  |       keep_tmp:                   args.keep_tmp?, | 
					
						
							| 
									
										
										
										
											2022-07-26 12:15:53 +01:00
										 |  |  |       debug_symbols:              args.debug_symbols?, | 
					
						
							| 
									
										
										
										
											2021-03-18 14:46:48 +00:00
										 |  |  |       force:                      args.force?, | 
					
						
							|  |  |  |       debug:                      args.debug?, | 
					
						
							|  |  |  |       quiet:                      args.quiet?, | 
					
						
							|  |  |  |       verbose:                    args.verbose?, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2020-07-02 12:53:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-28 02:10:17 +02:00
										 |  |  |     if casks.any? | 
					
						
							| 
									
										
										
										
											2023-04-10 22:07:06 +09:00
										 |  |  |       Cask::Reinstall.reinstall_casks( | 
					
						
							| 
									
										
										
										
											2020-09-28 02:10:17 +02:00
										 |  |  |         *casks, | 
					
						
							| 
									
										
										
										
											2021-01-10 20:19:31 +01:00
										 |  |  |         binaries:       args.binaries?, | 
					
						
							| 
									
										
										
										
											2020-09-28 02:10:17 +02:00
										 |  |  |         verbose:        args.verbose?, | 
					
						
							|  |  |  |         force:          args.force?, | 
					
						
							| 
									
										
										
										
											2021-01-10 20:19:31 +01:00
										 |  |  |         require_sha:    args.require_sha?, | 
					
						
							| 
									
										
										
										
											2020-09-28 02:10:17 +02:00
										 |  |  |         skip_cask_deps: args.skip_cask_deps?, | 
					
						
							| 
									
										
										
										
											2021-01-10 20:19:31 +01:00
										 |  |  |         quarantine:     args.quarantine?, | 
					
						
							| 
									
										
										
										
											2022-04-05 00:57:33 +01:00
										 |  |  |         zap:            args.zap?, | 
					
						
							| 
									
										
										
										
											2020-09-28 02:10:17 +02:00
										 |  |  |       ) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-06-24 15:03:35 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-20 08:24:55 -07:00
										 |  |  |     Cleanup.periodic_clean! | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-28 02:10:17 +02:00
										 |  |  |     Homebrew.messages.display_messages(display_times: args.display_times?) | 
					
						
							| 
									
										
										
										
											2014-03-15 10:40:18 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-02-17 13:23:41 +00:00
										 |  |  | end |