Improvements
This commit is contained in:
parent
d4c4432f2d
commit
eab3d077bc
@ -252,21 +252,20 @@ module Cask
|
|||||||
if @dsl.on_system_blocks_exist?
|
if @dsl.on_system_blocks_exist?
|
||||||
[:arm, :intel].each do |arch|
|
[:arm, :intel].each do |arch|
|
||||||
MacOSVersions::SYMBOLS.each_key do |os_name|
|
MacOSVersions::SYMBOLS.each_key do |os_name|
|
||||||
# Big Sur is the first version of macOS that supports arm
|
bottle_tag = ::Utils::Bottles::Tag.new(system: os_name, arch: arch)
|
||||||
next if arch == :arm && MacOS::Version.from_symbol(os_name) < MacOS::Version.from_symbol(:big_sur)
|
next unless bottle_tag.valid_combination?
|
||||||
|
|
||||||
Homebrew::SimulateSystem.os = os_name
|
Homebrew::SimulateSystem.os = os_name
|
||||||
Homebrew::SimulateSystem.arch = arch
|
Homebrew::SimulateSystem.arch = arch
|
||||||
|
|
||||||
refresh
|
refresh
|
||||||
|
|
||||||
bottle_tag = ::Utils::Bottles::Tag.new(system: os_name, arch: arch).to_sym
|
|
||||||
to_hash.each do |key, value|
|
to_hash.each do |key, value|
|
||||||
next if hash_keys_to_skip.include? key
|
next if hash_keys_to_skip.include? key
|
||||||
next if value.to_s == hash[key].to_s
|
next if value.to_s == hash[key].to_s
|
||||||
|
|
||||||
variations[bottle_tag] ||= {}
|
variations[bottle_tag.to_sym] ||= {}
|
||||||
variations[bottle_tag][key] = value
|
variations[bottle_tag.to_sym][key] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2010,40 +2010,29 @@ class Formula
|
|||||||
hash = to_hash_without_variations
|
hash = to_hash_without_variations
|
||||||
variations = {}
|
variations = {}
|
||||||
|
|
||||||
hash_keys_to_skip = %w[installed linked_keg pinned outdated]
|
os_versions = [*MacOSVersions::SYMBOLS.keys, :linux]
|
||||||
os_versions = MacOSVersions::SYMBOLS.keys.append :linux
|
|
||||||
|
|
||||||
if path.exist? && self.class.instance_eval { @on_system_blocks_exist }
|
if path.exist? && self.class.on_system_blocks_exist?
|
||||||
formula_contents = path.read
|
formula_contents = path.read
|
||||||
[:arm, :intel].each do |arch|
|
[:arm64, :x86_64].each do |arch|
|
||||||
os_versions.each do |os_name|
|
os_versions.each do |os_name|
|
||||||
# Big Sur is the first version of macOS that supports arm
|
bottle_tag = Utils::Bottles::Tag.new(system: os_name, arch: arch)
|
||||||
if os_name != :linux && arch == :arm &&
|
next unless bottle_tag.valid_combination?
|
||||||
MacOS::Version.from_symbol(os_name) < MacOS::Version.from_symbol(:big_sur)
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
bottle_tag = if os_name == :linux
|
|
||||||
:linux
|
|
||||||
else
|
|
||||||
Utils::Bottles::Tag.new(system: os_name, arch: arch).to_sym
|
|
||||||
end
|
|
||||||
|
|
||||||
Homebrew::SimulateSystem.os = os_name
|
Homebrew::SimulateSystem.os = os_name
|
||||||
Homebrew::SimulateSystem.arch = arch
|
Homebrew::SimulateSystem.arch = arch
|
||||||
|
|
||||||
variations_namespace = Formulary.class_s("Variations#{bottle_tag.capitalize}")
|
variations_namespace = Formulary.class_s("Variations#{bottle_tag.to_sym.capitalize}")
|
||||||
variations_formula_class = Formulary.load_formula(name, path, formula_contents, variations_namespace,
|
variations_formula_class = Formulary.load_formula(name, path, formula_contents, variations_namespace,
|
||||||
flags: self.class.build_flags, ignore_errors: true)
|
flags: self.class.build_flags, ignore_errors: true)
|
||||||
variations_formula = variations_formula_class.new(name, path, :stable,
|
variations_formula = variations_formula_class.new(name, path, :stable,
|
||||||
alias_path: alias_path, force_bottle: force_bottle)
|
alias_path: alias_path, force_bottle: force_bottle)
|
||||||
|
|
||||||
variations_formula.to_hash_without_variations.each do |key, value|
|
variations_formula.to_hash_without_variations.each do |key, value|
|
||||||
next if hash_keys_to_skip.include? key
|
|
||||||
next if value.to_s == hash[key].to_s
|
next if value.to_s == hash[key].to_s
|
||||||
|
|
||||||
variations[bottle_tag] ||= {}
|
variations[bottle_tag.to_sym] ||= {}
|
||||||
variations[bottle_tag][key] = value
|
variations[bottle_tag.to_sym][key] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2519,6 +2508,7 @@ class Formula
|
|||||||
|
|
||||||
# The methods below define the formula DSL.
|
# The methods below define the formula DSL.
|
||||||
class << self
|
class << self
|
||||||
|
extend Predicable
|
||||||
include BuildEnvironment::DSL
|
include BuildEnvironment::DSL
|
||||||
include OnSystem::MacOSAndLinux
|
include OnSystem::MacOSAndLinux
|
||||||
|
|
||||||
@ -2533,6 +2523,11 @@ class Formula
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Whether this formula contains OS/arch-specific blocks
|
||||||
|
# (e.g. `on_macos`, `on_arm`, `on_monterey :or_older`, `on_system :linux, macos: :big_sur_or_newer`).
|
||||||
|
# @private
|
||||||
|
attr_predicate :on_system_blocks_exist?
|
||||||
|
|
||||||
# The reason for why this software is not linked (by default) to
|
# The reason for why this software is not linked (by default) to
|
||||||
# {::HOMEBREW_PREFIX}.
|
# {::HOMEBREW_PREFIX}.
|
||||||
# @private
|
# @private
|
||||||
|
|||||||
@ -187,25 +187,25 @@ describe Cask::Cmd::List, :cask do
|
|||||||
"container": null,
|
"container": null,
|
||||||
"auto_updates": null,
|
"auto_updates": null,
|
||||||
"variations": {
|
"variations": {
|
||||||
"arm_big_sur": {
|
"arm64_big_sur": {
|
||||||
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.0/arm.zip",
|
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.0/arm.zip",
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||||
},
|
},
|
||||||
"intel_monterey": {
|
"monterey": {
|
||||||
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.3/intel.zip"
|
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.3/intel.zip"
|
||||||
},
|
},
|
||||||
"intel_big_sur": {
|
"big_sur": {
|
||||||
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.0/intel.zip",
|
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.2.0/intel.zip",
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
"sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||||
},
|
},
|
||||||
"intel_catalina": {
|
"catalina": {
|
||||||
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.0.0/intel.zip",
|
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.0.0/intel.zip",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"sha256": "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216"
|
"sha256": "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216"
|
||||||
},
|
},
|
||||||
"intel_mojave": {
|
"mojave": {
|
||||||
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.0.0/intel.zip",
|
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine/1.0.0/intel.zip",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"sha256": "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216"
|
"sha256": "1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216"
|
||||||
|
|||||||
@ -36,4 +36,37 @@ describe Utils::Bottles::Tag do
|
|||||||
expect(tag.linux?).to be true
|
expect(tag.linux?).to be true
|
||||||
expect(tag.to_sym).to eq(symbol)
|
expect(tag.to_sym).to eq(symbol)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#standardized_arch" do
|
||||||
|
it "returns :x86_64 for :intel" do
|
||||||
|
expect(described_class.new(system: :all, arch: :intel).standardized_arch).to eq(:x86_64)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns :arm64 for :arm" do
|
||||||
|
expect(described_class.new(system: :all, arch: :arm).standardized_arch).to eq(:arm64)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#valid_combination?" do
|
||||||
|
it "returns true for intel archs" do
|
||||||
|
tag = described_class.new(system: :big_sur, arch: :intel)
|
||||||
|
expect(tag.valid_combination?).to be true
|
||||||
|
tag = described_class.new(system: :linux, arch: :x86_64)
|
||||||
|
expect(tag.valid_combination?).to be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false for arm archs and macos versions older than big_sur" do
|
||||||
|
tag = described_class.new(system: :catalina, arch: :arm64)
|
||||||
|
expect(tag.valid_combination?).to be false
|
||||||
|
tag = described_class.new(system: :mojave, arch: :arm)
|
||||||
|
expect(tag.valid_combination?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false for arm archs and linux " do
|
||||||
|
tag = described_class.new(system: :linux, arch: :arm64)
|
||||||
|
expect(tag.valid_combination?).to be false
|
||||||
|
tag = described_class.new(system: :linux, arch: :arm)
|
||||||
|
expect(tag.valid_combination?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -169,14 +169,21 @@ module Utils
|
|||||||
[system, arch].hash
|
[system, arch].hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def standardized_arch
|
||||||
|
return :x86_64 if [:x86_64, :intel].include? arch
|
||||||
|
return :arm64 if [:arm64, :arm].include? arch
|
||||||
|
|
||||||
|
arch
|
||||||
|
end
|
||||||
|
|
||||||
sig { returns(Symbol) }
|
sig { returns(Symbol) }
|
||||||
def to_sym
|
def to_sym
|
||||||
if system == :all && arch == :all
|
if system == :all && arch == :all
|
||||||
:all
|
:all
|
||||||
elsif macos? && arch == :x86_64
|
elsif macos? && [:x86_64, :intel].include?(arch)
|
||||||
system
|
system
|
||||||
else
|
else
|
||||||
"#{arch}_#{system}".to_sym
|
"#{standardized_arch}_#{system}".to_sym
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -203,6 +210,15 @@ module Utils
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
|
def valid_combination?
|
||||||
|
return true unless [:arm64, :arm].include? arch
|
||||||
|
return false if linux?
|
||||||
|
|
||||||
|
# Big Sur is the first version of macOS that runs on ARM
|
||||||
|
to_macos_version >= :big_sur
|
||||||
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def default_prefix
|
def default_prefix
|
||||||
if linux?
|
if linux?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user