Skip to contentSkip to conversation

data_smart: Fix an unusual variable reference bug

PATCH New Richard Purdie 1 participant 1 message May 21, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 data_smart: Fix an unusual variable reference bug

If you try:

Y = ""
Y_remove = "X"

in OE-Core, bitbake will crash with a KeyError during expansion. The reason is that no expansion of the empty value is attempted but removal from is it and hence no varparse data is present for it in the expand_cache.

If the value is empty, there is nothing to remove so the best fix is simply not to check for None but check it has any value.

Also add a test for this error so it doesn't get reintroduced.

bitbake/lib/bb/data_smart.py +1 -1
index 27806f9..db0f8e6 100644
@@ -641,7 +641,7 @@ class DataSmart(MutableMapping):
             else:
                 cachename = var + "[" + flag + "]"
             value = self.expand(value, cachename)
-        if value is not None and flag == "_content" and local_var is not None and "_removeactive" in local_var:
+        if value and flag == "_content" and local_var is not None and "_removeactive" in local_var:
             filtered = filter(lambda v: v not in local_var["_removeactive"],
                               value.split(" "))
             value = " ".join(filtered)
bitbake/lib/bb/tests/data.py +5 -0
index ee66b22..228f72c 100644
@@ -253,6 +253,11 @@ class TestConcatOverride(unittest.TestCase):
         bb.data.update_data(self.d)
         self.assertEqual(self.d.getVar("TEST_TEST", True), "bar bar")
 
+    def test_empty_remove(self):
+        self.d.setVar("TEST", "")
+        self.d.setVar("TEST_remove", "val")
+        bb.data.update_data(self.d)
+        self.assertEqual(self.d.getVar("TEST", True), "")
 
 class TestOverrides(unittest.TestCase):
     def setUp(self):