* [PATCH v4 1/2] archiver.bbclass: unpack original sources without a localpath
2026-12-02 20:54 [PATCH v4 0/2] archiver.bbclass: archive shallow git sources without a clone, drop .git ecordonnier
@ 2026-12-02 20:54 ` ecordonnier
2026-12-02 20:54 ` [PATCH v4 2/2] archiver.bbclass: remove .git from original git source archives ecordonnier
1 sibling, 0 replies; 3+ messages in thread
From: ecordonnier @ 2026-12-02 20:54 UTC (permalink / raw)
To: openembedded-core; +Cc: Etienne Cordonnier
From: Etienne Cordonnier <ecordonnier@snap.com>
In "original" mode, do_ar_original only archived a source whose localpath()
was a file or a directory, and silently skipped any other. A shallow git
fetch which uses only the gitshallow tarball has no clone, so localpath() is
missing and the source was not archived at all.
Unpack every source which is not a file with fetch.unpack(), which works from
the shallow tarball. Fail if nothing was unpacked, so an incomplete archive is
no longer silent.
AI-Generated: Claude Code with Claude Haiku 5.5
Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
---
meta/classes/archiver.bbclass | 10 +++--
meta/lib/oeqa/selftest/cases/archiver.py | 48 ++++++++++++++++++++++++
2 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/meta/classes/archiver.bbclass b/meta/classes/archiver.bbclass
index 792e85445f..9ce12b0e9b 100644
--- a/meta/classes/archiver.bbclass
+++ b/meta/classes/archiver.bbclass
@@ -166,8 +166,8 @@ do_ar_prepare() {
}
# Take all the sources for a recipe and put them in WORKDIR/archiver-work/.
-# Files in SRC_URI are copied directly, anything that's a directory
-# (e.g. git repositories) is "unpacked" and then put into a tarball.
+# Files in SRC_URI are copied directly, anything else (e.g. git repositories,
+# which may have no clone in DL_DIR) is "unpacked" and then put into a tarball.
python do_ar_original() {
import shutil, tempfile
@@ -207,9 +207,13 @@ python do_ar_original() {
local = fetch.localpath(url).rstrip("/");
if os.path.isfile(local):
shutil.copy(local, ar_outdir)
- elif os.path.isdir(local):
+ else:
+ # Unpack whatever the fetcher has, even when localpath() does not
+ # exist: a shallow git fetch may have no clone, only the tarball.
tmpdir = tempfile.mkdtemp(dir=d.getVar('ARCHIVER_WORKDIR'))
fetch.unpack(tmpdir, (url,))
+ if not os.listdir(tmpdir):
+ bb.fatal("Cannot archive original source %s: nothing was unpacked" % url)
# To handle recipes with more than one source, we add the "name"
# URL parameter as suffix. We treat it as an error when
# there's more than one URL without a name, or a name gets reused.
diff --git a/meta/lib/oeqa/selftest/cases/archiver.py b/meta/lib/oeqa/selftest/cases/archiver.py
index 8c5aa75e9b..629b5eb63a 100644
--- a/meta/lib/oeqa/selftest/cases/archiver.py
+++ b/meta/lib/oeqa/selftest/cases/archiver.py
@@ -7,6 +7,8 @@
import os
import glob
import re
+import shutil
+import tarfile
from oeqa.utils.commands import bitbake, get_bb_vars
from oeqa.selftest.case import OESelftestTestCase
@@ -176,6 +178,52 @@ class Archiver(OESelftestTestCase):
self._test_archiver_mode('original', 'ed-1.21.1.tar.lz')
+ def test_archiver_mode_original_git_shallow(self):
+ """
+ Test that the archiver archives a shallow git source with
+ `ARCHIVER_MODE[src] = "original"` when only the shallow tarball is
+ available, but not the clone. This is what happens with the fast
+ initial shallow fetch, or when the shallow tarball is fetched from a
+ mirror.
+ """
+ target = 'gitrepotest'
+
+ features = 'INHERIT += "archiver"\n'
+ features += 'ARCHIVER_MODE[src] = "original"\n'
+ features += 'BB_GIT_SHALLOW = "1"\n'
+ features += 'BB_GENERATE_SHALLOW_TARBALLS = "1"\n'
+ features += 'DL_DIR = "${TOPDIR}/downloads-shallow"\n'
+ self.write_config(features)
+
+ # Fetch to create the shallow tarball, then remove the clone if the
+ # fetcher fell back to a full clone, so that the second fetch has to
+ # use the shallow tarball. cleansstate makes sure that the archive is
+ # created again and not restored from sstate.
+ bitbake('-c cleansstate %s' % target)
+ bitbake('-c fetch %s' % target)
+ bb_vars = get_bb_vars(['DL_DIR'])
+ self.track_for_cleanup(bb_vars['DL_DIR'])
+ self.assertTrue(glob.glob(os.path.join(bb_vars['DL_DIR'], 'gitshallow_*.tar.gz')),
+ 'Missing shallow tarball in DL_DIR')
+ shutil.rmtree(os.path.join(bb_vars['DL_DIR'], 'git2'), ignore_errors=True)
+ bitbake('-c cleansstate %s' % target)
+
+ bitbake('-c deploy_archives %s' % target)
+
+ names = self._get_original_git_archive_names(target)
+ self.assertTrue([n for n in names if n.endswith('/COPYING')], 'Archive has no source files: %s' % names[:20])
+
+ def _get_original_git_archive_names(self, target):
+ """
+ Return the names of the files in the original source archive of the
+ git source of target.
+ """
+ bb_vars = get_bb_vars(['DEPLOY_DIR_SRC'], target)
+ archives = glob.glob(os.path.join(bb_vars['DEPLOY_DIR_SRC'], '*', '%s-*' % target, '%s-*.tar.*' % target))
+ self.assertEqual(len(archives), 1, 'Expected one source archive for %s, found %s' % (target, archives))
+ with tarfile.open(archives[0]) as tar:
+ return tar.getnames()
+
def test_archiver_mode_patched(self):
"""
Test that the archiver works with `ARCHIVER_MODE[src] = "patched"`.
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v4 2/2] archiver.bbclass: remove .git from original git source archives
2026-12-02 20:54 [PATCH v4 0/2] archiver.bbclass: archive shallow git sources without a clone, drop .git ecordonnier
2026-12-02 20:54 ` [PATCH v4 1/2] archiver.bbclass: unpack original sources without a localpath ecordonnier
@ 2026-12-02 20:54 ` ecordonnier
1 sibling, 0 replies; 3+ messages in thread
From: ecordonnier @ 2026-12-02 20:54 UTC (permalink / raw)
To: openembedded-core; +Cc: Etienne Cordonnier
From: Etienne Cordonnier <ecordonnier@snap.com>
The unpacked tree of a git source includes its .git, which has no use in the
archive. The .git of a clone has no objects, only a reference to DL_DIR via
objects/info/alternates, and the .git of a shallow tarball duplicates the
sources, which roughly doubles the archive. Remove it, and the .git files of
submodules. Keep it with nocheckout (and bareclone), where the repository is
the source.
AI-Generated: Claude Code with Claude Haiku 5.5
Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
---
meta/classes/archiver.bbclass | 13 +++++
meta/lib/oeqa/selftest/cases/archiver.py | 63 ++++++++++++++++++++++++
2 files changed, 76 insertions(+)
diff --git a/meta/classes/archiver.bbclass b/meta/classes/archiver.bbclass
index 9ce12b0e9b..3c201a9009 100644
--- a/meta/classes/archiver.bbclass
+++ b/meta/classes/archiver.bbclass
@@ -204,6 +204,7 @@ python do_ar_original() {
fetch = bb.fetch.Fetch(urls, ld)
tarball_suffix = {}
for url in fetch.urls:
+ ud = fetch.ud[url]
local = fetch.localpath(url).rstrip("/");
if os.path.isfile(local):
shutil.copy(local, ar_outdir)
@@ -214,6 +215,18 @@ python do_ar_original() {
fetch.unpack(tmpdir, (url,))
if not os.listdir(tmpdir):
bb.fatal("Cannot archive original source %s: nothing was unpacked" % url)
+ if isinstance(ud.method, bb.fetch.git.Git) and not ud.nocheckout:
+ # The .git of a clone has no objects (clone -s only references
+ # them via objects/info/alternates), and the one of a shallow
+ # tarball duplicates the sources, so it is of no use in the
+ # archive. This includes the .git files of submodules. Keep it
+ # with nocheckout (and bareclone), where it is the source.
+ for root, dirs, files in os.walk(ud.destdir):
+ if '.git' in dirs:
+ dirs.remove('.git')
+ bb.utils.remove(os.path.join(root, '.git'), recurse=True)
+ if '.git' in files:
+ os.remove(os.path.join(root, '.git'))
# To handle recipes with more than one source, we add the "name"
# URL parameter as suffix. We treat it as an error when
# there's more than one URL without a name, or a name gets reused.
diff --git a/meta/lib/oeqa/selftest/cases/archiver.py b/meta/lib/oeqa/selftest/cases/archiver.py
index 629b5eb63a..0a85046cda 100644
--- a/meta/lib/oeqa/selftest/cases/archiver.py
+++ b/meta/lib/oeqa/selftest/cases/archiver.py
@@ -212,6 +212,69 @@ class Archiver(OESelftestTestCase):
names = self._get_original_git_archive_names(target)
self.assertTrue([n for n in names if n.endswith('/COPYING')], 'Archive has no source files: %s' % names[:20])
+ self._assert_no_git(names)
+
+ def test_archiver_mode_original_git(self):
+ """
+ Test that the archive of a git source with
+ `ARCHIVER_MODE[src] = "original"` has no .git directory.
+ """
+ target = 'gitrepotest'
+
+ features = 'INHERIT += "archiver"\n'
+ features += 'ARCHIVER_MODE[src] = "original"\n'
+ self.write_config(features)
+
+ bitbake('-c cleansstate %s' % target)
+ bitbake('-c deploy_archives %s' % target)
+
+ names = self._get_original_git_archive_names(target)
+ self.assertTrue([n for n in names if n.endswith('/COPYING')], 'Archive has no source files: %s' % names[:20])
+ self._assert_no_git(names)
+
+ def test_archiver_mode_original_gitsm(self):
+ """
+ Test that the archive of a git source with submodules with
+ `ARCHIVER_MODE[src] = "original"` contains the submodules, but neither
+ the .git directory nor the .git files of the submodules.
+ """
+ target = 'git-submodule-test'
+
+ features = 'INHERIT += "archiver"\n'
+ features += 'ARCHIVER_MODE[src] = "original"\n'
+ features += 'COPYLEFT_LICENSE_INCLUDE = "*"\n'
+ self.write_config(features)
+
+ bitbake('-c cleansstate %s' % target)
+ bitbake('-c deploy_archives %s' % target)
+
+ names = self._get_original_git_archive_names(target)
+ self.assertTrue([n for n in names if n.endswith('/.gitmodules')], 'Archive has no .gitmodules: %s' % names[:20])
+ # .gitmodules is part of the superproject, check a file of a submodule
+ self.assertTrue([n for n in names if n.endswith('/bitbake/lib/bb/__init__.py')], 'Archive has no submodule content: %s' % names[:20])
+ self._assert_no_git(names)
+
+ def test_archiver_mode_original_git_nocheckout(self):
+ """
+ Test that the archive of a git source with nocheckout=1 keeps the .git
+ directory, since the repository is the source in this case.
+ """
+ target = 'gitrepotest'
+
+ features = 'INHERIT += "archiver"\n'
+ features += 'ARCHIVER_MODE[src] = "original"\n'
+ features += 'SRC_URI:pn-%s = "git://git.yoctoproject.org/matchbox-panel-2;branch=master;protocol=https;nocheckout=1 file://0001-testpatch.patch"\n' % target
+ self.write_config(features)
+
+ bitbake('-c cleansstate %s' % target)
+ bitbake('-c deploy_archives %s' % target)
+
+ names = self._get_original_git_archive_names(target)
+ self.assertTrue([n for n in names if '.git' in n.split('/')], 'Archive has no .git: %s' % names[:20])
+
+ def _assert_no_git(self, names):
+ git = [n for n in names if '.git' in n.split('/')]
+ self.assertFalse(git, 'Archive contains .git: %s' % git[:20])
def _get_original_git_archive_names(self, target):
"""
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread