Skip to content
Snippets Groups Projects
Commit b14f18ac authored by Massimiliano Culpo's avatar Massimiliano Culpo Committed by Todd Gamblin
Browse files

microarchitectures: look in /sbin and /usr/sbin for sysctl (#13365)

This PR ensures that on Darwin we always append /sbin and /usr/sbin to PATH, if they are not already present, when looking for sysctl.

* Make sure we look into /sbin and /usr/sbin for sysctl
* Refactor sysctl for better readability
* Remove marker to make test pass
parent 8808207d
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import collections import collections
import functools import functools
import os
import platform import platform
import re import re
import subprocess import subprocess
...@@ -75,32 +76,39 @@ def proc_cpuinfo(): ...@@ -75,32 +76,39 @@ def proc_cpuinfo():
return info return info
def check_output(args): def check_output(args, env):
output = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()[0] output = subprocess.Popen(
args, stdout=subprocess.PIPE, env=env
).communicate()[0]
return six.text_type(output.decode('utf-8')) return six.text_type(output.decode('utf-8'))
@info_dict(operating_system='Darwin') @info_dict(operating_system='Darwin')
def sysctl(): def sysctl_info_dict():
"""Returns a raw info dictionary parsing the output of sysctl.""" """Returns a raw info dictionary parsing the output of sysctl."""
# Make sure that /sbin and /usr/sbin are in PATH as sysctl is
info = {} # usually found there
info['vendor_id'] = check_output( child_environment = dict(os.environ.items())
['sysctl', '-n', 'machdep.cpu.vendor'] search_paths = child_environment.get('PATH', '').split(os.pathsep)
).strip() for additional_path in ('/sbin', '/usr/sbin'):
info['flags'] = check_output( if additional_path not in search_paths:
['sysctl', '-n', 'machdep.cpu.features'] search_paths.append(additional_path)
).strip().lower() child_environment['PATH'] = os.pathsep.join(search_paths)
info['flags'] += ' ' + check_output(
['sysctl', '-n', 'machdep.cpu.leaf7_features'] def sysctl(*args):
).strip().lower() return check_output(
info['model'] = check_output( ['sysctl'] + list(args), env=child_environment
['sysctl', '-n', 'machdep.cpu.model']
).strip()
info['model name'] = check_output(
['sysctl', '-n', 'machdep.cpu.brand_string']
).strip() ).strip()
flags = (sysctl('-n', 'machdep.cpu.features').lower() + ' '
+ sysctl('-n', 'machdep.cpu.leaf7_features').lower())
info = {
'vendor_id': sysctl('-n', 'machdep.cpu.vendor'),
'flags': flags,
'model': sysctl('-n', 'machdep.cpu.model'),
'model name': sysctl('-n', 'machdep.cpu.brand_string')
}
# Super hacky way to deal with slight representation differences # Super hacky way to deal with slight representation differences
# Would be better to somehow consider these "identical" # Would be better to somehow consider these "identical"
if 'sse4.1' in info['flags']: if 'sse4.1' in info['flags']:
......
...@@ -24,7 +24,7 @@ def no_compilers_yaml(mutable_config, monkeypatch): ...@@ -24,7 +24,7 @@ def no_compilers_yaml(mutable_config, monkeypatch):
os.remove(compilers_yaml) os.remove(compilers_yaml)
@pytest.mark.regression('11678') @pytest.mark.regression('11678,13138')
def test_compiler_find_without_paths(no_compilers_yaml, working_env, tmpdir): def test_compiler_find_without_paths(no_compilers_yaml, working_env, tmpdir):
with tmpdir.as_cwd(): with tmpdir.as_cwd():
with open('gcc', 'w') as f: with open('gcc', 'w') as f:
......
...@@ -67,7 +67,7 @@ def _open(not_used_arg): ...@@ -67,7 +67,7 @@ def _open(not_used_arg):
key, value = line.split(':') key, value = line.split(':')
info[key.strip()] = value.strip() info[key.strip()] = value.strip()
def _check_output(args): def _check_output(args, env):
current_key = args[-1] current_key = args[-1]
return info[current_key] return info[current_key]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment