31 Commits

Author SHA1 Message Date
Sam Ford
473f448b22
OnSystem: handle non-macOS current_os values
The `OnSystem.os_condition_met?` method only handles Linux and macOS
values for the current OS, so this fails when testing with a generic
OS. This shortcoming is only being surfaced now because there weren't
any tests for `OnSystem` before.

This addresses the issue by accounting for macOS values (`:macos` or
a symbol from `MacOSVersion::SYMBOLS`) and returning `false` for any
other values (`:linux`, `:generic`, etc.).
2025-06-08 10:13:40 -04:00
Sam Ford
01825acabd
UsesOnSystem: Collect macOS requirements
When determining macOS requirements for a cask, we may need to
reference requirements from related on_system blocks (e.g.,
`on_monterey :or_older`, `on_ventura`, `on_sonoma :or_newer`) when
`depends_on macos` isn't adequate.

Sometimes casks specify different `depends_on macos` values in macOS
on_system blocks but that value is only set when the cask is loaded
in an environment that satisfies the on_system block's requirements.
There are other casks that contain macOS on_system blocks and use
`depends_on macos` outside of the on_system blocks but it may only
use the macOS version of the lowest on_system block (e.g.,
`>= :monterey`), which isn't sufficient if the cask's values vary
based on macOS version.

To be able to simulate macOS versions that meet the requirements of
all the on_system blocks in a cask, we need to collect the macOS
requirements in a way that doesn't require OS simulation. This is also
something that's easy to do in on_system methods, so this adds a
`macos_requirements` array to `UsesOnSystem`, containing
`MacOSRequirement` objects created from the cask's macOS on_system
block conditions.
2025-06-08 00:57:22 -04:00
Sam Ford
3df8f70511
OnSystem: Add UsesOnSystem class
This adds a `UsesOnSystem` class to `OnSystem`, containing boolean
instance variables to indicate which types of on_system methods are
used in a formula or cask. This is intended as a replacement for
`@on_system_blocks_exist`, which doesn't allow us to determine what
kinds of on_system calls were used. This provides more granularity
but we can still use `@uses_on_system.present?` to determine whether
any on_system calls were used (and this doubles as a `nil` check in
`Formula`, as the `self.class` instance variable has to use a nilable
type).

The `UsesOnSystem` instance variables cover the current
`ARCH_OPTIONS` and `BASE_OS_OPTIONS`. At the moment, we mostly need
to tell whether there are macOS/Linux or Intel/ARM on_system calls,
so I've omitted instance variables for specific macOS version until
we have a need for them.

As a practical example, if you wanted to determine whether a cask
uses Linux on_system calls, you can call
`cask.uses_on_system.linux?`. The `linux` boolean will be `true` if
the cask has an `on_linux` block, an `on_system` block (which requires
Linux), or uses `os linux: ...`. This is something that would be
challenging to determine from outside of `OnSystem` but it's
relatively easy to collect the information in `OnSystem` methods and
make it available like this.
2025-06-07 17:58:12 -04:00
Sam Ford
2d603b0c26
OnSystem: enable strict typing 2025-06-06 15:09:35 -04:00
Rylan Polster
c03f70f1dc
Refactor OnSystem and SimulateSystem bottle tag handling 2025-06-03 11:57:17 -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
Eric Knibbe
3f73f32286
cask/audit: handle on_os range bounded by depends_on 2024-07-01 23:11:26 -04:00
Eric Knibbe
f627c6331d
cask/audit: support on_os blocks in audit_min_os 2024-06-21 19:25:51 -04:00
Patrick Linnane
9dee80cb2d
various: fix style errors 2023-12-18 09:34:01 -08:00
Bo Anderson
5692c8ecbf
Fix style violations under newer RuboCop 2023-12-14 05:47:12 +00:00
apainintheneck
5760ae4fb2 cmd/readall: Cleanup todos
- keep running the command against all os/arch combinations
  as the default
- remove todos and deprecations related to changing the behavior
- create constants for os/arch combinations
2023-09-19 21:33:13 -07:00
Markus Reiter
8274920217
Rename OS::Mac::Version to MacOSVersion. 2023-05-09 05:08:38 +02:00
Douglas Eichelberger
24cf6076e8 brew style --fix 2023-04-24 20:42:39 -07:00
Carlo Cabrera
a4ebb96fe6
Remove MacOS definition from generic OS
We don't want to define `MacOS` in the generic OS, so let's make sure we
refer to it as `OS::Mac` in the places we need it.

This reverts commit 575cb0263cb1428c63b9428bbd913ffde83bd317.
2023-04-04 23:10:51 +08:00
Douglas Eichelberger
92b99b3132 Remove misleading upstream.rbi, enable types in on_system 2023-03-19 19:41:46 -07:00
Dawid Dziurla
0d0c98de29
Allow defining service run command per platform 2023-01-19 11:36:37 +01:00
Rylan Polster
43bbe2bcfc
Fix nil handling in arch cask DSL 2022-08-10 17:15:37 -04:00
Rylan Polster
76ae20a12f
Re-add on_arch_conditional DSL 2022-08-09 11:34:52 -04:00
Rylan Polster
7326019c93
Add clarification comment 2022-08-03 01:32:37 -04:00
Rylan Polster
58be76bc9d
Fix on_{system} handling of generic macOS versions 2022-07-31 20:44:51 -04:00
Rylan Polster
ea1f2098ac
Move HOMEBREW_SIMULATE_MACOS_ON_LINUX handling to SimulateSystem 2022-07-28 15:04:25 -04:00
Rylan Polster
4cc0e854ce
Rename treat_as_*? to simulating_or_running_on_*? 2022-07-28 09:18:16 -04:00
Rylan Polster
fa384b03fa
Simplify SimulateSystem usage 2022-07-23 03:08:56 +02:00
Rylan Polster
5e5c78ebef
Fix tests and improve style 2022-07-11 04:03:37 -04:00
Rylan Polster
57417dd016
Add on_system :linux, macos: wrapper to OnSystem 2022-07-11 02:19:24 -04:00
Rylan Polster
39453f87ef
Fix on_{macos_version} blocks on Linux 2022-07-05 19:05:42 -04:00
Rylan Polster
99447bb1c0
OnSystem: provide ::MacOSAndLinux and ::MacOSOnly 2022-06-30 12:57:35 -04:00
Rylan Polster
a9e62b9e38
include OnSystem to define DSL methods 2022-06-29 11:38:55 -04:00
Rylan Polster
ac067eedb2
Create MacOSVersions module 2022-06-29 11:34:49 -04:00
Rylan Polster
5ec19adf58
Rename Override module to SimulateSystem 2022-06-28 15:35:20 -04:00
Rylan Polster
b538ce7361
Add OnSystem module to generate on_* methods for formulae and casks 2022-06-24 14:37:50 -04:00