diff mbox series

[v2,2/2] data_smart: fix ??= operator for variable flags

Message ID 20250110225652.3892828-2-yoann.congal@smile.fr
State Accepted, archived
Commit 0329a7e3ac694737f2d2c1861f65492551360663
Headers show
Series [v2,1/2] tests/parse: add test for ?= and ??= operators for variable flags | expand

Commit Message

Yoann Congal Jan. 10, 2025, 10:56 p.m. UTC
From: Yoann Congal <yoann.congal@smile.fr>

??= operator works for variable value by defining a "_defaultval" flag.

Use something similar for flags: For the default value of the flag
"flag_name", define a flag "_defaultval_flag_flagname" that is used when
reading flag_name but no other value has been set.

Fixes [YOCTO #15685]

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
Reviewed-by: Ghislain Mangé <ghislain.mange@smile.fr>
Suggested-by: Ola Nilsson <ola.x.nilsson@axis.com>
---
v1->v2:
* Refactor condition from Ghislain's suggestion
* Added Suggested-by: Ola Nilsson <ola.x.nilsson@axis.com> since they
  correctly pointed out the fix location.
---
 lib/bb/data_smart.py | 2 ++
 lib/bb/parse/ast.py  | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/bb/data_smart.py b/lib/bb/data_smart.py
index c6049d578..897ceeb32 100644
--- a/lib/bb/data_smart.py
+++ b/lib/bb/data_smart.py
@@ -827,6 +827,8 @@  class DataSmart(MutableMapping):
                 value = copy.copy(local_var[flag])
             elif flag == "_content" and "_defaultval" in local_var and not noweakdefault:
                 value = copy.copy(local_var["_defaultval"])
+            elif "_defaultval_flag_"+flag in local_var and not noweakdefault:
+                value = copy.copy(local_var["_defaultval_flag_"+flag])
 
 
         if flag == "_content" and local_var is not None and ":append" in local_var and not parsing:
diff --git a/lib/bb/parse/ast.py b/lib/bb/parse/ast.py
index 2f6c6a005..30ede008d 100644
--- a/lib/bb/parse/ast.py
+++ b/lib/bb/parse/ast.py
@@ -152,7 +152,10 @@  class DataNode(AstNode):
 
         flag = None
         if 'flag' in groupd and groupd['flag'] is not None:
-            flag = groupd['flag']
+            if groupd["lazyques"]:
+                flag = "_defaultval_flag_"+groupd['flag']
+            else:
+                flag = groupd['flag']
         elif groupd["lazyques"]:
             flag = "_defaultval"