Bug 15685 - ??= behaves as = for variable flags
Summary: ??= behaves as = for variable flags
Status: RESOLVED FIXED
Alias: None
Product: BitBake
Classification: Build System, Metadata & Runtime
Component: bitbake (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Medium+ normal
Target Milestone: 5.2 M3
Assignee: Louis Rannou
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2024-12-09 10:32 UTC by Ola Nilsson
Modified: 2025-02-18 10:10 UTC (History)
7 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: Don't know


Attachments
Failing test case for getVarFlags() (3.12 KB, patch)
2025-02-11 17:10 UTC, Yoann Congal
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ola Nilsson 2024-12-09 10:32:38 UTC
VARIABLE[flag] ??= "value"
behaves as 
VARIABLE[flag] = "value"

while the docs say that "All the standard syntax operations previously mentioned work for variable flags except for override style syntax".

I _think_ it's because in DataNode::eval 

        flag = None
        if 'flag' in groupd and groupd['flag'] is not None:
            flag = groupd['flag']
        elif groupd["lazyques"]:
            flag = "_defaultval"

will leave op = "set" even if groupd['op'] == 'lazyques'. 
But I can't find the code that cares about op, so I could be wrong.

If ??= is not supported for flag assignments, we should at least get an error.
Comment 1 Richard Purdie 2024-12-09 17:49:46 UTC
I think this is a bug and ??= should work for flags as expected.

We should probably add a test case to lib/bb/tests/ and then fix the code, you're probably on the right track with the code fix but I need to look in more detail. The test case will help test before/after the fix.
Comment 2 Randy MacLeod 2024-12-12 15:40:20 UTC
Should fix but not urgent. Yoann will work on this next year!
Comment 3 Yoann Congal 2025-01-09 23:00:16 UTC
Reproducer:

#local.conf:
TEST = "good value"
TEST ??= "bad value"
TEST[flag] = "good flag"
TEST[flag] ??= "bad flag"

Then:

 $ bitbake-getvar TEST ; echo -n "TEST[flag] = " ; bitbake-getvar TEST -f flag --value 
#
# $TEST [4 operations]
#   set /home/yocon/Documents/projets/yocto/poky_bb_intero_flag/build/conf/local.conf:291
#     "good value"
#   set /home/yocon/Documents/projets/yocto/poky_bb_intero_flag/build/conf/local.conf:292
#     [_defaultval] "bad value"
#   set /home/yocon/Documents/projets/yocto/poky_bb_intero_flag/build/conf/local.conf:293
#     [flag] "good flag"
#   set /home/yocon/Documents/projets/yocto/poky_bb_intero_flag/build/conf/local.conf:294
#     [flag] "bad flag"
# pre-expansion value:
#   "good value"
TEST="good value"
TEST[flag] =bad flag

^ this should display "good flag" (like it does for "good value")
Comment 4 Yoann Congal 2025-01-10 19:11:37 UTC
Patch v1 sent:
bitbake-devel@lists.openembedded.org | [PATCH 1/2] tests/parse: add test for ?= and ??= operators for variable flags
https://lists.openembedded.org/g/bitbake-devel/topic/patch_1_2_tests_parse_add/110541105
bitbake-devel@lists.openembedded.org | [PATCH 2/2] data_smart: fix ??= operator for variable flags
https://lists.openembedded.org/g/bitbake-devel/topic/patch_2_2_data_smart_fix/110541106
Comment 5 Yoann Congal 2025-01-10 23:01:37 UTC
Patch v2:
bitbake-devel@lists.openembedded.org | [PATCH v2 1/2] tests/parse: add test for ?= and ??= operators for variable flags
https://lists.openembedded.org/g/bitbake-devel/topic/patch_v2_1_2_tests_parse/110545216
bitbake-devel@lists.openembedded.org | [PATCH v2 2/2] data_smart: fix ??= operator for variable flags
https://lists.openembedded.org/g/bitbake-devel/topic/patch_v2_2_2_data_smart/110545217
Comment 6 Yoann Congal 2025-01-15 23:01:58 UTC
Merged:
tests/parse: add test for ?= and ??= operators for variable flags - bitbake - Bitbake Development tree
https://git.openembedded.org/bitbake/commit/?id=d12c80125d810df54379cc4f019a95ab9064ad2c
data_smart: fix ??= operator for variable flags - bitbake - Bitbake Development tree
https://git.openembedded.org/bitbake/commit/?id=0329a7e3ac694737f2d2c1861f65492551360663
Comment 7 Yoann Congal 2025-02-11 17:10:38 UTC
Created attachment 5096 [details]
Failing test case for getVarFlags()
Comment 8 Yoann Congal 2025-02-11 17:14:00 UTC
Louis Rannou found a bug with the current fix:
* default varflags are excluded from d.getVarFlags() dict but should be (at least I would expect it)
* https://bugzilla.yoctoproject.org/attachment.cgi?id=5096 attached patch to trigger the bug
* Simpler version: In the current testcase:
  self.assertTrue("flag_default" in d.getVarFlags("A"))
Comment 9 Yoann Congal 2025-02-11 18:00:43 UTC
I guess we need to act on "_defaultval_flag_*" variables in getVarFlags() instead of skipping them currently: https://git.openembedded.org/bitbake/tree/lib/bb/data_smart.py?id=93059aad13a12cd69d86368795c88e5349197d5d#n952
Comment 10 Richard Purdie 2025-02-11 22:30:57 UTC
you may need to pass internalflags=True to getVarFlags()?
Comment 11 Louis Rannou 2025-02-13 13:46:35 UTC
Hello,

I'm quite ready for a v2 patch but I'm having some incoherences.

First of all, I found that calling delVar("A") will blow out all flags. Is that expected ? Perhaps we can have an extra argument to say if we want flags to be deleted or not.

Second, delVarFlag("A", "flag1") will erase the flag1 but not its weak default. I suppose the default must be removed too ?
Comment 12 Yoann Congal 2025-02-13 16:01:28 UTC
Louis sent a v2:
[PATCH v2 0/2] bitbake: fix ??= operator for variable flags and test
https://lists.openembedded.org/g/bitbake-devel/topic/patch_v2_0_2_bitbake_fix/111163809
[PATCH v2 1/2] bitbake: data_smart: fix ??= operator for variable flags
https://lists.openembedded.org/g/bitbake-devel/topic/patch_v2_1_2_bitbake/111163810
[PATCH v2 2/2] bitbake: tests/data: add tests for variable flags
https://lists.openembedded.org/g/bitbake-devel/topic/patch_v2_2_2_bitbake/111163811
Comment 13 Louis Rannou 2025-02-18 09:03:35 UTC
Merged:
bitbake: data_smart: fix ??= operator for variable flags
https://git.openembedded.org/bitbake/commit?id=2ee079fc1b7cf6d384ca17bd034b0a40461d9d18
bitbake: tests/data: add tests for variable flags
https://git.openembedded.org/bitbake/commit?id=ff8cae735cf489373af1aac7ee233d7b82d483d3
Comment 14 Louis Rannou 2025-02-18 09:04:39 UTC
Closing, but reoppen if delVar is not supposed to erase all variable flags
Comment 15 Richard Purdie 2025-02-18 10:10:09 UTC
I did mean to comment, delVar is supposed to remove all varflags so that behaviour is correct, thanks!