diff options
author | Jürg Billeter <j@bitron.ch> | 2017-07-04 09:45:27 +0200 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-07-05 20:32:20 +0900 |
commit | c9e6cb91a6a6f8ad096bbb7e025c005fc0051346 (patch) | |
tree | 7220d4357beef1f5bedc1298a2a0384401a47bb8 | |
parent | c4474f65641049d4261345f149782a87a7fe921b (diff) | |
download | buildstream-c9e6cb91a6a6f8ad096bbb7e025c005fc0051346.tar.gz |
element.py: Support dynamic public data
Plugin assemble() methods may supplement public data returned by
Element.get_public_data() with generated data. Public data is stored in
the artifact cache and automatically loaded as appropriate.
-rw-r--r-- | buildstream/element.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/buildstream/element.py b/buildstream/element.py index afaef0b05..e1e0c569d 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -112,6 +112,7 @@ class Element(Plugin): # Grab public domain data declared for this instance self.__public = self.__extract_public(meta) + self.__dynamic_public = None # Collect the composited element configuration and # ask the element to configure itself. @@ -420,7 +421,10 @@ class Element(Plugin): Returns: (dict): The public data dictionary for the given domain """ - return self.__public.get(domain) + if self.__dynamic_public is None: + self._load_public_data() + + return self.__dynamic_public.get(domain) def get_environment(self): """Fetch the environment suitable for running in the sandbox @@ -787,6 +791,10 @@ class Element(Plugin): sandbox_root = sandbox.get_directory() + # By default, the dynamic public data is the same as the static public data. + # The plugin's assemble() method may modify this, though. + self.__dynamic_public = self.__public + # Call the abstract plugin methods try: # Step 1 - Configure @@ -828,7 +836,7 @@ class Element(Plugin): shutil.copyfile(self.__log_path, os.path.join(logsdir, 'build.log')) # Store public data - _yaml.dump(_yaml.node_sanitize(self.__public), os.path.join(metadir, 'public.yaml')) + _yaml.dump(_yaml.node_sanitize(self.__dynamic_public), os.path.join(metadir, 'public.yaml')) with self.timed_activity("Caching Artifact"): self.__artifacts.commit(self, assembledir) @@ -1241,3 +1249,11 @@ class Element(Plugin): if include_file: yield filename.lstrip(os.sep) + + def _load_public_data(self): + self._assert_cached() + assert(self.__dynamic_public is None) + + # Load the public data from the artifact + metadir = os.path.join(self.__artifacts.extract(self), 'meta') + self.__dynamic_public = _yaml.load(os.path.join(metadir, 'public.yaml')) |