37 Commits

Author SHA1 Message Date
Issy Long
975a707b3c
Bump some utils/ files to Sorbet typed: strict 2025-01-22 22:01:34 +00:00
Issy Long
6ada9a9665
Add clarifying comments to rubocop:disables
- Needed for PR 18842 that adds a `DisableComment` RuboCop to ensure that all RuboCop disables have comments.
2025-01-12 16:59:07 +00:00
Bo Anderson
567f5eb4be
Allow sockets to use longer paths on macOS 2024-09-27 04:37:03 +01:00
Bo Anderson
6a0db5035f
Fix misuse of fork in sandbox causing crashes 2024-08-28 13:53:01 +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
Markus Reiter
447216a960
Avoid ignore_interrupts in safe_fork. 2024-07-14 14:32:49 -04:00
Markus Reiter
3c8497647e
Fix unused argument. 2024-07-14 13:18:33 -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
Caleb Xu
aac156ccdf
fork: pass error_pipe path to yielded block 2024-04-22 22:39:45 -04:00
Bo Anderson
636d883008
Support bash in privileged mode 2024-03-27 04:40:44 +00:00
Issy Long
b7d997e80d
sorbet: Bump some files from typed: false to typed: true
- This was done with `brew typecheck --update --suggest-typed` which
  (as of the previous commit) uses Spoom, yet another gem. I thought I'd
  see how well it works. There are no Sorbet errors after these changes!
2022-10-11 01:09:03 +01:00
Bo Anderson
f079373d8c
utils/fork: handle termsig in safe_fork 2021-02-25 13:42:44 +00:00
Mike McQuaid
240d2c34fb
utils/fork: fix bootsnap handling.
Also, while we're here:

- remove unused block argument
- remove unneeded RuboCop disable comment
2021-02-02 12:34:14 +00:00
Mike McQuaid
9216d8abe6
rubocop-rails: make fixes. 2020-12-02 10:43:04 +00:00
Markus Reiter
6750448d95 Fix some auto-correctable type errors. 2020-11-29 21:23:54 +01:00
Markus Reiter
24ae318a3d Move type annotations into files. 2020-10-10 14:59:39 +02:00
Mike McQuaid
84a110744a
utils/fork: check for inner exception command.
If it's not present then `ErrorDuringExecution` and `BuildError` don't
work correctly so better to fall back to a default `RuntimeError`.
2020-05-12 10:26:09 +01:00
Markus Reiter
6c03cc0040 Fix RuboCop namespace. 2019-10-21 20:09:56 +02:00
Mike McQuaid
cbf458ea9c
Lint/ElseAlignment: ignore some bugged autocorrections. 2019-10-14 09:03:02 +01:00
Issy Long
e5e28fbd69
Auto-fix more Layout/IndentationWidth offenses
- These didn't appear in the first pass as the other offense fixes caused them.
2019-10-13 16:04:30 +01:00
Issy Long
245c61017f
Auto-fix Layout/ElseAlignment offenses 2019-10-13 16:04:28 +01:00
Issy Long
341ea60807
Auto-fix Style/RedundantBegin offenses
- This also required auto-fixes for Layout/EmptyLinesAroundBlockBody and
  Layout/InconsistentIndentation once the auto-fixer had got rid of the
  "redundant begin"s.
2019-10-13 16:04:27 +01:00
Mike McQuaid
36dbad3922
Add frozen_string_literal to all files. 2019-04-20 13:27:36 +09:00
William Woodruff
649a630826
utils/fork: Check if error pipe is closed
Document special interrupt case.
2018-09-18 22:21:12 -04:00
William Woodruff
367629d289
utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.

Additionally, adds tests for the new behavior.
2018-09-04 11:03:32 -04:00
Mike McQuaid
7df5b7057e
Revert "Use JSON to marshal errors from children" 2018-08-18 08:20:13 +01:00
William Woodruff
5c90833f0a
Use JSON to marshal errors from children 2018-08-17 15:23:08 -04:00
Markus Reiter
e2d8e3c6ee Remove unneeded RuboCop comment. 2018-08-01 04:12:31 +02:00
Markus Reiter
175ca909ee Clean up code style and remove .rubocop_todo.yml. 2017-10-08 16:10:37 +02:00
Shaun Jackman
7b96fd008e safe_fork: Improve the error message 2017-08-25 12:43:07 -07:00
Mike McQuaid
021cef4b2b Autocorrect Rubocop Style/SpecialGlobalVars. 2017-06-12 09:11:42 +01:00
BrewTestBot
13d544e11e Core files style updates.
Closes Homebrew/homebrew#42354.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
2015-08-03 13:22:35 +01:00
Jack Nagel
ff11789933 Close the socket after sending the file descriptor to the child
Fixes Homebrew/homebrew#39691.
2015-05-12 21:53:04 -04:00
Jack Nagel
c07da9485f The forked build process should never run at_exit handlers
We don't use at_exit anywhere that matters, but the test framework does.
2015-04-28 01:39:28 -04:00
Jack Nagel
913c12fd43 Keep subprocess code inside begin block 2015-04-25 23:22:58 -04:00
Jack Nagel
f7ded45bc7 Clean up socket and filesystem resources separately 2015-04-25 23:17:13 -04:00
Xu Cheng
06f72ab38f move safe_fork into a standalone method 2015-04-15 19:51:54 +08:00