2024-04-01 10:09:48 -07:00
|
|
|
# typed: strict
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-04-01 10:09:48 -07:00
|
|
|
require "abstract_command"
|
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-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
|
2024-04-01 10:09:48 -07:00
|
|
|
module Cmd
|
|
|
|
class Reinstall < AbstractCommand
|
|
|
|
cmd_args do
|
|
|
|
description <<~EOS
|
|
|
|
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>.
|
|
|
|
|
2025-01-27 14:21:27 +00:00
|
|
|
Unless `$HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK` is set, `brew upgrade` or `brew reinstall` will be run for
|
2024-04-01 10:09:48 -07:00
|
|
|
outdated dependents and dependents with broken linkage, respectively.
|
|
|
|
|
2025-01-27 14:21:27 +00:00
|
|
|
Unless `$HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for the
|
2024-04-01 10:09:48 -07:00
|
|
|
reinstalled formulae or, every 30 days, for all formulae.
|
|
|
|
EOS
|
|
|
|
switch "-d", "--debug",
|
|
|
|
description: "If brewing fails, open an interactive debugging session with access to IRB " \
|
|
|
|
"or a shell inside the temporary build directory."
|
2024-04-08 07:35:01 -04:00
|
|
|
switch "--display-times",
|
2025-06-03 11:06:35 -04:00
|
|
|
description: "Print install times for each package at the end of the run.",
|
|
|
|
env: :display_install_times
|
2024-04-01 10:09:48 -07:00
|
|
|
switch "-f", "--force",
|
|
|
|
description: "Install without checking for previously installed keg-only or " \
|
|
|
|
"non-migrated versions."
|
|
|
|
switch "-v", "--verbose",
|
|
|
|
description: "Print the verification and post-install steps."
|
2025-05-07 12:07:29 -04:00
|
|
|
switch "--ask",
|
|
|
|
description: "Ask for confirmation before downloading and upgrading formulae. " \
|
2025-06-03 11:06:35 -04:00
|
|
|
"Print download, install and net install sizes of bottles and dependencies.",
|
2025-05-07 12:07:29 -04:00
|
|
|
env: :ask
|
2024-04-01 10:09:48 -07: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 " \
|
|
|
|
"run `./configure --help` and otherwise determine how to turn the software " \
|
|
|
|
"package into a Homebrew package.",
|
|
|
|
}],
|
|
|
|
[: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.",
|
|
|
|
}],
|
|
|
|
[:switch, "--debug-symbols", {
|
|
|
|
depends_on: "--build-from-source",
|
|
|
|
description: "Generate debug symbols on build. Source will be retained in a cache directory.",
|
|
|
|
}],
|
|
|
|
[:switch, "-g", "--git", {
|
|
|
|
description: "Create a Git repository, useful for creating patches to the software.",
|
|
|
|
}],
|
|
|
|
].each do |args|
|
|
|
|
options = args.pop
|
|
|
|
send(*args, **options)
|
|
|
|
conflicts "--cask", args.last
|
|
|
|
end
|
|
|
|
formula_options
|
|
|
|
[
|
|
|
|
[:switch, "--cask", "--casks", { description: "Treat all named arguments as casks." }],
|
|
|
|
[: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.*",
|
|
|
|
}],
|
|
|
|
].each do |args|
|
|
|
|
options = args.pop
|
|
|
|
send(*args, **options)
|
|
|
|
conflicts "--formula", args.last
|
|
|
|
end
|
|
|
|
cask_options
|
|
|
|
|
|
|
|
conflicts "--build-from-source", "--force-bottle"
|
|
|
|
|
|
|
|
named_args [:formula, :cask], min: 1
|
2023-02-17 14:33:53 +00:00
|
|
|
end
|
2021-03-22 16:11:27 +00:00
|
|
|
|
2024-04-01 10:09:48 -07:00
|
|
|
sig { override.void }
|
|
|
|
def run
|
2024-12-03 17:43:22 -08:00
|
|
|
formulae, casks = args.named.to_resolved_formulae_to_casks
|
2024-04-01 10:09:48 -07: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
|
|
|
|
end
|
|
|
|
|
2024-07-18 21:32:50 -07:00
|
|
|
formulae = Homebrew::Attestation.sort_formulae_for_install(formulae) if Homebrew::Attestation.enabled?
|
2024-07-15 13:30:47 -04:00
|
|
|
|
2024-10-11 16:49:01 +01:00
|
|
|
unless formulae.empty?
|
|
|
|
Install.perform_preinstall_checks_once
|
|
|
|
|
2025-06-09 00:14:16 -04:00
|
|
|
formulae_keg = formulae.map do |formula|
|
2024-10-11 16:49:01 +01:00
|
|
|
if formula.pinned?
|
|
|
|
onoe "#{formula.full_name} is pinned. You must unpin it to reinstall."
|
|
|
|
next
|
|
|
|
end
|
|
|
|
Migrator.migrate_if_needed(formula, force: args.force?)
|
2025-06-09 00:14:16 -04:00
|
|
|
Homebrew::Reinstall.get_formula_to_reinstall(
|
2024-10-11 16:49:01 +01:00
|
|
|
formula,
|
|
|
|
flags: args.flags_only,
|
|
|
|
force_bottle: args.force_bottle?,
|
|
|
|
build_from_source_formulae: args.build_from_source_formulae,
|
|
|
|
interactive: args.interactive?,
|
|
|
|
keep_tmp: args.keep_tmp?,
|
|
|
|
debug_symbols: args.debug_symbols?,
|
|
|
|
force: args.force?,
|
|
|
|
debug: args.debug?,
|
|
|
|
quiet: args.quiet?,
|
|
|
|
verbose: args.verbose?,
|
|
|
|
git: args.git?,
|
|
|
|
)
|
2024-04-01 10:09:48 -07:00
|
|
|
end
|
2024-10-11 16:49:01 +01:00
|
|
|
|
2025-06-09 00:14:16 -04:00
|
|
|
if args.ask?
|
|
|
|
dependants = Upgrade.get_dependants(
|
|
|
|
formulae,
|
|
|
|
flags: args.flags_only,
|
|
|
|
ask: args.ask?,
|
|
|
|
force_bottle: args.force_bottle?,
|
|
|
|
build_from_source_formulae: args.build_from_source_formulae,
|
|
|
|
interactive: args.interactive?,
|
|
|
|
keep_tmp: args.keep_tmp?,
|
|
|
|
debug_symbols: args.debug_symbols?,
|
|
|
|
force: args.force?,
|
|
|
|
debug: args.debug?,
|
|
|
|
quiet: args.quiet?,
|
|
|
|
verbose: args.verbose?,
|
|
|
|
)
|
|
|
|
|
|
|
|
formulae_dependencies = formulae_keg.map(&:formula_installer)
|
|
|
|
|
|
|
|
formulae_dependencies = Install.get_hierarchy(formulae_dependencies, dependants)
|
|
|
|
# Main block: if asking the user is enabled, show dependency and size information.
|
|
|
|
Install.ask_formulae(formulae_dependencies, args: args)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
formulae_keg.each do |f|
|
|
|
|
Homebrew::Reinstall.reinstall_formula(
|
|
|
|
f,
|
|
|
|
flags: args.flags_only,
|
|
|
|
force_bottle: args.force_bottle?,
|
|
|
|
build_from_source_formulae: args.build_from_source_formulae,
|
|
|
|
interactive: args.interactive?,
|
|
|
|
keep_tmp: args.keep_tmp?,
|
|
|
|
debug_symbols: args.debug_symbols?,
|
|
|
|
force: args.force?,
|
|
|
|
debug: args.debug?,
|
|
|
|
quiet: args.quiet?,
|
|
|
|
verbose: args.verbose?,
|
|
|
|
git: args.git?,
|
|
|
|
)
|
|
|
|
Cleanup.install_formula_clean!(f.formula)
|
|
|
|
end
|
|
|
|
|
|
|
|
unless args.ask?
|
|
|
|
dependants = Upgrade.get_dependants(
|
|
|
|
formulae,
|
|
|
|
flags: args.flags_only,
|
|
|
|
force_bottle: args.force_bottle?,
|
|
|
|
build_from_source_formulae: args.build_from_source_formulae,
|
|
|
|
interactive: args.interactive?,
|
|
|
|
keep_tmp: args.keep_tmp?,
|
|
|
|
debug_symbols: args.debug_symbols?,
|
|
|
|
force: args.force?,
|
|
|
|
debug: args.debug?,
|
|
|
|
quiet: args.quiet?,
|
|
|
|
verbose: args.verbose?,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
if dependants
|
|
|
|
Upgrade.upgrade_dependents(
|
|
|
|
dependants, formulae,
|
|
|
|
flags: args.flags_only,
|
|
|
|
force_bottle: args.force_bottle?,
|
|
|
|
build_from_source_formulae: args.build_from_source_formulae,
|
|
|
|
interactive: args.interactive?,
|
|
|
|
keep_tmp: args.keep_tmp?,
|
|
|
|
debug_symbols: args.debug_symbols?,
|
|
|
|
force: args.force?,
|
|
|
|
debug: args.debug?,
|
|
|
|
quiet: args.quiet?,
|
|
|
|
verbose: args.verbose?
|
|
|
|
)
|
|
|
|
end
|
2024-04-01 10:09:48 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
if casks.any?
|
2025-05-07 12:29:32 -04:00
|
|
|
Install.ask_casks casks if args.ask?
|
2024-04-01 10:09:48 -07:00
|
|
|
Cask::Reinstall.reinstall_casks(
|
|
|
|
*casks,
|
|
|
|
binaries: args.binaries?,
|
|
|
|
verbose: args.verbose?,
|
|
|
|
force: args.force?,
|
|
|
|
require_sha: args.require_sha?,
|
|
|
|
skip_cask_deps: args.skip_cask_deps?,
|
|
|
|
quarantine: args.quarantine?,
|
|
|
|
zap: args.zap?,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
Cleanup.periodic_clean!
|
|
|
|
|
|
|
|
Homebrew.messages.display_messages(display_times: args.display_times?)
|
2016-09-05 22:40:08 +03:00
|
|
|
end
|
|
|
|
end
|
2014-03-15 10:40:18 -05:00
|
|
|
end
|
2013-02-17 13:23:41 +00:00
|
|
|
end
|