121 Commits

Author SHA1 Message Date
Douglas Eichelberger
5b5cfe89de Resolve violations from removing hidden.rbi 2024-02-11 20:27:38 -08:00
Michael Cho
53accccfb2
formula_cellar_checks: detect cpuid in static libs 2023-12-21 12:08:18 -05:00
Mike McQuaid
1d4a24d226
Make more warnings quiet with environment hints disabled.
Combined with https://github.com/Homebrew/homebrew-test-bot/pull/963
this should make `brew test-bot` output a bit quieter and less annoying.
2023-08-04 09:36:27 +01:00
apainintheneck
1111706378 service: add custom service name DSL
The main thing is that this DSL allows us to provide an
interface that can be serialized to the JSON API.

Changes:
- Homebrew::Service
  - Adds `#service_name` and `#plist_name` methods
    - Each is now included in the `#serialize` method as well
  - Eval block on instantiation
    - Before we lazy evaluated this but the cost is not significant
      and it complicated the code a bunch. This only gets called
      during install, when evaluating caveats and in the `brew service`
      command. It skips this evaluation if the service block isn't there.
  - Add `#command?` helper to avoid `#command.blank?` and `#command.present?`
- Formula
  - `#service` now returns a service whenever it's called. This call is
    hidden behind a call to `#service?` most of the time anyway so this
    should be fine.
  - `#plist_name` and `#service_name` now call the methods of the same name
    on the service class. This should have already been in the service object
    to begin with and keeping these methods here helps preserve backwards
    compatibility with people who were overwriting these methods before.
- Caveats
  - Prefer `service#command?`
  - Add helpers for checking on service commands
    - This duplicates some of the work in `brew services`. Maybe we should
      merge that repo in at some point.
  - Check for installed service at `#plist_name` or `#service_name`. I think
    this should be used instead of `Keg#plist_installed?` which checked for any plist file.
    We should think about deprecating `#plist_installed?` in the future.
  - Stop using `ps aux | grep #{formula.plist_name}` to check for service files
    because it was inaccurate (it always returns true on my machine) because the grep
    process is started before the ps process.
  - Note: The behavior is the same as it was before. This means that caveats
    only show up for custom service files on install or if they're already installed.
    Otherwise it won't show up in `brew info`. This is because it has to check
    first if the service file has been installed.
- Utils::Service
  - Add utils for evaluating if a service is installed and running. This duplicates
    some of the work already found in `brew services`. We should seriously consider
    merging `brew services` with the main brew repo in the future since it's already
    tightly coupled to the code in the main repo.
- Formulary.load_formula_from_api
  - Be more explicit about which types can be deserialized into run params since
    it is now possible for run params to be nil.
- Update and add tests
2023-05-13 14:53:01 -07: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
7720485f40 Enable types in Formula files 2023-03-25 08:50:06 -07:00
Bo Anderson
5ecf76a611
Harden plist parsing 2023-02-22 22:52:06 +00:00
hyuraku
9241def1a2 reset formula_cellar_checks 2023-01-26 21:41:01 +09:00
hyuraku
f1eacb04f0 move check_binary_arches to extend/os 2023-01-25 22:26:49 +09:00
Dawid Dziurla
0d0c98de29
Allow defining service run command per platform 2023-01-19 11:36:37 +01:00
apainintheneck
c477b9aab3 Cleanup after adding os specific rubocop
- Change name of rubocop warning
- Disable linting on remaining offending lines
- Add todos to move lines with disabled linting
  checks to extend/os in the future
