aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend
diff options
context:
space:
mode:
authorMisty De Meo2017-04-15 22:05:56 +0800
committerMisty De Meo2017-04-15 22:59:55 +0800
commit944bff4de2ec3821480ee9097e06016cce2b2925 (patch)
tree3a98ac881c58de99d47f69cd705720bb65619729 /Library/Homebrew/extend
parentd7ff53fa1ddf649ce8ca3910fc5e901ea4aa5b5a (diff)
downloadbrew-944bff4de2ec3821480ee9097e06016cce2b2925.tar.bz2
Mac Hardware: provide a more Mac-specific implementation of can_run?
Diffstat (limited to 'Library/Homebrew/extend')
-rw-r--r--Library/Homebrew/extend/os/mac/hardware/cpu.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/os/mac/hardware/cpu.rb b/Library/Homebrew/extend/os/mac/hardware/cpu.rb
index f180995fb..22d118e1a 100644
--- a/Library/Homebrew/extend/os/mac/hardware/cpu.rb
+++ b/Library/Homebrew/extend/os/mac/hardware/cpu.rb
@@ -107,6 +107,20 @@ module Hardware
end
end
+ # Determines whether the current CPU and macOS combination
+ # can run an executable of the specified architecture.
+ # `arch` is a symbol in the same format returned by
+ # Hardware::CPU.family
+ def can_run?(arch)
+ if Hardware::CPU.intel?
+ intel_can_run? arch
+ elsif Hardware::CPU.ppc?
+ ppc_can_run? arch
+ else
+ false
+ end
+ end
+
def features
@features ||= sysctl_n(
"machdep.cpu.features",
@@ -162,6 +176,35 @@ module Hardware
@properties[keys] = Utils.popen_read("/usr/sbin/sysctl", "-n", *keys)
end
end
+
+ def intel_can_run?(arch)
+ case arch
+ when :ppc
+ # Rosetta is still available
+ MacOS.version < :lion
+ when :ppc64
+ # Rosetta never supported PPC64
+ false
+ when :x86_64
+ Hardware::CPU.is_64_bit?
+ when :i386
+ true
+ else # dunno
+ false
+ end
+ end
+
+ def ppc_can_run?(arch)
+ case arch
+ when :ppc
+ true
+ when :ppc64
+ Hardware::CPU.is_64_bit?
+ else
+ # Intel is never supported
+ false
+ end
+ end
end
end
end