summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim MacArthur <jim.macarthur@codethink.co.uk>2018-07-04 12:39:19 +0100
committerJim MacArthur <jim.macarthur@codethink.co.uk>2018-07-04 12:40:53 +0100
commit30c7009ee966119a07f7862b51d3a6df68064509 (patch)
treef1a1221e1d46dffee49533132a67e808df1b8f4b
parente1189540fe2037b066b079b90436dac1c841b8ed (diff)
downloadbuildstream-jmac/source_pushing_experiments.tar.gz
buildelement.py: Send build-root as an environment variable with an option to add it as a 'cd' command to the commands.jmac/source_pushing_experiments
-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))