424 Commits

Author SHA1 Message Date
Rylan Polster
dc39c12b39
Load replacement formula/cask from formula API 2025-08-28 16:48:32 -04:00
Rylan Polster
9c68b548e9
Include aliases and renames in FormulaStub 2025-08-26 17:02:57 -04:00
Douglas Eichelberger
4d11307d41
Refactor T.must called on .last 2025-08-25 20:30:31 -07:00
Rylan Polster
763531e821
Extract Pathname refinement from Formulary 2025-08-25 04:08:42 -04:00
Rylan Polster
879b7a5dd8
Work around PathnameWriteMkpath refinement recursion error 2025-08-24 14:08:01 -04:00
Rylan Polster
9a7fdd988c
Handle false case for @factory_cache_enabled in Formulary 2025-08-24 14:07:17 -04:00
Rylan Polster
4410388043
Enable strict typing in Formulary 2025-08-24 12:58:48 -04:00
Mike McQuaid
a1f112f3fe
Move o* output methods to Utils::Output
This reduces the surface area of our `Kernel` monkeypatch and removes
the need to `include Kernel` in a bunch of modules.

While we're here, also move `Kernel#require?` to `Homebrew` and fully
scope the calls to it.
2025-08-20 19:20:19 +01:00
Rylan Polster
b04b0971a1
Enable loading stubbed formulae 2025-08-19 02:47:07 -04:00
Bo Anderson
b1b28fb2f4
formulary: forbid cache paths 2025-08-18 15:24:02 +01:00
Bo Anderson
b30d13c3ef
formulary: do not allow using the cache if explicitly forbidding paths 2025-08-18 05:33:02 +01:00
Eric Knibbe
827480f06b
messages/comments: wording fixes 2025-08-16 00:57:59 -04:00
Mike McQuaid
640f16860b
formulary: provide ref and realpath when rejecting path.
This should help further debugging.

Also, no need to formulae that aren't `*.rb` files as they'll be rejected
later anyway (and already were before we changed the
`Homebrew::EnvConfig.forbid_packages_from_paths?` defaults).
2025-08-15 17:52:56 +01:00
Mike McQuaid
6024ccf7dd
formulary: tighter path rejection detection.
We need to handle symlinks in both directions for formulae in the
cellar/taps/cache otherwise we can get the nonsensical situation of
telling people a formula must me in a tap when it already is (but is
symlinked from elsewhere).
2025-08-15 08:18:59 +01:00
Mike McQuaid
c143b03280
Fix more HOMEBREW_FORBID_PACKAGES_FROM_PATHS issues
- Ensure that we're overriding it where necessary internally (but not
  allowing this to be used as a public opt-out API)
- Better handle formulae from paths that look like taps
2025-08-14 19:35:11 +01:00
Mike McQuaid
b73b1edd1b
Fix some test-bot failures/bad output
Noticed these when perusing the test-bot output from a third-party tap.
2025-08-14 14:45:50 +01:00
Mike McQuaid
c00413f0e9
formulary: improve/loosen path rejection logic.
- Don't check if the `realpath` includes `/`: it always will.
  Instead, see if the originally user-passed `ref` includes `/` or ends
  with `.rb`.
- Always raise an error message, don't silently return.
2025-08-14 08:41:35 +01:00
copilot-swe-agent[bot]
cfa7326620
Improve error message for local formula file installation attempts
Co-authored-by: MikeMcQuaid <125011+MikeMcQuaid@users.noreply.github.com>
2025-08-13 17:29:43 +01:00
HuaDeity
dd0e187eb5
Fix HEAD installations with HOMEBREW_FORBID_PACKAGES_FROM_PATHS
- Allow cache paths in FromPathLoader when HOMEBREW_FORBID_PACKAGES_FROM_PATHS is set
- Fixes issue where HEAD installations fail due to temporary source downloads
- Add test case to verify cache paths are allowed when path restrictions are enabled

The issue occurred because HEAD installations download formula sources to cache
directories, but HOMEBREW_FORBID_PACKAGES_FROM_PATHS only allowed paths from
HOMEBREW_CELLAR and HOMEBREW_LIBRARY/Taps, causing the installation to fail.

Closes: homebrew/brew#issue-number
2025-08-13 17:57:55 +08:00
Rylan Polster
0f9fb4f29a
Use API helper methods 2025-08-12 17:04:15 -04:00
Rylan Polster
8dccdd8e60
Store formula API data for use in to_hash_with_variations 2025-08-11 22:06:07 -04:00
Eric Knibbe
626b6aca2d
RubyDoc output fixes 2025-08-05 17:13:42 -04:00
Eric Knibbe
6255263b51
output: express environment variables consistently 2025-08-04 09:50:06 -04:00
Mike McQuaid
34bc30d639
Fix URI parser warning 2025-07-31 12:21:19 +01:00
Mike McQuaid
312f046302
Make --debug output a bit quieter by default
The `Formulary` and `system_command` debug output is incredibly verbose
by default and this is pretty annoying when all you want is to get
better backtraces when there's an error.

Instead, let's require `--verbose` and `--debug` for the noisiest output
message types.
2025-07-25 17:14:46 +01:00
botantony
5a50a0f232
formulary: make no_autobump! reason a symbol when needed
Signed-off-by: botantony <antonsm21@gmail.com>
2025-07-17 17:16:37 +02:00
Patrick Linnane
4513a43d53
Fix RuboCop failures.
Co-authored-by: Patrick Linnane <patrick@linnane.io>
Co-authored-by: Carlo Cabrera <github@carlo.cab>
Co-authored-by: Thierry Moisan <thierry.moisan@gmail.com>
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2025-07-14 19:12:38 +01:00
Carlo Cabrera
69ce5edd14
formulary: improve style
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2025-07-10 20:27:52 +08:00
Carlo Cabrera
6141c6a181
formulary: prevent formulae from printing to stdout while being loaded
Formulae can execute arbitrary Ruby code when being loaded. In
particular, they can print to stdout with methods like `puts`. This can
break the parsing of output of commands like `brew info --json=v2`.

Let's fix that by capturing the output to stdout, and then printing
those messages to stderr instead (using `opoo` to try to discourage
formula authors from doing this).
2025-07-10 03:58:39 +08:00
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