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
|
fork do
|
||||||
begin
|
begin
|
||||||
read.close
|
read.close
|
||||||
exec '/usr/bin/nice',
|
exec 'nice',
|
||||||
RUBY_PATH,
|
RUBY_PATH,
|
||||||
'-W0',
|
'-W0',
|
||||||
'-I', Pathname.new(__FILE__).dirname,
|
'-I', Pathname.new(__FILE__).dirname,
|
||||||
|
|||||||
@ -1,45 +1,13 @@
|
|||||||
class Hardware
|
class Hardware
|
||||||
# These methods use info spewed out by sysctl.
|
case RUBY_PLATFORM.downcase
|
||||||
# Look in <mach/machine.h> for decoding info.
|
when /darwin/
|
||||||
|
require 'os/mac/hardware'
|
||||||
def self.cpu_type
|
extend MacOSHardware
|
||||||
@@cpu_type ||= `/usr/sbin/sysctl -n hw.cputype`.to_i
|
when /linux/
|
||||||
|
require 'os/linux/hardware'
|
||||||
case @@cpu_type
|
extend LinuxHardware
|
||||||
when 7
|
else
|
||||||
:intel
|
raise "The system `#{`uname`.chomp}' is not supported."
|
||||||
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
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.processor_count
|
|
||||||
@@processor_count ||= `/usr/sbin/sysctl -n hw.ncpu`.to_i
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cores_as_words
|
def self.cores_as_words
|
||||||
@ -56,21 +24,7 @@ class Hardware
|
|||||||
not self.is_64_bit?
|
not self.is_64_bit?
|
||||||
end
|
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
|
def self.bits
|
||||||
Hardware.is_64_bit? ? 64 : 32
|
Hardware.is_64_bit? ? 64 : 32
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@ -40,6 +40,8 @@ module MachO
|
|||||||
end
|
end
|
||||||
when 0xcefaedfe, 0xcffaedfe, 0xfeedface, 0xfeedfacf # Single arch
|
when 0xcefaedfe, 0xcffaedfe, 0xfeedface, 0xfeedfacf # Single arch
|
||||||
offsets << 0
|
offsets << 0
|
||||||
|
when 0x7f454c46 # ELF
|
||||||
|
mach_data << { :arch => :x86_64, :type => :executable }
|
||||||
else
|
else
|
||||||
raise "Not a Mach-O binary."
|
raise "Not a Mach-O binary."
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
require 'macos/version'
|
require 'os/mac/version'
|
||||||
|
|
||||||
module MacOS extend self
|
module MacOS extend self
|
||||||
|
|
||||||
@ -238,5 +238,5 @@ module MacOS extend self
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'macos/xcode'
|
require 'os/mac/xcode'
|
||||||
require 'macos/xquartz'
|
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 'testing_env'
|
||||||
require 'version'
|
require 'version'
|
||||||
require 'macos/version'
|
require 'os/mac/version'
|
||||||
|
|
||||||
class MacOSVersionTests < Test::Unit::TestCase
|
class MacOSVersionTests < Test::Unit::TestCase
|
||||||
def setup
|
def setup
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user