diff options
| author | Shaun Jackman | 2013-03-10 17:33:06 +0000 |
|---|---|---|
| committer | Mike McQuaid | 2013-03-11 18:26:25 +0000 |
| commit | 076fcd11b0258a2ff0f37f2a93961df19594a6a2 (patch) | |
| tree | d448572980513f4189db2c2fca9a230ed45aabf9 | |
| parent | 22322867a1ff3822d11142fb25c3713a957afe9f (diff) | |
| download | homebrew-076fcd11b0258a2ff0f37f2a93961df19594a6a2.tar.bz2 | |
Portability fixes to run Homebrew on Linux systems
Closes #16344.
Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
| -rw-r--r-- | Library/Homebrew/formula_installer.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/hardware.rb | 64 | ||||
| -rw-r--r-- | Library/Homebrew/mach.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/macos.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/os/linux/hardware.rb | 25 | ||||
| -rw-r--r-- | Library/Homebrew/os/mac/hardware.rb | 57 | ||||
| -rw-r--r-- | Library/Homebrew/os/mac/version.rb (renamed from Library/Homebrew/macos/version.rb) | 0 | ||||
| -rw-r--r-- | Library/Homebrew/os/mac/xcode.rb (renamed from Library/Homebrew/macos/xcode.rb) | 0 | ||||
| -rw-r--r-- | Library/Homebrew/os/mac/xquartz.rb (renamed from Library/Homebrew/macos/xquartz.rb) | 0 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_version_subclasses.rb | 2 |
10 files changed, 98 insertions, 60 deletions
diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index a84502ed8..9251fe487 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -284,7 +284,7 @@ class FormulaInstaller fork do begin read.close - exec '/usr/bin/nice', + exec 'nice', RUBY_PATH, '-W0', '-I', Pathname.new(__FILE__).dirname, 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 diff --git a/Library/Homebrew/mach.rb b/Library/Homebrew/mach.rb index be93aca57..537b2588e 100644 --- a/Library/Homebrew/mach.rb +++ b/Library/Homebrew/mach.rb @@ -40,6 +40,8 @@ module MachO end when 0xcefaedfe, 0xcffaedfe, 0xfeedface, 0xfeedfacf # Single arch offsets << 0 + when 0x7f454c46 # ELF + mach_data << { :arch => :x86_64, :type => :executable } else raise "Not a Mach-O binary." end diff --git a/Library/Homebrew/macos.rb b/Library/Homebrew/macos.rb index b28be62dc..2d378932c 100644 --- a/Library/Homebrew/macos.rb +++ b/Library/Homebrew/macos.rb @@ -1,4 +1,4 @@ -require 'macos/version' +require 'os/mac/version' module MacOS extend self @@ -238,5 +238,5 @@ module MacOS extend self end end -require 'macos/xcode' -require 'macos/xquartz' +require 'os/mac/xcode' +require 'os/mac/xquartz' diff --git a/Library/Homebrew/os/linux/hardware.rb b/Library/Homebrew/os/linux/hardware.rb new file mode 100644 index 000000000..8fd4b09b9 --- /dev/null +++ b/Library/Homebrew/os/linux/hardware.rb @@ -0,0 +1,25 @@ +module LinuxHardware + def cpu_type + @@cpu_type ||= case `uname -m` + when /x86_64/ + :intel + when /i386/ + :intel + else + :dunno + end + end + + def intel_family + :dunno + end + + def processor_count + `grep -c ^processor /proc/cpuinfo`.to_i + end + + def is_64_bit? + return @@is_64_bit if defined? @@is_64_bit + @@is_64_bit = /64/ === `uname -m` + end +end diff --git a/Library/Homebrew/os/mac/hardware.rb b/Library/Homebrew/os/mac/hardware.rb new file mode 100644 index 000000000..ffdc6246c --- /dev/null +++ b/Library/Homebrew/os/mac/hardware.rb @@ -0,0 +1,57 @@ +module MacOSHardware + # These methods use info spewed out by sysctl. + # Look in <mach/machine.h> for decoding info. + def 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 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 + end + + def processor_count + @@processor_count ||= `/usr/sbin/sysctl -n hw.ncpu`.to_i + end + + def is_64_bit? + return @@is_64_bit if defined? @@is_64_bit + @@is_64_bit = sysctl_bool("hw.cpu64bit_capable") + end + +protected + def 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 diff --git a/Library/Homebrew/macos/version.rb b/Library/Homebrew/os/mac/version.rb index 090b1ffb7..090b1ffb7 100644 --- a/Library/Homebrew/macos/version.rb +++ b/Library/Homebrew/os/mac/version.rb diff --git a/Library/Homebrew/macos/xcode.rb b/Library/Homebrew/os/mac/xcode.rb index 0bb68636a..0bb68636a 100644 --- a/Library/Homebrew/macos/xcode.rb +++ b/Library/Homebrew/os/mac/xcode.rb diff --git a/Library/Homebrew/macos/xquartz.rb b/Library/Homebrew/os/mac/xquartz.rb index a515d8915..a515d8915 100644 --- a/Library/Homebrew/macos/xquartz.rb +++ b/Library/Homebrew/os/mac/xquartz.rb diff --git a/Library/Homebrew/test/test_version_subclasses.rb b/Library/Homebrew/test/test_version_subclasses.rb index 93711ac44..6b18246ba 100644 --- a/Library/Homebrew/test/test_version_subclasses.rb +++ b/Library/Homebrew/test/test_version_subclasses.rb @@ -1,6 +1,6 @@ require 'testing_env' require 'version' -require 'macos/version' +require 'os/mac/version' class MacOSVersionTests < Test::Unit::TestCase def setup |
