summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-04-29 19:37:52 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2019-04-29 19:37:52 +0900
commit48c031745d2e7f1a89a8a318eb40f289672cc4a4 (patch)
treea2e6aec2da63a888a8ecd03e4470c1c22476891f
parent0312f051fe78d620a56371c7c07fce40c52a510e (diff)
downloadbuildstream-48c031745d2e7f1a89a8a318eb40f289672cc4a4.tar.gz
plugin.py: Allow passing a unique_id through the constructor.
In the case of cloned Sources, they should not be allocating a new ID in track() and fetch() in case they do communicate their ID back to the main process, they should inherit the same ID of the Source they were cloned from.
-rw-r--r--buildstream/plugin.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/buildstream/plugin.py b/buildstream/plugin.py
index 307aefa69..fbcf249bb 100644
--- a/buildstream/plugin.py
+++ b/buildstream/plugin.py
@@ -167,7 +167,7 @@ class Plugin():
# scheduling tasks.
__TABLE = WeakValueDictionary()
- def __init__(self, name, context, project, provenance, type_tag):
+ def __init__(self, name, context, project, provenance, type_tag, unique_id=None):
self.name = name
"""The plugin name
@@ -188,10 +188,14 @@ class Plugin():
# to give us a topological sort over all elements.
# Modifying how we handle ids here will modify the behavior of the
# Element's state handling.
- self._unique_id = next(self.__id_generator)
-
- # register ourself in the table containing all existing plugins
- self.__TABLE[self._unique_id] = self
+ if unique_id is None:
+ # Register ourself in the table containing all existing plugins
+ self._unique_id = next(self.__id_generator)
+ self.__TABLE[self._unique_id] = self
+ else:
+ # If the unique ID is passed in the constructor, then it is a cloned
+ # plugin in a subprocess and should use the same ID.
+ self._unique_id = unique_id
self.__context = context # The Context object
self.__project = project # The Project object