Skip to content

Commit f01fb86

Browse files
committed
cask: tolerate asymmetric variations in to_hash_with_variations
When a cask uses on_system blocks that legitimately omit some arches on a given OS (e.g. on_linux with only x86_64_linux sha256 plus depends_on arch: :x86_64), `refresh` under `SimulateSystem.with_tag` raises CaskInvalidError for the unsupported combos. Rescue these so the variations iteration produces the supported subset instead of aborting the entire call chain. Fixes generate-cask-ci-matrix failures on cask PRs with intentional arch asymmetry (e.g. devin-cli).
1 parent 5d7251a commit f01fb86

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

Library/Homebrew/cask/cask.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -592,16 +592,20 @@ def to_hash_with_variations
592592
!dsl!.depends_on_set_in_block? &&
593593
macos_requirements.any? { |requirement| !requirement.allows?(bottle_tag.to_macos_version) }
594594

595-
Homebrew::SimulateSystem.with_tag(bottle_tag) do
596-
refresh
595+
begin
596+
Homebrew::SimulateSystem.with_tag(bottle_tag) do
597+
refresh
597598

598-
to_h.each do |key, value|
599-
next if HASH_KEYS_TO_SKIP.include? key
600-
next if value.to_s == hash[key].to_s
599+
to_h.each do |key, value|
600+
next if HASH_KEYS_TO_SKIP.include? key
601+
next if value.to_s == hash[key].to_s
601602

602-
variations[bottle_tag.to_sym] ||= {}
603-
variations[bottle_tag.to_sym][key] = value
603+
variations[bottle_tag.to_sym] ||= {}
604+
variations[bottle_tag.to_sym][key] = value
605+
end
604606
end
607+
rescue CaskInvalidError, CaskUnreadableError
608+
# Skip OS/arch combinations the cask intentionally doesn't define.
605609
end
606610
end
607611
ensure

Library/Homebrew/test/cask/cask_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,14 @@ def write_auto_updates_cask(path, version:, artifacts:, token: "auto-updates-bun
744744
expect(JSON.pretty_generate(h["variations"])).to eq expected_sha256_variations_os.strip
745745
end
746746

747+
it "omits tags a cask intentionally doesn't define in on_system blocks" do
748+
c = Cask::CaskLoader.load("on-linux-asymmetric")
749+
h = c.to_hash_with_variations
750+
751+
expect(h["variations"]).to include(:x86_64_linux)
752+
expect(h["variations"]).not_to include(:arm64_linux)
753+
end
754+
747755
# NOTE: The calls to `Cask.generating_hash!` and `Cask.generated_hash!`
748756
# are not idempotent so they can only be used in one test.
749757
it "returns the correct hash placeholders" do
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# typed: false
2+
3+
cask "on-linux-asymmetric" do
4+
arch arm: "arm", intel: "intel"
5+
os macos: "darwin", linux: "linux"
6+
7+
version "1.2.3"
8+
9+
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine-#{arch}-#{os}.zip"
10+
homepage "https://brew.sh/"
11+
12+
on_macos do
13+
sha256 arm: "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94",
14+
intel: "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
15+
end
16+
17+
on_linux do
18+
sha256 x86_64_linux: "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
19+
20+
depends_on arch: :x86_64
21+
end
22+
23+
app "Caffeine.app"
24+
end

0 commit comments

Comments
 (0)