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.van.berkom@gmail.com>2019-04-30 11:52:59 +0000
commit9053ee3846e70d082dac893703b87f8b04b0f195 (patch)
treeafd88321d69ce7f9422ae16bc9a2ab1f3740f90b
parent60bbe8daa1995b471aa69e234a4d39d61525adbd (diff)
downloadbuildstream-9053ee3846e70d082dac893703b87f8b04b0f195.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 fe4c0c0d0..d8b6a7359 100644
--- a/buildstream/plugin.py
+++ b/buildstream/plugin.py
@@ -205,7 +205,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
@@ -226,10 +226,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