diff options
author | Jürg Billeter <j@bitron.ch> | 2017-11-21 17:48:09 +0100 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2018-02-08 14:04:04 +0100 |
commit | 00c6e649f455dcad9e19071ead31b9e0960fb078 (patch) | |
tree | 97be0e569e24480b6d0548a4b6da97a285e96dde | |
parent | 1d331b9b7db812e3f18c3eed33af92739c2ffb7b (diff) | |
download | buildstream-00c6e649f455dcad9e19071ead31b9e0960fb078.tar.gz |
Move element and source factories from Pipeline to Project
Element and source factories use a project-specific search path.
-rw-r--r-- | buildstream/_frontend/widget.py | 4 | ||||
-rw-r--r-- | buildstream/_pipeline.py | 22 | ||||
-rw-r--r-- | buildstream/_project.py | 22 | ||||
-rw-r--r-- | buildstream/element.py | 13 |
4 files changed, 31 insertions, 30 deletions
diff --git a/buildstream/_frontend/widget.py b/buildstream/_frontend/widget.py index d61f338df..701efe162 100644 --- a/buildstream/_frontend/widget.py +++ b/buildstream/_frontend/widget.py @@ -470,8 +470,8 @@ class LogLine(Widget): text += '\n' # Plugins - text += self.format_plugins(pipeline.element_factory.loaded_dependencies, - pipeline.source_factory.loaded_dependencies) + text += self.format_plugins(project._element_factory.loaded_dependencies, + project._source_factory.loaded_dependencies) # Pipeline state text += self.content_profile.fmt("Pipeline\n", bold=True) diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py index 9ce97cea3..b588717e3 100644 --- a/buildstream/_pipeline.py +++ b/buildstream/_pipeline.py @@ -27,14 +27,11 @@ import tarfile import itertools from contextlib import contextmanager from operator import itemgetter -from pluginbase import PluginBase from tempfile import TemporaryDirectory from ._exceptions import PipelineError, ArtifactError, ImplError, BstError from ._message import Message, MessageType -from ._elementfactory import ElementFactory from ._loader import Loader -from ._sourcefactory import SourceFactory from . import Consistency from . import Scope from . import _site @@ -130,11 +127,6 @@ class Pipeline(): with self.timed_activity("Loading pipeline", silent_nested=True): meta_elements = loader.load(rewritable, None) - # Create the factories after resolving the project - pluginbase = PluginBase(package='buildstream.plugins') - self.element_factory = ElementFactory(pluginbase, project._plugin_element_origins) - self.source_factory = SourceFactory(pluginbase, project._plugin_source_origins) - # Resolve the real elements now that we've resolved the project with self.timed_activity("Resolving pipeline"): resolved_elements = [self.resolve(meta_element) @@ -282,11 +274,9 @@ class Pipeline(): if meta_element in self._resolved_elements: return self._resolved_elements[meta_element] - element = self.element_factory.create(meta_element.kind, - self.context, - self.project, - self.artifacts, - meta_element) + element = self.project._create_element(meta_element.kind, + self.artifacts, + meta_element) self._resolved_elements[meta_element] = element @@ -299,10 +289,8 @@ class Pipeline(): # resolve sources for meta_source in meta_element.sources: element._add_source( - self.source_factory.create(meta_source.kind, - self.context, - self.project, - meta_source) + self.project._create_source(meta_source.kind, + meta_source) ) return element diff --git a/buildstream/_project.py b/buildstream/_project.py index d44a891bd..b913ff24d 100644 --- a/buildstream/_project.py +++ b/buildstream/_project.py @@ -21,6 +21,7 @@ import os import multiprocessing # for cpu_count() from collections import Mapping +from pluginbase import PluginBase from . import utils from . import _cachekey from . import _site @@ -29,6 +30,8 @@ from ._profile import Topics, profile_start, profile_end from ._exceptions import LoadError, LoadErrorReason from ._options import OptionPool from ._artifactcache import artifact_cache_specs_from_config_node +from ._elementfactory import ElementFactory +from ._sourcefactory import SourceFactory # The base BuildStream format version @@ -38,15 +41,6 @@ from ._artifactcache import artifact_cache_specs_from_config_node # BST_FORMAT_VERSION = 0 -# The base BuildStream artifact version -# -# The artifact version changes whenever the cache key -# calculation algorithm changes in an incompatible way -# or if buildstream was changed in a way which can cause -# the same cache key to produce something that is no longer -# the same. -BST_ARTIFACT_VERSION = 1 - # The separator we use for user specified aliases _ALIAS_SEPARATOR = ':' @@ -232,6 +226,10 @@ class Project(): self._store_origin(origin, 'sources', self._plugin_source_origins) self._store_origin(origin, 'elements', self._plugin_element_origins) + pluginbase = PluginBase(package='buildstream.plugins') + self._element_factory = ElementFactory(pluginbase, self._plugin_element_origins) + self._source_factory = SourceFactory(pluginbase, self._plugin_source_origins) + # Source url aliases self._aliases = _yaml.node_get(config, Mapping, 'aliases', default_value={}) @@ -443,3 +441,9 @@ class Project(): self._cache_key = _cachekey.generate_key({}) return self._cache_key + + def _create_element(self, kind, artifacts, meta): + return self._element_factory.create(kind, self._context, self, artifacts, meta) + + def _create_source(self, kind, meta): + return self._source_factory.create(kind, self._context, self, meta) diff --git a/buildstream/element.py b/buildstream/element.py index 5a2d491d7..3ae02332e 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -37,7 +37,6 @@ from . import _yaml from ._variables import Variables from ._exceptions import BstError, LoadError, LoadErrorReason, ImplError, ErrorDomain from . import Plugin, Consistency -from ._project import BST_ARTIFACT_VERSION as BST_CORE_ARTIFACT_VERSION from . import SandboxFlags from . import utils from . import _cachekey @@ -46,6 +45,16 @@ from . import _site from ._platform import Platform +# The base BuildStream artifact version +# +# The artifact version changes whenever the cache key +# calculation algorithm changes in an incompatible way +# or if buildstream was changed in a way which can cause +# the same cache key to produce something that is no longer +# the same. +_BST_CORE_ARTIFACT_VERSION = 1 + + # _KeyStrength(): # # Strength of cache key @@ -911,7 +920,7 @@ class Element(Plugin): operating_system, _, _, _, machine_arch = os.uname() self.__cache_key_dict = { - 'artifact-version': "{}.{}".format(BST_CORE_ARTIFACT_VERSION, + 'artifact-version': "{}.{}".format(_BST_CORE_ARTIFACT_VERSION, self.BST_ARTIFACT_VERSION), 'context': context._get_cache_key(), 'project': project._get_cache_key(), |