mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Add arch
cask DSL
This commit is contained in:
parent
336335abe5
commit
dd72f1ac95
@ -243,6 +243,24 @@ module Cask
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @api public
|
||||||
|
def arch(arm: nil, intel: nil)
|
||||||
|
should_return = arm.blank? && intel.blank?
|
||||||
|
|
||||||
|
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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# `depends_on` uses a load method so that multiple stanzas can be merged.
|
# `depends_on` uses a load method so that multiple stanzas can be merged.
|
||||||
# @api public
|
# @api public
|
||||||
def depends_on(*args)
|
def depends_on(*args)
|
||||||
|
@ -143,7 +143,8 @@ class Livecheck
|
|||||||
end
|
end
|
||||||
|
|
||||||
delegate version: :@package_or_resource
|
delegate version: :@package_or_resource
|
||||||
private :version
|
delegate arch: :@package_or_resource
|
||||||
|
private :version, :arch
|
||||||
|
|
||||||
# Returns a `Hash` of all instance variable values.
|
# Returns a `Hash` of all instance variable values.
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
|
@ -6,7 +6,7 @@ module RuboCop
|
|||||||
# Constants available globally for use in all cask cops.
|
# Constants available globally for use in all cask cops.
|
||||||
module Constants
|
module Constants
|
||||||
STANZA_GROUPS = [
|
STANZA_GROUPS = [
|
||||||
[:version, :sha256],
|
[:version, :sha256, :arch],
|
||||||
[:language],
|
[:language],
|
||||||
[:url, :appcast, :name, :desc, :homepage],
|
[:url, :appcast, :name, :desc, :homepage],
|
||||||
[:livecheck],
|
[:livecheck],
|
||||||
|
@ -305,6 +305,62 @@ describe Cask::DSL, :cask do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "arch stanza" do
|
||||||
|
let(:token) { "invalid/invalid-two-arch" }
|
||||||
|
|
||||||
|
it "prevents defining multiple arches" 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 running on arm" do
|
||||||
|
before do
|
||||||
|
allow(Hardware::CPU).to receive(:type).and_return(:arm)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the value" do
|
||||||
|
expect(cask.url.to_s).to eq "file://#{TEST_FIXTURE_DIR}/cask/caffeine-arm.zip"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when running on intel" do
|
||||||
|
before do
|
||||||
|
allow(Hardware::CPU).to receive(:type).and_return(:intel)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "defaults to `nil` for the other when no arrays are passed" do
|
||||||
|
expect(cask.url.to_s).to eq "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
|
||||||
|
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
|
describe "appcast stanza" do
|
||||||
let(:token) { "with-appcast" }
|
let(:token) { "with-appcast" }
|
||||||
|
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
cask "invalid-two-arch" do
|
||||||
|
version "1.2.3"
|
||||||
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
|
arch arm: "arm", intel: "intel"
|
||||||
|
arch arm: "amd64", intel: "x86_64"
|
||||||
|
|
||||||
|
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
|
||||||
|
homepage "https://brew.sh/"
|
||||||
|
|
||||||
|
app "Caffeine.app"
|
||||||
|
end
|
@ -1,11 +1,7 @@
|
|||||||
cask "multiple-versions" do
|
cask "multiple-versions" do
|
||||||
arch = "arm"
|
|
||||||
version "1.2.3"
|
version "1.2.3"
|
||||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
|
arch arm: "arm", intel: "intel"
|
||||||
on_intel do
|
|
||||||
arch = "intel"
|
|
||||||
end
|
|
||||||
|
|
||||||
on_big_sur do
|
on_big_sur do
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
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
|
@ -0,0 +1,10 @@
|
|||||||
|
cask "one-string-arch" do
|
||||||
|
version "1.2.3"
|
||||||
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
|
arch arm: "-arm"
|
||||||
|
|
||||||
|
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine#{arch}.zip"
|
||||||
|
homepage "https://brew.sh/"
|
||||||
|
|
||||||
|
app "Caffeine.app"
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user