diff options
author | bst-marge-bot <marge-bot@buildstream.build> | 2019-04-30 05:53:33 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-04-30 05:53:33 +0000 |
commit | ad3d842af9e4c0836cfac5ee8c0160e71117d803 (patch) | |
tree | 9bbf0e71ee7fadf55fef046f97052c9fe83c19dc | |
parent | 162c4166ce011f8dfca265549e6a343101a129aa (diff) | |
parent | a703de6ac374dfd22d2e0db0454f19ebb9722adf (diff) | |
download | buildstream-ad3d842af9e4c0836cfac5ee8c0160e71117d803.tar.gz |
Merge branch 'tristan/fix-cloned-plugin-ids-1.2' into 'bst-1.2'
Tristan/fix cloned plugin ids 1.2
See merge request BuildStream/buildstream!1315
-rw-r--r-- | buildstream/plugin.py | 23 | ||||
-rw-r--r-- | buildstream/source.py | 8 |
2 files changed, 21 insertions, 10 deletions
diff --git a/buildstream/plugin.py b/buildstream/plugin.py index 2c94c212c..fbcf249bb 100644 --- a/buildstream/plugin.py +++ b/buildstream/plugin.py @@ -149,8 +149,12 @@ class Plugin(): # Unique id generator for Plugins # # Each plugin gets a unique id at creation. - # Ids are a monotically increasing integer - __id_generator = itertools.count() + # + # Ids are a monotically increasing integer which + # starts as 1 (a falsy plugin ID is considered unset + # in various parts of the codebase). + # + __id_generator = itertools.count(1) # Hold on to a lookup table by counter of all instantiated plugins. # We use this to send the id back from child processes so we can lookup @@ -163,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 @@ -184,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 @@ -656,6 +664,7 @@ class Plugin(): # @classmethod def _lookup(cls, unique_id): + assert unique_id != 0, "Looking up invalid plugin ID 0, ID counter starts at 1" assert unique_id in cls.__TABLE, "Could not find plugin with ID {}".format(unique_id) return cls.__TABLE[unique_id] diff --git a/buildstream/source.py b/buildstream/source.py index b8759c0d8..f72aeae86 100644 --- a/buildstream/source.py +++ b/buildstream/source.py @@ -225,10 +225,10 @@ class Source(Plugin): __defaults = {} # The defaults from the project __defaults_set = False # Flag, in case there are not defaults at all - def __init__(self, context, project, meta, *, alias_override=None): + def __init__(self, context, project, meta, *, alias_override=None, unique_id=None): provenance = _yaml.node_get_provenance(meta.config) super().__init__("{}-{}".format(meta.element_name, meta.element_index), - context, project, provenance, "source") + context, project, provenance, "source", unique_id=unique_id) self.__element_name = meta.element_name # The name of the element owning this source self.__element_index = meta.element_index # The index of the source in the owning element's source list @@ -916,7 +916,9 @@ class Source(Plugin): alias = self._get_alias() source_kind = type(self) - clone = source_kind(context, project, self.__meta, alias_override=(alias, uri)) + clone = source_kind(context, project, self.__meta, + alias_override=(alias, uri), + unique_id=self._unique_id) # Do the necessary post instantiation routines here # |