bitbake: fix ??= operator for getVarFlags and test
cover bitbake: fix ??= operator for getVarFlags and test
Since commit 0329a7e3ac694737f2d2c1861f65492551360663, weak default values are omitted while they were only incorrect before. The first patch fixes the issue, the second adds a test for validation.
Fixes [YOCTO #15685]
---
Louis Rannou (2):
bitbake: data_smart: fix ??= operator for getVarFlags
bitbake: tests/parse: add test for getVarFlags
lib/bb/data_smart.py | 16 +++++++++++++--- lib/bb/tests/parse.py | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-)
---
base-commit: bcf090ed631bbd523a5341baebba0765f1a847f8
change-id: 20250212-varflags-7e56f73a3966
Best regards,
Signature · 1 line
Louis Rannou <[email protected]>
PATCH 1/2 bitbake: data_smart: fix ??= operator for getVarFlags
From: Louis Rannou <[email protected]>
Variable flags have been fixed in commit 0329a7e3ac694737f2d2c1861f65492551360663 which introduces the "_defaultval_flag_" prefix for default values. This must not be ignored as others "_"-prefixed flags names.
Split the processing of default values to be sure they are overwritted by the others operators disregarding of their order.
Fixes [YOCTO #15685]
--- lib/bb/data_smart.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
lib/bb/data_smart.py +13 -3
@@ -952,12 +952,22 @@ class DataSmart(MutableMapping): def getVarFlags(self, var, expand = False, internalflags=False): local_var = self._findVar(var) flags = {} + flags_set = {} if local_var: - for i in local_var: - if i.startswith(("_", ":")) and not internalflags: + for i, val in local_var.items(): + if i.startswith("_defaultval_flag_"): + i = i[len("_defaultval_flag_"):] + flags[i] = val + elif i.startswith(("_", ":")) and not internalflags: continue - flags[i] = local_var[i] + else: + flags_set[i] = val + + # Flags sets take over defaults + flags.update(flags_set) + + for i in flags: if expand and i in expand: flags[i] = self.expand(flags[i], var + "[" + i + "]") if len(flags) == 0:
Signature · 1 line
2.48.1
Re: [bitbake-devel] [PATCH 1/2] bitbake: data_smart: fix ??= operator for getVarFlags
Quoted 44 lines · Louis Rannou via lists.openembedded.org
From: Louis Rannou <[email protected]>
Variable flags have been fixed in commit
0329a7e3ac694737f2d2c1861f65492551360663which introduces the "_defaultval_flag_" prefix for default values. This must not be ignored as others "_"-prefixed flags names.Split the processing of default values to be sure they are overwritted by the others operators disregarding of their order.
Fixes [YOCTO #15685]
Signed-off-by Louis Rannou <[email protected]>---
lib/bb/data_smart.py | 16 +++++++++++++---1 file changed, 13 insertions(+), 3 deletions(-)lib/bb/data_smart.py +0
-0@@ -952,12 +952,22 @@ class DataSmart(MutableMapping):def
getVarFlags(self, var, expand = False, internalflags=False):
local_var=self._findVar(var)
flags = {}
+flags_set= {}
iflocal_var:
- for i inlocal_var:
- ifi.startswith(("_", ":"))and not internalflags:
+ for i, val inlocal_var.items():
+ ifi.startswith("_defaultval_flag_"):
+ i = i[len("_defaultval_flag_"):]
+ flags[i] = val
+ elifi.startswith(("_", ":"))and not internalflags:
continue
- flags[i] = local_var[i]
+ else:
+ flags_set[i] = vallib/bb/data_smart.py +5
-0+ + # Flags sets take over defaults + flags.update(flags_set) + + for i in flags:
Quoted 4 lines
if expand and i in expand:
flags[i] =self.expand(flags[i], var + "[" + i + "]")if len(flags) == 0:
I've not gone into the details but this doesn't look right at all unfortunately. It looks over complicated, it is special casing magic values which we try very very hard not to do and I don't think this is going to be maintainable code. We're need to find a better solution. Without diving into the code I'm going to struggle to provide better advice though.
Cheers,
Richard
Re: [bitbake-devel] [PATCH 1/2] bitbake: data_smart: fix ??= operator for getVarFlags
In reply to Louis RannouQuoted 44 lines · Louis Rannou via lists.openembedded.org
From: Louis Rannou <[email protected]>
Variable flags have been fixed in commit
0329a7e3ac694737f2d2c1861f65492551360663which introduces the "_defaultval_flag_" prefix for default values. This must not be ignored as others "_"-prefixed flags names.Split the processing of default values to be sure they are overwritted by the others operators disregarding of their order.
Fixes [YOCTO #15685]
Signed-off-by Louis Rannou <[email protected]>---
lib/bb/data_smart.py | 16 +++++++++++++---1 file changed, 13 insertions(+), 3 deletions(-)lib/bb/data_smart.py +0
-0@@ -952,12 +952,22 @@ class DataSmart(MutableMapping):def
getVarFlags(self, var, expand = False, internalflags=False):
local_var=self._findVar(var)
flags = {}
+flags_set= {}
iflocal_var:
- for i inlocal_var:
- ifi.startswith(("_", ":"))and not internalflags:
+ for i, val inlocal_var.items():
+ ifi.startswith("_defaultval_flag_"):
+ i = i[len("_defaultval_flag_"):]
+ flags[i] = val
+ elifi.startswith(("_", ":"))and not internalflags:
continue
- flags[i] = local_var[i]
+ else:
+ flags_set[i] = vallib/bb/data_smart.py +5
-0+ + # Flags sets take over defaults + flags.update(flags_set) + + for i in flags:
Quoted 3 lines
if expand and i in expand:
flags[i] =self.expand(flags[i], var + "[" + i + "]")if len(flags) == 0:
I did spend more time looking at this and I had misunderstood the problem. I think this can still be simplified though and I also suspect the internalflags handling above isn't correct. If internalflags is set, I think it probably should return _defaultval_flag_ values unchanged. The code would therefore look more like:
for i, val in local_var.items():
if i.startswith("_defaultval_flag_") and not internalflags:
i = i[len("_defaultval_flag_"):]
if i not in local_var:
flags[i] = val
elif i.startswith(("_", ":")) and not internalflags:
continue
else:
flags_set[i] = val
I'd also add a comment to the test case explaining that we're testing weak default make it to the getVarFlags output.
Cheers,
Richard
Re: [bitbake-devel] [PATCH 1/2] bitbake: data_smart: fix ??= operator for getVarFlags
Hello,
Ok for the solution which is indeed prettier. I'll add a test with internalflags.
I also agree the test is not exactly at the right place as it does not test parsing but the result of getVarFlags. Perhaps it would fit better in tests/data.py ? (if that's ok to make a call to bb.parse there)
Thanks,
Louis
Quoted 72 lines · Richard Purdie
Quoted 37 lines · Louis Rannou via lists.openembedded.org
From: Louis Rannou <[email protected]>
Variable flags have been fixed in commit
0329a7e3ac694737f2d2c1861f65492551360663which introduces the "_defaultval_flag_" prefix for default values. This must not be ignored as others "_"-prefixed flags names.Split the processing of default values to be sure they are overwritted by the others operators disregarding of their order.
Fixes [YOCTO #15685]
Signed-off-by Louis Rannou <[email protected]>--- lib/bb/data_smart.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)lib/bb/data_smart.py +6
-3@@ -952,12 +952,22 @@ class DataSmart(MutableMapping): def getVarFlags(self, var, expand = False, internalflags=False): local_var = self._findVar(var) flags = {} + flags_set = {} if local_var: - for i in local_var: - if i.startswith(("_", ":")) and not internalflags: + for i, val in local_var.items(): + if i.startswith("_defaultval_flag_"): + i = i[len("_defaultval_flag_"):] + flags[i] = val + elif i.startswith(("_", ":")) and not internalflags: continue - flags[i] = local_var[i]lib/bb/data_smart.py class DataSmart(MutableMapping): · line 973
Quoted 10 lines
lib/bb/data_smart.py +7
-0+ else: + flags_set[i] = val + + # Flags sets take over defaults + flags.update(flags_set) + + for i in flags: if expand and i in expand: flags[i] = self.expand(flags[i], var + "[" + i + "]") if len(flags) == 0:I did spend more time looking at this and I had misunderstood the problem. I think this can still be simplified though and I also suspect the internalflags handling above isn't correct. If internalflags is set, I think it probably should return _defaultval_flag_ values unchanged. The code would therefore look more like:
for i, val in
local_var.items():
ifi.startswith("_defaultval_flag_")and not internalflags:
i = i[len("_defaultval_flag_"):]
if i not inlocal_var:
flags[i] = val
elifi.startswith(("_", ":"))and not internalflags:
continue
else:
flags_set[i] = valI'd also add a comment to the test case explaining that we're testing weak default make it to the getVarFlags output.
Cheers,
Richard
PATCH 2/2 bitbake: tests/parse: add test for getVarFlags
In reply to Louis RannouFrom: Louis Rannou <[email protected]>
Run the test with:
$ bitbake-selftest bb.tests.parse.ParseTest.test_parse_defaulttest
test_parse_defaulttest (bb.tests.parse.ParseTest.test_parse_defaulttest) ... ok ----------------------------------------------------------------------
Ran 1 test in 0.001s
OKThis is a test case for [YOCTO #15685]
--- lib/bb/tests/parse.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
lib/bb/tests/parse.py +16 -0
@@ -127,6 +127,22 @@ A[flag_default_twice] ??= "default flag second" self.assertEqual(d.getVarFlag("A","flag_set_twice"), "set flag second") self.assertEqual(d.getVarFlag("A","flag_question_twice"), "question flag first") self.assertEqual(d.getVarFlag("A","flag_default_twice"), "default flag second") + self.assertDictEqual( + d.getVarFlags("A"), + { + "flag_set_vs_question": "set flag", + "flag_set_vs_default": "set flag", + "flag_question": "question flag", + "flag_default": "default flag", + "flag_question_vs_default": "question flag", + "flag_default_vs_question": "question flag", + "flag_set_question_default": "set flag", + "flag_set_default_question": "set flag", + "flag_set_twice": "set flag second", + "flag_question_twice": "question flag first", + "flag_default_twice": "default flag second", + } + ) exporttest = """ A = "a"
Signature · 1 line
2.48.1