OnSystem: Add UsesOnSystem class #19721
Draft
+84
−38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?This adds a
UsesOnSystem
class toOnSystem
, 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 anil
check inFormula
, as theself.class
instance variable has to use a nilable type).The
UsesOnSystem
instance variables cover the currentARCH_OPTIONS
andBASE_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?
. Thelinux
boolean will betrue
if the the cask has anon_linux
block, anon_system
block (which requires Linux), or usesos linux: ...
. This is something that would be challenging to determine from outside ofOnSystem
but it's relatively easy to collect the information inOnSystem
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 runningbrew typecheck --update
and committing the RBI change (it suddenly occurred to me while I was doing something completely unrelated 😆).