brew/Library/Homebrew/os/mac/version.rb

68 lines
1.7 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: true
# frozen_string_literal: true
require "hardware"
require "version"
2013-02-06 22:49:43 -06:00
module OS
module Mac
2020-08-25 00:35:07 +02:00
# A macOS version.
#
# @api private
class Version < ::Version
SYMBOLS = {
big_sur: "11.0",
2019-06-03 11:45:08 -07:00
catalina: "10.15",
mojave: "10.14",
high_sierra: "10.13",
sierra: "10.12",
el_capitan: "10.11",
yosemite: "10.10",
2016-09-11 17:49:27 +01:00
}.freeze
2013-06-15 19:39:27 -05:00
def self.from_symbol(sym)
str = SYMBOLS.fetch(sym) { raise MacOSVersionError, sym }
new(str)
end
2013-06-15 19:39:27 -05:00
2020-10-05 14:46:43 +02:00
def initialize(value)
super(value)
raise MacOSVersionError, value unless value.match?(/\A1\d+(?:\.\d+){0,2}\Z/)
@comparison_cache = {}
end
def <=>(other)
@comparison_cache.fetch(other) do
v = SYMBOLS.fetch(other) { other.to_s }
2020-10-05 14:46:43 +02:00
@comparison_cache[other] = super(::Version.new(v))
end
end
def to_sym
2020-06-22 14:09:33 +01:00
SYMBOLS.invert.fetch(@version, :dunno)
2013-06-14 14:47:16 -07:00
end
def pretty_name
to_sym.to_s.split("_").map(&:capitalize).join(" ")
end
# For {OS::Mac::Version} compatibility.
def requires_nehalem_cpu?
unless Hardware::CPU.intel?
raise "Unexpected architecture: #{Hardware::CPU.arch}. This only works with Intel architecture."
end
Hardware.oldest_cpu(self) == :nehalem
end
# https://en.wikipedia.org/wiki/Nehalem_(microarchitecture)
# Ensure any extra methods are also added to version/null.rb
alias requires_sse4? requires_nehalem_cpu?
alias requires_sse41? requires_nehalem_cpu?
alias requires_sse42? requires_nehalem_cpu?
alias requires_popcnt? requires_nehalem_cpu?
end
2013-02-06 22:49:43 -06:00
end
end