diff options
author | William Salmon <will.salmon@codethink.co.uk> | 2018-09-13 16:47:44 +0100 |
---|---|---|
committer | Phil Dawson <phildawson.0807@gmail.com> | 2018-10-16 12:39:14 +0000 |
commit | 6298e4093d48845b4d49bd95505b44961f7d37bd (patch) | |
tree | 960e80e69b21f111c5d81741f28a158cba5623e2 | |
parent | 086c47c44b35c1041d39fafa4fed455ffd165433 (diff) | |
download | buildstream-6298e4093d48845b4d49bd95505b44961f7d37bd.tar.gz |
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.
For issue #512 in Gitlab.
-rw-r--r-- | buildstream/sandbox/_sandboxbwrap.py | 12 | ||||
-rw-r--r-- | buildstream/sandbox/_sandboxchroot.py | 3 | ||||
-rw-r--r-- | buildstream/sandbox/sandbox.py | 4 |
3 files changed, 8 insertions, 11 deletions
diff --git a/buildstream/sandbox/_sandboxbwrap.py b/buildstream/sandbox/_sandboxbwrap.py index 5effadf41..8c406e53e 100644 --- a/buildstream/sandbox/_sandboxbwrap.py +++ b/buildstream/sandbox/_sandboxbwrap.py @@ -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. diff --git a/buildstream/sandbox/_sandboxchroot.py b/buildstream/sandbox/_sandboxchroot.py index b3a2a6d9d..f19052b23 100644 --- a/buildstream/sandbox/_sandboxchroot.py +++ b/buildstream/sandbox/_sandboxchroot.py @@ -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) diff --git a/buildstream/sandbox/sandbox.py b/buildstream/sandbox/sandbox.py index 42cfb9a15..83714efdd 100644 --- a/buildstream/sandbox/sandbox.py +++ b/buildstream/sandbox/sandbox.py @@ -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__)) |