395 Commits

Author SHA1 Message Date
Mike McQuaid
dc71b7c8f6
Cleanup extend/ directory usage.
- move some things out of `extend` that don't really fit there e.g.
  `Module`s that are included but not doing any
  overriding/monkeypatching
- move some code into `extend/os` to fix all remaining
  `rubocop:todo Homebrew/MoveToExtendOS`s
- remove some unneeded `bundle` skipper code that doesn't really make
  sense given our current bottling strategy
- extract some `Pathname` extensions to `extend/pathname` for separate
  files
- move a `ENV` `Kernel` extension into `kernel.rb`
- `odeprecate` a seemingly unused backwards compatibility method
- move `readline_nonblock` from a monkeypatch to a
  `ReadlineNonblock.read` method as its only used in one place
- fix up a link in documentation
2025-06-09 19:06:16 +01:00
botantony
a10b635fe9 no_autobump!: suggestions from contributors and docs
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
Signed-off-by: botantony <antonsm21@gmail.com>
2025-04-29 18:04:59 +02:00
botantony
1fcacdc2dc formula/cask DSL: add no_autobump! method
Signed-off-by: botantony <antonsm21@gmail.com>
2025-04-29 18:04:59 +02:00
apainintheneck
f916f27d82 remove all references to JSON v3
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.
2025-02-06 21:04:08 -08:00
Sam Ford
cf22382921
Curl: use typed: strict
This upgrades `utils/curl.rb` to `typed: strict`, which requires
a number of changes to pass `brew typecheck`. The most
straightforward are adding type signatures to methods, adding type
annotations (e.g., `T.let`) to variables that need them, and ensuring
that methods always use the expected return type.

I had to refactor areas where we call a `Utils::Curl` method and use
array destructuring on a `SystemCommand::Result` return value
(e.g., `output, errors, status = curl_output(...)`), as Sorbet
doesn't understand implicit array conversion. As suggested by Markus,
I've switched these areas to use `#stdout`, `#stderr`, and `#status`.
This requires the use of an intermediate variable (`result`) in some
cases but this was a fairly straightforward substitution.

I also had to refactor how `Cask::URL::BlockDSL::PageWithURL` works.
It currently uses `page.extend PageWithURL` to add a `url` attribute
but this reworks it to subclass `SimpleDelegator` and use an
`initialize` method instead. This achieves the same goal but in a way
that Sorbet can understand.
2025-01-14 08:14:39 -05:00
Douglas Eichelberger
e2d10337f3 Fix alias_name logic 2024-12-06 11:25:51 -08:00
Douglas Eichelberger
9a2b386a52 Remove unsafe references from CLI and Formulary code 2024-12-06 11:06:27 -08:00
Douglas Eichelberger
521c463e36
Manually resolve Style/SafeNavigationChainLength violations 2024-11-05 16:44:12 +00:00
Carlo Cabrera
fe1f330e60
Revert "Deprecate installing casks/formulae from paths." 2024-09-27 10:17:04 +08:00
Mike McQuaid
bbdea29a0f
Deprecate installing casks/formulae from paths.
We've already disabled installing casks/formulae from URLs and we
regularly tell people not to install from paths so let's just deprecate
this behaviour entirely.

Even Homebrew developers do not need to work this way.
2024-09-26 20:25:07 +01:00
Issy Long
45978435e7
rubocop: Use Sorbet/StrictSigil as it's better than comments
- 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
```
2024-08-12 15:24:27 +01:00
Bo Anderson
10cbf191dc
Add env to disable finding packages from paths 2024-07-25 11:37:44 +01:00
Rylan Polster
b563d9920b
FormulaURILoader: use regex to validate refs before attempting to cast 2024-07-15 14:07:55 -04:00
Mike McQuaid
c5dbd3ca24
Rearrange requires
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
```
2024-07-14 08:49:39 -04:00
Rylan Polster
8b0a4a98bf
Restrict direct url installs to the file:// scheme 2024-07-13 13:30:36 -04:00
Markus Reiter
2601551f3a
Only allow loading local bottles. 2024-07-13 11:57:44 -04:00
Markus Reiter
643fa83a28
Use Downloadable API in FromBottleLoader. 2024-07-13 11:36:13 -04:00
apainintheneck
16e605e056 Load tap migration renames from API with short names
This is a follow-up to 484498e. I added loading for tap migration
renames from the API but it apparently only worked for full names.

