diff options
author | bst-marge-bot <marge-bot@buildstream.build> | 2019-04-30 13:50:23 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-04-30 13:50:23 +0000 |
commit | 377f20fe5f2a20d8d432e9a5a09e666cdba5afb3 (patch) | |
tree | eac30031538cfc65f6fb9c6e71cbe5d83182ac39 | |
parent | 0c064be9a7af972946dc8aa1d9daf63d4527cf4e (diff) | |
parent | 7900c09a27c1b6de12f7eef52e25116ff590c973 (diff) | |
download | buildstream-377f20fe5f2a20d8d432e9a5a09e666cdba5afb3.tar.gz |
Merge branch 'tristan/fix-cloned-plugin-ids' into 'master'
Fix cloned plugin ids
Closes #1012
See merge request BuildStream/buildstream!1316
-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 5fdcdaeb8..d8b6a7359 100644 --- a/buildstream/plugin.py +++ b/buildstream/plugin.py @@ -187,8 +187,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 @@ -201,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 @@ -222,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 @@ -756,6 +764,7 @@ class Plugin(): # @classmethod def _lookup(cls, unique_id): + assert unique_id != 0, "Looking up invalid plugin ID 0, ID counter starts at 1" try: return cls.__TABLE[unique_id] except KeyError: diff --git a/buildstream/source.py b/buildstream/source.py index 6f4ff575b..daf2cb27c 100644 --- a/buildstream/source.py +++ b/buildstream/source.py @@ -286,10 +286,10 @@ class Source(Plugin): *Since: 1.4* """ - 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.__source_cache = context.sourcecache @@ -1092,7 +1092,9 @@ class Source(Plugin): meta.first_pass = self.__first_pass - clone = source_kind(context, project, meta, alias_override=(alias, uri)) + clone = source_kind(context, project, meta, + alias_override=(alias, uri), + unique_id=self._unique_id) # Do the necessary post instantiation routines here # |