Skip to content
Snippets Groups Projects
Commit 6be25d8e authored by William Salmon's avatar William Salmon
Browse files

Sandbox: 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 by using the bubblewarp `--dir` directive to ensure that cwd
exists we can cover both workspace and non workspace situations with
the same method.
parent 350c6796
No related branches found
No related tags found
No related merge requests found
......@@ -108,9 +108,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',
......@@ -151,6 +148,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']
......@@ -179,11 +180,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.
......
......@@ -100,9 +100,8 @@ class SandboxChroot(Sandbox):
# Ensure the cwd exists
if cwd is not None:
workdir = os.path.join(root_mount_source, cwd.lstrip(os.sep))
workdir = os.path.join(rootfs, cwd.lstrip(os.sep))
os.makedirs(workdir, exist_ok=True)
status = self.chroot(rootfs, command, stdin, stdout,
stderr, cwd, env, flags)
......
......@@ -223,7 +223,9 @@ class Sandbox():
.. note::
The optional *cwd* argument will default to the value set with
:func:`~buildstream.sandbox.Sandbox.set_work_directory`
:func:`~buildstream.sandbox.Sandbox.set_work_directory` and this
function must make sure the directory will be created if it does
not exist yet, even if a workspace is being used.
"""
raise ImplError("Sandbox of type '{}' does not implement run()"
.format(type(self).__name__))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment