brew/Library/Homebrew/cmd/reinstall.rb
Mike McQuaid 2c133a3d45
Check installed dependents on install and reinstall
It's not sufficient to do this merely on `brew upgrade` because
`brew install` and `brew reinstall` can also result in formulae being
upgraded.

This requires moving logic from `cmd/upgrade.rb` to `upgrade.rb`. To
save you searching the diff the changes that resulted from doing that:

- Query the installed formulae from class state in `FormulaInstaller`
  rather than the (incomplete) list that we passed into it.
- Don't output the "Checking dependents" message. It was there for
  systems and configurations where this is slow but for most users
  and most installations this will be a (annoying, noisy) no-op.

Fixes https://github.com/Homebrew/brew/issues/7860
2020-07-02 12:53:52 +01:00

75 lines
2.6 KiB
Ruby

# frozen_string_literal: true
require "formula_installer"
require "development_tools"
require "messages"
require "reinstall"
require "cli/parser"
require "cleanup"
require "upgrade"
module Homebrew
module_function
def reinstall_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`reinstall` [<options>] <formula>
Uninstall and then install <formula> using the same options it was originally
installed with, plus any appended brew formula options.
Unless `HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for the
reinstalled formulae or, every 30 days, for all formulae.
EOS
switch :debug,
description: "If brewing fails, open an interactive debugging session with access to IRB "\
"or a shell inside the temporary build directory."
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 :force,
description: "Install without checking for previously installed keg-only or "\
"non-migrated versions."
switch :verbose,
description: "Print the verification and postinstall steps."
switch "--display-times",
env: :display_install_times,
description: "Print install times for each formula at the end of the run."
conflicts "--build-from-source", "--force-bottle"
formula_options
min_named :formula
end
end
def reinstall
reinstall_args.parse
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
Install.perform_preinstall_checks
args.resolved_formulae.each do |f|
if f.pinned?
onoe "#{f.full_name} is pinned. You must unpin it to reinstall."
next
end
Migrator.migrate_if_needed(f)
reinstall_formula(f)
Cleanup.install_formula_clean!(f)
end
check_installed_dependents
Homebrew.messages.display_messages
end
end