[v4] bitbake-user-manual: Correct description of the ??= operator

Message ID 20220615042424.7606-1-jacob.kroon@gmail.com
State Accepted, archived
Commit 8189f58d0449d16f162b6e8d98c4e5edc6bff875
Headers show
Series [v4] bitbake-user-manual: Correct description of the ??= operator | expand

Commit Message

Jacob Kroon June 15, 2022, 4:24 a.m. UTC
Stating that the assignment is done at the end of parsing is misleading.
The weak default value is the value which a variable will expand to if no value
has been assigned to it using any of the assignment operators.

Signed-off-by: Jacob Kroon <jacob.kroon@gmail.com>
---

Changes in v4:
* Mention that "??=" operator overrides previously defined weak default values
* Add examples when appending/prepending, with and without override-style syntax

Changes in v3:
* Update commit message
* Change "... via one of ..." to "... via any of ..."

Changes in v2:
* Add comment to line with immediate variable expansion

 .../bitbake-user-manual-metadata.rst          | 55 +++++++++++++------
 1 file changed, 39 insertions(+), 16 deletions(-)

Comments

Richard Purdie June 15, 2022, 7:23 a.m. UTC | #1
On Wed, 2022-06-15 at 06:24 +0200, Jacob Kroon wrote:
> Stating that the assignment is done at the end of parsing is misleading.
> The weak default value is the value which a variable will expand to if no value
> has been assigned to it using any of the assignment operators.
> 
> Signed-off-by: Jacob Kroon <jacob.kroon@gmail.com>
> ---
> 
> Changes in v4:
> * Mention that "??=" operator overrides previously defined weak default values
> * Add examples when appending/prepending, with and without override-style syntax
> 
> Changes in v3:
> * Update commit message
> * Change "... via one of ..." to "... via any of ..."
> 
> Changes in v2:
> * Add comment to line with immediate variable expansion
> 
>  .../bitbake-user-manual-metadata.rst          | 55 +++++++++++++------
>  1 file changed, 39 insertions(+), 16 deletions(-)
> 
> diff --git a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> index af4b1358..3250c205 100644
> --- a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> +++ b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
> @@ -195,22 +195,45 @@ value. However, if ``A`` is not set, the variable is set to "aval".
>  Setting a weak default value (??=)
>  ----------------------------------
>  
> -It is possible to use a "weaker" assignment than in the previous section
> -by using the "??=" operator. This assignment behaves identical to "?="
> -except that the assignment is made at the end of the parsing process
> -rather than immediately. Consequently, when multiple "??=" assignments
> -exist, the last one is used. Also, any "=" or "?=" assignment will
> -override the value set with "??=". Here is an example::
> -
> -   A ??= "somevalue"
> -   A ??= "someothervalue"
> -
> -If ``A`` is set before the above statements are
> -parsed, the variable retains its value. If ``A`` is not set, the
> -variable is set to "someothervalue".
> -
> -Again, this assignment is a "lazy" or "weak" assignment because it does
> -not occur until the end of the parsing process.
> +The weak default value of a variable is the value which that variable
> +will expand to if no value has been assigned to it via any of the other
> +assignment operators. The "??=" operator takes effect immediately, overriding

Generally looks good but I'd replace "overriding" with "replacing"
since overriding means something very specific to bitbake!

Cheers,

Richard
Jacob Kroon June 15, 2022, 9:17 a.m. UTC | #2
On 6/15/22 09:23, Richard Purdie wrote:
> On Wed, 2022-06-15 at 06:24 +0200, Jacob Kroon wrote:
>> Stating that the assignment is done at the end of parsing is misleading.
>> The weak default value is the value which a variable will expand to if no value
>> has been assigned to it using any of the assignment operators.
>>
>> Signed-off-by: Jacob Kroon <jacob.kroon@gmail.com>
>> ---
>>
>> Changes in v4:
>> * Mention that "??=" operator overrides previously defined weak default values
>> * Add examples when appending/prepending, with and without override-style syntax
>>
>> Changes in v3:
>> * Update commit message
>> * Change "... via one of ..." to "... via any of ..."
>>
>> Changes in v2:
>> * Add comment to line with immediate variable expansion
>>
>>   .../bitbake-user-manual-metadata.rst          | 55 +++++++++++++------
>>   1 file changed, 39 insertions(+), 16 deletions(-)
>>
>> diff --git a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
>> index af4b1358..3250c205 100644
>> --- a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
>> +++ b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
>> @@ -195,22 +195,45 @@ value. However, if ``A`` is not set, the variable is set to "aval".
>>   Setting a weak default value (??=)
>>   ----------------------------------
>>   
>> -It is possible to use a "weaker" assignment than in the previous section
>> -by using the "??=" operator. This assignment behaves identical to "?="
>> -except that the assignment is made at the end of the parsing process
>> -rather than immediately. Consequently, when multiple "??=" assignments
>> -exist, the last one is used. Also, any "=" or "?=" assignment will
>> -override the value set with "??=". Here is an example::
>> -
>> -   A ??= "somevalue"
>> -   A ??= "someothervalue"
>> -
>> -If ``A`` is set before the above statements are
>> -parsed, the variable retains its value. If ``A`` is not set, the
>> -variable is set to "someothervalue".
>> -
>> -Again, this assignment is a "lazy" or "weak" assignment because it does
>> -not occur until the end of the parsing process.
>> +The weak default value of a variable is the value which that variable
>> +will expand to if no value has been assigned to it via any of the other
>> +assignment operators. The "??=" operator takes effect immediately, overriding
> 
> Generally looks good but I'd replace "overriding" with "replacing"
> since overriding means something very specific to bitbake!
> 

Agreed, new version on the way.

/Jacob

Patch

diff --git a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
index af4b1358..3250c205 100644
--- a/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
+++ b/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
@@ -195,22 +195,45 @@  value. However, if ``A`` is not set, the variable is set to "aval".
 Setting a weak default value (??=)
 ----------------------------------
 
-It is possible to use a "weaker" assignment than in the previous section
-by using the "??=" operator. This assignment behaves identical to "?="
-except that the assignment is made at the end of the parsing process
-rather than immediately. Consequently, when multiple "??=" assignments
-exist, the last one is used. Also, any "=" or "?=" assignment will
-override the value set with "??=". Here is an example::
-
-   A ??= "somevalue"
-   A ??= "someothervalue"
-
-If ``A`` is set before the above statements are
-parsed, the variable retains its value. If ``A`` is not set, the
-variable is set to "someothervalue".
-
-Again, this assignment is a "lazy" or "weak" assignment because it does
-not occur until the end of the parsing process.
+The weak default value of a variable is the value which that variable
+will expand to if no value has been assigned to it via any of the other
+assignment operators. The "??=" operator takes effect immediately, overriding
+any previously defined weak default value. Here is an example::
+
+   W ??= "x"
+   A := "${W}" # Immediate variable expansion
+   W ??= "y"
+   B := "${W}" # Immediate variable expansion
+   W ??= "z"
+   C = "${W}"
+   W ?= "i"
+
+After parsing we will have::
+
+   A = "x"
+   B = "y"
+   C = "i"
+   W = "i"
+
+Appending and prepending non-override style will not substitute the weak
+default value, which means that after parsing::
+
+   W ??= "x"
+   W += "y"
+
+we will have::
+
+   W = " y"
+
+On the other hand, override-style appends/prepends/removes are applied after
+any active weak default value has been substituted::
+
+   W ??= "x"
+   W:append = "y"
+
+After parsing we will have::
+
+   W = "xy"
 
 Immediate variable expansion (:=)
 ---------------------------------