summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-01-22 14:17:30 +0100
committerJürg Billeter <j@bitron.ch>2020-02-10 11:35:06 +0100
commit06d24cd52e065c4c7692bd5328a1b7e44eb037aa (patch)
treed83f1c4f8866906dd02115254f38e27b66a5631f
parent570fd0e623824e8f127693f5cf8eb86b8061cef2 (diff)
downloadbuildstream-06d24cd52e065c4c7692bd5328a1b7e44eb037aa.tar.gz
sandbox: Add _create_empty_file() method
-rw-r--r--src/buildstream/sandbox/_sandboxreapi.py3
-rw-r--r--src/buildstream/sandbox/sandbox.py46
2 files changed, 48 insertions, 1 deletions
diff --git a/src/buildstream/sandbox/_sandboxreapi.py b/src/buildstream/sandbox/_sandboxreapi.py
index 2c02c693e..c31490cfa 100644
--- a/src/buildstream/sandbox/_sandboxreapi.py
+++ b/src/buildstream/sandbox/_sandboxreapi.py
@@ -226,3 +226,6 @@ class _SandboxREAPIBatch(_SandboxBatch):
label = command.label or cmdline
quoted_label = shlex.quote("'{}'".format(label))
self.script += " || (echo Command {} failed with exitcode $? >&2 ; exit 1)\n".format(quoted_label)
+
+ def create_empty_file(self, name):
+ self.script += "touch -- {}\n".format(shlex.quote(name))
diff --git a/src/buildstream/sandbox/sandbox.py b/src/buildstream/sandbox/sandbox.py
index 31eb6eb11..b82e2da59 100644
--- a/src/buildstream/sandbox/sandbox.py
+++ b/src/buildstream/sandbox/sandbox.py
@@ -580,6 +580,30 @@ class Sandbox:
return False
+ # _create_empty_file()
+ #
+ # Creates an empty file in the current working directory.
+ #
+ # If this is called outside a batch context, the file is created
+ # immediately.
+ #
+ # If this is called in a batch context, creating the file is deferred.
+ #
+ # Args:
+ # path (str): The path of the file to be created
+ #
+ def _create_empty_file(self, name):
+ if self.__batch:
+ batch_file = _SandboxBatchFile(name)
+
+ current_group = self.__batch.current_group
+ current_group.append(batch_file)
+ else:
+ vdir = self.get_virtual_directory()
+ cwd = self._get_work_directory()
+ cwd_vdir = vdir.descend(*cwd.lstrip(os.sep).split(os.sep), create=True)
+ cwd_vdir._create_empty_file(name)
+
# _get_element_name()
#
# Get the plugin's element full name
@@ -655,6 +679,12 @@ class _SandboxBatch:
"Command failed with exitcode {}".format(exitcode), detail=label, collect=self.collect
)
+ def create_empty_file(self, name):
+ vdir = self.sandbox.get_virtual_directory()
+ cwd = self.sandbox._get_work_directory()
+ cwd_vdir = vdir.descend(*cwd.lstrip(os.sep).split(os.sep), create=True)
+ cwd_vdir._create_empty_file(name)
+
# _SandboxBatchItem()
#
@@ -705,4 +735,18 @@ class _SandboxBatchGroup(_SandboxBatchItem):
item.execute(batch)
def combined_label(self):
- return "\n".join(item.combined_label() for item in self.children)
+ return "\n".join(filter(None, (item.combined_label() for item in self.children)))
+
+
+# _SandboxBatchFile()
+#
+# A file creation item in a command batch.
+#
+class _SandboxBatchFile(_SandboxBatchItem):
+ def __init__(self, name):
+ super().__init__()
+
+ self.name = name
+
+ def execute(self, batch):
+ batch.create_empty_file(self.name)