summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buildstream/buildelement.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/buildstream/buildelement.py b/buildstream/buildelement.py
index 82bbf983c..f637bcd78 100644
--- a/buildstream/buildelement.py
+++ b/buildstream/buildelement.py
@@ -241,7 +241,17 @@ class BuildElement(Element):
# Note the -e switch to 'sh' means to exit with an error
# if any untested command fails.
#
- exitcode = sandbox.run(['sh', '-c', '-e', cmd + '\n'],
- SandboxFlags.ROOT_READ_ONLY)
+ arguments = ['sh', '-c', '-e']
+ change_directory = False
+ if change_directory:
+ # Add a CD. '&&' should be supported by all POSIX shells.
+ cmd = '"cd '+self.get_variable('build-root') + ' && ' + cmd + '"'
+ arguments.append(cmd + '\n')
+
+ # Buildbox does not handle 'cd' at the moment, so we also add
+ # the buildroot to an environment variable called PWD.
+
+ exitcode = sandbox.run(arguments, SandboxFlags.ROOT_READ_ONLY,
+ env={"PWD": self.get_variable('build-root')})
if exitcode != 0:
raise ElementError("Command '{}' failed with exitcode {}".format(cmd, exitcode))