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
- Make `brew extract` strip out bottle blocks
- Make `brew extract` output the path in a readable fashion
- Warn about building from source before fetching (not installing)
- If fetching a bottle fails, refetch and build from source.
- Trying to test out a user-submitted `brew bump-formula-pr` for
`app-engine-java` gave an error locally that [hasn't shown up on
CI](https://github.com/Homebrew/homebrew-core/pull/55798/checks?check_run_id=740165542),
oddly.
```
➜ brew install app-engine-java -s && brew test app-engine-java
Error: Calling Formula#installed? is deprecated! Use Formula#latest_version_installed? (or Formula#any_version_installed? ) instead.
/usr/local/Homebrew/Library/Homebrew/compat/formula.rb:6:in `installed?'
/usr/local/Homebrew/Library/Homebrew/formula_installer.rb:421:in `block (2 levels) in check_requirements'
/usr/local/Homebrew/Library/Homebrew/formula_installer.rb:420:in `each'
/usr/local/Homebrew/Library/Homebrew/formula_installer.rb:420:in `block in check_requirements'
/usr/local/Homebrew/Library/Homebrew/formula_installer.rb:419:in `each_pair'
/usr/local/Homebrew/Library/Homebrew/formula_installer.rb:419:in `check_requirements'
/usr/local/Homebrew/Library/Homebrew/formula_installer.rb:392:in `compute_dependencies'
/usr/local/Homebrew/Library/Homebrew/formula_installer.rb:149:in `verify_deps_exist'
/usr/local/Homebrew/Library/Homebrew/formula_installer.rb:143:in `prelude'
/usr/local/Homebrew/Library/Homebrew/cmd/install.rb:328:in `install_formula'
/usr/local/Homebrew/Library/Homebrew/cmd/install.rb:261:in `block in install'
/usr/local/Homebrew/Library/Homebrew/cmd/install.rb:259:in `each'
/usr/local/Homebrew/Library/Homebrew/cmd/install.rb:259:in `install'
/usr/local/Homebrew/Library/Homebrew/brew.rb:110:in `<main>'
```
This ensures that dependencies are verified and tapped before they are
fetched. `FormulaInstaller#lock` has been moved into
`FormulaInstaller#install` to avoid locking until necessary.
While we're here, don't compute dependencies before fetching if we're
not going to use them.
Only prune test dependencies from the tree when they aren't also build
dependencies (and vice-versa with build dependencies) and the include
test argument hasn't been passed.
Also:
- when `brew test` or `brew postinstall` is run allow `Resource#stage`
to fetch the resource.
- make `Formula#fetch` and `Resource#fetch` fetch external patches too.
Follow-up from #7549 and #7546.
Whenever you are fetching a dependency you only care about fetching that
specific dependency and not all the dependencies of that dependency.
Unlike installing, dependencies can be fetched in any order and have no
"chains" between them.
This uses `FormulaInstaller#fetch` to recursively fetch dependencies
through the dependency tree and allows `install_dependency` to not
do any fetching.
Remove usage where `Homebrew.args` could be used instead or, due to the
`Homebrew.args` parsing, there was dead code that was never executed
(and no-one complained about not working).
Refactor the CLI::Args module so it doesn't have different paths to
check arguments depending on whether the arguments have been parsed or
not. Instead, set the values we need from the global ARGV at
first, global initialisation time where they will be thrown away when
the actual arguments are parsed.
To do this some other general refactoring was needed:
- more methods made private when possible
- e.g. `HEAD?` used consistently instead of `head` before arguments
are parsed.
- formula options are only parsed after named arguments are extracted