diff --git a/Library/Homebrew/extend/os/mac/hardware/cpu.rb b/Library/Homebrew/extend/os/mac/hardware/cpu.rb index ca9cded68d..96c6fb6fb4 100644 --- a/Library/Homebrew/extend/os/mac/hardware/cpu.rb +++ b/Library/Homebrew/extend/os/mac/hardware/cpu.rb @@ -22,33 +22,10 @@ module Hardware end def family - case sysctl_int("hw.cpufamily") - when 0x73d67300 # Yonah: Core Solo/Duo - :core - when 0x426f69ef # Merom: Core 2 Duo - :core2 - when 0x78ea4fbc # Penryn - :penryn - when 0x6b5a4cd2 # Nehalem - :nehalem - when 0x573B5EEC # Arrandale - :arrandale - when 0x5490B78C # Sandy Bridge - :sandybridge - when 0x1F65E835 # Ivy Bridge - :ivybridge - when 0x10B282DC # Haswell - :haswell - when 0x582ed09c # Broadwell - :broadwell - when 0x37fc219f # Skylake - :skylake - when 0x0f817246 # Kaby Lake - :kabylake - when 0x38435547 # Ice Lake - :icelake - when 0x07d34b9f # ARMv8.3-A (Vortex, Tempest) - :arm_vortex_tempest + if arm? + arm_family + elsif intel? + intel_family else :dunno end @@ -124,6 +101,48 @@ module Hardware private + def arm_family + case sysctl_int("hw.cpufamily") + when 0x07d34b9f # ARMv8.3-A (Vortex, Tempest) + :arm_vortex_tempest + when 0x573b5eec, 0x1b588bb3 # ARMv8.4-A (Firestorm, Icestorm) + :arm_firestorm_icestorm + else + :dunno + end + end + + def intel_family + case sysctl_int("hw.cpufamily") + when 0x73d67300 # Yonah: Core Solo/Duo + :core + when 0x426f69ef # Merom: Core 2 Duo + :core2 + when 0x78ea4fbc # Penryn + :penryn + when 0x6b5a4cd2 # Nehalem + :nehalem + when 0x573b5eec # Arrandale + :arrandale + when 0x5490b78c # Sandy Bridge + :sandybridge + when 0x1f65e835 # Ivy Bridge + :ivybridge + when 0x10b282dc # Haswell + :haswell + when 0x582ed09c # Broadwell + :broadwell + when 0x37fc219f # Skylake + :skylake + when 0x0f817246 # Kaby Lake + :kabylake + when 0x38435547 # Ice Lake + :icelake + else + :dunno + end + end + def sysctl_bool(key) sysctl_int(key) == 1 end diff --git a/Library/Homebrew/test/hardware/cpu_spec.rb b/Library/Homebrew/test/hardware/cpu_spec.rb index adace43ae9..75d336e7d8 100644 --- a/Library/Homebrew/test/hardware/cpu_spec.rb +++ b/Library/Homebrew/test/hardware/cpu_spec.rb @@ -22,6 +22,7 @@ describe Hardware::CPU do describe "::family" do let(:cpu_families) { [ + :arm_firestorm_icestorm, :arm_vortex_tempest, :arrandale, :atom, @@ -48,5 +49,28 @@ describe Hardware::CPU do it "returns the current CPU's family name as a symbol, or :dunno if it cannot be detected" do expect(cpu_families).to include described_class.family end + + context "when hw.cpufamily is 0x573b5eec on a Mac", :needs_macos do + before do + allow(described_class) + .to receive(:sysctl_int) + .with("hw.cpufamily") + .and_return(0x573b5eec) + end + + it "returns :arm_firestorm_icestorm on ARM" do + allow(described_class).to receive(:arm?).and_return(true) + allow(described_class).to receive(:intel?).and_return(false) + + expect(described_class.family).to eq(:arm_firestorm_icestorm) + end + + it "returns :westmere on Intel" do + allow(described_class).to receive(:arm?).and_return(false) + allow(described_class).to receive(:intel?).and_return(true) + + expect(described_class.family).to eq(:westmere) + end + end end end