aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/hardware.rb
diff options
context:
space:
mode:
authorShaun Jackman2013-03-10 17:33:06 +0000
committerMike McQuaid2013-03-11 18:26:25 +0000
commit076fcd11b0258a2ff0f37f2a93961df19594a6a2 (patch)
treed448572980513f4189db2c2fca9a230ed45aabf9 /Library/Homebrew/hardware.rb
parent22322867a1ff3822d11142fb25c3713a957afe9f (diff)
downloadhomebrew-076fcd11b0258a2ff0f37f2a93961df19594a6a2.tar.bz2
Portability fixes to run Homebrew on Linux systems
Closes #16344. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Diffstat (limited to 'Library/Homebrew/hardware.rb')
-rw-r--r--Library/Homebrew/hardware.rb64
1 files changed, 9 insertions, 55 deletions
diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb
index 20794be0a..ded0c9ccb 100644
--- a/Library/Homebrew/hardware.rb
+++ b/Library/Homebrew/hardware.rb
@@ -1,47 +1,15 @@
class Hardware
- # These methods use info spewed out by sysctl.
- # Look in <mach/machine.h> for decoding info.
-
- def self.cpu_type
- @@cpu_type ||= `/usr/sbin/sysctl -n hw.cputype`.to_i
-
- case @@cpu_type
- when 7
- :intel
- when 18
- :ppc
- else
- :dunno
- end
- end
-
- def self.intel_family
- @@intel_family ||= `/usr/sbin/sysctl -n hw.cpufamily`.to_i
-
- case @@intel_family
- 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
- else
- :dunno
- end
+ case RUBY_PLATFORM.downcase
+ when /darwin/
+ require 'os/mac/hardware'
+ extend MacOSHardware
+ when /linux/
+ require 'os/linux/hardware'
+ extend LinuxHardware
+ else
+ raise "The system `#{`uname`.chomp}' is not supported."
end
- def self.processor_count
- @@processor_count ||= `/usr/sbin/sysctl -n hw.ncpu`.to_i
- end
-
def self.cores_as_words
case Hardware.processor_count
when 1 then 'single'
@@ -56,21 +24,7 @@ class Hardware
not self.is_64_bit?
end
- def self.is_64_bit?
- return @@is_64_bit if defined? @@is_64_bit
- @@is_64_bit = self.sysctl_bool("hw.cpu64bit_capable")
- end
-
def self.bits
Hardware.is_64_bit? ? 64 : 32
end
-
-protected
- def self.sysctl_bool(property)
- result = nil
- IO.popen("/usr/sbin/sysctl -n #{property} 2>/dev/null") do |f|
- result = f.gets.to_i # should be 0 or 1
- end
- $?.success? && result == 1 # sysctl call succeded and printed 1
- end
end