Skip to contentSkip to conversation

Fix dependency handling bug of remove operator

PATCH New Insu Park 1 participant 2 messages Sep 19, 2023

lore
Share & tools
lore

Insu Park

author
#0 lore raw

v2 cover Fix dependency handling bug of remove operator

Unlike the meta layers under the Yocto projects, custom layers frequently use following style of overriding to disable something default in the base layer without touching it:
bb in the base layer:
OPTIONS = "foo bar"
bbappend in the custom layer:
OPTIONS:remove = "${@bb.utils.contains('CUSTOM_FEATURES', 'no-foo', 'foo', '', d)}"

The problem is that the value of "CUSTOM_FEATURES" is not shown in the task signature. Here is a test example.

test-override-operators.bb:

    ANOTHERVAR = "testval"
    ANOTHERVAR:prepend = "${@bb.utils.filter('TESTVAR1', 'testval1', d)} "
    ANOTHERVAR:append = " ${@bb.utils.filter('TESTVAR2', 'testval2', d)}"
    ANOTHERVAR:remove = "${@bb.utils.contains('TESTVAR3', 'no-testval', 'testval', '', d)}"

local.conf:
TESTVAR1 = "blah"
TESTVAR2 = "testval2"
TESTVAR3 = "blah"

Signature dump (Bug):
Variable ANOTHERVAR value is ${@bb.utils.filter('TESTVAR1', 'testval1', d)} testval ${@bb.utils.filter('TESTVAR2', 'testval2', d)} TESTVAR1{testval1} = Unset
TESTVAR2{testval2} = Set
_remove of ${@bb.utils.contains('TESTVAR3', 'no-testval', 'testval', '', d)}

Note that the signature dump above doesn't take the value of TESTVAR3 into account. Therefore, even if the local.conf changes the TESTVAR3 value to "no-testval", the two different configs produce exactly same signature, so the recipe won't be re-built, even worse, its sstate-cache output is not deterministic (depend on the config it first met).

With the fixed code, the new signature recognizes the TESTVAR3, and the problem solved. Signature dump (Fixed):
(Same as above)
TESTVAR3{no-testval} = Unset

Now, the new test case fails without the fix:

|$ bitbake-selftest bb.tests.codeparser.DependencyReferenceTest.test_contains_vardeps_override_operators
|F
|======================================================================
|FAIL: test_contains_vardeps_override_operators (bb.tests.codeparser.DependencyReferenceTest)
|----------------------------------------------------------------------
|Traceback (most recent call last):
|  File "/home/worker/work/poky-test/bitbake/lib/bb/tests/codeparser.py", line 454, in test_contains_vardeps_override_operators
|    self.assertEqual(sorted(values.splitlines()),
|AssertionError: Lists differ: ['${@[155 chars]t', '_remove of ${@bb.utils.contains("TESTVAR3[32 chars]d)}'] != ['${@[155 chars]t', 'TESTVAR3{no-testval} = Set', '_remove of [62 chars]d)}']
|
|First differing element 3:
|'_remove of ${@bb.utils.contains("TESTVAR3", "no-testval", "testval", "", d)}'
|'TESTVAR3{no-testval} = Set'
|
|Second list contains 1 additional elements.
|First extra element 4:
|'_remove of ${@bb.utils.contains("TESTVAR3", "no-testval", "testval", "", d)}'
|
|  ['${@bb.utils.filter("TESTVAR1", "testval1", d)} testval '
|   '${@bb.utils.filter("TESTVAR2", "testval2", d)}',
|   'TESTVAR1{testval1} = Unset',
|   'TESTVAR2{testval2} = Set',
|+  'TESTVAR3{no-testval} = Set',
|   '_remove of ${@bb.utils.contains("TESTVAR3", "no-testval", "testval", "", d)}']
|
|----------------------------------------------------------------------
|Ran 1 test in 0.002s
|
|FAILED (failures=1)

Insu Park (1):
bitbake: data: Add missing dependency handling of remove operator

 lib/bb/data.py             |  1 +
 lib/bb/tests/codeparser.py | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 1/1 bitbake: data: Add missing dependency handling of remove operator

A recipe variable handles its dependencies even on the "contains" variables within the "inline Python expressions" like bb.utils.filter(). And it also handles those in the append operator correctly, but the problem is that it does not so in the remove operator.

Fix it by adding the missing dependencies every time the remove operator has been handled.
Also add a test case to check if the override operators handle dependencies correctly.

---
 lib/bb/data.py             |  1 +
 lib/bb/tests/codeparser.py | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
lib/bb/data.py +1 -0
index 3ee8f5e7..505f4295 100644
@@ -285,6 +285,7 @@ def build_dependencies(key, keys, mod_funcs, shelldeps, varflagsexcl, ignored_va
             value += "\n_remove of %s" % r
             deps |= r2.references
             deps = deps | (keys & r2.execs)
+            value = handle_contains(value, r2.contains, exclusions, d)
         return value
 
     deps = set()
lib/bb/tests/codeparser.py +26 -0
index a64c614b..b6f2b77e 100644
@@ -436,6 +436,32 @@ esac
         self.assertEqual(deps, set(["TESTVAR2"]))
         self.assertEqual(self.d.getVar('ANOTHERVAR').split(), ['testval3', 'anothervalue'])
 
+    def test_contains_vardeps_override_operators(self):
+        # Check override operators handle dependencies correctly with the contains functionality
+        expr_plain = 'testval'
+        expr_prepend = '${@bb.utils.filter("TESTVAR1", "testval1", d)} '
+        expr_append = ' ${@bb.utils.filter("TESTVAR2", "testval2", d)}'
+        expr_remove = '${@bb.utils.contains("TESTVAR3", "no-testval", "testval", "", d)}'
+        # Check dependencies
+        self.d.setVar('ANOTHERVAR', expr_plain)
+        self.d.prependVar('ANOTHERVAR', expr_prepend)
+        self.d.appendVar('ANOTHERVAR', expr_append)
+        self.d.setVar('ANOTHERVAR:remove', expr_remove)
+        self.d.setVar('TESTVAR1', 'blah')
+        self.d.setVar('TESTVAR2', 'testval2')
+        self.d.setVar('TESTVAR3', 'no-testval')
+        deps, values = bb.data.build_dependencies("ANOTHERVAR", set(self.d.keys()), set(), set(), set(), set(), self.d, self.d)
+        self.assertEqual(sorted(values.splitlines()),
+                         sorted([
+                          expr_prepend + expr_plain + expr_append,
+                          '_remove of ' + expr_remove,
+                          'TESTVAR1{testval1} = Unset',
+                          'TESTVAR2{testval2} = Set',
+                          'TESTVAR3{no-testval} = Set',
+                          ]))
+        # Check final value
+        self.assertEqual(self.d.getVar('ANOTHERVAR').split(), ['testval2'])
+
     #Currently no wildcard support
     #def test_vardeps_wildcards(self):
     #    self.d.setVar("oe_libinstall", "echo test")
Signature · 1 line
2.25.1