Ensure that we don't try to check for broken linkage in a keg that
doesn't exist. Furthermore, fix the reason we checked for the keg that
doesn't exist by `Formula.clear_cache`.
While here, I noticed that there was other methods of caching at use in
`Formula` so consolidate them to be consistent.
Fixes#8997
After upgrading a formula, it currently checks for
broken dependents after upgrading any outdated dependents.
If there are no outdated dependents, it exits early
and doesn't check for broken dependents.
This adds an earlier check for already broken dependents
so they can be fixed even if there are no outdated dependents.
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