diff options
author | Jürg Billeter <j@bitron.ch> | 2020-02-11 19:01:07 +0100 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2020-04-28 19:18:57 +0200 |
commit | 312afad28c51551bf13c904e62c3e7bfeb5f8929 (patch) | |
tree | 8eabfe59091e198d9e2e5dcb1d6f4ca3fd4efbfe | |
parent | eada71cb4d6bfce85d9d1481c9f25f8b777a9bc6 (diff) | |
download | buildstream-312afad28c51551bf13c904e62c3e7bfeb5f8929.tar.gz |
Switch preferred sandbox from bwrap to buildbox-run
This also enables local builds on non-Linux platforms, if a buildbox-run
implementation is available.
-rw-r--r-- | src/buildstream/_platform/linux.py | 2 | ||||
-rw-r--r-- | src/buildstream/_platform/platform.py | 6 | ||||
-rw-r--r-- | src/buildstream/testing/_utils/site.py | 11 | ||||
-rw-r--r-- | tests/sandboxes/fallback.py | 68 | ||||
-rw-r--r-- | tests/sandboxes/missing_dependencies.py | 42 | ||||
-rw-r--r-- | tests/sandboxes/selection.py | 6 |
6 files changed, 13 insertions, 122 deletions
diff --git a/src/buildstream/_platform/linux.py b/src/buildstream/_platform/linux.py index 670cfc6b9..74d0e1227 100644 --- a/src/buildstream/_platform/linux.py +++ b/src/buildstream/_platform/linux.py @@ -35,7 +35,7 @@ class Linux(Platform): } preferred_sandboxes = [ - "bwrap", + "buildbox-run", ] self._try_sandboxes(force_sandbox, sandbox_setups, preferred_sandboxes) diff --git a/src/buildstream/_platform/platform.py b/src/buildstream/_platform/platform.py index ad967604f..d0debfc7b 100644 --- a/src/buildstream/_platform/platform.py +++ b/src/buildstream/_platform/platform.py @@ -47,7 +47,11 @@ class Platform: def _setup_sandbox(self, force_sandbox): # The buildbox-run interface is not platform-specific sandbox_setups = {"buildbox-run": self.setup_buildboxrun_sandbox, "dummy": self._setup_dummy_sandbox} - preferred_sandboxes = [] + + preferred_sandboxes = [ + "buildbox-run", + ] + self._try_sandboxes(force_sandbox, sandbox_setups, preferred_sandboxes) def _try_sandboxes(self, force_sandbox, sandbox_setups, preferred_sandboxes): diff --git a/src/buildstream/testing/_utils/site.py b/src/buildstream/testing/_utils/site.py index 37c807d65..9f0e7aa41 100644 --- a/src/buildstream/testing/_utils/site.py +++ b/src/buildstream/testing/_utils/site.py @@ -5,7 +5,6 @@ import os import stat import subprocess import sys -import platform from typing import Optional # pylint: disable=unused-import from buildstream import _site, utils, ProgramNotFoundError @@ -64,24 +63,18 @@ CASD_SEPARATE_USER = bool(os.stat(casd_path).st_mode & stat.S_ISUID) del casd_path 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" MACHINE_ARCH = Platform.get_host_arch() HAVE_SANDBOX = os.getenv("BST_FORCE_SANDBOX") -if HAVE_SANDBOX is not None: - pass -elif IS_LINUX and HAVE_BWRAP and (not IS_WSL): - HAVE_SANDBOX = "bwrap" - - BUILDBOX_RUN = None -if HAVE_SANDBOX == "buildbox-run": +if HAVE_SANDBOX is None: try: path = utils.get_host_tool("buildbox-run") subprocess.run([path, "--capabilities"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) BUILDBOX_RUN = os.path.basename(os.readlink(path)) + HAVE_SANDBOX = "buildbox-run" except (ProgramNotFoundError, OSError, subprocess.CalledProcessError): pass diff --git a/tests/sandboxes/fallback.py b/tests/sandboxes/fallback.py deleted file mode 100644 index 0fd8ed4aa..000000000 --- a/tests/sandboxes/fallback.py +++ /dev/null @@ -1,68 +0,0 @@ -# -# Copyright (C) 2019 Bloomberg Finance LP -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library. If not, see <http://www.gnu.org/licenses/>. -# Pylint doesn't play well with fixtures and dependency injection from pytest -# pylint: disable=redefined-outer-name - -import os -import pytest - -from buildstream import _yaml -from buildstream.exceptions import ErrorDomain -from buildstream.testing import cli # pylint: disable=unused-import - -pytestmark = pytest.mark.integration - - -DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project") - - -@pytest.mark.datafiles(DATA_DIR) -def test_fallback_platform_fails(cli, datafiles): - project = str(datafiles) - element_path = os.path.join(project, "elements", "element.bst") - - # Write out our test target - element = { - "kind": "script", - "depends": [{"filename": "base.bst", "type": "build",},], - "config": {"commands": ["true",],}, - } - _yaml.roundtrip_dump(element, element_path) - - result = cli.run( - project=project, - args=["build", "element.bst"], - env={"BST_FORCE_BACKEND": "fallback", "BST_FORCE_SANDBOX": None}, - ) - result.assert_main_error(ErrorDomain.STREAM, None) - assert "FallBack platform only implements dummy sandbox" in result.stderr - # The dummy sandbox can not build the element but it can get the element read - # There for the element should be `buildable` rather than `waiting` - assert cli.get_element_state(project, "element.bst") == "buildable" - - -@pytest.mark.datafiles(DATA_DIR) -def test_fallback_platform_can_use_dummy(cli, datafiles): - project = str(datafiles) - - result = cli.run( - project=project, - args=["build", "import-file1.bst"], - env={"BST_FORCE_BACKEND": "fallback", "BST_FORCE_SANDBOX": None}, - ) - result.assert_success() - # The fallback platform can still provide a dummy sandbox that alows simple elemnts that do not need - # a full sandbox to still be built on new platforms. diff --git a/tests/sandboxes/missing_dependencies.py b/tests/sandboxes/missing_dependencies.py index 2e96a1b1f..fb9fdafb9 100644 --- a/tests/sandboxes/missing_dependencies.py +++ b/tests/sandboxes/missing_dependencies.py @@ -24,7 +24,7 @@ def _symlink_host_tools_to_dir(host_tools, dir_): @pytest.mark.skipif(not IS_LINUX, reason="Only available on Linux") @pytest.mark.datafiles(DATA_DIR) -def test_missing_bwrap_has_nice_error_message(cli, datafiles, tmp_path): +def test_missing_buildbox_run_has_nice_error_message(cli, datafiles, tmp_path): # Create symlink to buildbox-casd and git to work with custom PATH bin_dir = tmp_path / "bin" _symlink_host_tools_to_dir(["buildbox-casd", "git"], bin_dir) @@ -46,43 +46,3 @@ def test_missing_bwrap_has_nice_error_message(cli, datafiles, tmp_path): ) result.assert_task_error(ErrorDomain.SANDBOX, "unavailable-local-sandbox") assert "not found" in result.stderr - - -@pytest.mark.skipif(not IS_LINUX, reason="Only available on Linux") -@pytest.mark.datafiles(DATA_DIR) -def test_old_brwap_has_nice_error_message(cli, datafiles, tmp_path): - bwrap = tmp_path.joinpath("bin/bwrap") - bwrap.parent.mkdir() - with bwrap.open("w") as fp: - fp.write( - """ - #!/bin/sh - echo bubblewrap 0.0.1 - """.strip() - ) - - bwrap.chmod(0o755) - - # Create symlink to buildbox-casd and git to work with custom PATH - bin_dir = tmp_path / "bin" - _symlink_host_tools_to_dir(["buildbox-casd", "git"], bin_dir) - - project = str(datafiles) - element_path = os.path.join(project, "elements", "element3.bst") - - # Write out our test target - element = { - "kind": "script", - "depends": [{"filename": "base.bst", "type": "build",},], - "config": {"commands": ["false",],}, - } - _yaml.roundtrip_dump(element, element_path) - - # Build without access to host tools, this should fail with a nice error - result = cli.run( - project=project, - args=["--debug", "--verbose", "build", "element3.bst"], - env={"PATH": str(bin_dir), "BST_FORCE_SANDBOX": None}, - ) - result.assert_task_error(ErrorDomain.SANDBOX, "unavailable-local-sandbox") - assert "too old" in result.stderr diff --git a/tests/sandboxes/selection.py b/tests/sandboxes/selection.py index daee6dcdd..3e6e1c4f5 100644 --- a/tests/sandboxes/selection.py +++ b/tests/sandboxes/selection.py @@ -43,9 +43,11 @@ def test_force_sandbox(cli, datafiles): _yaml.roundtrip_dump(element, element_path) # Build without access to host tools, this will fail - result = cli.run(project=project, args=["build", "element.bst"], env={"PATH": "", "BST_FORCE_SANDBOX": "bwrap"}) + result = cli.run( + project=project, args=["build", "element.bst"], env={"PATH": "", "BST_FORCE_SANDBOX": "buildbox-run"} + ) result.assert_main_error(ErrorDomain.PLATFORM, None) - assert "Bubblewrap not found" in result.stderr + assert "buildbox-run not found" in result.stderr # we have asked for a spesific sand box, but it is not avalble so # bst should fail early and the element should be waiting assert cli.get_element_state(project, "element.bst") == "waiting" |