Skip to content
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

cask: skip variations for inapplicable versions #17386

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Library/Homebrew/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ def to_hash_with_variations(hash_method: :to_h)
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
EricFromCanada marked this conversation as resolved.
Show resolved Hide resolved
refresh
Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/macos_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def pretty_name
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
Expand Down
13 changes: 13 additions & 0 deletions Library/Homebrew/requirements/macos_requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ def version_specified?
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?

Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/test/macos_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
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
Expand Down
13 changes: 13 additions & 0 deletions Library/Homebrew/test/requirements/macos_requirement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
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?
Expand All @@ -20,4 +22,15 @@
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
Loading