Portability fixes to run Homebrew on Linux systems
Closes Homebrew/homebrew#16344. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
parent
98352b3b41
commit
258d70028f
@ -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,
|
||||
|
||||
@ -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
|
||||
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.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 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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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'
|
||||
|
||||
25
Library/Homebrew/os/linux/hardware.rb
Normal file
25
Library/Homebrew/os/linux/hardware.rb
Normal file
@ -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
|
||||
57
Library/Homebrew/os/mac/hardware.rb
Normal file
57
Library/Homebrew/os/mac/hardware.rb
Normal file
@ -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
|
||||
@ -1,6 +1,6 @@
|
||||
require 'testing_env'
|
||||
require 'version'
|
||||
require 'macos/version'
|
||||
require 'os/mac/version'
|
||||
|
||||
class MacOSVersionTests < Test::Unit::TestCase
|
||||
def setup
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user