`ensure_formula_installed!` requires the `Formula` class to be loaded
before being called to work properly.
Let's guarantee that instead by implementing it as an instance method of
the `Formula` class.
See discussion at #20358.
This does the same as #20356 for `ensure_formula_installed!`. See
discussion at #20352.
Unfortunately, one must still `require "formula"` before using this
method because of the `returns(Formula)`, but tightening the type
signature is generally a good idea anyway.
Closes#20352.
Allowing either `Formula`e or `String`s in these methods leads to errors
at runtime when one hasn't done `require "formula"` yet.
Let's tighten these up so that they only accept `Formula` arguments to
guarantee that `require "formula"` has been done before they are called.
For callers that need to pass a `String`, we update them to call a
version of these methods that accepts only `String`s.
See discussion at #20352.
Fixes
❯ HOMEBREW_BAT=1 brew cat xz
Error: uninitialized constant Kernel::Formula
Warning: Removed Sorbet lines from backtrace!
Rerun with `--verbose` to see the original backtrace
/opt/homebrew/Library/Homebrew/extend/kernel.rb:445:in 'block in <module:Kernel>'
/opt/homebrew/Library/Homebrew/dev-cmd/cat.rb:33:in 'block in Homebrew::DevCmd::Cat#run'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.4.5/lib/ruby/3.4.0/fileutils.rb:241:in 'Dir.chdir'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.4.5/lib/ruby/3.4.0/fileutils.rb:241:in 'FileUtils#cd'
/opt/homebrew/Library/Homebrew/dev-cmd/cat.rb:29:in 'Homebrew::DevCmd::Cat#run'
/opt/homebrew/Library/Homebrew/brew.rb:113:in '<main>'
Please report this issue:
https://docs.brew.sh/Troubleshooting
These were being downloaded twice simultaneously which causes a locking
race condition.
While we're here, also improve the output of bottle manifests and
patches in the download queue.
The error message to be fixed:
```console
% brew audit --strict --online xz
xz
* Stable: The source URL http://downloads.sourceforge.net/project/lzmautils/xz-5.8.1.tar.gz should use HTTPS rather than HTTP
Error: 1 problem in 1 formula detected.
% brew edit xz # change it to https
% brew audit --strict --online xz
xz
* Stable: should always include at least one HTTP mirror
Error: 1 problem in 1 formula detected.
```
- Fixes https://github.com/Homebrew/brew/issues/15728
This must set `disable` to `true` to have correct behaviour.
Also, don't allow setting it to `false` to avoid confusion as
that's what `odeprecated` is for.
`cmd` can be a `Pathname` (see the type signature), but `ohai` seems to
expect only `String`s now.
While we're here, let's assert that `cmd` exists whenever it is a
`Pathname`, to avoid passing arguments like `bin/"cmd --version"` (which
is not a valid `Pathname`).
See, for example, Homebrew/homebrew-core#231882.