101 Commits

Author SHA1 Message Date
Mike McQuaid
9ac306e464
Remove alias generic_* definitions in favour of using super
This is the pattern we've been adopting for a while and it's a bit
cleaner. Let's remove all of the existing usage of the existing pattern
to avoid confusion when adopting the new one.
2025-06-16 08:10:08 +00:00
Carlo Cabrera
d77c0392ef
linkage_checker: replace Fiddle.dlopen with libSystem call
`dlopen`ing a library executes potentially untrusted code (e.g. if the
library has initialisers). We can avoid the `dlopen` call by asking
`libSystem` directly about whether a library can be found in the shared
cache.

Of course, the `dlopen` happens after a `ENOENT`, so the attack surface here
is relatively small. But relying on this still exposes us to a potential
TOCTOU[^1] bug. Let's avoid it entirely by skipping `dlopen` altogether.

Also: add RBI for `Fiddle` constants used in `linkage_checker`

Upstream don't have these definitions yet, so I've added an RBI for them
in the meantime.

[^1]: https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use
2024-10-03 23:20:52 +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
Michael Cho
dd25679d0a
linkage_checker: skip broken linkage in Julia 2024-09-10 12:59:07 -04:00
Michael Cho
49fbf01a44
linkage_checker: exclude test deps from being considered runtime dep 2024-09-07 13:16:50 -04: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
Mike McQuaid
1c6549517d
linkage_checker: test indirect dependencies.
Check for indirect dependencies with linkage with linkage in strict
test mode.

This should be done to ensure we accurately declare dependencies in
homebrew/core.
2024-05-14 12:12:19 +09:00
Markus Reiter
0b56d0be4a
Document Tab.for_keg and use Keg#tab where possible. 2024-04-28 20:50:13 +02:00
Markus Reiter
0f0055ede4
Make documentation @api private by default. 2024-04-26 19:04:20 +02:00
Mike McQuaid
ea2892f8ee
brew.rb: handle missing args. 2024-03-07 16:20:20 +00:00
Bo Anderson
b42256d286
Deprecate, disable & delete code for Homebrew 4.2.0 2023-12-07 23:42:13 +00:00
Rylan Polster
8704e79cc0
Separate MacOS references 2023-11-15 18:19:39 -05:00
Carlo Cabrera
cff8d8c155
Merge pull request #15571 from gerlero/relocate-relative-names
mac/keg_relocate: use relative install names
2023-07-11 04:38:26 +08:00
Gabriel Gerlero
15a0c7fd7d linkage_checker: resolve some variable install names on macOS 2023-07-06 14:15:14 -03:00
Mike McQuaid
7da934f7e2
Deprecate/disable/delete code.
The next release after this is merged will be 4.1.0.

Co-authored-by: Markus Reiter <me@reitermark.us>
2023-07-06 16:56:20 +01:00
Douglas Eichelberger
24cf6076e8 brew style --fix 2023-04-24 20:42:39 -07:00
Carlo Cabrera
957c2c983c
linkage_checker: ignore broken linkage with LLVM libc++.
This linkage will be broken in LLVM 15, but this is typically harmless
since dyld will load `/usr/lib/libc++.1.dylib` instead.
2022-09-19 12:37:32 +08:00
Bo Anderson
0593597a11
linkage_checker: don't reinstall formula on some linkage failures 2022-08-23 09:38:52 +01:00
Carlo Cabrera
e61bcb45f7
linkage_checker: report linkage with system frameworks
Currently, `brew linkage` reports linkage with system frameworks only if
they can be found on the file system. This results in this linkage not
being reported on Big Sur and newer, where system libraries are stored
in the dyld cache instead.

Let's fix that by avoiding silently ignoring system frameworks by moving
them out of `#harmless_broken_link?`. We retain the behaviour desired
from 7228e60da51392b20d55e0c087b2082b86fb3bbf by deferring checking if a
broken library is actually a system framework to just before we add it
to `@broken_dylibs`.

