]> code.ossystems Code Review - openembedded-core.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)
committerRichard Purdie <rpurdie@linux.intel.com>
Tue, 4 Jan 2011 14:46:52 +0000 (14:46 +0000)
(Bitbake rev: 40778a6e9e82c7ea4673a74fc19574430fa63e8d)

Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
bitbake/lib/bb/cooker.py
bitbake/lib/bb/data_smart.py

index 548273380f69d65dbd671416b4c48e9db9ef7d69..9c48194a614661ebf052fa12aaae41473b87be6f 100644 (file)
@@ -502,19 +502,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 16270461a443d5cc7e3ab184016da3a8bb6732be..ca72449b751856f8547dbba4781443cd3e90b44f 100644 (file)
@@ -361,6 +361,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):