47 Commits

Author SHA1 Message Date
Douglas Eichelberger
d3d25beb35 Use requires_ancestor consistently 2024-10-06 09:25:57 -07: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
7da94a8f01
Preliminary macOS 15 (Sequoia) support 2024-06-11 02:59:31 +01:00
Markus Reiter
0f0055ede4
Make documentation @api private by default. 2024-04-26 19:04:20 +02:00
Douglas Eichelberger
c59d9fa833 Prefer numbered block params over proc conversion, cont'd 2024-04-08 09:47:27 -07:00
Mike McQuaid
ea2892f8ee
brew.rb: handle missing args. 2024-03-07 16:20:20 +00:00
Bo Anderson
5692c8ecbf
Fix style violations under newer RuboCop 2023-12-14 05:47:12 +00:00
Carlo Cabrera
93b43ad7a9
os/mac/mach: fix rpath deletion of fat machos
Fixes #15859.
2023-08-14 14:29:05 +08:00
Carlo Cabrera
b5334b818c
os/mac/mach: avoid recursively resolving rpaths
This is just a recipe for infinite loops. Plus, recursive references are
likely to be invalid, so we don't really gain much by attempting to
resolve them.[^1] (But we could if we made the logic here much more
complicated.)

Fixes a CI failure seen at Homebrew/homebrew-core#138323.

[^1]: See, for example, embree/embree#455.
2023-08-05 23:40:22 +08:00
Carlo Cabrera
b80940e1d8
os/mac/mach: simplify
We can avoid having to define a local variable and then reference it
inside these blocks by passing a proc instead.
2023-07-27 12:02:20 +08:00
Carlo Cabrera
acae97e70f
os/mac/mach: resolve rpaths too
We can add a small amount of logic to `#resolve_variable_name` that will
allow us to perform (limited) resolution of rpath references. This is
for informational purposes only: failing to resolve an `@rpath`
reference will not (and should not) result in `brew linkage` failures.

`dyld` will typically have more information than we do to resolve these
references, so not failing `brew linkage` when we fail to resolve an
`@rpath` reference is the right behaviour here.

As an example, before:

    ❯ brew linkage jpeg-turbo
    System libraries:
      /usr/lib/libSystem.B.dylib
    @rpath-referenced libraries:
      @rpath/libjpeg.8.dylib
      @rpath/libturbojpeg.0.dylib

After:

    ❯ brew linkage jpeg-turbo
    System libraries:
      /usr/lib/libSystem.B.dylib
    Homebrew libraries:
      /usr/local/Cellar/jpeg-turbo/3.0.0/lib/libjpeg.8.dylib (jpeg-turbo)
      /usr/local/Cellar/jpeg-turbo/3.0.0/lib/libturbojpeg.0.dylib (jpeg-turbo)
