diff mbox series

classes/archiver: handle original sources unpacked outside ${BP}

Message ID 20261021120609.14844-1-jaipaul.cheernam@est.tech
State Under Review
Headers show
Series classes/archiver: handle original sources unpacked outside ${BP} | expand

Commit Message

Jaipaul Cheernam Oct. 21, 2026, 12:06 p.m. UTC
With ARCHIVER_MODE[src] = "original", do_ar_original fails if the
source unpacks into a directory other than ${BP}.

Commit c73dbd0fa8a3 changed do_ar_original to archive tmpdir/${BP}
instead of tmpdir, preventing the temporary directory created by
mkdtemp (e.g. tmp8pu2nsck/) from appearing as the top-level directory
in the tarball.

However, this assumes the source always unpacks into ${BP}. Git
sources using 'subpath' can unpack into a differently named directory,
such as tmpdir/tools, causing tar to fail because tmpdir/${BP} does
not exist.

Use the directory created during unpacking when it contains a single
top-level directory, falling back to tmpdir otherwise. This preserves
the existing behavior for release tarballs while supporting sources
unpacked outside ${BP}.

Reproduced with sdbus-c++-tools from meta-oe:

    INHERIT += "archiver"
    ARCHIVER_MODE[src] = "original"

    bitbake-layers add-layer <path>/meta-openembedded/meta-oe
    bitbake sdbus-c++-tools -c do_ar_original -f

Signed-off-by: Jaipaul Cheernam <jaipaul.cheernam@est.tech>
---
 meta/classes/archiver.bbclass | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/classes/archiver.bbclass b/meta/classes/archiver.bbclass
index c824718a1dd..29e0af648e6 100644
--- a/meta/classes/archiver.bbclass
+++ b/meta/classes/archiver.bbclass
@@ -230,7 +230,14 @@  python do_ar_original() {
                     else:
                         bb.fatal("Cannot determine archive names for original source because 'name=' URL parameter '%s' is used twice. Make it unique in: %s %s" % (tarball_suffix[name], url))
             tarball_suffix[name] = url
-            create_tarball(d, os.path.join(tmpdir, d.getVar('BP'), '.'), name, ar_outdir)
+            # unpacked source may not be ${BP}, e.g. git with subpath.
+            # Use the single top-level directory when present, otherwise tmpdir.
+            entries = os.listdir(tmpdir)
+            if len(entries) == 1 and os.path.isdir(os.path.join(tmpdir, entries[0])):
+                srcsubdir = os.path.join(tmpdir, entries[0], '.')
+            else:
+                srcsubdir = os.path.join(tmpdir, '.')
+            create_tarball(d, srcsubdir, name, ar_outdir)
 
     # Emit patch series files for 'original'
     bb.note('Writing patch series files...')