2022-11-29 23:13:50 -08:00
Mike McQuaid
36d14ae49c
Merge pull request #13366 from hyuraku/repair-check_cpuid_instruction
move check ENV.runtime_cpu_detection to `utils/ast`
2022-06-28 09:59:41 +01:00
Bo Anderson
02164a35db
Use ORIGINAL_PATHS over envs; reject nil PATH 2022-06-17 19:47:57 +01:00
hyuraku
7a95219d2b remove new method and reset without TODO 2022-06-14 21:33:17 +09:00
hyuraku
f2fe1b59a1 move check ENV.runtime_cpu_detection to utils/ast 2022-06-14 21:33:17 +09:00
EricFromCanada
774537d3c2
formula_installer: handle unexpected .brew presence/absence 2022-04-13 10:53:57 -04:00
Rylan Polster
c0e8569c93
Fix mismatch_binary_allowlist check 2021-10-21 21:22:18 -04:00
Rylan Polster
fa4bb7d74a
Refactor audit exception handling 2021-10-21 21:11:05 -04:00
Carlo Cabrera
72f7ab8bfc
formula_cellar_checks: fix alignment when listing files
The extra spacing came from before we used squiggly heredocs. Now that
we do, they're no longer necessary, and produce misaligned output.
2021-10-10 14:16:10 +08:00
Carlo Cabrera
1f3de1d5b2
Merge pull request #12092 from carlocab/binary-arch-edge-case
formula_cellar_checks: fix edge case handling in `check_binary_arches`
2021-09-21 16:43:57 +08:00
Rylan Polster
e8e1deeb32
Cleanup code and remove unneeded methods 2021-09-21 00:43:30 -04:00
Carlo Cabrera
c7badb1e54
formula_cellar_checks: fix edge case handling in check_binary_arches
Currently, if formula `foo` ships both universal and non-native
binaries and `foo` is on both allowlists, then `brew audit --strict`
errors out with an empty error message:

    ❯ brew audit --strict foo
    foo:
      *
    Error: 1 problem in 1 formula detected

Let's fix this (admittedly obscure) corner case by returning early when
a formula is present on both allowlists.
2021-09-21 01:02:29 +08:00
Rylan Polster
50fac1737a
install: fix HEAD installations with HOMEBREW_INSTALL_FROM_API 2021-09-17 23:46:28 -04:00
Akihiro Suda
f63c3b08fe
New allow list: mismatched_binary_allowlist
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-08-11 18:09:26 +09:00
Carlo Cabrera
8e6731b7c7
formula_cellar_checks: show mismatched arch in check_binary_arches
This will make the error more informative by showing the architecture a
binary was built for along with the error message.

Before:

    foo:
      * Binaries built for an incompatible architecture were installed into foo's prefix.
        The offending files are:
          /usr/local/Cellar/foo/1.0/lib/libbar.dylib
          /usr/local/Cellar/foo/1.0/lib/libfoo.dylib
          /usr/local/Cellar/foo/1.0/lib/libincompatible.dylib
        Unexpected universal binaries were found.
        The offending files are:
          /usr/local/Cellar/foo/1.0/lib/liball.dylib
          /usr/local/Cellar/foo/1.0/lib/libuniversal.dylib

After:

    foo:
      * Binaries built for a non-native architecture were installed into foo's prefix.
        The offending files are:
          /usr/local/Cellar/foo/1.0/lib/libbar.dylib        (i386)
          /usr/local/Cellar/foo/1.0/lib/libfoo.dylib        (arm64)
          /usr/local/Cellar/foo/1.0/lib/libincompatible.dylib       (universal)
        Unexpected universal binaries were found.
        The offending files are:
          /usr/local/Cellar/foo/1.0/lib/liball.dylib
          /usr/local/Cellar/foo/1.0/lib/libuniversal.dylib
2021-07-23 11:40:01 +08:00
Carlo Cabrera
a29098c813
Use #partition to simplify extracting compatible_universal_binaries 2021-07-21 12:05:54 +08:00
Carlo Cabrera
699051b3c3
Use #present? instead of #any? 2021-07-20 18:53:53 +08:00
Carlo Cabrera
663aee0a67
Fix style
The linter complained about useless assignment to
`universal_binaries_expected`. It wasn't useless, but ok.
2021-07-20 18:48:40 +08:00
Carlo Cabrera
239fd06728
Enforce universal binary check only for Homebrew/core
Also, prefer `if` to `unless`.
2021-07-20 18:40:19 +08:00
Carlo Cabrera
55cc1eb8b0
Check tap_audit_exception only if tap is present 2021-07-20 13:08:15 +08:00
Carlo Cabrera
1678a3785e
Fix logic in check_binary_arches 2021-07-20 12:35:09 +08:00
Carlo Cabrera
7b74730f9d
formula_cellar_checks: fix universal binary handling
The `check_binary_arches` audit will fail any formula that produces
universal binaries. We have a handful of formulae in Homebrew/core that
do this (see any formula that does `ENV.permit_arch_flags`, for
example). Moreover, some third party taps may have their own formulae
that build universal binaries.

