brew/Library/Homebrew/hardware.rb

75 lines
1.1 KiB
Ruby
Raw Normal View History

2013-10-18 12:56:51 -05:00
require 'os'
class Hardware
module CPU extend self
INTEL_32BIT_ARCHS = [:i386].freeze
INTEL_64BIT_ARCHS = [:x86_64].freeze
PPC_32BIT_ARCHS = [:ppc, :ppc7400, :ppc7450, :ppc970].freeze
PPC_64BIT_ARCHS = [:ppc64].freeze
def type
@type || :dunno
end
def family
@family || :dunno
end
def cores
@cores || 1
end
def bits
@bits || 64
end
def is_32_bit?
bits == 32
end
def is_64_bit?
bits == 64
end
def intel?
type == :intel
end
def ppc?
type == :ppc
end
end
2013-10-18 12:56:51 -05:00
if OS.mac?
require 'os/mac/hardware'
CPU.extend MacCPUs
2013-10-18 12:56:51 -05:00
elsif OS.linux?
require 'os/linux/hardware'
CPU.extend LinuxCPUs
else
raise "The system `#{`uname`.chomp}' is not supported."
end
def self.cores_as_words
2013-06-13 12:04:58 -05:00
case Hardware::CPU.cores
when 1 then 'single'
when 2 then 'dual'
when 4 then 'quad'
else
2013-06-13 12:04:58 -05:00
Hardware::CPU.cores
end
end
2013-06-06 16:02:27 -05:00
def self.oldest_cpu
if Hardware::CPU.intel?
2013-06-06 16:02:27 -05:00
if Hardware::CPU.is_64_bit?
:core2
else
:core
end
else
Hardware::CPU.family
end
end
end