diff options
author | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2018-10-11 11:18:15 +0100 |
---|---|---|
committer | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2018-10-30 15:42:05 +0000 |
commit | 825963b5cf7e6f2b116c0ed45300e52d178c691a (patch) | |
tree | ec35c792c2277737e101fb12abbcab81de65a995 /buildstream | |
parent | ec76cbe1b2c8fb73e3d3b402623715b56ade777f (diff) | |
download | buildstream-825963b5cf7e6f2b116c0ed45300e52d178c691a.tar.gz |
element: Make "--sysroot" take a bare directory
i.e. instead of taking a directory that must contain "root" and
"scratch", and treating "root" as the root, use the directory directly.
In element.py:
* __sandbox takes the `bare_sandbox` arg, to pass into the sandbox's constructor
In sandbox.py:
* If bare_sandbox, `_root` is the passed-in directory, and `__scratch`
is None.
* Trying to use `__scratch` when bare_sandbox is True is a bug.
In _mount.py:
* Don't get the value of `__scratch` if it's not needed.
This is part of #539
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/element.py | 11 | ||||
-rw-r--r-- | buildstream/sandbox/_mount.py | 2 | ||||
-rw-r--r-- | buildstream/sandbox/sandbox.py | 17 |
3 files changed, 22 insertions, 8 deletions
diff --git a/buildstream/element.py b/buildstream/element.py index 83d7f9705..27c5014a3 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -1318,7 +1318,9 @@ class Element(Plugin): @contextmanager def _prepare_sandbox(self, scope, directory, deps='run', integrate=True): # bst shell and bst checkout require a local sandbox. - with self.__sandbox(directory, config=self.__sandbox_config, allow_remote=False) as sandbox: + bare_directory = True if directory else False + with self.__sandbox(directory, config=self.__sandbox_config, allow_remote=False, + bare_directory=bare_directory) as sandbox: # Configure always comes first, and we need it. self.configure_sandbox(sandbox) @@ -2156,12 +2158,14 @@ class Element(Plugin): # stderr (fileobject): The stream for stderr for the sandbox # config (SandboxConfig): The SandboxConfig object # allow_remote (bool): Whether the sandbox is allowed to be remote + # bare_directory (bool): Whether the directory is bare i.e. doesn't have + # a separate 'root' subdir # # Yields: # (Sandbox): A usable sandbox # @contextmanager - def __sandbox(self, directory, stdout=None, stderr=None, config=None, allow_remote=True): + def __sandbox(self, directory, stdout=None, stderr=None, config=None, allow_remote=True, bare_directory=False): context = self._get_context() project = self._get_project() platform = Platform.get_platform() @@ -2192,6 +2196,7 @@ class Element(Plugin): stdout=stdout, stderr=stderr, config=config, + bare_directory=bare_directory, allow_real_directory=not self.BST_VIRTUAL_DIRECTORY) yield sandbox @@ -2201,7 +2206,7 @@ class Element(Plugin): # Recursive contextmanager... with self.__sandbox(rootdir, stdout=stdout, stderr=stderr, config=config, - allow_remote=allow_remote) as sandbox: + allow_remote=allow_remote, bare_directory=False) as sandbox: yield sandbox # Cleanup the build dir diff --git a/buildstream/sandbox/_mount.py b/buildstream/sandbox/_mount.py index aff9e8a2d..c0f26c8d7 100644 --- a/buildstream/sandbox/_mount.py +++ b/buildstream/sandbox/_mount.py @@ -31,7 +31,6 @@ from .._fuse import SafeHardlinks # class Mount(): def __init__(self, sandbox, mount_point, safe_hardlinks, fuse_mount_options=None): - scratch_directory = sandbox._get_scratch_directory() # Getting _get_underlying_directory() here is acceptable as # we're part of the sandbox code. This will fail if our # directory is CAS-based. @@ -51,6 +50,7 @@ class Mount(): # a regular mount point within the parent's redirected mount. # if self.safe_hardlinks: + scratch_directory = sandbox._get_scratch_directory() # Redirected mount self.mount_origin = os.path.join(root_directory, mount_point.lstrip(os.sep)) self.mount_base = os.path.join(scratch_directory, utils.url_directory_name(mount_point)) diff --git a/buildstream/sandbox/sandbox.py b/buildstream/sandbox/sandbox.py index 6aea4b54b..eabe57d75 100644 --- a/buildstream/sandbox/sandbox.py +++ b/buildstream/sandbox/sandbox.py @@ -98,15 +98,23 @@ class Sandbox(): self.__config = kwargs['config'] self.__stdout = kwargs['stdout'] self.__stderr = kwargs['stderr'] + self.__bare_directory = kwargs['bare_directory'] # Setup the directories. Root and output_directory should be # available to subclasses, hence being single-underscore. The # others are private to this class. - self._root = os.path.join(directory, 'root') + # If the directory is bare, it probably doesn't need scratch + if self.__bare_directory: + self._root = directory + self.__scratch = None + os.makedirs(self._root, exist_ok=True) + else: + self._root = os.path.join(directory, 'root') + self.__scratch = os.path.join(directory, 'scratch') + for directory_ in [self._root, self.__scratch]: + os.makedirs(directory_, exist_ok=True) + self._output_directory = None - self.__scratch = os.path.join(directory, 'scratch') - for directory_ in [self._root, self.__scratch]: - os.makedirs(directory_, exist_ok=True) self._vdir = None # This is set if anyone requests access to the underlying @@ -333,6 +341,7 @@ class Sandbox(): # Returns: # (str): The sandbox scratch directory def _get_scratch_directory(self): + assert not self.__bare_directory, "Scratch is not going to work with bare directories" return self.__scratch # _get_output() |