Skip to content

OnSystem: Add UsesOnSystem class #19721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

samford
Copy link
Member

@samford samford commented Apr 7, 2025

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

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 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.


I've set this as a draft for now, so we can discuss whether this is the right approach (I will add tests, documentation comments, etc. once that's settled). There may be room for improvement here but this works how I intended, at least.

Edit: I resolved the Method uses_on_system does not exist on Cask::Cask error by running brew typecheck --update and committing the RBI change (it suddenly occurred to me while I was doing something completely unrelated 😆).

@samford samford force-pushed the on_system-add-uses_on_system-class branch 2 times, most recently from 59e913c to e9b1180 Compare April 7, 2025 23:26
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, a much improved API, nice work @samford!

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 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.
@samford samford force-pushed the on_system-add-uses_on_system-class branch from e9b1180 to f0b7523 Compare April 8, 2025 14:26
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale No recent activity label Apr 30, 2025
@samford samford added in progress Maintainers are working on this and removed stale No recent activity in progress Maintainers are working on this labels Apr 30, 2025
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale No recent activity label May 21, 2025
@samford samford removed the stale No recent activity label May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants