diff --git a/Library/Homebrew/extend/os/mac/hardware.rb b/Library/Homebrew/extend/os/mac/hardware.rb index 975e308d4a..25e9d0c58c 100644 --- a/Library/Homebrew/extend/os/mac/hardware.rb +++ b/Library/Homebrew/extend/os/mac/hardware.rb @@ -1,6 +1,6 @@ module Hardware - def self.oldest_cpu - if MacOS.version >= :mojave + def self.oldest_cpu(version = MacOS.version) + if version >= :mojave :nehalem else generic_oldest_cpu diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index b687b841a7..9f48c4b971 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -134,7 +134,7 @@ module Hardware end end - def oldest_cpu + def oldest_cpu(_version = nil) if Hardware::CPU.intel? if Hardware::CPU.is_64_bit? :core2 diff --git a/Library/Homebrew/os/mac/version.rb b/Library/Homebrew/os/mac/version.rb index 8adf848d2f..4527bdafe9 100644 --- a/Library/Homebrew/os/mac/version.rb +++ b/Library/Homebrew/os/mac/version.rb @@ -38,6 +38,17 @@ module OS def pretty_name to_sym.to_s.split("_").map(&:capitalize).join(" ") end + + # For OS::Mac::Version compatability + def requires_nehalem_cpu? + 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 end end diff --git a/Library/Homebrew/test/os/mac/version_spec.rb b/Library/Homebrew/test/os/mac/version_spec.rb index cb45a14001..a74f541461 100644 --- a/Library/Homebrew/test/os/mac/version_spec.rb +++ b/Library/Homebrew/test/os/mac/version_spec.rb @@ -46,4 +46,9 @@ describe OS::Mac::Version do expect(described_class.new("10.14").pretty_name).to eq("Mojave") expect(described_class.new("10.10").pretty_name).to eq("Yosemite") end + + specify "#requires_nehalem_cpu?" do + expect(described_class.new("10.14").requires_nehalem_cpu?).to be true + expect(described_class.new("10.12").requires_nehalem_cpu?).to be false + end end diff --git a/Library/Homebrew/version/null.rb b/Library/Homebrew/version/null.rb index 9549ba3284..230907754a 100644 --- a/Library/Homebrew/version/null.rb +++ b/Library/Homebrew/version/null.rb @@ -26,6 +26,15 @@ class Version true end + # For OS::Mac::Version compatability + def requires_nehalem_cpu? + false + end + alias_method :requires_sse4?, :requires_nehalem_cpu? + alias_method :requires_sse41?, :requires_nehalem_cpu? + alias_method :requires_sse42?, :requires_nehalem_cpu? + alias_method :requires_popcnt?, :requires_nehalem_cpu? + def to_f Float::NAN end