]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
Move LAYERDIR expansion hack into DataSmart
authorChris Larson <chris_larson@mentor.com>
Fri, 17 Dec 2010 19:15:48 +0000 (12:15 -0700)
committerChris Larson <chris_larson@mentor.com>
Fri, 17 Dec 2010 19:15:54 +0000 (12:15 -0700)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
TODO
lib/bb/cooker.py
lib/bb/data_smart.py

diff --git a/TODO b/TODO
index e978427536eeaf415f2c5b6b95a8c5ca6c957c74..cfc9ee964a6e3f4b11957794267506d4ba248f3b 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,4 @@
 - Reimplement the interactive mode as a proper ui
-- Move the LAYERDIR expansion hack into DataSmart, as that's where code that
-  depends upon its internals belongs
 - Continue dropping fatal/SystemExit/sys.exit usage in favor of raising
   appropriate exceptions
 - Continue pylint / pyflakes / pychecker / pep8 fixups
index 68d07cb14dce1de6315adfc7672fbbae4a3396af..c8ca099805a3dbf492b69e7659fda21bf28821c6 100644 (file)
@@ -500,19 +500,7 @@ class BBCooker:
                 parselog.debug(2, "Adding layer %s", layer)
                 bb.data.setVar('LAYERDIR', layer, data)
                 data = _parse(os.path.join(layer, "conf", "layer.conf"), data)
-
-                # XXX: Hack, relies on the local keys of the datasmart
-                # instance being stored in the 'dict' attribute and makes
-                # assumptions about how variable expansion works, but
-                # there's no better way to force an expansion of a single
-                # variable across the datastore today, and this at least
-                # lets us reference LAYERDIR without having to immediately
-                # eval all our variables that use it.
-                for key in data.dict:
-                    if key != "_data":
-                        value = data.getVar(key, False)
-                        if value and "${LAYERDIR}" in value:
-                            data.setVar(key, value.replace("${LAYERDIR}", layer))
+                data.expandVarref('LAYERDIR')
 
             bb.data.delVar('LAYERDIR', data)
 
index 7a81bd14d1262c933c996c9fa3674e63c5aae2f3..a766f3241ae89b31b1fd260771eb90a77af1fe7b 100644 (file)
@@ -335,6 +335,27 @@ class DataSmart(MutableMapping):
 
         return data
 
+    def expandVarref(self, variable, parents=False):
+        """Find all references to variable in the data and expand it
+           in place, optionally descending to parent datastores."""
+
+        if parents:
+            keys = iter(self)
+        else:
+            keys = self.localkeys()
+
+        ref = '${%s}' % variable
+        value = self.getVar(variable, False)
+        for key in keys:
+            referrervalue = self.getVar(key, False)
+            if ref in referrervalue:
+                self.setVar(key, referrervalue.replace(ref, value))
+
+    def localkeys(self):
+        for key in self.dict:
+            if key != '_data':
+                yield key
+
     def __iter__(self):
         seen = set()
         def _keys(d):