diff options
| author | Misty De Meo | 2017-04-17 18:01:33 +0800 |
|---|---|---|
| committer | GitHub | 2017-04-17 18:01:33 +0800 |
| commit | 1deb884314e875872032b86e327dc9f79e2cf042 (patch) | |
| tree | 564796012b89f2b47ead98cf3d38c676ccfe41ed /Library/Homebrew/extend | |
| parent | 46f6dc4c93b96abd528c3a0a808a5ca5a795c7f3 (diff) | |
| parent | 944bff4de2ec3821480ee9097e06016cce2b2925 (diff) | |
| download | brew-1deb884314e875872032b86e327dc9f79e2cf042.tar.bz2 | |
Merge pull request #2496 from mistydemeo/hardware_cpu_can_run_arch_helper
Hardware cpu can run arch helper
Diffstat (limited to 'Library/Homebrew/extend')
| -rw-r--r-- | Library/Homebrew/extend/os/mac/hardware/cpu.rb | 43 |
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 |
