summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-05 21:36:51 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-05 21:36:51 +0900
commit8806a8841e1829791c1b532e71cf6b4b4f5e4a26 (patch)
treee582efe0e049f837975665ab24fd6665f4c31c7f
parent2fe770f6859c25cb9d93f1cb732b35d02ddaa334 (diff)
downloadbuildstream-8806a8841e1829791c1b532e71cf6b4b4f5e4a26.tar.gz
element.py: Added Element.set_public_data()
And use deep copies with both Element.set_public_data() and Element.get_public_data(), avoiding unintentional mutations of the underlying data model.
-rw-r--r--buildstream/element.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/buildstream/element.py b/buildstream/element.py
index 5e1996d73..c27ce690c 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -420,11 +420,44 @@ class Element(Plugin):
Returns:
(dict): The public data dictionary for the given domain
+
+ .. note::
+
+ This can only be called in the build phase of an element and
+ never before. This may be called in
+ :func:`Element.configure_sandbox() <buildstream.element.Element.configure_sandbox>`,
+ :func:`Element.stage() <buildstream.element.Element.stage>` and in
+ :func:`Element.assemble() <buildstream.element.Element.assemble>`
+
"""
if self.__dynamic_public is None:
self._load_public_data()
- return self.__dynamic_public.get(domain)
+ data = self.__dynamic_public.get(domain)
+ if data is not None:
+ data = copy.deepcopy(data)
+
+ return data
+
+ def set_public_data(self, domain, data):
+ """Set public data on this element
+
+ Args:
+ domain (str): A public domain name to fetch data for
+ data (dict): The public data dictionary for the given domain
+
+ This allows an element to dynamically mutate public data of
+ elements or add new domains as the result of success completion
+ of the :func:`Element.assemble() <buildstream.element.Element.assemble>`
+ method.
+ """
+ if self.__dynamic_public is None:
+ self._load_public_data()
+
+ if data is not None:
+ data = copy.deepcopy(data)
+
+ self.__dynamic_public[domain] = data
def get_environment(self):
"""Fetch the environment suitable for running in the sandbox