To see how this changes the behaviour of `brew linkage`, here's an
example with this change:

    ❯ brew linkage neovim
    System libraries:
      /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
      /usr/lib/libSystem.B.dylib
      /usr/lib/libiconv.2.dylib
      /usr/lib/libutil.dylib
    Homebrew libraries:
      /usr/local/opt/gettext/lib/libintl.8.dylib (gettext)
      /usr/local/opt/libtermkey/lib/libtermkey.1.dylib (libtermkey)
      /usr/local/opt/libuv/lib/libuv.1.dylib (libuv)
      /usr/local/opt/luajit/lib/libluajit-5.1.2.dylib (luajit)
      /usr/local/opt/luv/lib/libluv.1.dylib (luv)
      /usr/local/opt/msgpack/lib/libmsgpackc.2.dylib (msgpack)
      /usr/local/opt/tree-sitter/lib/libtree-sitter.0.dylib (tree-sitter)
      /usr/local/opt/unibilium/lib/libunibilium.4.dylib (unibilium)

and without this change:

    ❯ brew linkage neovim
    System libraries:
      /usr/lib/libSystem.B.dylib
      /usr/lib/libiconv.2.dylib
      /usr/lib/libutil.dylib
    Homebrew libraries:
      /usr/local/opt/gettext/lib/libintl.8.dylib (gettext)
      /usr/local/opt/libtermkey/lib/libtermkey.1.dylib (libtermkey)
      /usr/local/opt/libuv/lib/libuv.1.dylib (libuv)
      /usr/local/opt/luajit/lib/libluajit-5.1.2.dylib (luajit)
      /usr/local/opt/luv/lib/libluv.1.dylib (luv)
      /usr/local/opt/msgpack/lib/libmsgpackc.2.dylib (msgpack)
      /usr/local/opt/tree-sitter/lib/libtree-sitter.0.dylib (tree-sitter)
      /usr/local/opt/unibilium/lib/libunibilium.4.dylib (unibilium)
