title: yocto do_unpack() - same directory names in different layers
body: <p>During experiments with Yocto's <a href="https://docs.yoctoproject.org/kernel-dev/advanced.html" rel="nofollow noreferrer">Advanced Kernel Metadata</a> I got into a situation where I would like to have the <code>.scc</code>, <code>.patch</code> and <code>.cfg</code> files organized into a directory structure as mentioned in the <a href="https://docs.yoctoproject.org/kernel-dev/advanced.html#kernel-metadata-syntax" rel="nofollow noreferrer">syntax</a> section, and to keep that structure in all the layers (consider 2 layers here - <code>meta-main_layer</code> and <code>meta-bsp_layer</code>):</p>
  <pre><code>meta-main_layer
  └── recipes-kernel
      └── linux
          └── linux-yocto.bb
          └── linux-yocto
              ├── cfg
              │   ├── main_frag_1.cfg
              │   └── main_frag_1.scc
              ├── features
              │   ├── main_feature_1.cfg
              │   ├── main_feature_1.patch
              │   └── main_feature_1.scc
              └── patches
                  ├── main_patch_1.patch
                  └── main_patch_1.scc
  meta-bsp_layer
  └── recipes-kernel
      └── linux
          └── linux-yocto.bbappend
          └── linux-yocto
              ├── bsp
              │   └── bsp_definition.scc
              ├── cfg
              │   ├── bsp_frag_1.cfg
              │   └── bsp_frag_1.scc
              ├── features
              │   ├── bsp_feature_1.cfg
              │   ├── bsp_feature_1.patch
              │   └── bsp_feature_1.scc
              └── patches
                  ├── bsp_patch_1.patch
                  └── bsp_patch_1.scc
  </code></pre>
  <p><code>meta-main_layer/recipes-kernel/linux/linux-yocto.bb</code> contains:</p>
  <pre><code>FILESEXTRAPATHS_prepend := &quot;${THISDIR}:&quot;
  ...
  SRC_URI = &quot;file://linux-yocto;type=kmeta \
         &quot;
  </code></pre>
  <p><strong>Edit:</strong></p>
  <p>And <code>meta-bsp_layer/recipes-kernel/linux/linux-yocto.bbappend</code>:</p>
  <pre><code>FILESEXTRAPATHS_prepend := &quot;${THISDIR}:&quot;
  ...
  SRC_URI += &quot; file://linux-yocto;type=kmeta \
         &quot;
  </code></pre>
  <p><strong>... end of edit</strong></p>
  <p>This means that after parsing the recipes, the <code>SRC_URI</code> will contain <code>file://linux-yocto;type=kmeta</code> twice, and <code>FILESEXTRAPATHS=meta-bsp_layer/recipes-kernel/linux:meta-main_layer/recipes-kernel/linux:</code>. The way I understand it, the <code>do_unpack()</code> task goes through the files in <code>SRC_URI</code> and for each of them, it searches <code>FILESEXTRAPATHS</code> for that file, and it takes the first one it finds. That means that in my case, only the files from <code>meta-bsp_layer</code> are taken, as its path is the first in <code>FILESEXTRAPATHS</code>, and the files from the <code>meta-main_layer</code> are ignored.</p>
  <p>What I would like to achieve is that instead of taking the files from only the first path found in <code>FILESEXTRAPATHS</code>, <code>do_unpack()</code> would go through all of the paths in <code>FILESEXTRAPATHS</code> and merge the directories of the same name (<code>cfg</code>, <code>features</code> and <code>patches</code>) from both layers. Without that, I don't see any big benefits of using the Advanced Kernel Metadata mechanism. Could anyone advise how to get this done?</p>
  <p>PS: I'm using Yocto Zeus.</p>