cask: skip variations for inapplicable versions

This commit is contained in:
Eric Knibbe 2024-06-03 12:33:00 -04:00
parent c0dd639c7f
commit 2d00e50071
No known key found for this signature in database
GPG Key ID: 179D9CDDDB814168
5 changed files with 36 additions and 0 deletions

View File

@ -440,6 +440,7 @@ module Cask
MacOSVersion::SYMBOLS.keys.product(OnSystem::ARCH_OPTIONS).each do |os, arch|
bottle_tag = ::Utils::Bottles::Tag.new(system: os, arch:)
next unless bottle_tag.valid_combination?
next if depends_on.macos && !depends_on.macos.allows?(bottle_tag.to_macos_version)
Homebrew::SimulateSystem.with(os:, arch:) do
refresh

View File

@ -100,6 +100,11 @@ class MacOSVersion < Version
pretty_name
end
sig { returns(String) }
def inspect
"#<#{self.class.name}: #{to_s.inspect}>"
end
sig { returns(T::Boolean) }
def outdated_release?
self < HOMEBREW_MACOS_OLDEST_SUPPORTED

View File

@ -61,6 +61,19 @@ class MacOSRequirement < Requirement
false
end
def allows?(other)
return true unless version_specified?
case @comparator
when ">=" then other >= @version
when "<=" then other <= @version
else
return @version.include?(other) if @version.respond_to?(:to_ary)
@version == other
end
end
def message(type: :formula)
return "macOS is required for this software." unless version_specified?

View File

@ -80,6 +80,10 @@ RSpec.describe MacOSVersion do
expect(described_class.new("10.14").pretty_name).to eq("Mojave")
end
specify "#inspect" do
expect(described_class.new("11").inspect).to eq("#<MacOSVersion: \"11\">")
end
specify "#requires_nehalem_cpu?", :needs_macos do
expect(Hardware::CPU).to receive(:type).at_least(:twice).and_return(:intel)
expect(described_class.new("10.14").requires_nehalem_cpu?).to be true

View File

@ -5,6 +5,8 @@ require "requirements/macos_requirement"
RSpec.describe MacOSRequirement do
subject(:requirement) { described_class.new }
let(:big_sur_major) { MacOSVersion.new("11.0") }
describe "#satisfied?" do
it "returns true on macOS" do
expect(requirement.satisfied?).to eq OS.mac?
@ -20,4 +22,15 @@ RSpec.describe MacOSRequirement do
expect(requirement.satisfied?).to eq MacOS.version <= :catalina
end
end
specify "#allows?" do
max_requirement = described_class.new([:mojave], comparator: "<=")
min_requirement = described_class.new([:catalina], comparator: ">=")
exact_requirement = described_class.new([:big_sur], comparator: "==")
range_requirement = described_class.new([[:monterey, :big_sur]], comparator: "==")
expect(max_requirement.allows?(big_sur_major)).to be false
expect(min_requirement.allows?(big_sur_major)).to be true
expect(exact_requirement.allows?(big_sur_major)).to be true
expect(range_requirement.allows?(big_sur_major)).to be true
end
end