doc: bitbake-user-manual-metadata: clarify inherit_defer documentation
v3 cover doc: bitbake-user-manual-metadata: clarify inherit_defer documentation
v3 of a series addressing a few inaccuracies I came across while reading the inherit_defer documentation.
1)
Drop the claim that "If VARNAME is going to be set, it needs to be set before the inherit_defer statement is parsed" which is wrong and defeats the purpose of inherit_defer.
The whole point of deferred evaluation is that assignments made after the directive are taken into account.
2)
Drop the anonymous Python example of assigning the class name from an anonymous Python function, which does not work:
python () {
if d.getVar('SOMETHING') == 'value':
d.setVar('VARIABLE', 'someclass')
else:
d.setVar('VARIABLE', '')
}
inherit_defer ${VARIABLE}
inherit_defer is resolved before anonymous Python functions run, so ${VARIABLE} always expands to empty
and the inherit is a no-op.
add a warning explaining that using a anonymous python has no effect
on the inherit_defer3)
Add a short explanation of how inherit_defer interacts with conditional overrides, and rename VARNAME to VARIABLE for consistency with the rest of documentation.
Changes since v2:
- Link to v2: [2]
- Picked up Quentin's Reviewed-by for patch 1 from [3]
- Applied Quentin's suggestion from [4] and added Suggested-by:
Quentin to patch 2
- Renamed VARNAME to VARIABLE as suggested by Quentin in [5] in patch 3
- Dropped patch 4 following NACK in [6]
Changes since v1:
- Link to v1: [1]
- Split single patch into four
- Shorten the override example explanation
- Drop the "footgun" example from the previous patch
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/
[5] https://lore.kernel.org/all/[email protected]/
[6] https://lore.kernel.org/all/[email protected]/
Greets,
Dawid
Dawid Bijak (3):
doc: bitbake-user-manual-metadata: remove incorrect claim
doc: bitbake-user-manual-metadata: remove invalid anonymous Python
example
doc: bitbake-user-manual-metadata: explain inherit_defer example
.../bitbake-user-manual-metadata.rst | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-)
Signature · 1 line
2.48.1
PATCH v3 1/3 doc: bitbake-user-manual-metadata: remove incorrect claim
The documentation for inherit_defer contained the claim "If VARNAME is going to be set, it needs to be set before the inherit_defer statement is parsed"
which is incorrect and contradicts the purpose of inherit_defer.
Drop the incorrect statement.
--- doc/bitbake-user-manual/bitbake-user-manual-metadata.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
doc/bitbake-user-manual/bitbake-user-manual-metadata.rst +1 -3
@@ -829,9 +829,7 @@ Here is an example:: inherit_defer ${VARNAME} -If ``VARNAME`` is -going to be set, it needs to be set before the ``inherit_defer`` statement is -parsed. One way to achieve a conditional inherit in this case is to use +One way to achieve a conditional inherit in this case is to use overrides:: VARIABLE = ""
Signature · 1 line
2.48.1
PATCH v3 2/3 doc: bitbake-user-manual-metadata: remove invalid anonymous Python example
In reply to Dawid BijakThe documentation for inherit_defer suggested that conditional inheritance can be achieved by setting a variable inside an anonymous python function and then referencing it from inherit_defer.
This does not work: inherit_defer is resolved before the anonymous Python functions run.
Replace the example with a warning explaining that anonymous Python functions cannot be used to drive inherit_defer, since they run after the directive has already been resolved.
--- .../bitbake-user-manual-metadata.rst | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
doc/bitbake-user-manual/bitbake-user-manual-metadata.rst +8 -11
@@ -835,17 +835,6 @@ overrides:: VARIABLE = "" VARIABLE:someoverride = "myclass" -Another method is by using :ref:`anonymous Python -<bitbake-user-manual/bitbake-user-manual-metadata:Anonymous Python Functions>`. -Here is an example:: - - python () { - if condition == value: - d.setVar('VARIABLE', 'myclass') - else: - d.setVar('VARIABLE', '') - } - Alternatively, you could use an inline Python expression in the following form::
@@ -859,6 +848,14 @@ In all cases, if the expression evaluates to an empty string, the statement does not trigger a syntax error because it becomes a no-op. +.. warning:: + + Setting or modifying variables within an :ref:`anonymous Python function + <bitbake-user-manual/bitbake-user-manual-metadata:Anonymous Python Functions>` + will have no impact on the value of that variable in an + :ref:`inherit_defer <ref-bitbake-user-manual-metadata-inherit-defer>` directive + as the function is run after the directive is resolved. + See also :term:`BB_DEFER_BBCLASSES` for automatically promoting classes ``inherit`` calls to ``inherit_defer``.
Signature · 1 line
2.48.1
PATCH v3 3/3 doc: bitbake-user-manual-metadata: explain inherit_defer example
In reply to Dawid BijakAdd a short paragraph describing how the inherit_defer makes use of override syntax to achieve conditional inheritance, and rename VARNAME to VARIABLE to assure consistent naming throughout the documentation.
--- doc/bitbake-user-manual/bitbake-user-manual-metadata.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
doc/bitbake-user-manual/bitbake-user-manual-metadata.rst +6 -1
@@ -827,7 +827,7 @@ the variable after the line is parsed will take effect. With the :ref:`inherit Here is an example:: - inherit_defer ${VARNAME} + inherit_defer ${VARIABLE} One way to achieve a conditional inherit in this case is to use overrides::
@@ -835,6 +835,11 @@ overrides:: VARIABLE = "" VARIABLE:someoverride = "myclass" +:ref:`inherit_defer <ref-bitbake-user-manual-metadata-inherit-defer>` +defers the evaluation of ``${VARIABLE}`` until the end of +parsing. Assuming ``someoverride`` is in :term:`OVERRIDES`, ``${VARIABLE}`` +expands to ``myclass``, which is then inherited. + Alternatively, you could use an inline Python expression in the following form::
Signature · 1 line
2.48.1
Quoted 2 lines · Dawid Bijak via lists.yoctoproject.org
v3 of a series addressing a few inaccuracies I came across while reading the
inherit_deferdocumentation.
Hi Dawid,
Thanks for the new version.
I believe most of the v2 was merged. Can you rebase on top of master?
Thanks,
Mathieu
Signature · 3 lines
Mathieu Dubois-Briand, Bootlin Embedded Linux and Kernel engineering https://bootlin.com