2022-07-18 12:04:24 +08:00
Bo Anderson
5d28c5166b
linkage_checker: deprecate linkage to libcrypt.so.1 2022-04-18 16:42:08 +01:00
Carlo Cabrera
39923cdb7f
linkage_checker: restrict RPATH test to --strict
This test is causing some rebuilds due to failed linkage upon upgrade.
That's a problem because rebuilds won't fix the problem that the `RPATH`
check identifies.
2022-03-10 07:09:47 +08:00
Chris Araman
440adcbec0
linkage: expand check to dylibs and bundles 2022-02-11 21:22:40 -08: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
Carlo Cabrera
601bf83fee
linkage: add --strict flag to detect opportunistic linkage
There was a previous discussion about making `brew linkage --test` fail
for unrequested dependencies (#9172). I'm not sure what the outcome of
that was, but it still seems like a good idea to try to help us find
cases of opportunistic linkage as they happen rather than when they
cause CI failures in another PR sometime later.

Let's do this by adding a `--strict` flag to `brew linkage --test`. My
intention is for `brew linkage --test --strict` failures to be warnings
rather than errors in CI, which should mitigate some of the concerns
about doing this that were raised in #9172.
2021-11-19 18:14:38 +08:00
Carlo Cabrera
7bd5374dcc
Revert "linkage_checker: check variable references with dlopen"
Trying to `dlopen` some Qt libraries causes Ruby to crash.

This reverts commit 0191a275ccc3e1a9377c956751bbc1c4ba7b0cea.
2021-11-16 01:32:42 +08:00
Carlo Cabrera
0191a275cc
linkage_checker: check variable references with dlopen
The linkage check currently does nothing to check the validity of
variable-referenced libraries (prefixed with an `@`).

We could rectify that by mimicking the dynamic linker in looking up the
variable-referenced library, but this could get quite complicated.
Instead, let's let the linker do the hard work by checking if we can
`dlopen` libraries and bundles that contain variable linkage. The
`dlopen` will fail if the linker cannot resolve the variable reference.

There are at least two disadvantages to this approach relative to the
alternative suggested above:
1. This doesn't work for binary executables.
2. This doesn't identify which variable references are broken.

It's still better than not checking them at all, which is what we do
currently, and saves us from having to carry around code that parses and
verifies variable references directly.
2021-11-15 02:24:16 +08:00
Seeker
b9854bd4cf rubocops: add unless_multiple_conditions 2021-01-08 10:33:54 -08:00
Mike McQuaid
9216d8abe6
rubocop-rails: make fixes. 2020-12-02 10:43:04 +00:00
Mike McQuaid
7228e60da5
linkage_checker: system framework links are harmless.
These do not seem to cause runtime errors.

Fixes #9338
2020-11-30 16:00:42 +00:00
Mike McQuaid
7c56fa9caf
linkage: correctly detect missing kegs.
- manually `raise Errno::ENOENT` to ensure that a keg that doesn't exist
  isn't flagged as a system dependency.
- remove the inconsistent and incorrect summary messaging.
2020-11-27 13:12:09 +00:00
Markus Reiter
0184e271d8 Fix RuboCop offenses. 2020-11-17 11:09:55 +01:00
Markus Reiter
da9289eff0 Add more type signatures. 2020-11-13 12:26:36 +01:00
EricFromCanada
3768b7a6e9 apidoc: update comment wording, punctuation, formatting 2020-11-06 00:21:02 -05:00
Markus Reiter
24ae318a3d Move type annotations into files. 2020-10-10 14:59:39 +02:00
Markus Reiter
3a04377b51 Document LinkageChecker. 2020-08-26 03:13:59 +02:00
Maxim Belkin
4f119ad85f
linkage_checker.rb: Use ||= instead of "return ... if ... "
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2020-07-23 08:40:45 -05:00
Maxim Belkin
2918f92b89
linkage_checker.rb: fix indentation in display_items
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2020-07-23 08:38:42 -05:00
Maxim Belkin
590f77b111 Unexpected linkage 2020-07-22 17:25:16 +00:00
Maxim Belkin
42f90dba46 linkage_checker.rb: rename lib to broken_lib 2020-07-22 14:41:15 +00:00
Maxim Belkin
77a38aed0d linkage_checker.rb: meld allowed_missing_lib? into unexpected_broken_dylibs 2020-07-22 14:39:29 +00:00
Maxim Belkin
1b8c32c716 Move allowed_missing_libs? to linkage_checker.rb.
Optimize 'unexpected_broken_dylibs'
2020-07-22 14:30:52 +00:00
Maxim Belkin
28227bd26b linkage_checker.rb: replace conditional assignment with an if-else 2020-07-21 14:11:00 +00:00
Maxim Belkin
c61aba4ec3 Formula: ignore_missing_libraries DSL 2020-07-16 13:51:16 +00:00
Maxim Belkin
e7b3b8e559 Allow missing libraries 2020-07-16 13:51:16 +00:00
Mike McQuaid
f951ea83d4
Fix brew style. 2020-07-07 12:23:29 +01:00
Bo Anderson
9c4aaa9719 linkage_checker: handle system libraries on Big Sur 2020-06-24 16:27:57 +01:00
Mike McQuaid
dfa22680df
Autofix rubocop checks. 2020-02-19 11:24:12 +00:00
Mike McQuaid
36dbad3922
Add frozen_string_literal to all files. 2019-04-20 13:27:36 +09:00
Mike McQuaid
fe6b78a3f3
Use cache_store for descriptions
This makes use of both the existing interfaces and could use the
existing cache file but we'll create a new one and cleanup the old one
to avoid issues and use a more consistent name.
2018-10-13 08:22:52 -07:00