There was a bug in both the code and the tests which prevented
loading by short names. This fixes those bugs so everything should
be good now.
2024-07-01 18:53:31 -07:00
apainintheneck
10aa981209 Load tap migration renames from the API
These would not get loaded from the API at all meaning these
were not loadable by the old names when the core formula or cask
tap was not installed. We assume that most users don't have those
core taps tapped which means this is broken for most everyone.
2024-06-30 11:26:03 -07:00
Kevin
f8b1d1f56c
Merge pull request #17385 from pe/migrations-broken
Fix migrations of formulae and casks to non homebrew taps
2024-06-08 19:34:14 -07:00
Philippe Eberli
20fb068085 Fix migrations of formulae and casks to non homebrew taps 2024-06-08 16:29:23 +02:00
Douglas Eichelberger
179419d8bc rm unnecessary casts 2024-05-31 15:49:12 -07:00
apainintheneck
37cbfc40bf Fix internal formula json v3 frozen hash parsing bug
This caused formulae with uses from macos bounds to not load correctly
because they tried to modify a frozen hash. It wasn't obvious from
the tests because I didn't replicate the real world JSON parsing
conditions closely enough. I also had to modify `Cachable#clear_cache`
so that it can clear frozen hashes.

Error:
```
Error: can't modify frozen Hash: {"since"=>"catalina"}
Warning: Removed Sorbet lines from backtrace!
Rerun with `--verbose` to see the original backtrace
/usr/local/Homebrew/Library/Homebrew/extend/hash/keys.rb:123:in `delete'
/usr/local/Homebrew/Library/Homebrew/extend/hash/keys.rb:123:in `block in _deep_transform_keys_in_object!'
/usr/local/Homebrew/Library/Homebrew/extend/hash/keys.rb:122:in `each'
/usr/local/Homebrew/Library/Homebrew/extend/hash/keys.rb:122:in `_deep_transform_keys_in_object!'
/usr/local/Homebrew/Library/Homebrew/extend/hash/keys.rb:48:in `deep_transform_keys!'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:230:in `block (2 levels) in load_formula_from_api'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:218:in `each'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:218:in `block in load_formula_from_api'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:304:in `instance_exec'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:304:in `block (2 levels) in load_formula_from_api'
/usr/local/Homebrew/Library/Homebrew/formula.rb:3664:in `instance_eval'
/usr/local/Homebrew/Library/Homebrew/formula.rb:3664:in `stable'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:293:in `block in load_formula_from_api'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:283:in `initialize'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:283:in `new'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:283:in `load_formula_from_api'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:962:in `load_from_api'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:955:in `klass'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:569:in `get_formula'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:1009:in `factory'
/usr/local/Homebrew/Library/Homebrew/dependency.rb:41:in `to_formula'
/usr/local/Homebrew/Library/Homebrew/utils/autoremove.rb:46:in `block (2 levels) in formulae_with_no_formula_dependents'
/usr/local/Homebrew/Library/Homebrew/utils/autoremove.rb:45:in `each'
/usr/local/Homebrew/Library/Homebrew/utils/autoremove.rb:45:in `block in formulae_with_no_formula_dependents'
/usr/local/Homebrew/Library/Homebrew/utils/autoremove.rb:39:in `each'
/usr/local/Homebrew/Library/Homebrew/utils/autoremove.rb:39:in `formulae_with_no_formula_dependents'
/usr/local/Homebrew/Library/Homebrew/utils/autoremove.rb:59:in `unused_formulae_with_no_formula_dependents'
/usr/local/Homebrew/Library/Homebrew/utils/autoremove.rb:16:in `removable_formulae'
/usr/local/Homebrew/Library/Homebrew/cleanup.rb:693:in `autoremove'
/usr/local/Homebrew/Library/Homebrew/cleanup.rb:291:in `clean!'
/usr/local/Homebrew/Library/Homebrew/cmd/cleanup.rb:52:in `run'
/usr/local/Homebrew/Library/Homebrew/brew.rb:92:in `<main>'
```
2024-05-01 21:36:37 -07:00
Markus Reiter
480e264d9a
Lint Ruby docs. 2024-05-01 11:35:21 +02:00
Mike McQuaid
7c0b989740
Merge pull request #17153 from apainintheneck/new-formula-json-dependencies-format
New formula internal json v3 dependencies format
2024-05-01 08:45:18 +01:00
Markus Reiter
0b56d0be4a
Document Tab.for_keg and use Keg#tab where possible. 2024-04-28 20:50:13 +02:00
apainintheneck
541305ae98 Update internal json v3 formula tests 2024-04-27 18:07:54 -07:00
apainintheneck
ff0c24786b Unpack new internal json v3 dep format 2024-04-27 18:07:54 -07:00
Markus Reiter
0f0055ede4
Make documentation @api private by default. 2024-04-26 19:04:20 +02:00
Markus Reiter
4b432c7ea4
Explicitly mark non-private APIs. 2024-04-22 21:16:49 +02:00
apainintheneck
db507be41a keg: update sorting by version logic
This updates logic to add a `#scheme_and_version` method to be used
with `.sort_by` and `.max_by`. Using `Keg#version` by itself can be
inaccurate when different version schemes are present. This also
updates the behavior of `Formula#eligible_kegs_for_cleanup` to match
the previous behavior. We were dropping the wrong keg based on the
sort being reversed in a previous PR.
2024-03-31 17:52:32 -07:00
Bo Anderson
dd382487c7
Sort kegs based on version scheme 2024-03-29 23:33:41 +00:00
Mike McQuaid
ea2892f8ee
brew.rb: handle missing args. 2024-03-07 16:20:20 +00:00
Markus Reiter
a24da6b072
Remove FromDefaultNameLoader to avoid warning twice. 2024-03-06 23:14:28 +01:00
Markus Reiter
a851bb86ef
Add type signature for Tap::fetch. 2024-03-06 14:30:17 +01:00
Mike McQuaid
f1eea64523
Merge pull request #16779 from reitermarkus/fix-load-from-path
Fix loading casks/formulae from relative paths.
2024-03-01 08:47:41 +00:00
Markus Reiter
3da0f8c4a6
Fix loading casks/formulae from relative paths. 2024-03-01 04:05:15 +01:00
Markus Reiter
2a78eba1ad
Simplify Tap#formula_files_by_name. 2024-02-29 22:48:50 +01:00
apainintheneck
cd5b93a2f2 internal json v3: parse ruby source checksum correctly
Currently we are including this in the API but not actually
parsing and loading it correctly from the JSON. I think this
was an oversight when addressing feedback and refactoring
the JSON shape. Not a big deal, of course, because I'm the
only person using it right now.

