summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan van Berkom <tristan@codethink.co.uk>2020-12-11 18:58:26 +0900
committerTristan van Berkom <tristan@codethink.co.uk>2020-12-11 19:28:40 +0900
commit55d82db8c91827157e8765372d73831162ef9014 (patch)
tree25e8cea2b9cc6607bfd6068b7b673e98536faddd
parent0f59c939884d618a6ef743aa2e57eb50016f0abf (diff)
downloadbuildstream-55d82db8c91827157e8765372d73831162ef9014.tar.gz
element.py: Added internal API _mimic_artifact()
This function causes the element to mimic it's artifact instance, and is initially used when instantiating from an artifact. This needs to be exposed so that ArtifactElement can trigger this activity in response to _pull_done(). Additionally, this adds the declaration of __environment and __variables to the __init__ function, as I received some complaints from pylint and mypy from this commit.
-rw-r--r--src/buildstream/element.py38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index 945ca5cf7..6c813f764 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -315,6 +315,9 @@ class Element(Plugin):
self.__resolved_initial_state = False # Whether the initial state of the Element has been resolved
+ self.__environment: Dict[str, str] = {}
+ self.__variables: Optional[Variables] = None
+
if artifact:
self.__initialize_from_artifact(artifact)
else:
@@ -816,6 +819,7 @@ class Element(Plugin):
variable was declared with the given name.
"""
# Flat is not recognized correctly by Pylint as being a dictionary
+ assert self.__variables
return self.__variables.get(varname) # pylint: disable=no-member
def batch_prepare_assemble(self, flags: int, *, collect: Optional[str] = None) -> None:
@@ -2418,6 +2422,28 @@ class Element(Plugin):
assert self.__artifact, "{}: has no Artifact object".format(self.name)
return self.__artifact
+ # _mimic_artifact()
+ #
+ # Assume the state dictated by the currently set artifact.
+ #
+ # This is used both when initializing an Element's state
+ # from a loaded artifact, or after pulling the artifact from
+ # a remote.
+ #
+ def _mimic_artifact(self):
+ artifact = self._get_artifact()
+
+ # Load bits which have been stored on the artifact
+ #
+ if artifact.cached():
+ self.__environment = artifact.load_environment()
+ self.__sandbox_config = artifact.load_sandbox_config()
+ self.__variables = artifact.load_variables()
+
+ self.__cache_key = artifact.strong_key
+ self.__strict_cache_key = artifact.strict_key
+ self.__weak_cache_key = artifact.weak_key
+
# _add_build_dependency()
#
# Add a build dependency to the Element
@@ -2858,17 +2884,7 @@ class Element(Plugin):
#
def __initialize_from_artifact(self, artifact: Artifact):
self.__artifact = artifact
-
- # Load bits which have been stored on the artifact
- #
- if artifact.cached():
- self.__environment = artifact.load_environment()
- self.__sandbox_config = artifact.load_sandbox_config()
- self.__variables = artifact.load_variables()
-
- self.__cache_key = artifact.strong_key
- self.__strict_cache_key = artifact.strict_key
- self.__weak_cache_key = artifact.weak_key
+ self._mimic_artifact()
@classmethod
def __compose_default_splits(cls, project, defaults, first_pass):