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
This commit is contained in:
parent
8808207ddf
commit
b14f18acda
3 changed files with 29 additions and 21 deletions
|
@ -4,6 +4,7 @@
|
|||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
import collections
|
||||
import functools
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import subprocess
|
||||
|
@ -75,32 +76,39 @@ def proc_cpuinfo():
|
|||
return info
|
||||
|
||||
|
||||
def check_output(args):
|
||||
output = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()[0]
|
||||
def check_output(args, env):
|
||||
output = subprocess.Popen(
|
||||
args, stdout=subprocess.PIPE, env=env
|
||||
).communicate()[0]
|
||||
return six.text_type(output.decode('utf-8'))
|
||||
|
||||
|
||||
@info_dict(operating_system='Darwin')
|
||||
def sysctl():
|
||||
def sysctl_info_dict():
|
||||
"""Returns a raw info dictionary parsing the output of sysctl."""
|
||||
# Make sure that /sbin and /usr/sbin are in PATH as sysctl is
|
||||
# usually found there
|
||||
child_environment = dict(os.environ.items())
|
||||
search_paths = child_environment.get('PATH', '').split(os.pathsep)
|
||||
for additional_path in ('/sbin', '/usr/sbin'):
|
||||
if additional_path not in search_paths:
|
||||
search_paths.append(additional_path)
|
||||
child_environment['PATH'] = os.pathsep.join(search_paths)
|
||||
|
||||
info = {}
|
||||
info['vendor_id'] = check_output(
|
||||
['sysctl', '-n', 'machdep.cpu.vendor']
|
||||
).strip()
|
||||
info['flags'] = check_output(
|
||||
['sysctl', '-n', 'machdep.cpu.features']
|
||||
).strip().lower()
|
||||
info['flags'] += ' ' + check_output(
|
||||
['sysctl', '-n', 'machdep.cpu.leaf7_features']
|
||||
).strip().lower()
|
||||
info['model'] = check_output(
|
||||
['sysctl', '-n', 'machdep.cpu.model']
|
||||
).strip()
|
||||
info['model name'] = check_output(
|
||||
['sysctl', '-n', 'machdep.cpu.brand_string']
|
||||
def sysctl(*args):
|
||||
return check_output(
|
||||
['sysctl'] + list(args), env=child_environment
|
||||
).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
|
||||
# Would be better to somehow consider these "identical"
|
||||
if 'sse4.1' in info['flags']:
|
||||
|
|
|
@ -24,7 +24,7 @@ def no_compilers_yaml(mutable_config, monkeypatch):
|
|||
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):
|
||||
with tmpdir.as_cwd():
|
||||
with open('gcc', 'w') as f:
|
||||
|
|
|
@ -67,7 +67,7 @@ def _open(not_used_arg):
|
|||
key, value = line.split(':')
|
||||
info[key.strip()] = value.strip()
|
||||
|
||||
def _check_output(args):
|
||||
def _check_output(args, env):
|
||||
current_key = args[-1]
|
||||
return info[current_key]
|
||||
|
||||
|
|
Loading…
Reference in a new issue