349 Commits

Author SHA1 Message Date
Eric Knibbe
37315cf8ad
write_env_script: allow setting args without env 2025-09-01 10:51:28 -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
Mike McQuaid
0a9fec107e
Merge pull request #20396 from Homebrew/more_pathname_types
extend/pathname: fix another type error.
2025-08-07 08:47:07 +00:00
Mike McQuaid
0a881b9a0d
extend/pathname: fix another type error.
Let's make this consistent with the rest of this file.
2025-08-07 09:32:22 +01:00
Mike McQuaid
31e12d68e3
extend/pathname: fix type error.
`install_p` is sometimes called with a `Pathname` for `new_basename`.
2025-08-07 09:05:40 +01:00
Ruoyu Zhong
10e2c2b298
extend/pathname: accept String as target in write_env_script
There is too much existing usage outside of Homebrew for us to break
[1].

[1]: https://github.com/search?q=%22write_env_script%20%5C%22%22%20NOT%20org%3AHomebrew%20NOT%20is%3Afork&type=code

Closes https://github.com/Homebrew/homebrew-core/pull/232573.
2025-08-07 08:13:15 +08:00
Daeho Ro
af7966cb2a
pathname: add type to 2025-08-03 18:23:47 +09:00
Mike McQuaid
ea53fdc096
extend/pathname: fix type signature for write_env_script.
It needs to be more permissive.
2025-08-01 15:28:53 +01:00
Mike McQuaid
ec56bbf289
Improve extend/* Sorbet typing 2025-07-31 17:31:27 +01:00
Mike McQuaid
e3c3f5a356
Deprecate/disable/remove code for Homebrew 4.6
The next minor release will be Homebrew 4.6.0 so let's do the usual
deprecation/disable/remove code cycle.
2025-07-31 12:13:01 +01:00
Adrian Ho
8a0a887056 env_script_all_files: don't overwrite existing stuff
Overwriting upstream content potentially causes major confusion at best, major breakage at worst.
2025-07-21 12:41:42 +08:00
Mike McQuaid
d57efd9ea2
Improve some Pathname instance variable handling
Will fix or at least partly address:
```
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/os/linux/elf.rb:225: warning: The class Pathname reached 8 shape variations, instance variables accesses will be slower and memory usage increased.
35
It is recommended to define instance variables in a consistent order, for instance by eagerly defining them all in the #initialize method.
```
2025-07-11 08:02:27 +00: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
1035024b83
Revert "feat: allow env for write_jar_script" 2025-05-26 17:19:48 +01:00
Sean Molenaar
81ea767ea3
Update Library/Homebrew/extend/pathname.rb 2025-05-26 21:17:05 +09:00
Sean Molenaar
ca911fb446
feat: allow env for write_jar_script 2025-05-14 11:56:31 +02:00
Mike McQuaid
c9a7b62b1d
Homebrew 4.5 deprecations/disables/removals
The usual cycle of deprecating, disabling, and removing things in
Homebrew major/minor releases.
2025-04-22 17:15:23 +01:00
Douglas Eichelberger
d3d25beb35 Use requires_ancestor consistently 2024-10-06 09:25:57 -07:00
Carlo Cabrera
6329db9065
Remove macOS implementation of #arch_compatible?
We don't really need this.
2024-09-30 22:29:03 +08:00
Carlo Cabrera
861d7b9087
linkage_checker: skip files with incompatible architectures
Some formulae include these files, and they can't always be removed.
However, they can cause spurious linkage failures, so let's skip them
when checking for linkage. See, for example, faust at
Homebrew/homebrew-core#191308.
2024-09-29 05:15:36 +08: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
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
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
Kevin
c3c1528611
Revert "Use cp -c when copying files" 2024-06-17 21:17:10 -07:00
Daiki Mizukami
028cfe1ea6
Utils::Cp: Rename to Utils::Copy
As per review feedback:

https://github.com/Homebrew/brew/pull/17373#discussion_r1633217748
2024-06-11 20:31:34 +09:00
Daiki Mizukami
b2ddeecdd9
Utils::Cp: Remove copy prefix from method name
As per review feedback:

https://github.com/Homebrew/brew/pull/17373#pullrequestreview-2104523770

Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2024-06-08 07:58:20 +09:00
Daiki Mizukami
58852106c1
Utils::Cp: Rename copy* methods to copy*_with_attributes
As per review feedback:

https://github.com/Homebrew/brew/pull/17373#pullrequestreview-2103870774
2024-06-07 19:03:33 +09:00
Daiki Mizukami
deaac7ce47
Use Utils::Cp to copy files
This replaces `FileUtils.cp` and `system_command! "cp"` with the new
`Utils::Cp` utility where it is expected that the performance
improvement outweighs the cost of the system command invocation.
2024-05-27 12:11:41 +09:00
Mike McQuaid
a92e6fc1c8
extend/pathname: import rmtree again.
The separate file is no longer required now that
https://github.com/sorbet/sorbet/pull/7895 was merged.
2024-05-18 18:02:31 +02:00
Bo Anderson
727cf5e917
extend/pathname: restore old rmtree behaviour 2024-05-17 12:32:29 +09:00
Markus Reiter
caf87c0336
Warn about undocumented non-private APIs. 2024-05-01 11:35:20 +02:00
Markus Reiter
0f0055ede4
Make documentation @api private by default. 2024-04-26 19:04:20 +02:00
Bo Anderson
28a80a6ebf
Avoid writable_real? 2024-03-27 06:26:32 +00:00
Douglas Eichelberger
eb7c3e52a0 Require SystemInclude only where needed 2024-01-31 11:42:01 -08:00
Douglas Eichelberger
8c832e0905 Remove some fixed FIXMEs 2024-01-26 12:00:13 -08:00
Douglas Eichelberger
8e9d294df2 Add File.atomic_write to extend/ 2024-01-19 13:36:16 -08:00
Douglas Eichelberger
0191af7899 resolve typecheck errors 2023-11-05 08:55:58 -08:00
Bo Anderson
e74f0dd787
extend/pathname: fix text_executable? regex 2023-06-25 17:33:49 +01:00
Douglas Eichelberger
08af78a2a5 brew style --fix 2023-04-25 09:26:24 -07:00
Douglas Eichelberger
24cf6076e8 brew style --fix 2023-04-24 20:42:39 -07:00
Douglas Eichelberger
9ba677f6d4
Update Library/Homebrew/extend/pathname.rb
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2023-03-22 10:04:53 -07:00
Douglas Eichelberger
91afda651a Update Pathname#magic_number 2023-03-21 17:37:48 -07:00
Douglas Eichelberger
b1f722aed7 Update RBI files 2023-03-21 17:37:48 -07:00
Douglas Eichelberger
82dc57dfea Enable UnpackStrategy types 2023-03-21 17:37:46 -07:00
Ruiyang Wu
4ac228cc41 Use install-info from texinfo if not available in /usr/bin
`install-info` is not shipped with macOS Ventura and some Linux
distros. This commit uses `install-info` from `texinfo` formula if it
is not available in `/usr/bin`.

See: https://github.com/Homebrew/discussions/discussions/4306
2023-03-18 18:24:03 -04:00
Mike McQuaid
b698cef945
brew style --fix (and a manual one) 2023-03-07 10:48:35 +00:00
Nanda H Krishna
75045e91f8
brew style --fix 2023-02-06 13:50:39 -05:00
Chris Araman
caf310038f
linkage: display executables with missing rpath
An executable that links against @rpath-prefixed dylibs must include at least
one runtime path. This will prevent issues like the one resolved in #91485.

Caveats:
1. This won't find executables that have only recursive dylib dependencies with
   @rpath prefixes.
2. This makes no attempt to resolve @rpath, @executable_path or @loader_path
   dylibs, or to verify the correctness of any LC_RPATH entries, or to
   otherwise simulate dlopen logic.
3. Weakly-linked dylibs are still excluded from the search for broken linkage.

The scope is narrow in order to focus on this particular problem. It is meant
only as a sanity check.
2021-12-20 13:44:35 -08:00
Alexander Bayandin
fe9a039774
unpack_strategy: add zstd 2021-09-20 14:12:30 +01:00
Mike McQuaid
714bfee81f
extend/pathname: handle missing permissions on removal.
Fixes #11783
2021-07-28 15:40:23 +01:00