diff options
author | Jürg Billeter <j@bitron.ch> | 2020-06-03 11:37:14 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2020-06-03 13:49:39 +0200 |
commit | 07275d01416b204bd578c1c3617fcbed8b6e30ed (patch) | |
tree | c7538d077b5bfd35c774c5c8d2041e79cdea274f | |
parent | 0b79b37a14cfa4db0d991ad2fbcb0891f49ef0b9 (diff) | |
download | buildstream-07275d01416b204bd578c1c3617fcbed8b6e30ed.tar.gz |
Drop sandbox selection and BST_FORCE_SANDBOX
buildbox-run is the only local sandbox and there are no plans to add
other sandboxing backends in the future. New platforms can be supported
by new buildbox-run implementations without requiring any changes in
BuildStream.
-rw-r--r-- | src/buildstream/_platform/linux.py | 11 | ||||
-rw-r--r-- | src/buildstream/_platform/platform.py | 63 | ||||
-rw-r--r-- | src/buildstream/testing/_utils/site.py | 19 | ||||
-rw-r--r-- | tests/integration/cachedfail.py | 6 | ||||
-rw-r--r-- | tests/sandboxes/missing_dependencies.py | 4 | ||||
-rw-r--r-- | tests/sandboxes/selection.py | 30 | ||||
-rw-r--r-- | tox.ini | 1 |
7 files changed, 22 insertions, 112 deletions
diff --git a/src/buildstream/_platform/linux.py b/src/buildstream/_platform/linux.py index 13fe0b64c..c6065b416 100644 --- a/src/buildstream/_platform/linux.py +++ b/src/buildstream/_platform/linux.py @@ -24,17 +24,6 @@ from .platform import Platform class Linux(Platform): - def _setup_sandbox(self, force_sandbox): - sandbox_setups = { - "buildbox-run": self.setup_buildboxrun_sandbox, - "dummy": self._setup_dummy_sandbox, - } - - preferred_sandboxes = [ - "buildbox-run", - ] - - self._try_sandboxes(force_sandbox, sandbox_setups, preferred_sandboxes) ################################################ # Private Methods # diff --git a/src/buildstream/_platform/platform.py b/src/buildstream/_platform/platform.py index 84d1fb231..8a1794cbf 100644 --- a/src/buildstream/_platform/platform.py +++ b/src/buildstream/_platform/platform.py @@ -35,53 +35,18 @@ class Platform: # A class to manage platform-specific details. Currently holds the # sandbox factory as well as platform helpers. # - # Args: - # force_sandbox (bool): Force bst to use a particular sandbox - # - def __init__(self, force_sandbox=None): + def __init__(self): self._local_sandbox = None self.dummy_reasons = [] - self._setup_sandbox(force_sandbox) - - 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 = [ - "buildbox-run", - ] - - self._try_sandboxes(force_sandbox, sandbox_setups, preferred_sandboxes) + self._setup_sandbox() - def _try_sandboxes(self, force_sandbox, sandbox_setups, preferred_sandboxes): - # Any sandbox from sandbox_setups can be forced by BST_FORCE_SANDBOX - # But if a specific sandbox is not forced then only `first class` sandbox are tried before - # falling back to the dummy sandbox. + def _setup_sandbox(self): + # Try to setup buildbox-run sandbox, otherwise fallback to the dummy sandbox. # Where `first_class` sandboxes are those in preferred_sandboxes - if force_sandbox: - try: - sandbox_setups[force_sandbox]() - except KeyError: - raise PlatformError( - "Forced Sandbox is unavailable on this platform: BST_FORCE_SANDBOX" - " is set to {} but it is not available".format(force_sandbox) - ) - except SandboxError as Error: - raise PlatformError( - "Forced Sandbox Error: BST_FORCE_SANDBOX" - " is set to {} but cannot be setup".format(force_sandbox), - detail=" and ".join(self.dummy_reasons), - ) from Error - else: - for good_sandbox in preferred_sandboxes: - try: - sandbox_setups[good_sandbox]() - return - except SandboxError: - continue - except utils.ProgramNotFoundError: - continue - sandbox_setups["dummy"]() + try: + self._setup_buildboxrun_sandbox() + except (SandboxError, utils.ProgramNotFoundError): + self._setup_dummy_sandbox() def _check_sandbox(self, Sandbox): Sandbox._dummy_reasons = [] @@ -93,14 +58,6 @@ class Platform: @classmethod def create_instance(cls): - # Meant for testing purposes and therefore hidden in the - # deepest corners of the source code. Try not to abuse this, - # please? - if os.getenv("BST_FORCE_SANDBOX"): - force_sandbox = os.getenv("BST_FORCE_SANDBOX") - else: - force_sandbox = None - if os.getenv("BST_FORCE_BACKEND"): backend = os.getenv("BST_FORCE_BACKEND") elif sys.platform.startswith("darwin"): @@ -123,7 +80,7 @@ class Platform: else: raise PlatformError("No such platform: '{}'".format(backend)) - return PlatformImpl(force_sandbox=force_sandbox) + return PlatformImpl() def get_cpu_count(self, cap=None): # `psutil.Process.cpu_affinity()` is not available on all platforms. @@ -264,7 +221,7 @@ class Platform: return SandboxBuildBoxRun(*args, **kwargs) - def setup_buildboxrun_sandbox(self): + def _setup_buildboxrun_sandbox(self): from ..sandbox._sandboxbuildboxrun import SandboxBuildBoxRun # pylint: disable=cyclic-import self._check_sandbox(SandboxBuildBoxRun) diff --git a/src/buildstream/testing/_utils/site.py b/src/buildstream/testing/_utils/site.py index 70d23a5cc..577896fe5 100644 --- a/src/buildstream/testing/_utils/site.py +++ b/src/buildstream/testing/_utils/site.py @@ -59,14 +59,13 @@ IS_WINDOWS = os.name == "nt" MACHINE_ARCH = Platform.get_host_arch() -HAVE_SANDBOX = os.getenv("BST_FORCE_SANDBOX") - +HAVE_SANDBOX = None BUILDBOX_RUN = None -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 + +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/integration/cachedfail.py b/tests/integration/cachedfail.py index 68c59569d..f72c315d5 100644 --- a/tests/integration/cachedfail.py +++ b/tests/integration/cachedfail.py @@ -202,11 +202,7 @@ def test_host_tools_errors_are_not_cached(cli, datafiles, tmp_path): _yaml.roundtrip_dump(element, element_path) # Build without access to host tools, this will fail - result1 = cli.run( - project=project, - args=["build", "element.bst"], - env={"PATH": str(tmp_path.joinpath("bin")), "BST_FORCE_SANDBOX": None}, - ) + result1 = cli.run(project=project, args=["build", "element.bst"], env={"PATH": str(tmp_path.joinpath("bin"))},) result1.assert_task_error(ErrorDomain.SANDBOX, "unavailable-local-sandbox") assert cli.get_element_state(project, "element.bst") == "buildable" diff --git a/tests/sandboxes/missing_dependencies.py b/tests/sandboxes/missing_dependencies.py index fb9fdafb9..7ac7d7868 100644 --- a/tests/sandboxes/missing_dependencies.py +++ b/tests/sandboxes/missing_dependencies.py @@ -41,8 +41,6 @@ def test_missing_buildbox_run_has_nice_error_message(cli, datafiles, tmp_path): _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=["build", "element.bst"], env={"PATH": str(bin_dir), "BST_FORCE_SANDBOX": None} - ) + result = cli.run(project=project, args=["build", "element.bst"], env={"PATH": str(bin_dir)}) result.assert_task_error(ErrorDomain.SANDBOX, "unavailable-local-sandbox") assert "not found" in result.stderr diff --git a/tests/sandboxes/selection.py b/tests/sandboxes/selection.py index 3e6e1c4f5..0118fb5e0 100644 --- a/tests/sandboxes/selection.py +++ b/tests/sandboxes/selection.py @@ -30,30 +30,6 @@ DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project") @pytest.mark.datafiles(DATA_DIR) -def test_force_sandbox(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) - - # Build without access to host tools, this will fail - result = cli.run( - project=project, args=["build", "element.bst"], env={"PATH": "", "BST_FORCE_SANDBOX": "buildbox-run"} - ) - result.assert_main_error(ErrorDomain.PLATFORM, None) - 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" - - -@pytest.mark.datafiles(DATA_DIR) def test_dummy_sandbox_fallback(cli, datafiles, tmp_path): # Create symlink to buildbox-casd to work with custom PATH buildbox_casd = tmp_path.joinpath("bin/buildbox-casd") @@ -72,11 +48,7 @@ def test_dummy_sandbox_fallback(cli, datafiles, tmp_path): _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": str(tmp_path.joinpath("bin")), "BST_FORCE_SANDBOX": None}, - ) + result = cli.run(project=project, args=["build", "element.bst"], env={"PATH": str(tmp_path.joinpath("bin"))},) # But if we dont spesify a sandbox then we fall back to dummy, we still # fail early but only once we know we need a facny sandbox and that # dumy is not enough, there for element gets fetched and so is buildable @@ -51,7 +51,6 @@ passenv = ARTIFACT_CACHE_SERVICE BST_CAS_STAGING_ROOT BST_FORCE_BACKEND - BST_FORCE_SANDBOX BST_FORCE_START_METHOD GI_TYPELIB_PATH INTEGRATION_CACHE |