<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>14961</bug_id>
          
          <creation_ts>2022-11-04 19:55:10 +0000</creation_ts>
          <short_desc>addtask between do_populate_sysroot and do_package breaks useradd class</short_desc>
          <delta_ts>2023-12-15 13:55:43 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>BitBake</product>
          <component>bitbake</component>
          <version>5.99</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>4.3</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Mostafa Emami">mustafaemami</reporter>
          <assigned_to name="Eilís Ní Fhlannagáin">pidge</assigned_to>
          <cc>louis.rannou</cc>
    
    <cc>pidge</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>richard.purdie</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>94371</commentid>
    <comment_count>0</comment_count>
    <who name="Mostafa Emami">mustafaemami</who>
    <bug_when>2022-11-04 19:55:10 +0000</bug_when>
    <thetext>addtask between do_populate_sysroot and do_package breaks the build if recipe adds a user via useradd class.

```
inherit useradd

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

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

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

```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95814</commentid>
    <comment_count>1</comment_count>
    <who name="Louis Rannou">louis.rannou</who>
    <bug_when>2023-06-23 09:08:46 +0000</bug_when>
    <thetext>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, &quot;depends&quot;)
        if task != &apos;do_prepare_recipe_sysroot&apos; and (task == &quot;do_configure&quot; or (deps and &quot;populate_sysroot&quot; in deps)):
            d.prependVarFlag(task, &quot;prefuncs&quot;, &quot;extend_recipe_sysroot &quot;)
}
```

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 ?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96718</commentid>
    <comment_count>2</comment_count>
    <who name="Mostafa Emami">mustafaemami</who>
    <bug_when>2023-10-17 17:34:05 +0000</bug_when>
    <thetext>Hallo,

Thanks for your comment.
Having more insight into yocto design, I&apos;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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97580</commentid>
    <comment_count>3</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2023-12-15 13:55:43 +0000</bug_when>
    <thetext>Testcase added:

https://git.yoctoproject.org/poky/commit/?id=e3ce7ce2158cff3c4f4f27166fac125d3f664bde

Bug fixed and test enabled:

https://git.yoctoproject.org/poky/commit/?id=4bb222e0d71a4cb159b8a4f1a90b65b1af32ac10</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>