75 Commits

Author SHA1 Message Date
Alexander Bayandin
358291e841 extend/kernel: allow exec_editor to open multiple files at once 2025-08-03 16:44:19 +01:00
Carlo Cabrera
a29a643c66
Merge pull request #20359 from Homebrew/replace-ensure_formula_installed!
Replace `ensure_formula_installed!` with `Formula#ensure_installed!`
2025-08-01 21:13:59 +00:00
Carlo Cabrera
0fd3b8e4af
Uncomment odeprecated
This is close enough to #20331 to do now.
2025-08-02 04:00:52 +08:00
Carlo Cabrera
fb35add3b6
Replace ensure_formula_installed! with Formula#ensure_installed!
`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.
2025-08-02 03:43:37 +08:00
Carlo Cabrera
9dc111247f
Merge pull request #20358 from Homebrew/require-formula-ensure-formula-installed
Ensure we `require "formula"` before doing `ensure_formula_installed!`
2025-08-01 19:21:35 +00:00
Carlo Cabrera
cc5df09845
Ensure we require "formula" before doing ensure_formula_installed!
This is needed to avoid Sorbet runtime errors. See #20352.
2025-08-02 02:46:38 +08:00
Carlo Cabrera
1fc4225850
Merge pull request #20357 from Homebrew/more-extend-kernel-sigs
extend/kernel: tighten type sig for `ensure_formula_installed!`
2025-08-01 18:44:44 +00:00
Carlo Cabrera
cf6c5acce0
extend/kernel: tighten type sig for ensure_formula_installed!
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.
2025-08-02 02:23:47 +08:00
Carlo Cabrera
a0a78e6c6c
Remove support for passing Formulae to pretty_*ed methods
It doesn't look like these are even needed.
2025-08-02 02:11:12 +08:00
Carlo Cabrera
a76c33f7bb
extend/kernel: tighten up some type signatures
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.
2025-08-02 01:59:46 +08:00
Mike McQuaid
f405f7316c
extend/kernel: fix odisabled call.
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.
2025-08-01 08:47:38 +01:00
Mike McQuaid
ec56bbf289
Improve extend/* Sorbet typing 2025-07-31 17:31:27 +01: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
Mike McQuaid
6a5a48de29
extend/kernel: fix failures with differing filenames. 2025-07-14 19:12:37 +01: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
Mike McQuaid
cc03340af3
Reduce Homebrew/brew CI warnings
- Remove a bunch of non-actionable/unnecessary noise in GitHub Actions
  CI.
- Limit number of threads used to generate analytics API data to avoid
  reproducible failures producing errors and requiring retries.
- Move to Debian Old Stable for testing non-system `glibc`.
- Remove unneeded core taps/updates.
- Improve naming of CI jobs to clarify purpose i.e. we're testing
  things work on Linux, not Ubuntu specifically.
- Remove dedicated non-online/non-generic Linux `brew tests` jobs from
  3 to 1.

Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2025-06-09 12:47:22 +01:00
Mike McQuaid
d899f00c4b
Link to Support Tiers in diagnostic/error messages
Now that we have this nice URL let's reference it to allow our other
messages to be a bit shorter/kinder.
2025-04-01 11:35:27 +01:00
Mike McQuaid
d84fac5af4
Look for VSCode variants
We've had requests for this in Homebrew/bundle a few times so let's
implement it both for there and for `brew edit`.

Tested on my machine with `cursor` and working as expected.
2025-03-19 11:42:37 +00:00
thibhero
49007fbccd modifying kernel.rb to accept negative value for disk_usage_readable 2025-03-04 20:01:07 -05:00
Mike McQuaid
d555ec9218
Fix handling of case-mistyped commands
- hide warnings when requiring files repeatedly on a case-insensitive
  filesystem and add reference to Ruby bugs
- add another case to check for command require failures
- also handle commands with `-` in them

Fixes #19125
2025-01-27 08:42:49 +00:00
Patrick Linnane
d04430d1a5
brew style --fix
Signed-off-by: Patrick Linnane <patrick@linnane.io>
2024-11-26 14:09:13 -08:00
Bo Anderson
aff41779c4
extend/kernel: fix error on early deprecations 2024-10-16 03:58:05 +01:00
Carlo Cabrera
7a8f9fa489
extend/kernel: fix duplicate messages in GitHub Actions
Calls to `opoo` and `onoe` produce duplicate `Warning:` and `Error:`
messages in CI logs because we print something to stdout and print an
annotation. Annotations also produce `Error:` and `Warning:` lines in
the log.

Let's fix this by skipping printing the message if we've already printed
an annotation.
2024-10-14 12:15:24 +08:00
Patrick Linnane
ada5e2d219
brew style --fix
Signed-off-by: Patrick Linnane <patrick@linnane.io>
2024-10-02 10:03:48 -07:00
Patrick Linnane
c2e2b23c50
brew style --fix
Signed-off-by: Patrick Linnane <patrick@linnane.io>
2024-10-02 10:03:12 -07:00
Mike McQuaid
94416e82f0
Add new odeprecated, odisabled, remove disabled code.
Prepare the usual deprecation cycle for Homebrew 4.4.0.
2024-09-24 10:15:34 +01:00
Mike McQuaid
1c390093f8
Revert "Limit usage of GitHub Actions Annotations" 2024-09-16 16:52:03 +01:00
Carlo Cabrera
c6e2cd9037
Limit usage of GitHub Actions Annotations
- only use annotations for `opoo` and `onoe` if
  `HOMEBREW_GITHUB_ACTIONS` is set. This will make using `brew` less
  noisy in GitHub Actions for third parties. See
  Homebrew/discussions#5602.
- if we've already called `puts_annotation_if_env_set`, then we no
  longer need to print the message to `$stderr`. The message from the
  annotation already show up in the GitHub Actions log, so printing to
  `$stderr` just leads to duplicate messages in the log.

While we're here, let's make sure to forward the `file:` and `line:`
kwargs of `puts_annotation_if_env_set` to the `Annotation` constructor.
2024-09-15 11:31:54 +08:00
Mike McQuaid
02d414d79b
Merge pull request #18008 from Homebrew/deprecate-old-style-cmds 2024-08-14 07:45:13 +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
Douglas Eichelberger
4fd659797f Deprecate invoking commands in the old style 2024-08-10 11:20:47 -07:00
William Woodruff
107d57d220
extend/kernel: forward the latest: kwarg
Signed-off-by: William Woodruff <william@yossarian.net>
2024-07-29 13:43:42 -04:00
William Woodruff
5e0e0d56af
attestation: remove gh version detection
I'm declaring bankruptcy on this entire approach:

1. We can attempt to match on versions, but this will fail
   when the version of `gh` installed is built from `HEAD`
   or similar.
2. We can match on dates instead (since `gh --version` also includes
   the date), but this is even more brittle + implies a support
   contract we don't actually have (we don't actually want
   to say we support random dated builds between public releases
   of `gh`).

This moves us back to a simpler approach: if `gh` is present,
we use it. If `gh` is not present, we attempt to install it
with `ensure_executable!`. If the user's `gh` is present but too old,
it'll fail during attestation verification with a reasonable error,
which IMO is fine for now since this is all still in beta.

Signed-off-by: William Woodruff <william@yossarian.net>
2024-07-29 13:13:55 -04:00
Mike McQuaid
42438f45ae
extend/kernel: add missing utils require.
Don't require this globally to avoid slowing down boot.
2024-07-26 19:48:51 +01:00
Markus Reiter
b8847a90d9
Remove unused argument. 2024-07-14 15:08:37 -04:00
Markus Reiter
44766945fc
Fix variable type. 2024-07-14 14:32:17 -04:00
Markus Reiter
27a70a40c2
Disallow nested ignore_interrupts. 2024-07-14 13:36:43 -04:00
Markus Reiter
3c8497647e
Fix unused argument. 2024-07-14 13:18:33 -04:00
Markus Reiter
bcded854ce
Make ignore_interrupts thread-safe. 2024-07-14 11:43:14 -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
Mike McQuaid
e573a53868
Output GitHub warning/error annotations to stderr
This will mean e.g. `opoo` etc. will output to stdout and not end up
being in the stdout of `brew deps` etc.

While we're here, remove a duplicate annotation output I noticed in
`extend/kernel.rb`.

Inspired by conversation in:
https://github.com/Homebrew/homebrew-test-bot/issues/1082
2024-05-31 09:31:44 +01:00
Patrick Linnane
992b50a413
various: fix minor typos
Signed-off-by: Patrick Linnane <patrick@linnane.io>
2024-05-13 14:30:06 -07:00
Mike McQuaid
50384591c7
extend/kernel: add sigs to opoo/onoe/ofail
Add these and correctly pass through a string to
`GitHub::Actions.puts_annotation_if_env_set`.

Also, fix some call sites to not rely on the `void` return.
2024-05-10 14:12:19 +01:00
Mike McQuaid
16901a674f
extend/kernel: make opoo/odie/etc. print GitHub Actions notes.
We already do this for deprecations but these may make warnings
and errors from Homebrew easier to spot in GitHub Actions logs.

While we're here, cleanup other cases that should have used
`GitHub::Actions::Annotation` but didn't and provide some helpers and
tweaks there necessary for our use case here.
2024-05-09 14:43:53 +01:00
Markus Reiter
caf87c0336
Warn about undocumented non-private APIs. 2024-05-01 11:35:20 +02:00
Markus Reiter
5e636174e8
Explicitly mark non-public APIs. 2024-04-23 19:10:45 +02:00
Markus Reiter
4b432c7ea4
Explicitly mark non-private APIs. 2024-04-22 21:16:49 +02:00
William Woodruff
0f0dee42b4
ensure_executable!: add opt_bin path to search
Signed-off-by: William Woodruff <william@yossarian.net>
2024-04-18 11:11:26 -07:00
Mike McQuaid
f086138043
Fix GitHub Actions annotation format.
Co-authored-by: Bo Anderson <mail@boanderson.me>
2024-03-14 14:09:11 +00:00
Mike McQuaid
dcaa69a2dc
Add GitHub Actions warning/error annotations for deprecations/disables.
This should make these messages, particular warnings, more obvious to
GitHub Actions users.

There's an argument perhaps we should do this more broadly for all
warning/error messages but: this feels like a good start.
2024-03-14 09:49:12 +00:00