From c30f4a56e1f802f338e4b248b2ba925e479d3418 Mon Sep 17 00:00:00 2001 From: Phil Dawson Date: Tue, 26 Mar 2019 09:46:32 +0000 Subject: plugintestutils._utils: Copy subset of tests.testutils.site A subset of the functionality provided by this module is not available from buildstream._site but is necessary for the templated source plugin tests. --- buildstream/plugintestutils/_utils/site.py | 46 +++++++++++++++++++++++++++++ tests/sources/generic/source_determinism.py | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 buildstream/plugintestutils/_utils/site.py diff --git a/buildstream/plugintestutils/_utils/site.py b/buildstream/plugintestutils/_utils/site.py new file mode 100644 index 000000000..54c5b467b --- /dev/null +++ b/buildstream/plugintestutils/_utils/site.py @@ -0,0 +1,46 @@ +# Some things resolved about the execution site, +# so we dont have to repeat this everywhere +# +import os +import sys +import platform + +from buildstream import _site, utils, ProgramNotFoundError + + +try: + GIT = utils.get_host_tool('git') + HAVE_GIT = True + GIT_ENV = { + 'GIT_AUTHOR_DATE': '1320966000 +0200', + 'GIT_AUTHOR_NAME': 'tomjon', + 'GIT_AUTHOR_EMAIL': 'tom@jon.com', + 'GIT_COMMITTER_DATE': '1320966000 +0200', + 'GIT_COMMITTER_NAME': 'tomjon', + 'GIT_COMMITTER_EMAIL': 'tom@jon.com' + } +except ProgramNotFoundError: + GIT = None + HAVE_GIT = False + GIT_ENV = dict() + +try: + utils.get_host_tool('bwrap') + HAVE_BWRAP = True + HAVE_BWRAP_JSON_STATUS = _site.get_bwrap_version() >= (0, 3, 2) +except ProgramNotFoundError: + HAVE_BWRAP = False + HAVE_BWRAP_JSON_STATUS = False + +IS_LINUX = os.getenv('BST_FORCE_BACKEND', sys.platform).startswith('linux') +IS_WSL = (IS_LINUX and 'Microsoft' in platform.uname().release) +IS_WINDOWS = (os.name == 'nt') + +if not IS_LINUX: + HAVE_SANDBOX = True # fallback to a chroot sandbox on unix +elif IS_WSL: + HAVE_SANDBOX = False # Sandboxes are inoperable under WSL due to lack of FUSE +elif IS_LINUX and HAVE_BWRAP: + HAVE_SANDBOX = True +else: + HAVE_SANDBOX = False diff --git a/tests/sources/generic/source_determinism.py b/tests/sources/generic/source_determinism.py index e3203a891..bd83da007 100644 --- a/tests/sources/generic/source_determinism.py +++ b/tests/sources/generic/source_determinism.py @@ -22,7 +22,7 @@ import os import pytest -from tests.testutils.site import HAVE_SANDBOX +from .._utils.site import HAVE_SANDBOX from buildstream.plugintestutils import create_repo, ALL_REPO_KINDS from buildstream.plugintestutils import cli # pylint: disable=unused-import -- cgit v1.2.1