The logic has now been removed in previous commits. This just
removes some references to the `HOMEBREW_INTERNAL_JSON_V3`
environment variable along with reverting the changes to the
`Cachable` class that were originally added in
bd72ec812c3ed656dfcf8e24f77df142a1fe9cc1.
Copy and tweak code from Library/Homebrew/system_config.rb:110 to commit
and date information. This information can be useful when debugging
formulae in custom taps to ensure the tap has been correctly updated
recently or to suss out important differences from one version of a tap
to another.
This removes the need to ask users to run something like
git -C $(brew --repository)/Library/Taps/<tap> show -s --decorate
Close https://github.com/Homebrew/brew/issues/18381
This is yet another approach to f3a5a3c449cf004aee662966e6c8dd2ebe122c0f
which got merged in over the weekend. It is much simpler than what we've
got now with almost exactly the same performance characteristics. A great
combination of maintability and performance.
```console
$ hyperfine --parameter-list branch master,speed-up-loading-cask-and-formula-file-names_v4 --warmup 5 --setup 'git switch {branch}' 'brew cat gimp'
Benchmark 1: brew cat gimp (branch = master)
Time (mean ± σ): 1.459 s ± 0.012 s [User: 0.892 s, System: 0.536 s]
Range (min … max): 1.448 s … 1.483 s 10 runs
Benchmark 2: brew cat gimp (branch = speed-up-loading-cask-and-formula-file-names_v4)
Time (mean ± σ): 1.456 s ± 0.009 s [User: 0.889 s, System: 0.536 s]
Range (min … max): 1.445 s … 1.468 s 10 runs
Summary
brew cat gimp (branch = speed-up-loading-cask-and-formula-file-names_v4) ran
1.00 ± 0.01 times faster than brew cat gimp (branch = master)
```
Currently, ruby files that are not in the Cask directory are
considered to be formulae if a Formula or HomebrewFormula directory
doesn't exist which doesn't make sense. We know that these should
only be in a few directories so we can check for that explicitly.
Beyond that the `Tap#cask_file?` and `Tap.formula_file?` methods
were only used inside update-report so it doesn't make sense to
turn them into pathnames and expand things when we know that
each string will be a relative path from a tap that we can just
check with a regex.
This change will stop other tap changes like new commands or
changes to other directories like lib/ from showing up as new formulae.
I tried opening a PR for this a long time ago but I got busy
with other things and it got closed by the stale bot.
- https://github.com/Homebrew/brew/pull/15489
These are slow because of some Pathname related reasons so it's been
changed up to use `Dir.glob` instead and that makes a large difference.
```
$ hyperfine --parameter-list branch master,speed-up-loading-cask-and-formula-file-names,speed-up-loading-cask-and-formula-file-names_v2 --warmup 5 --setup 'git switch {branch}' 'brew cat gimp'
Benchmark 1: brew cat gimp (branch = master)
Time (mean ± σ): 2.150 s ± 0.014 s [User: 1.369 s, System: 0.745 s]
Range (min … max): 2.126 s … 2.174 s 10 runs
Benchmark 2: brew cat gimp (branch = speed-up-loading-cask-and-formula-file-names)
Time (mean ± σ): 1.814 s ± 0.012 s [User: 1.068 s, System: 0.711 s]
Range (min … max): 1.797 s … 1.840 s 10 runs
Benchmark 3: brew cat gimp (branch = speed-up-loading-cask-and-formula-file-names_v2)
Time (mean ± σ): 1.489 s ± 0.009 s [User: 0.905 s, System: 0.550 s]
Range (min … max): 1.478 s … 1.503 s 10 runs
Summary
brew cat gimp (branch = speed-up-loading-cask-and-formula-file-names_v2) ran
1.22 ± 0.01 times faster than brew cat gimp (branch = speed-up-loading-cask-and-formula-file-names)
1.44 ± 0.01 times faster than brew cat gimp (branch = master)
```
This is most noticeable when you have a large local tap and it ends
up taking a nontrivial percentage of the overall run time for simple
commands like `brew info gimp`. The improvement here is to just
create paths later on in the loop which copies what we already do
for formulae.
See b1ddb05
```console
$ hyperfine --parameter-list branch master,speed-up-cask-files-by-name --warmup 5 --setup 'git switch {branch}' 'brew info gimp'
Benchmark 1: brew info gimp (branch = master)
Time (mean ± σ): 2.737 s ± 0.010 s [User: 1.958 s, System: 0.732 s]
Range (min … max): 2.720 s … 2.748 s 10 runs
Benchmark 2: brew info gimp (branch = speed-up-cask-files-by-name)
Time (mean ± σ): 2.597 s ± 0.017 s [User: 1.828 s, System: 0.724 s]
Range (min … max): 2.577 s … 2.624 s 10 runs
Summary
brew info gimp (branch = speed-up-cask-files-by-name) ran
1.05 ± 0.01 times faster than brew info gimp (branch = master)
```
- Previously I thought that comments were fine to discourage people from
wasting their time trying to bump things that used `undef` that Sorbet
didn't support. But RuboCop is better at this since it'll complain if
the comments are unnecessary.
- Suggested in https://github.com/Homebrew/brew/pull/18018#issuecomment-2283369501.
- I've gone for a mixture of `rubocop:disable` for the files that can't
be `typed: strict` (use of undef, required before everything else, etc)
and `rubocop:todo` for everything else that should be tried to make
strictly typed. There's no functional difference between the two as
`rubocop:todo` is `rubocop:disable` with a different name.
- And I entirely disabled the cop for the docs/ directory since
`typed: strict` isn't going to gain us anything for some Markdown
linting config files.
- This means that now it's easier to track what needs to be done rather
than relying on checklists of files in our big Sorbet issue:
```shell
$ git grep 'typed: true # rubocop:todo Sorbet/StrictSigil' | wc -l
268
```
- And this is confirmed working for new files:
```shell
$ git status
On branch use-rubocop-for-sorbet-strict-sigils
Untracked files:
(use "git add <file>..." to include in what will be committed)
Library/Homebrew/bad.rb
Library/Homebrew/good.rb
nothing added to commit but untracked files present (use "git add" to track)
$ brew style
Offenses:
bad.rb:1:1: C: Sorbet/StrictSigil: Sorbet sigil should be at least strict got true.
^^^^^^^^^^^^^
1340 files inspected, 1 offense detected
```
We were selectively requiring the tap.rb file in a few places for
performance reasons. The main method we were referencing was the
`Tap.cmd_directories` method which uses `Pathname` and the `TAP_DIRECTORY`
constant internally. `Tap.cmd_directories` is mostly used in the `Commands`
module and that is loaded very early on in the program so it made sense
to move that command to that module. To facilitate that I moved the
`TAP_DIRECTORY` constant to the top-level and renamed it to
`HOMEBREW_TAP_DIRECTORY`. It now lies in the tap_constants.rb file.
A nice bonus of this refactor is that it speeds up loading external
commands since the tap.rb file is no longer required by default in
those cases.
This improves the load time of most brew commands. For an example of
one of the simplest commands this speeds up:
Without Bootsnap:
```
$ hyperfine 'git checkout master; brew help' 'git checkout optimise_requires; brew help'
Benchmark 1: git checkout master; brew help
Time (mean ± σ): 525.0 ms ± 35.8 ms [User: 229.9 ms, System: 113.1 ms]
Range (min … max): 465.3 ms … 576.6 ms 10 runs
Benchmark 2: git checkout optimise_requires; brew help
Time (mean ± σ): 383.3 ms ± 25.1 ms [User: 133.0 ms, System: 72.1 ms]
Range (min … max): 353.0 ms … 443.6 ms 10 runs
Summary
git checkout optimise_requires; brew help ran
1.37 ± 0.13 times faster than git checkout master; brew help
```
With Bootsnap:
```
$ hyperfine 'git checkout master; brew help' 'git checkout optimise_requires; brew help'
Benchmark 1: git checkout master; brew help
Time (mean ± σ): 386.0 ms ± 30.9 ms [User: 130.2 ms, System: 93.8 ms]
Range (min … max): 359.5 ms … 469.3 ms 10 runs
Benchmark 2: git checkout optimise_requires; brew help
Time (mean ± σ): 330.2 ms ± 32.4 ms [User: 93.4 ms, System: 73.0 ms]
Range (min … max): 302.9 ms … 413.9 ms 10 runs
Summary
git checkout optimise_requires; brew help ran
1.17 ± 0.15 times faster than git checkout master; brew help
```
Extend the allow/forbid of taps during formula installation to allow or
forbid the installation of taps themselves based on the values of the
`HOMEBREW_ALLOWED_TAPS` and `HOMEBREW_FORBIDDEN_TAPS` environment
variables.
Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
Most users don't need the core taps to be installed locally but the
current message doesn't communicate that they're sometimes necessary
for local development. This just tweaks the message to be more
informative.
```console
$ brew tap homebrew/cask
Error: Tapping homebrew/cask is no longer typically necessary.
Add --force if you are sure you need it for local development.
```
We already had `HOMEBREW_FORBIDDEN_LICENSES` but this commit adds
`HOMEBREW_FORBIDDEN_CASKS`, `HOMEBREW_FORBIDDEN_FORMULAE` and
`HOMEBREW_FORBIDDEN_TAPS` for also forbidding those.
Relatedly, add `HOMEBREW_FORBIDDEN_OWNER` and
`HOMEBREW_FORBIDDEN_OWNER_CONTACT` to allow customising these
messages.
There were no existing tests for `HOMEBREW_FORBIDDEN_LICENSES` so have
added more tests for all of these checks.
Co-authored-by: Bo Anderson <mail@boanderson.me>