populate_sdk: Execute populate_sdk before rm_work if rm_work.bbclass active
PATCH 1/1 populate_sdk: Execute populate_sdk before rm_work if rm_work.bbclass active
In case the rm_work.bbclass is inherited via INHERIT += "rm_work" into a build, it is currently possible for an image build to execute both rm_work and populate_sdk tasks in parallel, which usually leads to an unusual failure of the populate_sdk task.
This can be reproduced with oe-core and bitbake as follows:
$ . oe-init-build-env /path/to/build $ bitbake core-image-base core-image-base:do_populate_sdk
Fix this in a manner similar to 00b1911c65fa ("populate_sdk_ext.bbclass:
enhance compatibility with rm_work.bbclass"). Make sure do_populate_sdk is executed before rm_work for both image and SDK only recipes. Use the RM_WORK_BUILD_WITHOUT variable provided by rm_work bbclass to determine whether rm_work is inherited or not. This way, in case rm_work is not inherited, the dependencies remain unchanged, otherwise populate_sdk is surely executed before the rm_work task.
---
Cc: Adam Nilsson <[email protected]>
Cc: Alexander Kanavin <[email protected]>
Cc: Khem Raj <[email protected]>
Cc: Mathieu Dubois-Briand <[email protected]>
Cc: Patrick Ohly <[email protected]>
Cc: Peter Kjellerstedt <[email protected]>
Cc: Philip Lorenz <[email protected]>
Cc: Richard Purdie <[email protected]>
--- meta/classes-recipe/populate_sdk.bbclass | 9 ++++++++- meta/classes-recipe/populate_sdk_base.bbclass | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
meta/classes-recipe/populate_sdk.bbclass +8 -1
@@ -10,4 +10,11 @@ inherit populate_sdk_base addtask populate_sdk after do_install before do_build - +addhandler inject_sdk_rm_work +inject_sdk_rm_work[eventmask] = "bb.event.RecipeTaskPreProcess" +python inject_sdk_rm_work() { + if d.getVar('RM_WORK_BUILD_WITHOUT'): + bb.build.addtask('do_populate_sdk', 'do_rm_work do_build', ' ', d) + else: + bb.build.addtask('do_populate_sdk', 'do_build', ' ', d) +}
meta/classes-recipe/populate_sdk_base.bbclass +7 -0
@@ -435,3 +435,10 @@ do_populate_sdk[rdepends] = "${@' '.join([x + ':do_package_write_${IMAGE_PKGTYPE do_populate_sdk[recrdeptask] += "do_packagedata do_package_write_rpm do_package_write_ipk do_package_write_deb do_package_qa" do_populate_sdk[file-checksums] += "${POSTINST_INTERCEPT_CHECKSUMS}" addtask populate_sdk + +addhandler inject_sdk_rm_work +inject_sdk_rm_work[eventmask] = "bb.event.RecipeTaskPreProcess" +python inject_sdk_rm_work() { + if d.getVar('RM_WORK_BUILD_WITHOUT'): + bb.build.addtask('do_populate_sdk', 'do_rm_work', ' ', d) +}
Signature · 1 line
2.53.0
Quoted 57 lines · Marek Vasut
In case the rm_work.bbclass is inherited via INHERIT += "
rm_work" into a build, it is currently possible for an image build to execute bothrm_workandpopulate_sdktasks in parallel, which usually leads to an unusual failure of thepopulate_sdktask.This can be reproduced with oe-core and bitbake as follows:
$ . oe-init-build-env /path/to/build $ bitbake core-image-base core-image-base:do_populate_sdkFix this in a manner similar to
00b1911c65fa("populate_sdk_ext.bbclass:
enhance compatibility with rm_work.bbclass"). Make suredo_populate_sdkis executed beforerm_workfor both image and SDK only recipes. Use theRM_WORK_BUILD_WITHOUTvariable provided byrm_workbbclass to determine whetherrm_workis inherited or not. This way, in caserm_workis not inherited, the dependencies remain unchanged, otherwisepopulate_sdkis surely executed before therm_worktask.Signed-off-by Marek Vasut <[email protected]>---
Cc: Adam Nilsson <[email protected]>
Cc: Alexander Kanavin <[email protected]>
Cc: Khem Raj <[email protected]>
Cc: Mathieu Dubois-Briand <[email protected]>
Cc: Patrick Ohly <[email protected]>
Cc: Peter Kjellerstedt <[email protected]>
Cc: Philip Lorenz <[email protected]>
Cc: Richard Purdie <[email protected]>
---
meta/classes-recipe/populate_sdk.bbclass | 9 ++++++++- meta/classes-recipe/populate_sdk_base.bbclass | 7 +++++++2 files changed, 15 insertions(+), 1 deletion(-)meta/classes-recipe/populate_sdk.bbclass +0
-0@@ -10,4 +10,11 @@inherit
populate_sdk_base
addtaskpopulate_sdkafterdo_installbeforedo_buildmeta/classes-recipe/populate_sdk.bbclass +8
-1- +addhandler inject_sdk_rm_work +inject_sdk_rm_work[eventmask] = "bb.event.RecipeTaskPreProcess" +python inject_sdk_rm_work() { + if d.getVar('RM_WORK_BUILD_WITHOUT'): + bb.build.addtask('do_populate_sdk', 'do_rm_work do_build', ' ', d) + else: + bb.build.addtask('do_populate_sdk', 'do_build', ' ', d) +}meta/classes-recipe/populate_sdk_base.bbclass +0
-0@@ -435,3 +435,10 @@ do_populate_sdk[rdepends] = "${@' '.join([x + ':do_package_write_${IMAGE_PKGTYPEdo_populate_sdk[recrdeptask] += "
do_packagedatado_package_write_rpmdo_package_write_ipkdo_package_write_debdo_package_qa" do_populate_sdk[file-checksums] += "${POSTINST_INTERCEPT_CHECKSUMS}"
addtaskpopulate_sdk
meta/classes-recipe/populate_sdk_base.bbclass do_populate_sdk[rdepends] = "${@' '.join([x + ':do_package_write_${IMAGE_PKGTYPE · line 444
Quoted 7 lines
meta/classes-recipe/populate_sdk_base.bbclass +7
-0+ +addhandler inject_sdk_rm_work +inject_sdk_rm_work[eventmask] = "bb.event.RecipeTaskPreProcess" +python inject_sdk_rm_work() { + if d.getVar('RM_WORK_BUILD_WITHOUT'): + bb.build.addtask('do_populate_sdk', 'do_rm_work', ' ', d) +}
The solution is creative but I suspect it will cause problems with populate_sdk being injected into builds where it otherwise wasn't going to run.
There is clearly an issue here but I'm not sure it can be solved with the way tehe task graph code currently works. It might be time to have some kind of bitbake level API to better handle a task with the requirements rm_work has. I've long wondered if we should do something like that and this is a further sign we may not be able to do much else.
Cheers,
Richard
On 4/30/26 10:46 AM, Richard Purdie wrote:
Hello Richard,
Quoted 28 lines
Quoted 28 lines
meta/classes-recipe/populate_sdk.bbclass +8
-1@@ -10,4 +10,11 @@ inherit populate_sdk_base addtask populate_sdk after do_install before do_build - +addhandler inject_sdk_rm_work +inject_sdk_rm_work[eventmask] = "bb.event.RecipeTaskPreProcess" +python inject_sdk_rm_work() { + if d.getVar('RM_WORK_BUILD_WITHOUT'): + bb.build.addtask('do_populate_sdk', 'do_rm_work do_build', ' ', d) + else: + bb.build.addtask('do_populate_sdk', 'do_build', ' ', d) +}meta/classes-recipe/populate_sdk_base.bbclass +3
-0@@ -435,3 +435,10 @@ do_populate_sdk[rdepends] = "${@' '.join([x + ':do_package_write_${IMAGE_PKGTYPE do_populate_sdk[recrdeptask] += "do_packagedata do_package_write_rpm do_package_write_ipk do_package_write_deb do_package_qa" do_populate_sdk[file-checksums] += "${POSTINST_INTERCEPT_CHECKSUMS}" addtask populate_sdk + +addhandler inject_sdk_rm_work +inject_sdk_rm_work[eventmask] = "bb.event.RecipeTaskPreProcess"
Quoted 8 lines
meta/classes-recipe/populate_sdk_base.bbclass do_populate_sdk[rdepends] = "${@' '.join([x + ':do_package_write_${IMAGE_PKGTYPE · line 444
Quoted 4 lines
meta/classes-recipe/populate_sdk_base.bbclass +4
-0+python inject_sdk_rm_work() { + if d.getVar('RM_WORK_BUILD_WITHOUT'): + bb.build.addtask('do_populate_sdk', 'do_rm_work', ' ', d) +}The solution is creative but I suspect it will cause problems with
populate_sdkbeing injected into builds where it otherwise wasn't going to run.
Currently, both populate_sdk.bbclass and populate_sdk_base.bbclass already contain "addtask populate_sdk", so aren't those tasks already injected into all such builds?
My understanding is, that bb.build.addtask() only extends that addtask with optional " ... before rm_work" in case the rm_work bbclass is inherited in the build, so it shouldn't change the current behavior of these bbclasses, except for the rm_work case.
Quoted 6 lines
There is clearly an issue here but I'm not sure it can be solved with the way tehe task graph code currently works. It might be time to have some kind of bitbake level API to better handle a task with the requirements
rm_workhas. I've long wondered if we should do something like that and this is a further sign we may not be able to do much else.
Quoted 41 lines · Marek Vasut
On 4/30/26 10:46 AM, Richard Purdie wrote:
Hello Richard,
Quoted 28 lines
Quoted 28 lines
meta/classes-recipe/populate_sdk.bbclass +0
-0@@ -10,4 +10,11 @@inherit
populate_sdk_base
addtaskpopulate_sdkafterdo_installbeforedo_buildmeta/classes-recipe/populate_sdk.bbclass +8
-1- +addhandler inject_sdk_rm_work +inject_sdk_rm_work[eventmask] = "bb.event.RecipeTaskPreProcess" +python inject_sdk_rm_work() { + if d.getVar('RM_WORK_BUILD_WITHOUT'): + bb.build.addtask('do_populate_sdk', 'do_rm_work do_build', ' ', d) + else: + bb.build.addtask('do_populate_sdk', 'do_build', ' ', d) +}meta/classes-recipe/populate_sdk_base.bbclass +0
-0@@ -435,3 +435,10 @@ do_populate_sdk[rdepends] = "${@' '.join([x + ':do_package_write_${IMAGE_PKGTYPEdo_populate_sdk[recrdeptask] += "
do_packagedatado_package_write_rpmdo_package_write_ipkdo_package_write_debdo_package_qa" do_populate_sdk[file-checksums] += "${POSTINST_INTERCEPT_CHECKSUMS}"
addtaskpopulate_sdkmeta/classes-recipe/populate_sdk_base.bbclass +3
-0+ +addhandler inject_sdk_rm_work +inject_sdk_rm_work[eventmask] = "bb.event.RecipeTaskPreProcess"Quoted 8 lines
meta/classes-recipe/populate_sdk_base.bbclass do_populate_sdk[rdepends] = "${@' '.join([x + ':do_package_write_${IMAGE_PKGTYPE · line 444
Quoted 4 lines
meta/classes-recipe/populate_sdk_base.bbclass +4
-0+python inject_sdk_rm_work() { + if d.getVar('RM_WORK_BUILD_WITHOUT'): + bb.build.addtask('do_populate_sdk', 'do_rm_work', ' ', d) +}The solution is creative but I suspect it will cause problems with
populate_sdkbeing injected into builds where it otherwise wasn't going to run.
Quoted 8 lines
Currently, both populate_sdk.bbclass and populate_sdk_base.bbclass already contain "addtask
populate_sdk", so aren't those tasks already injected into all such builds?My understanding is, that
bb.build.addtask()only extends that addtask with optional " ... beforerm_work" in case therm_workbbclass is inherited in the build, so it shouldn't change the current behavior of these bbclasses, except for therm_workcase.
When you run "bitbake XXX", it executes the default task, which is do_build.
If you add:
addtask do_populate_sdk before do_build
it will always run do_populate_sdk when you run "bitbake XXX", which is a change of behaviour to what currently happens.
Cheers,
Richard
On 5/3/26 12:07 AM, Richard Purdie wrote:
Hello Richard,
Quoted 20 lines
Quoted 11 lines
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+addhandler inject_sdk_rm_work +inject_sdk_rm_work[eventmask] = "bb.event.RecipeTaskPreProcess" +python inject_sdk_rm_work() { + if d.getVar('RM_WORK_BUILD_WITHOUT'): + bb.build.addtask('do_populate_sdk', 'do_rm_work', ' ', d) +}The solution is creative but I suspect it will cause problems with
populate_sdkbeing injected into builds where it otherwise wasn't going to run.Quoted 8 lines
Currently, both populate_sdk.bbclass and populate_sdk_base.bbclass already contain "addtask
populate_sdk", so aren't those tasks already injected into all such builds?My understanding is, that
bb.build.addtask()only extends that addtask with optional " ... beforerm_work" in case therm_workbbclass is inherited in the build, so it shouldn't change the current behavior of these bbclasses, except for therm_workcase.
Quoted 8 lines
When you run "bitbake XXX", it executes the default task, which is
do_build.If you add:
addtask
do_populate_sdkbeforedo_buildit will always run
do_populate_sdkwhen you run "bitbake XXX", which is a change of behaviour to what currently happens.
Ahh, I understand, thank you for clarifying, it wasn't immediately obvious to me.
Would it be acceptable to remove rm_work from image recipes to mitigate this issue , or maybe image recipes which also inherit populate_sdk ? I know this does reduce the usefulness of rm_work bbclass by keeping the image recipe content around. Something like this is what I have in mind:
meta/classes/rm_work.bbclass +2 -0
@@ -166,6 +166,8 @@ inject_rm_work[eventmask] = "bb.event.RecipeTaskPreProcess" python inject_rm_work() { if bb.data.inherits_class('kernel', d): d.appendVar("RM_WORK_EXCLUDE", ' ' + d.getVar("PN")) + if bb.data.inherits_class('image', d): + d.appendVar("RM_WORK_EXCLUDE", ' ' + d.getVar("PN")) # If the recipe name is in the RM_WORK_EXCLUDE, skip the recipe. excludes = (d.getVar("RM_WORK_EXCLUDE") or "").split() pn = d.getVar("PN")