I've updated the check so that it ignores a formula that produces
universal binaries whenever the formula is in the appropriate allowlist.
We'll need to create one in Homebrew/core for the handful of formulae
that do (expectedly) build universal binaries.

If we don't want to maintain an allowlist, we can easily modify this to
pass over any formulae that builds compatible universal binaries.

I've also fixed the spacing of the error this audit produces whenever
there is more than one file that fails the audit.
2021-07-20 12:15:59 +08:00
Carlo Cabrera
d696250ddb
Fix ELF architecture offset for x86_64
The current offset results in ELF binaries returning an `#arch` of
`:dunno`.

Also, skip the `check_binary_arches` audit on the generic OS.
2021-07-18 16:55:57 +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
Carlo Cabrera
16e56907b5
formula_cellar_checks: fix cpuid instruction check on Mojave
The output format of `objdump` on Mojave is different from newer
versions of macOS, so I've adjusted the relevant audit to account for
this difference.
2021-07-08 04:26:34 +01:00
Carlo Cabrera
5ed4430daf
Apply suggestions from code review
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2021-07-05 10:12:34 -07:00
Carlo Cabrera
63aa192088
Incorporate suggestions from feedback
1. Never install `binutils`. Instead, report an audit failure.
2. Tighten instruction check with a stricter matching strategy.
2021-07-05 17:47:20 +01:00
Carlo Cabrera
c59a42b24e
formula_cellar_checks: check for cpuid instruction when needed
This implements the second audit discussed in #11608.
2021-07-04 00:31:31 +01:00
Sean Molenaar
2ec4125178
Audit: make sure service commands exist 2021-04-27 09:36:36 +02:00
Mike McQuaid
6109f00d64
Revert "audit: check for installed empty files" 2021-03-30 14:14:24 +01:00
Kenneth Chew
5adf8cbe7b
audit: add additional (in)valid empty files, refactor empty file check 2021-03-25 16:56:26 -04:00
Kenneth Chew
844e865363
audit: check for installed empty files
Empty files sometimes indicate that problems occurred during building or installation.
2021-03-14 17:59:09 -04:00
EricFromCanada
6fc116318e fixes for grammar and wording 2021-01-26 16:19:47 -05:00
EricFromCanada
2ed324ebc0 use backticks around suggested input, flags, and binaries 2021-01-26 16:19:47 -05:00
Mike McQuaid
0bbf965807
More bottling HOMEBREW_LIBRARY changes
- Refuse to create bottles which have non-relocatable references to
  `HOMEBREW_LIBRARY`. This allows us to make all bottles ignore where
  `HOMEBREW_REPOSITORY` is (even those that aren't `cellar :any`).
  I cannot see any circumstances in which any bottle should link to
  anything within `HOMEBREW_REPOSITORY`.
- Remove audit that becomes unnecessary given the above change.
- Relocate references to `@HOMEBREW_LIBRARY@` but don't actually write
  any references yet. This will allow us to move to using
  `@HOMEBREW_LIBRARY` and remove all relocation of `HOMEBREW_REPOSITORY`
  in a future release (2.7.1, most likely).
2020-12-18 13:50:10 +00:00
Shaun Jackman
c56681a227 Comment needed changes if HOMEBREW_LIBRARY changes 2020-12-16 14:03:10 -08:00
Shaun Jackman
7fb1620c58 Enable check_repository_references conditionally
Enable check_repository_references when HOMEBREW_PREFIX == HOMEBREW_REPOSITORY.

Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2020-12-15 12:47:08 -08:00
Shaun Jackman
7b408dffc9 audit: Add check_repository_references
Ensure that any references to HOMEBREW_REPOSITORY
are within HOMEBREW_LIBRARY.
2020-12-15 12:47:08 -08:00
Rylan Polster
6e82f77108 audit: allow python symlinks based on keg-only status 2020-10-20 12:46:23 -04:00