Re-add on_arch_conditional DSL

This commit is contained in:
Rylan Polster 2022-08-09 11:34:52 -04:00
parent dd72f1ac95
commit 76ae20a12f
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
8 changed files with 20 additions and 52 deletions

View File

@ -250,14 +250,7 @@ module Cask
set_unique_stanza(:arch, should_return) do
@on_system_blocks_exist = true
# If arm and intel are arrays and one isn't specified, default to an array that is the same size as the other
empty_value = Array.new(arm&.count || intel&.count) if arm.is_a?(Array) || intel.is_a?(Array)
if OnSystem.arch_condition_met? :arm
arm || empty_value
elsif OnSystem.arch_condition_met? :intel
intel || empty_value
end
on_arch_conditional(arm: arm, intel: intel)
end
end

View File

@ -65,6 +65,13 @@ module OnSystem
result
end
end
base.define_method(:on_arch_conditional) do |arm:, intel:|
@on_system_blocks_exist = true
return arm if OnSystem.arch_condition_met? :arm
return intel if OnSystem.arch_condition_met? :intel
end
end
sig { params(base: Class).void }

View File

@ -218,25 +218,25 @@ describe Cask::Cask, :cask do
<<~JSON
{
"arm64_big_sur": {
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.0/arm.zip",
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/darwin-arm64/1.2.0/arm.zip",
"version": "1.2.0",
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
},
"monterey": {
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.3/intel.zip"
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/darwin/1.2.3/intel.zip"
},
"big_sur": {
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.0/intel.zip",
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/darwin/1.2.3/intel.zip",
"version": "1.2.0",
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
},
"catalina": {
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.0.0/intel.zip",
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/darwin/1.2.3/intel.zip",
"version": "1.0.0",
"sha256": "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216"
},
"mojave": {
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.0.0/intel.zip",
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/darwin/1.2.3/intel.zip",
"version": "1.0.0",
"sha256": "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216"
}

View File

@ -160,7 +160,7 @@ describe Cask::Cmd::List, :cask do
],
"desc": null,
"homepage": "https://brew.sh/",
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.3/arm.zip",
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/darwin-arm64/1.2.3/arm.zip",
"appcast": null,
"version": "1.2.3",
"versions": {

View File

@ -312,8 +312,8 @@ describe Cask::DSL, :cask do
expect { cask }.to raise_error(Cask::CaskInvalidError, /'arch' stanza may only appear once/)
end
context "when only one string value is passed for intel" do
let(:token) { "one-string-arch" }
context "when no intel value is specified" do
let(:token) { "arch-arm-only" }
context "when running on arm" do
before do
@ -335,30 +335,6 @@ describe Cask::DSL, :cask do
end
end
end
context "when only one array arch value is passed for intel" do
let(:token) { "one-array-arch" }
context "when running on arm" do
before do
allow(Hardware::CPU).to receive(:type).and_return(:arm)
end
it "defaults to an array of the same size as the other when an array is passed" do
expect(cask.url.to_s).to eq "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
end
end
context "when running on intel" do
before do
allow(Hardware::CPU).to receive(:type).and_return(:intel)
end
it "returns the value" do
expect(cask.url.to_s).to eq "file://#{TEST_FIXTURE_DIR}/cask/intel-caffeine-x86_64.zip"
end
end
end
end
describe "appcast stanza" do

View File

@ -1,4 +1,4 @@
cask "one-string-arch" do
cask "arch-arm-only" do
version "1.2.3"
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
arch arm: "-arm"

View File

@ -3,6 +3,8 @@ cask "multiple-versions" do
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
arch arm: "arm", intel: "intel"
platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
on_big_sur do
version "1.2.0"
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
@ -13,7 +15,7 @@ cask "multiple-versions" do
sha256 "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216"
end
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine/#{version}/#{arch}.zip"
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine/#{platform}/#{version}/#{arch}.zip"
homepage "https://brew.sh/"
app "Caffeine.app"

View File

@ -1,10 +0,0 @@
cask "one-array-arch" do
version "1.2.3"
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
arch intel: ["intel-", "-x86_64"]
url "file://#{TEST_FIXTURE_DIR}/cask/#{arch.first}caffeine#{arch.last}.zip"
homepage "https://brew.sh/"
app "Caffeine.app"
end