summaryrefslogtreecommitdiff
path: root/buildstream/sandbox/sandbox.py
diff options
context:
space:
mode:
Diffstat (limited to 'buildstream/sandbox/sandbox.py')
-rw-r--r--buildstream/sandbox/sandbox.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/buildstream/sandbox/sandbox.py b/buildstream/sandbox/sandbox.py
index 9d34f0195..9d0b69b73 100644
--- a/buildstream/sandbox/sandbox.py
+++ b/buildstream/sandbox/sandbox.py
@@ -279,20 +279,38 @@ class Sandbox():
# Fetches the environment variables for running commands
# in the sandbox.
#
+ # Args:
+ # cwd (str): The working directory the command has been requested to run in, if any.
+ # env (str): The environment the command has been requested to run in, if any.
+ #
# Returns:
# (str): The sandbox work directory
- def _get_environment(self):
- return self.__env
+ def _get_environment(self, *, cwd=None, env=None):
+ cwd = self._get_work_directory(cwd=cwd)
+ if env is None:
+ env = self.__env
+
+ # Naive getcwd implementations can break when bind-mounts to different
+ # paths on the same filesystem are present. Letting the command know
+ # what directory it is in makes it unnecessary to call the faulty
+ # getcwd.
+ env = dict(env)
+ env['PWD'] = cwd
+
+ return env
# _get_work_directory()
#
# Fetches the working directory for running commands
# in the sandbox.
#
+ # Args:
+ # cwd (str): The working directory the command has been requested to run in, if any.
+ #
# Returns:
# (str): The sandbox work directory
- def _get_work_directory(self):
- return self.__cwd
+ def _get_work_directory(self, *, cwd=None):
+ return cwd or self.__cwd or '/'
# _get_scratch_directory()
#