I found this out while testing installs using the API and I got
this error while running `brew reinstall tree`.

```
Warning: Cannot verify integrity of '60fc4212023d3fef00e6de4b9f3f0d63402cf3eca00778d09f4f2d3481b524a1--tree.rb'.
No checksum was provided.
```
2024-02-28 21:34:31 -08:00
apainintheneck
670e2188d7 formulary: update api loader to load internal json v3 2024-02-27 20:55:16 -08:00
Issy Long
f4218a6316
Fix RuboCop Performance/MapCompact offenses
- Rename an iterator variable since it would make the line too long.
2024-02-25 22:59:59 +00:00
Markus Reiter
0684a16293
Pass warn in FromNameLoader. 2024-02-22 22:12:07 +01:00
Markus Reiter
964f005b3e
Only treat symlinks in taps as alias paths.
Fixes https://github.com/Homebrew/homebrew-core/issues/162946.
2024-02-22 18:28:53 +01:00
Markus Reiter
e0743a1436
Reapply "Refactor Formulary::loader_for."
This reverts commit 24683525cb5abf3cc79a9e0e268fa6efd0af558b.
2024-02-22 18:24:57 +01:00
Markus Reiter
ab27efbd9d
Make Tap::each respect the API. 2024-02-22 17:56:47 +01:00
Mike McQuaid
24683525cb
Revert "Refactor Formulary::loader_for." 2024-02-16 13:41:54 +00:00
Markus Reiter
fe1f6c95f5
Fix FromDefaultNameLoader. 2024-02-14 23:09:18 +01:00
Markus Reiter
b717f5d954
Remove unused TapFormulaWithOldnameAmbiguityError. 2024-02-14 22:56:25 +01:00
Markus Reiter
177e9163c2
Fix code style. 2024-02-14 22:47:29 +01:00
Markus Reiter
f4ac2996a7
Fix type signature. 2024-02-14 22:11:51 +01:00