Merge pull request #9464 from MikeMcQuaid/arch_version_handling
MacOS::Version architecture handling
This commit is contained in:
commit
8bf6ec5739
@ -36,13 +36,8 @@ module Homebrew
|
|||||||
args = dispatch_build_bottle_args.parse
|
args = dispatch_build_bottle_args.parse
|
||||||
|
|
||||||
# Fixup version for ARM/Apple Silicon
|
# Fixup version for ARM/Apple Silicon
|
||||||
arm_regex = Regexp.union(/^arm64_/, /-arm$/)
|
# TODO: fix label name to be 11-arm64 instead and remove this.
|
||||||
arm_label = if arm_regex.match?(args.macos)
|
args.macos&.gsub!(/^11-arm$/, "11-arm64")
|
||||||
args.macos&.gsub!(arm_regex, "")
|
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
macos = args.macos&.yield_self do |s|
|
macos = args.macos&.yield_self do |s|
|
||||||
MacOS::Version.from_symbol(s.to_sym)
|
MacOS::Version.from_symbol(s.to_sym)
|
||||||
@ -53,7 +48,8 @@ module Homebrew
|
|||||||
raise UsageError, "Must specify --macos option" if macos.blank?
|
raise UsageError, "Must specify --macos option" if macos.blank?
|
||||||
|
|
||||||
# Fixup label for ARM/Apple Silicon
|
# Fixup label for ARM/Apple Silicon
|
||||||
macos_label = if arm_label
|
macos_label = if macos.arch == :arm64
|
||||||
|
# TODO: fix label name to be 11-arm64 instead.
|
||||||
"#{macos}-arm"
|
"#{macos}-arm"
|
||||||
else
|
else
|
||||||
macos.to_s
|
macos.to_s
|
||||||
|
|||||||
@ -42,7 +42,10 @@ module Utils
|
|||||||
return if tag_version.blank?
|
return if tag_version.blank?
|
||||||
|
|
||||||
keys.find do |key|
|
keys.find do |key|
|
||||||
MacOS::Version.from_symbol(key) <= tag_version
|
key_version = MacOS::Version.from_symbol(key)
|
||||||
|
next if key_version.arch != tag_version.arch
|
||||||
|
|
||||||
|
key_version <= tag_version
|
||||||
rescue MacOSVersionError
|
rescue MacOSVersionError
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,6 +11,14 @@ module Hardware
|
|||||||
INTEL_64BIT_ARCHS = [:x86_64].freeze
|
INTEL_64BIT_ARCHS = [:x86_64].freeze
|
||||||
PPC_32BIT_ARCHS = [:ppc, :ppc32, :ppc7400, :ppc7450, :ppc970].freeze
|
PPC_32BIT_ARCHS = [:ppc, :ppc32, :ppc7400, :ppc7450, :ppc970].freeze
|
||||||
PPC_64BIT_ARCHS = [:ppc64, :ppc64le, :ppc970].freeze
|
PPC_64BIT_ARCHS = [:ppc64, :ppc64le, :ppc970].freeze
|
||||||
|
ARM_64BIT_ARCHS = [:arm64].freeze
|
||||||
|
ALL_ARCHS = [
|
||||||
|
*INTEL_32BIT_ARCHS,
|
||||||
|
*INTEL_64BIT_ARCHS,
|
||||||
|
*PPC_32BIT_ARCHS,
|
||||||
|
*PPC_64BIT_ARCHS,
|
||||||
|
*ARM_64BIT_ARCHS,
|
||||||
|
].freeze
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|||||||
@ -13,6 +13,8 @@ module OS
|
|||||||
class Version < ::Version
|
class Version < ::Version
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
|
attr_reader :arch
|
||||||
|
|
||||||
SYMBOLS = {
|
SYMBOLS = {
|
||||||
big_sur: "11",
|
big_sur: "11",
|
||||||
catalina: "10.15",
|
catalina: "10.15",
|
||||||
@ -25,16 +27,37 @@ module OS
|
|||||||
|
|
||||||
sig { params(sym: Symbol).returns(T.attached_class) }
|
sig { params(sym: Symbol).returns(T.attached_class) }
|
||||||
def self.from_symbol(sym)
|
def self.from_symbol(sym)
|
||||||
str = SYMBOLS.fetch(sym) { raise MacOSVersionError, sym }
|
version, arch = version_arch(sym)
|
||||||
new(str)
|
version ||= sym
|
||||||
|
str = SYMBOLS.fetch(version.to_sym) { raise MacOSVersionError, sym }
|
||||||
|
new(str, arch: arch)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(value: T.nilable(String)).void }
|
sig { params(value: T.any(String, Symbol)).returns(T::Array[String]) }
|
||||||
def initialize(value)
|
def self.version_arch(value)
|
||||||
raise MacOSVersionError, value unless /\A1\d+(?:\.\d+){0,2}\Z/.match?(value)
|
@all_archs_regex ||= begin
|
||||||
|
all_archs = Hardware::CPU::ALL_ARCHS.map(&:to_s)
|
||||||
|
/^((#{Regexp.union(all_archs)})_)?([\w.]+)(-(#{Regexp.union(all_archs)}))?$/
|
||||||
|
end
|
||||||
|
match = @all_archs_regex.match(value)
|
||||||
|
return [] unless match
|
||||||
|
|
||||||
super(value)
|
version = match[3]
|
||||||
|
arch = match[2] || match[5]
|
||||||
|
[version, arch]
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { params(value: T.nilable(String), arch: T.nilable(String)).void }
|
||||||
|
def initialize(value, arch: nil)
|
||||||
|
version, arch = Version.version_arch(value) if value.present? && arch.nil?
|
||||||
|
version ||= value
|
||||||
|
arch ||= "intel"
|
||||||
|
|
||||||
|
raise MacOSVersionError, version unless /\A1\d+(?:\.\d+){0,2}\Z/.match?(version)
|
||||||
|
|
||||||
|
super(version)
|
||||||
|
|
||||||
|
@arch = arch.to_sym
|
||||||
@comparison_cache = {}
|
@comparison_cache = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -62,12 +62,44 @@ describe OS::Mac::Version do
|
|||||||
described_class.new("1.2")
|
described_class.new("1.2")
|
||||||
}.to raise_error(MacOSVersionError, 'unknown or unsupported macOS version: "1.2"')
|
}.to raise_error(MacOSVersionError, 'unknown or unsupported macOS version: "1.2"')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "creates a new version from a valid macOS version" do
|
||||||
|
string_version = described_class.new("11")
|
||||||
|
expect(string_version).to eq(:big_sur)
|
||||||
|
expect(string_version.arch).to eq(:intel)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a new version from a valid macOS version with architecture" do
|
||||||
|
string_version = described_class.new("11-arm64")
|
||||||
|
expect(string_version).to eq(:big_sur)
|
||||||
|
expect(string_version.arch).to eq(:arm64)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a new version from a valid macOS version and architecture" do
|
||||||
|
string_version = described_class.new("11", arch: "arm64")
|
||||||
|
expect(string_version).to eq(:big_sur)
|
||||||
|
expect(string_version.arch).to eq(:arm64)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
specify "#from_symbol" do
|
describe "#from_symbol" do
|
||||||
expect(described_class.from_symbol(:mojave)).to eq(version)
|
it "raises an error if the symbol is not a valid macOS version" do
|
||||||
expect { described_class.from_symbol(:foo) }
|
expect {
|
||||||
.to raise_error(MacOSVersionError, "unknown or unsupported macOS version: :foo")
|
described_class.from_symbol(:foo)
|
||||||
|
}.to raise_error(MacOSVersionError, "unknown or unsupported macOS version: :foo")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a new version from a valid macOS version" do
|
||||||
|
symbol_version = described_class.from_symbol(:mojave)
|
||||||
|
expect(symbol_version).to eq(version)
|
||||||
|
expect(symbol_version.arch).to eq(:intel)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a new version from a valid macOS version with architecture" do
|
||||||
|
symbol_version = described_class.from_symbol(:arm64_big_sur)
|
||||||
|
expect(symbol_version).to eq(:big_sur)
|
||||||
|
expect(symbol_version.arch).to eq(:arm64)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
specify "#pretty_name" do
|
specify "#pretty_name" do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user