Bug 14961

Summary: addtask between do_populate_sysroot and do_package breaks useradd class
Product: [Build System, Metadata & Runtime] BitBake Reporter: Mostafa Emami <mustafaemami>
Component: bitbakeAssignee: Eilís Ní Fhlannagáin <pidge>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: Medium CC: louis.rannou, pidge, poky.bs.watcher, poky.watcher, randy.macleod, richard.purdie
Version: 5.99   
Target Milestone: 4.3   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Mostafa Emami 2022-11-04 19:55:10 UTC
addtask between do_populate_sysroot and do_package breaks the build if recipe adds a user via useradd class.

```
inherit useradd

USERADD_PACKAGES = "${PN}"
USERADD_PARAM_${PN}  = "--system --home-dir /var/lib/foo -g foo --shell /bin/false foo"
GROUPADD_PARAM_${PN} = "--system foo"

do_something() {
:
}
addtask something after do_populate_sysroot before do_package
```
results in following:

```
Exception: FileExistsError: [Errno 17] File exists: '<build-folder>/tmp/sysroots-components/x86-64-generic/<recipe-name>/usr/bin/postinst-useradd-foo' -> '<build-folder>/tmp/work/x86-64-generic-mbient-linux/<recipe-name>/<PN>/recipe-sysroot/usr/bin/postinst-useradd-foo'

```
Comment 1 Louis Rannou 2023-06-23 09:08:46 UTC
Hello,

In my opinion, it does not make sense to add a task between do_populate_sysroot and do_package which are unrelated.
Doing so creates a indirect dependency from do_package to do_populate_sysroot. That means we are populating a recipe with itself, which is probably useless.

The chain of tasks at that point is :

do_install --- do_package
            \
             \--- do_populate_sysroot

do_package is used to create the package while do_populate_sysroot is used for recipes that depends on that one.


The issue is raised because of that creates an extra call to `extend_recipe_sysroot` (which was already called in do_prepare_recipe_sysroot):

```
python staging_taskhandler() {
    bbtasks = e.tasklist
    for task in bbtasks:
        deps = d.getVarFlag(task, "depends")
        if task != 'do_prepare_recipe_sysroot' and (task == "do_configure" or (deps and "populate_sysroot" in deps)):
            d.prependVarFlag(task, "prefuncs", "extend_recipe_sysroot ")
}
```

To avoid the error, we can check in this python code that `deps` is not the task itself.

Still, I agree the log does not help. It does not give a good logging because it does not make circular dependencies.

Perhaps we should forbid to create relations between those two tasks ?
Comment 2 Mostafa Emami 2023-10-17 17:34:05 UTC
Hallo,

Thanks for your comment.
Having more insight into yocto design, I'd agree that there should be no dependency between do_package and do_populate_sysroot, and agree even more that a meaningful error message on such dependency introduction is required.