summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngelos Evripiotis <jevripiotis@bloomberg.net>2019-03-27 11:31:05 +0000
committerAngelos Evripiotis <angelos.evripiotis@gmail.com>2019-04-11 13:58:33 +0000
commit0d4e40d96c773fdc769069fed4d5c654ba6d25f0 (patch)
tree14ee5d7a335cb9cd592cf098fec1de04ec7952ae
parent9a9b06a5b52ced084b447c0468617e963555e068 (diff)
downloadbuildstream-0d4e40d96c773fdc769069fed4d5c654ba6d25f0.tar.gz
Use platform.uname instead of os.uname for win32
The 'platform' module in the standard library provides a more portable version of uname(), which also works on Windows. In CPython, the platform version is implemented in terms of the os version: https://github.com/python/cpython/blob/60875db2f67815d7d181c552bfac59e8c97619e3/Lib/platform.py#L747
-rw-r--r--buildstream/_options/optionos.py4
-rw-r--r--buildstream/_platform/platform.py5
-rw-r--r--tests/format/optionarch.py10
-rw-r--r--tests/format/optionos.py6
-rw-r--r--tests/testutils/__init__.py2
-rw-r--r--tests/testutils/platform.py20
6 files changed, 23 insertions, 24 deletions
diff --git a/buildstream/_options/optionos.py b/buildstream/_options/optionos.py
index e76cf177c..501ad6046 100644
--- a/buildstream/_options/optionos.py
+++ b/buildstream/_options/optionos.py
@@ -18,7 +18,7 @@
# Authors:
# Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>
-import os
+import platform
from .optionenum import OptionEnum
@@ -32,7 +32,7 @@ class OptionOS(OptionEnum):
super(OptionOS, self).load(node, allow_default_definition=False)
def load_default_value(self, node):
- return os.uname()[0]
+ return platform.uname()[0]
def resolve(self):
diff --git a/buildstream/_platform/platform.py b/buildstream/_platform/platform.py
index eef07812a..eae464682 100644
--- a/buildstream/_platform/platform.py
+++ b/buildstream/_platform/platform.py
@@ -18,6 +18,7 @@
# Tristan Maat <tristan.maat@codethink.co.uk>
import os
+import platform
import sys
import resource
@@ -75,7 +76,7 @@ class Platform():
@staticmethod
def get_host_os():
- return os.uname()[0]
+ return platform.uname()[0]
# canonicalize_arch():
#
@@ -122,7 +123,7 @@ class Platform():
@staticmethod
def get_host_arch():
# get the hardware identifier from uname
- uname_machine = os.uname()[4]
+ uname_machine = platform.uname()[4]
return Platform.canonicalize_arch(uname_machine)
##################################################################
diff --git a/tests/format/optionarch.py b/tests/format/optionarch.py
index 3f779e5ea..a7d38c8be 100644
--- a/tests/format/optionarch.py
+++ b/tests/format/optionarch.py
@@ -9,7 +9,7 @@ from buildstream import _yaml
from buildstream._exceptions import ErrorDomain, LoadErrorReason
from buildstream.plugintestutils.runcli import cli # pylint: disable=unused-import
-from tests.testutils import override_os_uname
+from tests.testutils import override_platform_uname
# Project directory
DATA_DIR = os.path.dirname(os.path.realpath(__file__))
@@ -31,7 +31,7 @@ DATA_DIR = os.path.dirname(os.path.realpath(__file__))
('x86_64', 'aarch64', 'Aarchy'),
])
def test_conditional(cli, datafiles, machine, value, expected):
- with override_os_uname(machine=machine):
+ with override_platform_uname(machine=machine):
project = os.path.join(datafiles.dirname, datafiles.basename, 'option-arch')
bst_args = []
@@ -54,7 +54,7 @@ def test_conditional(cli, datafiles, machine, value, expected):
@pytest.mark.datafiles(DATA_DIR)
def test_unsupported_arch(cli, datafiles):
- with override_os_uname(machine="x86_64"):
+ with override_platform_uname(machine="x86_64"):
project = os.path.join(datafiles.dirname, datafiles.basename, 'option-arch')
result = cli.run(project=project, silent=True, args=[
'show',
@@ -69,7 +69,7 @@ def test_unsupported_arch(cli, datafiles):
@pytest.mark.datafiles(DATA_DIR)
def test_alias(cli, datafiles):
- with override_os_uname(machine="arm"):
+ with override_platform_uname(machine="arm"):
project = os.path.join(datafiles.dirname, datafiles.basename, 'option-arch-alias')
result = cli.run(project=project, silent=True, args=[
'show',
@@ -84,7 +84,7 @@ def test_alias(cli, datafiles):
@pytest.mark.datafiles(DATA_DIR)
def test_unknown_host_arch(cli, datafiles):
- with override_os_uname(machine="x86_128"):
+ with override_platform_uname(machine="x86_128"):
project = os.path.join(datafiles.dirname, datafiles.basename, 'option-arch')
result = cli.run(project=project, silent=True, args=[
'show',
diff --git a/tests/format/optionos.py b/tests/format/optionos.py
index a4e2a6cf9..6856fd69c 100644
--- a/tests/format/optionos.py
+++ b/tests/format/optionos.py
@@ -9,7 +9,7 @@ from buildstream import _yaml
from buildstream._exceptions import ErrorDomain, LoadErrorReason
from buildstream.plugintestutils.runcli import cli # pylint: disable=unused-import
-from tests.testutils import override_os_uname
+from tests.testutils import override_platform_uname
DATA_DIR = os.path.dirname(os.path.realpath(__file__))
@@ -30,7 +30,7 @@ DATA_DIR = os.path.dirname(os.path.realpath(__file__))
('HaikuOS', 'SunOS', 'SunOSy'),
])
def test_conditionals(cli, datafiles, system, value, expected):
- with override_os_uname(system=system):
+ with override_platform_uname(system=system):
project = os.path.join(datafiles.dirname, datafiles.basename, 'option-os')
bst_args = []
@@ -53,7 +53,7 @@ def test_conditionals(cli, datafiles, system, value, expected):
@pytest.mark.datafiles(DATA_DIR)
def test_unsupported_arch(cli, datafiles):
- with override_os_uname(system="AIX"):
+ with override_platform_uname(system="AIX"):
project = os.path.join(datafiles.dirname, datafiles.basename, 'option-os')
result = cli.run(project=project, silent=True, args=[
'show',
diff --git a/tests/testutils/__init__.py b/tests/testutils/__init__.py
index 31912fed9..929ffc5f2 100644
--- a/tests/testutils/__init__.py
+++ b/tests/testutils/__init__.py
@@ -30,4 +30,4 @@ from .junction import generate_junction
from .runner_integration import wait_for_cache_granularity
from .python_repo import setup_pypi_repo
from .yaml import yaml_file_get_provenance
-from .platform import override_os_uname
+from .platform import override_platform_uname
diff --git a/tests/testutils/platform.py b/tests/testutils/platform.py
index e00a131bd..f8faf286e 100644
--- a/tests/testutils/platform.py
+++ b/tests/testutils/platform.py
@@ -18,34 +18,32 @@
# Angelos Evripiotis <jevripiotis@bloomberg.net>
from contextlib import contextmanager
-import os
+import platform
# override_platform_uname()
#
-# Context manager to override the reported value of `os.uname()`.
+# Context manager to override the reported value of `platform.uname()`.
#
# Args:
# system (str): Optional str to replace the 1st entry of uname with.
# machine (str): Optional str to replace the 5th entry of uname with.
#
@contextmanager
-def override_os_uname(*, system=None, machine=None):
- orig_func = os.uname
- result = orig_func()
+def override_platform_uname(*, system=None, machine=None):
+ orig_func = platform.uname
+ result = platform.uname()
- result = list(result)
if system is not None:
- result[0] = system
+ result = result._replace(system=system)
if machine is not None:
- result[4] = machine
- result = tuple(result)
+ result = result._replace(machine=machine)
def override_func():
return result
- os.uname = override_func
+ platform.uname = override_func
try:
yield
finally:
- os.uname = orig_func
+ platform.uname = orig_func