summaryrefslogtreecommitdiff
path: root/src/buildstream/_elementproxy.py
diff options
context:
space:
mode:
authorTristan van Berkom <tristan@codethink.co.uk>2020-09-09 17:11:33 +0900
committerTristan van Berkom <tristan@codethink.co.uk>2020-09-18 12:36:34 +0900
commit71f1b3c3c29738921ce6fab3d200f74e1e275d0d (patch)
treefeb61dd48d8b06cf89ff86a8ea49d6563e3fb9a3 /src/buildstream/_elementproxy.py
parent70b12f1fc119fced823b71436d7f923cda512dfc (diff)
downloadbuildstream-71f1b3c3c29738921ce6fab3d200f74e1e275d0d.tar.gz
element.py, _elementproxy.py: Use new OverlapCollector
Setup the OverlapCollector in Element.stage() routines, and ensure we call OverlapCollector.start_session() and OverlapCollector.end_session() in the right places. This adds the OverlapAction `action` parameter to the Element.stage_artifact() and Element.stage_dependency_artifacts() APIs so that Elements can choose how to behave when multiple artifact staging calls overlap with files staged by previous artifact staging calls.
Diffstat (limited to 'src/buildstream/_elementproxy.py')
-rw-r--r--src/buildstream/_elementproxy.py38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/buildstream/_elementproxy.py b/src/buildstream/_elementproxy.py
index acb08ce8b..a7b1f09a0 100644
--- a/src/buildstream/_elementproxy.py
+++ b/src/buildstream/_elementproxy.py
@@ -18,7 +18,7 @@
# Tristan Van Berkom <tristan.vanberkom@codethink.co.uk>
from typing import TYPE_CHECKING, cast, Optional, Iterator, Dict, List, Sequence
-from .types import _Scope
+from .types import _Scope, OverlapAction
from .utils import FileListResult
from ._pluginproxy import PluginProxy
@@ -96,13 +96,23 @@ class ElementProxy(PluginProxy):
sandbox: "Sandbox",
*,
path: str = None,
+ action: str = OverlapAction.WARNING,
include: Optional[List[str]] = None,
exclude: Optional[List[str]] = None,
orphans: bool = True
) -> FileListResult:
- return cast("Element", self._plugin).stage_artifact(
- sandbox, path=path, include=include, exclude=exclude, orphans=orphans
- )
+
+ owner = cast("Element", self._owner)
+ element = cast("Element", self._plugin)
+
+ assert owner._overlap_collector is not None, "Attempted to stage artifacts outside of Element.stage()"
+
+ with owner._overlap_collector.session(action, path):
+ result = element._stage_artifact(
+ sandbox, path=path, action=action, include=include, exclude=exclude, orphans=orphans, owner=owner
+ )
+
+ return result
def stage_dependency_artifacts(
self,
@@ -110,6 +120,7 @@ class ElementProxy(PluginProxy):
selection: Sequence["Element"] = None,
*,
path: str = None,
+ action: str = OverlapAction.WARNING,
include: Optional[List[str]] = None,
exclude: Optional[List[str]] = None,
orphans: bool = True
@@ -120,7 +131,7 @@ class ElementProxy(PluginProxy):
if selection is None:
selection = [cast("Element", self._plugin)]
cast("Element", self._owner).stage_dependency_artifacts(
- sandbox, selection, path=path, include=include, exclude=exclude, orphans=orphans
+ sandbox, selection, path=path, action=action, include=include, exclude=exclude, orphans=orphans
)
def integrate(self, sandbox: "Sandbox") -> None:
@@ -154,3 +165,20 @@ class ElementProxy(PluginProxy):
def _file_is_whitelisted(self, path):
return cast("Element", self._plugin)._file_is_whitelisted(path)
+
+ def _stage_artifact(
+ self,
+ sandbox: "Sandbox",
+ *,
+ path: str = None,
+ action: str = OverlapAction.WARNING,
+ include: Optional[List[str]] = None,
+ exclude: Optional[List[str]] = None,
+ orphans: bool = True,
+ owner: Optional["Element"] = None
+ ) -> FileListResult:
+ owner = cast("Element", self._owner)
+ element = cast("Element", self._plugin)
+ return element._stage_artifact(
+ sandbox, path=path, action=action, include=include, exclude=exclude, orphans=orphans, owner=owner
+ )