summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Salmon <will.salmon@codethink.co.uk>2018-09-13 16:47:44 +0100
committerWilliam Salmon <will.salmon@codethink.co.uk>2018-09-14 11:48:06 +0100
commite60c72ee31a84ee6473591c5e39f643a5fd383d2 (patch)
tree9fcc6619b6a4ca74dfab51f37dce6fe7c12064e0
parent3b81d4510656fcff808e4c37e29ac4a2f5e38de6 (diff)
downloadbuildstream-e60c72ee31a84ee6473591c5e39f643a5fd383d2.tar.gz
Bug: CWD was not being created for workspaces
The code was creating the cwd folder but when the workspace was mounted in to the buildroot it was hiding the folder created in it behind the bind mounted workspace. However buy using the bubble warp `--dir` directive to ensure that cwd exists then we can cover both workspace and non workspace situation with the same method.
-rw-r--r--buildstream/sandbox/_sandboxbwrap.py12
-rw-r--r--buildstream/sandbox/sandbox.py5
2 files changed, 9 insertions, 8 deletions
diff --git a/buildstream/sandbox/_sandboxbwrap.py b/buildstream/sandbox/_sandboxbwrap.py
index 88b697dca..8ba1ff824 100644
--- a/buildstream/sandbox/_sandboxbwrap.py
+++ b/buildstream/sandbox/_sandboxbwrap.py
@@ -120,9 +120,6 @@ class SandboxBwrap(Sandbox):
bwrap_command += ['--unshare-uts', '--hostname', 'buildstream']
bwrap_command += ['--unshare-ipc']
- if cwd is not None:
- bwrap_command += ['--chdir', cwd]
-
# Give it a proc and tmpfs
bwrap_command += [
'--proc', '/proc',
@@ -163,6 +160,10 @@ class SandboxBwrap(Sandbox):
if flags & SandboxFlags.ROOT_READ_ONLY:
bwrap_command += ["--remount-ro", "/"]
+ if cwd is not None:
+ bwrap_command += ['--dir', cwd]
+ bwrap_command += ['--chdir', cwd]
+
# Set UID and GUI
if self.user_ns_available:
bwrap_command += ['--unshare-user']
@@ -191,11 +192,6 @@ class SandboxBwrap(Sandbox):
with ExitStack() as stack:
stack.enter_context(mount_map.mounted(self))
- # Ensure the cwd exists
- if cwd is not None:
- workdir = os.path.join(root_mount_source, cwd.lstrip(os.sep))
- os.makedirs(workdir, exist_ok=True)
-
# If we're interactive, we want to inherit our stdin,
# otherwise redirect to /dev/null, ensuring process
# disconnected from terminal.
diff --git a/buildstream/sandbox/sandbox.py b/buildstream/sandbox/sandbox.py
index 9d34f0195..9192df7c2 100644
--- a/buildstream/sandbox/sandbox.py
+++ b/buildstream/sandbox/sandbox.py
@@ -197,6 +197,11 @@ class Sandbox():
def run(self, command, flags, *, cwd=None, env=None):
"""Run a command in the sandbox.
+ Note:
+ When reimplementing this function for sandbox specific implementations it is the sandbox's and probably
+ this functions responsibility to ensure that cwd is created correctly and that if a workspace is used
+ then the directory must be correctly created to take this in to account.
+
Args:
command (list): The command to run in the sandboxed environment, as a list
of strings starting with the binary to run.