diff options
author | Jim MacArthur <jim.macarthur@codethink.co.uk> | 2018-03-13 15:17:22 +0000 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2018-03-23 14:37:38 +0000 |
commit | f4d3892e4b7276f25599ce6e9fbae840ab10c833 (patch) | |
tree | 5f300f0851a2b28bd4e569cc2b6d2fa4a4964d7c /buildstream/element.py | |
parent | 7d92ef0f39f64eb7dfddb969d88487287733e5b2 (diff) | |
download | buildstream-f4d3892e4b7276f25599ce6e9fbae840ab10c833.tar.gz |
Add 'sandbox' configuration key and build-uid/build-gid elements
This only affects SandboxBWrap at the moment.
buildstream/_loader.py: Add Symbol.SANDBOX and allow it in validation
buildstream/_metaelement.py: Add 'sandbox' variable and store it in the object
buildstream/_project.py: Add 'sandbox' configuration key and load it from
project.conf.
buildstream/data/projectconfig.yaml: Default build-uid/build-gid values of 0
for 'sandbox'.
buildstream/element.py: Add __extract_sandbox_config to find the final sandbox
configuration. Pass this to the sandbox constructor.
buildstream/sandbox/_sandboxbwrap.py: If sandbox configuration was supplied,
use it for uid and gid instead of the default 0.
buildstream/sandbox/_sandboxchroot.py: Throw exception if non-0 uid/gid were
supplied.
buildstream/sandbox/__init__.py: Import SandboxConfig.
buildstream/sandbox/_private.py: New file, containing SandboxConfig. Made private
to avoid documentation for this class.
Diffstat (limited to 'buildstream/element.py')
-rw-r--r-- | buildstream/element.py | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/buildstream/element.py b/buildstream/element.py index b62945f4b..57d3732e7 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -37,12 +37,13 @@ from . import _yaml from ._variables import Variables from ._exceptions import BstError, LoadError, LoadErrorReason, ImplError, ErrorDomain from . import Plugin, Consistency -from . import SandboxFlags +from . import Sandbox, SandboxFlags from . import utils from . import _cachekey from . import _signals from . import _site from ._platform import Platform +from .sandbox._config import SandboxConfig # The base BuildStream artifact version @@ -191,6 +192,9 @@ class Element(Plugin): self.__config = self.__extract_config(meta) self.configure(self.__config) + # Extract Sandbox config + self.__sandbox_config = self.__extract_sandbox_config(meta) + self.__tainted = None self.__workspaced_artifact = None self.__workspaced_dependencies_artifact = None @@ -1072,7 +1076,7 @@ class Element(Plugin): utils._force_rmtree(rootdir) with _signals.terminator(cleanup_rootdir), \ - self.__sandbox(rootdir, output_file, output_file) as sandbox: # nopep8 + self.__sandbox(rootdir, output_file, output_file, self.__sandbox_config) as sandbox: # nopep8 sandbox_root = sandbox.get_directory() @@ -1376,7 +1380,7 @@ class Element(Plugin): @contextmanager def _prepare_sandbox(self, scope, directory, integrate=True): - with self.__sandbox(directory) as sandbox: + with self.__sandbox(directory, config=self.__sandbox_config) as sandbox: # Configure always comes first, and we need it. self.configure_sandbox(sandbox) @@ -1694,7 +1698,7 @@ class Element(Plugin): # Private Local Methods # ############################################################# @contextmanager - def __sandbox(self, directory, stdout=None, stderr=None): + def __sandbox(self, directory, stdout=None, stderr=None, config=None): context = self._get_context() project = self._get_project() platform = Platform.get_platform() @@ -1703,7 +1707,8 @@ class Element(Plugin): sandbox = platform.create_sandbox(context, project, directory, stdout=stdout, - stderr=stderr) + stderr=stderr, + config=config) yield sandbox else: @@ -1711,7 +1716,7 @@ class Element(Plugin): rootdir = tempfile.mkdtemp(prefix="{}-".format(self.normal_name), dir=context.builddir) # Recursive contextmanager... - with self.__sandbox(rootdir, stdout=stdout, stderr=stderr) as sandbox: + with self.__sandbox(rootdir, stdout=stdout, stderr=stderr, config=config) as sandbox: yield sandbox # Cleanup the build dir @@ -1821,6 +1826,26 @@ class Element(Plugin): return config + # Sandbox-specific configuration data, to be passed to the sandbox's constructor. + # + def __extract_sandbox_config(self, meta): + project = self._get_project() + + # The default config is already composited with the project overrides + sandbox_defaults = _yaml.node_get(self.__defaults, Mapping, 'sandbox', default_value={}) + sandbox_defaults = _yaml.node_chain_copy(sandbox_defaults) + + sandbox_config = _yaml.node_chain_copy(project._sandbox) + _yaml.composite(sandbox_config, sandbox_defaults) + _yaml.composite(sandbox_config, meta.sandbox) + _yaml.node_final_assertions(sandbox_config) + + # Sandbox config, unlike others, has fixed members so we should validate them + _yaml.node_validate(sandbox_config, ['build-uid', 'build-gid']) + + return SandboxConfig(self.node_get_member(sandbox_config, int, 'build-uid'), + self.node_get_member(sandbox_config, int, 'build-gid')) + # This makes a special exception for the split rules, which # elements may extend but whos defaults are defined in the project. # |