2023-07-27 12:02:20 +08:00
Carlo Cabrera
6b728bf3bd
Implement ruby-macho TODOs
We now have the new release of ruby-macho (#15758), so we can now
finish off the remaining work from #15731.
2023-07-26 11:15:19 +08:00
Carlo Cabrera
4c73942fae
extend/os/mac/keg_relocate: improve rpath handling
This implements the TODO that I left as a comment from #15722.

In order to simplify the handling of deleting an absolute rpath that has
a relative duplicate (or vice-versa, i.e., a relative rpath with an
absolute duplicate), we relocate all rpaths first in one pass and then
delete the duplicates in a separate pass.

We currently rely on some lower-level (but still public) methods from
ruby-macho since the standard `#delete_rpath` method changes the order
in which rpaths are resolved. We can switch back to using
`#delete_rpath` when Homebrew/ruby-macho#555 is merged and released.
2023-07-23 00:22:05 +08:00
Carlo Cabrera
13f2dc325e
os/mac/mach: report duplicate rpaths
We don't want to call `uniq` on this because this breaks our handling of
duplicate rpaths.
2023-07-17 13:11:12 +08:00
Gabriel Gerlero
15a0c7fd7d linkage_checker: resolve some variable install names on macOS 2023-07-06 14:15:14 -03:00
Douglas Eichelberger
adfd12cfd0 Enable more typing 2023-03-21 21:42:51 -07:00
Carlo Cabrera
dee3638653
os/mac/{keg,mach}: fix cache invalidation
We were rewriting dylib IDs and install names using `MachO::Tools`,
which doesn't update the state of the file in memory. This leads to
those changes being undone when we call `delete_rpath`.

We fix this by making sure the state of the file in memory always
matches the state of file on disk.

Closes #12832.
2022-02-11 23:19:15 +08:00
Carlo Cabrera
568bc94f3e
os/mac/keg: use MachOFile#delete_rpath instead of MachO::Tools
This will allow us to avoid keeping track of the number of `RPATH`s
while trying to delete duplicates.

See discussion at #12745.
2022-01-19 00:34:39 +08:00
Carlo Cabrera
488ccfdf70
formula_cellar_checks: check keg for mismatched arches
There have been a few instances I've noticed that we've been silently
installing binaries built for x86_64 on ARM. There's probably more that
I haven't found yet, so it seems useful to check this with an audit.
2021-07-18 11:44:37 +08:00
Mike McQuaid
30a65342e8
Deprecate, disable, delete code for Homebrew 3.2.0
Do the usual deprecation, disable, delete dance for Homebrew 3.2.0.
2021-06-17 11:34:32 +01:00
Carlo Cabrera
28c0caae4d
extend/os/mac/keg_relocate: remove RPATHs rooted in build directory
Keeping dangling `RPATH`s is a security risk, and is bad for build
reproducibility.
2021-05-14 01:07:14 +01:00
Bo Anderson
450bc4ab33
Fix brew style 2021-03-26 14:11:03 +00:00
Bo Anderson
b670ab1c7b Deprecate additional arch functions 2021-02-02 16:19:24 +00:00
Markus Reiter
24ae318a3d Move type annotations into files. 2020-10-10 14:59:39 +02:00
Markus Reiter
390deeb5ac Document MachOShim. 2020-08-26 03:13:59 +02:00
Mike McQuaid
3381cbf5c7
Use Homebrew::EnvConfig. 2020-04-07 09:58:26 +01:00
Mike McQuaid
36dbad3922
Add frozen_string_literal to all files. 2019-04-20 13:27:36 +09:00
William Woodruff
a8c4136e9e
os/mac: Use delegation for Mach-O methods 2019-03-10 21:07:05 -04:00
William Woodruff
54aca0d14f
os/mac: Flush RPATHs from Mach-Os when possible 2019-03-10 21:07:04 -04:00
William Woodruff
618c5cd01a
os/mac: Expose rpaths 2019-03-10 21:07:03 -04:00
Markus Reiter
e9b9ea49a1 Update to RuboCop 0.59.1. 2018-09-17 03:45:59 +02:00
Mike McQuaid
d7eca0b57c
Use Bundler to manage vendor directory
Rather than having to manually keep track of what version each thing in
here is and copy files around by hand on update let's use Bundler's
standalone mode and careful use of `.gitignore` to help us do it.

This means a `bundle update --standalone` will allow us to update all
gems in vendor.

We could consider vendoring other gems this way in future but I'd
suggest only doing this for gems with no dependencies or at least gems
with no native extensions. The only gem this applies to that we
currently use is `ruby-prof` and I'm not convinced it's widely used
enough to warrant vendoring for everyone. Perhaps that's another
criteria: it should be functionality that's used by non-developer
commands and/or normal Homebrew usage.
2018-09-13 15:24:18 +01:00
William Woodruff
8bb4c4f96f
mach: Always report Mach-O parsing errors
This retains the raise-on-error behavior for developers, but
otherwise only prints an error message.
2018-06-06 11:22:21 -04:00
Shaun Jackman
d79c5ade1a Implement linkage for Linux 2017-12-03 16:22:51 -08:00
ilovezfs
e8da9613fb Revert "mach: Avoid reopening the file for relocation" 2017-09-27 02:08:23 -07:00
William Woodruff
d618e574fb
mach: Avoid reopening the file for relocation
This commit allows the relocation code to perform install name
and dylib ID changes without reopening the file separately.
2017-09-25 17:46:23 -04:00
Mike McQuaid
57db2e539e Revert "Merge pull request #2597 from MikeMcQuaid/vendor-gems"
This reverts commit 3e4547f52e7ebec633f8bfefc8a396d944edf908, reversing
changes made to 6edf9382bcc1240ad6f97c8b752cfe56cef9965d.
2017-05-07 17:28:39 +01:00
Mike McQuaid
e1bbab6ca6 Revert "Merge pull request #2603 from MikeMcQuaid/tweak-gem-vendoring"
This reverts commit 2372872974d1049c2beafe7dedb7f8f882502058, reversing
changes made to 3e4547f52e7ebec633f8bfefc8a396d944edf908.
2017-05-07 17:28:37 +01:00
Mike McQuaid
33f83be10e Tweak Gem vendoring.
If people have `HOMEBREW_RUBY_PATH` set then things explode in a rather
confusing fashion. Instead, run `bundle` for them with the arguments
that they'd want.

Also, move `macho` requires into the module itself; it's a pain having
to do everything for Bundler before requiring `pathname` which is a core
Ruby class.
2017-05-07 15:33:54 +01:00
Mike McQuaid
ee253e465b Vendor all Homebrew's gems.
Homebrew's actually ended up using a fair few gems. While we want to
avoid Bundler at runtime (and this PR still does that, in fact uses
Bundler even less at runtime than it did before) writing our own version
to use at build-time seems redundant.
2017-05-07 13:52:57 +01:00
FX Coudert
ac8dd9ae7d Don't list duplicate dylibs for universal 2017-03-04 14:05:32 +01:00
William Woodruff
9267511e6b
os/mac: Rename MachO -> MachOShim
Prevents namespace conflict with vendored ruby-macho.
2016-11-09 17:35:56 -05:00
William Woodruff
032ed07bce
os/mac: Allow MachO.dynamically_linked_libraries to be filtered by dylib type.
This allows us to filter out weak linkages during audits, preventing
a false error from occurring when the dylib cannot be found.
2016-11-09 17:35:56 -05:00
William Woodruff
d16e4a782e
os/mac: Delete old cctools-based relocation code.
Disable check for $HOMEBREW_NO_RUBY_MACHO now that no alternative exists.
2016-09-20 17:48:21 -04:00
William Woodruff
35e2209c10 architecture_list: add new module.
remove old mach.rb, replace with cctools_mach.rb and prune ELF case
move ArchitectureListExtension to separate file ELF support is
maintained in Linuxbrew
2016-02-03 21:24:21 +00:00
Xu Cheng
b743cadd87 use Utils.popen_read instead of ENV trick to escape path
Closes Homebrew/homebrew#45021.

Signed-off-by: Xu Cheng <xucheng@me.com>
2015-10-18 22:57:43 +08:00
Xu Cheng
646f94adfe move mach.rb to os/mac/mach.rb 2015-10-18 22:57:42 +08:00