@@ -254,7 +254,7 @@ def __init__(
254254 # Internal instance properties
255255 #
256256 self ._depth = None # Depth of Element in its current dependency graph
257- self ._overlap_collector = None # type: Optional[OverlapCollector]
257+ self ._overlap_collectors : Dict [ Sandbox , OverlapCollector ] = {} # Active overlap collector per sandbox
258258 self ._description = load_element .description or "" # type: str
259259
260260 #
@@ -642,15 +642,16 @@ def stage_artifact(
642642 :func:`Element.stage_dependency_artifacts() <buildstream.element.Element.stage_dependency_artifacts>`
643643 instead.
644644 """
645- assert self ._overlap_collector is not None , "Attempted to stage artifacts outside of Element.stage()"
645+ overlap_collector = self ._overlap_collectors .get (sandbox )
646+ assert overlap_collector is not None , "Attempted to stage artifacts outside of Element.stage()"
646647
647648 #
648649 # The public API can only be called on the implementing plugin itself.
649650 #
650651 # ElementProxy calls to stage_artifact() are routed directly to _stage_artifact(),
651652 # and the ElementProxy takes care of starting and ending the OverlapCollector session.
652653 #
653- with self . _overlap_collector .session (action , path ):
654+ with overlap_collector .session (action , path ):
654655 result = self ._stage_artifact (
655656 sandbox , path = path , action = action , include = include , exclude = exclude , orphans = orphans
656657 )
@@ -692,9 +693,10 @@ def stage_dependency_artifacts(
692693 Raises:
693694 (:class:`.ElementError`): if forbidden overlaps occur.
694695 """
695- assert self ._overlap_collector is not None , "Attempted to stage artifacts outside of Element.stage()"
696+ overlap_collector = self ._overlap_collectors .get (sandbox )
697+ assert overlap_collector is not None , "Attempted to stage artifacts outside of Element.stage()"
696698
697- with self . _overlap_collector .session (action , path ):
699+ with overlap_collector .session (action , path ):
698700 for dep in self .dependencies (selection ):
699701 dep ._stage_artifact (sandbox , path = path , include = include , exclude = exclude , orphans = orphans , owner = self )
700702
@@ -962,7 +964,8 @@ def _stage_artifact(
962964 ) -> FileListResult :
963965
964966 owner = owner or self
965- assert owner ._overlap_collector is not None , "Attempted to stage artifacts outside of Element.stage()"
967+ overlap_collector = owner ._overlap_collectors .get (sandbox )
968+ assert overlap_collector is not None , "Attempted to stage artifacts outside of Element.stage()"
966969
967970 if not self ._cached ():
968971 detail = (
@@ -989,7 +992,7 @@ def _stage_artifact(
989992 result = vstagedir ._import_files_internal (files_vdir , filter_callback = split_filter )
990993 assert result is not None
991994
992- owner . _overlap_collector .collect_stage_result (self , result )
995+ overlap_collector .collect_stage_result (self , result )
993996
994997 return result
995998
@@ -1013,7 +1016,7 @@ def _stage_artifact(
10131016 # occur.
10141017 #
10151018 def _stage_dependency_artifacts (self , sandbox , scope , * , path = None , include = None , exclude = None , orphans = True ):
1016- with self ._overlap_collector .session (OverlapAction .WARNING , path ):
1019+ with self ._overlap_collectors [ sandbox ] .session (OverlapAction .WARNING , path ):
10171020 for dep in self ._dependencies (scope ):
10181021 dep ._stage_artifact (sandbox , path = path , include = include , exclude = exclude , orphans = orphans , owner = self )
10191022
@@ -1435,7 +1438,7 @@ def _prepare_sandbox(self, scope, shell=False, integrate=True, usebuildtree=Fals
14351438 self .__stage (sandbox )
14361439 else :
14371440 # Stage deps in the sandbox root
1438- with self .timed_activity ("Staging dependencies" , silent_nested = True ), self .__collect_overlaps ():
1441+ with self .timed_activity ("Staging dependencies" , silent_nested = True ), self .__collect_overlaps (sandbox ):
14391442 self ._stage_dependency_artifacts (sandbox , scope )
14401443
14411444 # Run any integration commands provided by the dependencies
@@ -2703,7 +2706,7 @@ def __configure_sandbox(self, sandbox):
27032706 def __stage (self , sandbox ):
27042707
27052708 # Enable the overlap collector during the staging process
2706- with self .__collect_overlaps ():
2709+ with self .__collect_overlaps (sandbox ):
27072710 self .stage (sandbox )
27082711
27092712 # __preflight():
@@ -2806,10 +2809,12 @@ def __get_tainted(self, recalculate=False):
28062809 # this context manager.
28072810 #
28082811 @contextmanager
2809- def __collect_overlaps (self ):
2810- self ._overlap_collector = OverlapCollector (self )
2811- yield
2812- self ._overlap_collector = None
2812+ def __collect_overlaps (self , sandbox ):
2813+ self ._overlap_collectors [sandbox ] = OverlapCollector (self )
2814+ try :
2815+ yield
2816+ finally :
2817+ del self ._overlap_collectors [sandbox ]
28132818
28142819 # __sandbox():
28152820 #
0 commit comments