summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2020-05-12 12:13:05 +0000
committerBenjamin Schubert <contact@benschubert.me>2020-05-12 12:13:05 +0000
commitb847563a59bb70fd515618f3938f3d08b0a9971b (patch)
treeea650636a45e293fd24a9d9057b953493bf63590
parenteef74e422ad4d2b76bae5cd543b95526ead47015 (diff)
downloadbuildstream-bschubert/allow-source-variables-access.tar.gz
source.py: Allow access to element's variablebschubert/allow-source-variables-access
This automatically expands the variables from the element into the sources config
-rw-r--r--src/buildstream/_pluginfactory/sourcefactory.py5
-rw-r--r--src/buildstream/_project.py7
-rw-r--r--src/buildstream/element.py2
-rw-r--r--src/buildstream/source.py9
4 files changed, 16 insertions, 7 deletions
diff --git a/src/buildstream/_pluginfactory/sourcefactory.py b/src/buildstream/_pluginfactory/sourcefactory.py
index 5277577d4..d616702ef 100644
--- a/src/buildstream/_pluginfactory/sourcefactory.py
+++ b/src/buildstream/_pluginfactory/sourcefactory.py
@@ -45,6 +45,7 @@ class SourceFactory(PluginFactory):
# context (object): The Context object for processing
# project (object): The project object
# meta (object): The loaded MetaSource
+ # variables (Variables): The variables available to the source
#
# Returns:
# A newly created Source object of the appropriate kind
@@ -53,7 +54,7 @@ class SourceFactory(PluginFactory):
# PluginError (if the kind lookup failed)
# LoadError (if the source itself took issue with the config)
#
- def create(self, context, project, meta):
+ def create(self, context, project, meta, variables):
source_type, _ = self.lookup(context.messenger, meta.kind, meta.provenance)
- source = source_type(context, project, meta)
+ source = source_type(context, project, meta, variables)
return source
diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index 06c677051..1c6e7e950 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -375,16 +375,17 @@ class Project:
#
# Args:
# meta (MetaSource): The loaded MetaSource
+ # variables (Variables): The list of variables available to the source
# first_pass (bool): Whether to use first pass configuration (for junctions)
#
# Returns:
# (Source): A newly created Source object of the appropriate kind
#
- def create_source(self, meta, *, first_pass=False):
+ def create_source(self, meta, variables, *, first_pass=False):
if first_pass:
- return self.first_pass_config.source_factory.create(self._context, self, meta)
+ return self.first_pass_config.source_factory.create(self._context, self, meta, variables)
else:
- return self.config.source_factory.create(self._context, self, meta)
+ return self.config.source_factory.create(self._context, self, meta, variables)
# get_alias_uri()
#
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index 67a915e48..fa39eba12 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -901,7 +901,7 @@ class Element(Plugin):
# Instantiate sources and generate their keys
for meta_source in meta.sources:
meta_source.first_pass = meta.is_junction
- source = meta.project.create_source(meta_source, first_pass=meta.first_pass)
+ source = meta.project.create_source(meta_source, variables=element.__variables, first_pass=meta.first_pass)
redundant_ref = source._load_ref()
diff --git a/src/buildstream/source.py b/src/buildstream/source.py
index 7b790cdbb..049db7062 100644
--- a/src/buildstream/source.py
+++ b/src/buildstream/source.py
@@ -173,6 +173,7 @@ from ._cachekey import generate_key
from .storage import CasBasedDirectory
from .storage import FileBasedDirectory
from .storage.directory import Directory, VirtualDirectoryError
+from ._variables import Variables
if TYPE_CHECKING:
from typing import Any, Dict, Set
@@ -321,6 +322,7 @@ class Source(Plugin):
context: "Context",
project: "Project",
meta: MetaSource,
+ variables: Variables,
*,
alias_override: Optional[Tuple[str, str]] = None,
unique_id: Optional[int] = None
@@ -341,6 +343,7 @@ class Source(Plugin):
self.__element_kind = meta.element_kind # The kind of the element owning this source
self.__directory = meta.directory # Staging relative directory
self.__meta_kind = meta.kind # The kind of this source, required for unpickling
+ self.__variables = variables # The variables used to resolve the source's config
self.__key = None # Cache key for source
@@ -354,6 +357,8 @@ class Source(Plugin):
# ask the element to configure itself.
self.__init_defaults(project, meta)
self.__config = self.__extract_config(meta)
+ variables.expand(self.__config)
+
self.__first_pass = meta.first_pass
# cached values for commonly access values on the source
@@ -1238,7 +1243,9 @@ class Source(Plugin):
meta.first_pass = self.__first_pass
- clone = source_kind(context, project, meta, alias_override=(alias, uri), unique_id=self._unique_id)
+ clone = source_kind(
+ context, project, meta, self.__variables, alias_override=(alias, uri), unique_id=self._unique_id
+ )
# Do the necessary post instantiation routines here
#