Will Salmon pushed to branch willsalmon/bugfix/CWDnotcreated at BuildStream / buildstream
Commits:
-
e60c72ee
by William Salmon at 2018-09-14T10:48:06Z
-
c172e2df
by William Salmon at 2018-09-14T10:48:06Z
4 changed files:
- buildstream/sandbox/_sandboxbwrap.py
- buildstream/sandbox/sandbox.py
- + tests/integration/project/elements/workspace/workspace-commanddir.bst
- tests/integration/workspace.py
Changes:
... | ... | @@ -120,9 +120,6 @@ class SandboxBwrap(Sandbox): |
120 | 120 |
bwrap_command += ['--unshare-uts', '--hostname', 'buildstream']
|
121 | 121 |
bwrap_command += ['--unshare-ipc']
|
122 | 122 |
|
123 |
- if cwd is not None:
|
|
124 |
- bwrap_command += ['--chdir', cwd]
|
|
125 |
- |
|
126 | 123 |
# Give it a proc and tmpfs
|
127 | 124 |
bwrap_command += [
|
128 | 125 |
'--proc', '/proc',
|
... | ... | @@ -163,6 +160,10 @@ class SandboxBwrap(Sandbox): |
163 | 160 |
if flags & SandboxFlags.ROOT_READ_ONLY:
|
164 | 161 |
bwrap_command += ["--remount-ro", "/"]
|
165 | 162 |
|
163 |
+ if cwd is not None:
|
|
164 |
+ bwrap_command += ['--dir', cwd]
|
|
165 |
+ bwrap_command += ['--chdir', cwd]
|
|
166 |
+ |
|
166 | 167 |
# Set UID and GUI
|
167 | 168 |
if self.user_ns_available:
|
168 | 169 |
bwrap_command += ['--unshare-user']
|
... | ... | @@ -191,11 +192,6 @@ class SandboxBwrap(Sandbox): |
191 | 192 |
with ExitStack() as stack:
|
192 | 193 |
stack.enter_context(mount_map.mounted(self))
|
193 | 194 |
|
194 |
- # Ensure the cwd exists
|
|
195 |
- if cwd is not None:
|
|
196 |
- workdir = os.path.join(root_mount_source, cwd.lstrip(os.sep))
|
|
197 |
- os.makedirs(workdir, exist_ok=True)
|
|
198 |
- |
|
199 | 195 |
# If we're interactive, we want to inherit our stdin,
|
200 | 196 |
# otherwise redirect to /dev/null, ensuring process
|
201 | 197 |
# disconnected from terminal.
|
... | ... | @@ -197,6 +197,11 @@ class Sandbox(): |
197 | 197 |
def run(self, command, flags, *, cwd=None, env=None):
|
198 | 198 |
"""Run a command in the sandbox.
|
199 | 199 |
|
200 |
+ Note:
|
|
201 |
+ When reimplementing this function for sandbox specific implementations it is the sandbox's and probably
|
|
202 |
+ this functions responsibility to ensure that cwd is created correctly and that if a workspace is used
|
|
203 |
+ then the directory must be correctly created to take this in to account.
|
|
204 |
+ |
|
200 | 205 |
Args:
|
201 | 206 |
command (list): The command to run in the sandboxed environment, as a list
|
202 | 207 |
of strings starting with the binary to run.
|
1 |
+kind: manual
|
|
2 |
+description: Workspace mount test
|
|
3 |
+ |
|
4 |
+depends:
|
|
5 |
+ - filename: base.bst
|
|
6 |
+ type: build
|
|
7 |
+ |
|
8 |
+sources:
|
|
9 |
+ - kind: local
|
|
10 |
+ path: files/workspace-mount-src/
|
|
11 |
+ |
|
12 |
+variables:
|
|
13 |
+ command-subdir: build
|
|
14 |
+ |
|
15 |
+config:
|
|
16 |
+ build-commands:
|
|
17 |
+ - cc -c ../hello.c
|
... | ... | @@ -31,6 +31,21 @@ def test_workspace_mount(cli, tmpdir, datafiles): |
31 | 31 |
|
32 | 32 |
assert os.path.exists(os.path.join(cli.directory, 'workspace'))
|
33 | 33 |
|
34 |
+@pytest.mark.integration
|
|
35 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
36 |
+def test_workspace_commanddir(cli, tmpdir, datafiles):
|
|
37 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
38 |
+ workspace = os.path.join(cli.directory, 'workspace')
|
|
39 |
+ element_name = 'workspace/workspace-commanddir.bst'
|
|
40 |
+ |
|
41 |
+ res = cli.run(project=project, args=['workspace', 'open', element_name, workspace])
|
|
42 |
+ assert res.exit_code == 0
|
|
43 |
+ |
|
44 |
+ res = cli.run(project=project, args=['build', element_name])
|
|
45 |
+ assert res.exit_code == 0
|
|
46 |
+ |
|
47 |
+ assert os.path.exists(os.path.join(cli.directory, 'workspace'))
|
|
48 |
+ assert os.path.exists(os.path.join(cli.directory, 'workspace', 'build'))
|
|
34 | 49 |
|
35 | 50 |
@pytest.mark.integration
|
36 | 51 |
@pytest.mark.datafiles(DATA_DIR)
|