Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
944bff4d
Commit
944bff4d
authored
7 years ago
by
Misty De Meo
Browse files
Options
Downloads
Patches
Plain Diff
Mac Hardware: provide a more Mac-specific implementation of can_run?
parent
d7ff53fa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Library/Homebrew/extend/os/mac/hardware/cpu.rb
+43
-0
43 additions, 0 deletions
Library/Homebrew/extend/os/mac/hardware/cpu.rb
Library/Homebrew/test/os/mac/hardware_spec.rb
+56
-0
56 additions, 0 deletions
Library/Homebrew/test/os/mac/hardware_spec.rb
with
99 additions
and
0 deletions
Library/Homebrew/extend/os/mac/hardware/cpu.rb
+
43
−
0
View file @
944bff4d
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Library/Homebrew/test/os/mac/hardware_spec.rb
0 → 100644
+
56
−
0
View file @
944bff4d
require
"hardware"
require
"extend/os/mac/hardware/cpu"
describe
Hardware
::
CPU
do
describe
"::can_run?"
do
it
"reports that Intel Macs can run Intel executables"
do
allow
(
Hardware
::
CPU
).
to
receive
(
:type
).
and_return
:intel
allow
(
Hardware
::
CPU
).
to
receive
(
:bits
).
and_return
64
expect
(
Hardware
::
CPU
.
can_run?
(
:i386
)).
to
be
true
expect
(
Hardware
::
CPU
.
can_run?
(
:x86_64
)).
to
be
true
end
it
"reports that PowerPC Macs can run PowerPC executables"
do
allow
(
Hardware
::
CPU
).
to
receive
(
:type
).
and_return
:ppc
allow
(
Hardware
::
CPU
).
to
receive
(
:bits
).
and_return
64
expect
(
Hardware
::
CPU
.
can_run?
(
:ppc
)).
to
be
true
expect
(
Hardware
::
CPU
.
can_run?
(
:ppc64
)).
to
be
true
end
it
"reports that 32-bit Intel Macs can't run x86_64 executables"
do
allow
(
Hardware
::
CPU
).
to
receive
(
:type
).
and_return
:intel
allow
(
Hardware
::
CPU
).
to
receive
(
:bits
).
and_return
32
expect
(
Hardware
::
CPU
.
can_run?
(
:x86_64
)).
to
be
false
end
it
"reports that 32-bit PowerPC Macs can't run ppc64 executables"
do
allow
(
Hardware
::
CPU
).
to
receive
(
:type
).
and_return
:ppc
allow
(
Hardware
::
CPU
).
to
receive
(
:bits
).
and_return
32
expect
(
Hardware
::
CPU
.
can_run?
(
:ppc64
)).
to
be
false
end
it
"reports that Intel Macs can only run 32-bit PowerPC executables on 10.6 and older"
do
allow
(
Hardware
::
CPU
).
to
receive
(
:type
).
and_return
:intel
allow
(
OS
::
Mac
).
to
receive
(
:version
).
and_return
OS
::
Mac
::
Version
.
new
"10.6"
expect
(
Hardware
::
CPU
.
can_run?
(
:ppc
)).
to
be
true
allow
(
OS
::
Mac
).
to
receive
(
:version
).
and_return
OS
::
Mac
::
Version
.
new
"10.7"
expect
(
Hardware
::
CPU
.
can_run?
(
:ppc
)).
to
be
false
end
it
"reports that PowerPC Macs can't run Intel executables"
do
allow
(
Hardware
::
CPU
).
to
receive
(
:type
).
and_return
:ppc
expect
(
Hardware
::
CPU
.
can_run?
(
:i386
)).
to
be
false
expect
(
Hardware
::
CPU
.
can_run?
(
:x86_64
)).
to
be
false
end
it
"returns false for unknown CPU types"
do
allow
(
Hardware
::
CPU
).
to
receive
(
:type
).
and_return
:dunno
expect
(
Hardware
::
CPU
.
can_run?
(
:i386
)).
to
be
false
end
it
"returns false for unknown arches"
do
expect
(
Hardware
::
CPU
.
can_run?
(
:blah
)).
to
be
false
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment