cmd/fetch & cmd/audit: handle unsupported os/arch combos

It's possible for casks to only run on certain os/arch
combinations but we don't check for them in the fetch and
audit commands.

At first, I tried to check if the macos version was satisfied
in a previous PR but that doesn't work correctly because
MacOSRequirement and ArchRequirement don't respect SimulateSystem.

Instead I'm just checking to see if the url stanza is defined
for each os/arch combination and skipping those casks where
it ends up being nil. This is kind of brute forcing it but
should work.
This commit is contained in:
apainintheneck 2023-09-04 14:46:05 -07:00
parent 27902f0284
commit f4b15e95ac
2 changed files with 10 additions and 3 deletions

View File

@ -166,8 +166,8 @@ module Homebrew
SimulateSystem.with os: os, arch: arch do SimulateSystem.with os: os, arch: arch do
cask = Cask::CaskLoader.load(ref) cask = Cask::CaskLoader.load(ref)
if cask.depends_on.macos&.satisfied? == false if cask.url.nil?
opoo "#{cask.token}: #{cask.depends_on.macos.message(type: :cask)}" opoo "Cask #{cask} is not supported on os #{os} and arch #{arch}"
next next
end end

View File

@ -242,10 +242,17 @@ module Homebrew
next [] if os == :linux next [] if os == :linux
SimulateSystem.with os: os, arch: arch do SimulateSystem.with os: os, arch: arch do
simulated_cask = Cask::CaskLoader.load(path)
if simulated_cask.url.nil?
opoo "Cask #{cask} is not supported on os #{os} and arch #{arch}"
next []
end
odebug "Auditing Cask #{cask} on os #{os} and arch #{arch}" odebug "Auditing Cask #{cask} on os #{os} and arch #{arch}"
Cask::Auditor.audit( Cask::Auditor.audit(
Cask::CaskLoader.load(path), simulated_cask,
# For switches, we add `|| nil` so that `nil` will be passed # For switches, we add `|| nil` so that `nil` will be passed
# instead of `false` if they aren't set. # instead of `false` if they aren't set.
# This way, we can distinguish between "not set" and "set to false". # This way, we can distinguish between "not set" and "set to false".