brew/Library/Homebrew/cmd/reinstall.rb

163 lines
5.9 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
2014-10-31 20:10:08 -05:00
require "formula_installer"
require "development_tools"
require "messages"
require "install"
require "reinstall"
2019-04-17 18:25:08 +09:00
require "cli/parser"
require "cleanup"
require "cask/cmd"
require "cask/utils"
require "cask/macos"
require "upgrade"
2021-08-06 02:30:44 -04:00
require "api"
2013-02-17 13:23:41 +00:00
module Homebrew
2020-10-20 12:03:48 +02:00
extend T::Sig
2016-09-26 01:44:51 +02:00
module_function
2020-10-20 12:03:48 +02:00
sig { returns(CLI::Parser) }
def reinstall_args
Homebrew::CLI::Parser.new 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>.
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.
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.
EOS
2020-07-30 18:40:10 +02:00
switch "-d", "--debug",
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."
switch "-f", "--force",
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."
[
[: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.",
}],
[: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",
2022-08-12 09:34:51 +01:00
description: "Generate debug symbols on build. Source will be retained in a cache directory. ",
}],
[:switch, "--display-times", {
env: :display_install_times,
description: "Print install times for each formula at the end of the run.",
}],
[: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
2020-09-28 02:10:17 +02:00
end
formula_options
[
[:switch, "--cask", "--casks", { description: "Treat all named arguments as casks." }],
*Cask::Cmd::AbstractCommand::OPTIONS.map(&:dup),
*Cask::Cmd::Install::OPTIONS.map(&:dup),
].each do |args|
options = args.pop
send(*args, **options)
conflicts "--formula", args.last
2020-09-28 02:10:17 +02:00
end
cask_options
2020-09-28 02:10:17 +02:00
conflicts "--build-from-source", "--force-bottle"
2021-01-10 14:26:40 -05:00
named_args [:formula, :cask], min: 1
end
end
2013-02-17 13:23:41 +00:00
def reinstall
args = reinstall_args.parse
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) }
if args.build_from_source? && !DevelopmentTools.installed?
raise BuildFlagsError.new(["--build-from-source"], bottled: formulae.all?(&:bottled?))
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?,
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?,
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
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?,
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-09-28 02:10:17 +02:00
if casks.any?
Cask::Cmd::Reinstall.reinstall_casks(
*casks,
binaries: args.binaries?,
2020-09-28 02:10:17 +02:00
verbose: args.verbose?,
force: args.force?,
require_sha: args.require_sha?,
2020-09-28 02:10:17 +02:00
skip_cask_deps: args.skip_cask_deps?,
quarantine: args.quarantine?,
cask/reinstall: Support `--zap` for entirely purging cask files - The `brew uninstall` command has `--zap`, so let's make `brew reinstall` have parity here for a better user experience. (Requested in issue 12983.) - It feels weird that to get my new reinstall test to pass I had to add `--zap` to `cask/cmd/install.rb`, not `cask/cmd/reinstall.rb` to get the tests to pass. But the `brew reinstall --cask caffeine --zap` command worked fine all the time. The CLI argument parser from the test run was complaining about not knowing what `zap` was. As a result, `--zap` now shows up as a switch in `brew install --help` which I'm not 100% convinced is the desired UX. But I've edited the description accordingly to specify that it will only work on `reinstall` operations (and `--zap` on `install` is a no-op). ``` issyl0 at pictor in /opt/homebrew on reinstall-cask-zap ❯ brew reinstall --cask caffeine --zap ==> Downloading https://github.com/IntelliScape/caffeine/releases/download/1.1.3/Caffeine.dmg Already downloaded: /Users/issyl0/Library/Caches/Homebrew/downloads/3d6ccfdd3b8d0ab37d1c2468d6e69078c2d31d3b12bf51947c4db21e5f376af2--Caffeine.dmg ==> Implied `brew uninstall --cask caffeine` ==> Backing App 'Caffeine.app' up to '/opt/homebrew/Caskroom/caffeine/1.1.3/Caffeine.app' ==> Removing App '/Applications/Caffeine.app' ==> Dispatching zap stanza ==> Trashing files: ~/Library/Application Support/com.intelliscapesolutions.caffeine ~/Library/Preferences/com.intelliscapesolutions.caffeine.plist ~/Library/Caches/com.intelliscapesolutions.caffeine ~/Library/HTTPStoages/com.intelliscapesolutions.caffeine.binarycookies ==> Removing all staged versions of Cask 'caffeine' ==> Installing Cask caffeine ==> Moving App 'Caffeine.app' to '/Applications/Caffeine.app' 🍺 caffeine was successfully installed! ```
2022-04-05 00:57:33 +01:00
zap: args.zap?,
2020-09-28 02:10:17 +02:00
)
end
Cleanup.periodic_clean!
2020-09-28 02:10:17 +02:00
Homebrew.messages.display_messages(display_times: args.display_times?)
end
2013-02-17 13:23:41 +00:00
end