]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
archiver.bbclass: Properly remove artifacts when configuration changes
authorPeter Kjellerstedt <pkj@axis.com>
Mon, 8 Jun 2026 17:52:57 +0000 (19:52 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 11 Jun 2026 09:41:52 +0000 (10:41 +0100)
Before, the different archiver tasks that produce artifacts would just
add to the common output directory. This meant that changing how the
archiver is configured would just add more artifacts, but never remove
any. E.g., if "dumpdata" was enabled, it would add the environment data
for each built recipe to the artifacts. However, if it was then
disabled, all the generated artifacts would remain until each recipe was
manually cleaned, or the entire tmp directory was removed.

This adds a task that cleans the output directory if needed. It is a
separate task that all the other archiver tasks depend on because they
all write to the same output directory so it must only be cleaned once.
This also means it has to depend on all variables that affect any of
the other tasks.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/archiver.bbclass
meta/lib/oeqa/selftest/cases/archiver.py

index 1f1ee45bd7ae31abe40f8c0e405c7ef4b82f2941..a3f8689b1961283265c99621c2ff7aea8a7def16 100644 (file)
@@ -179,6 +179,20 @@ python () {
                 d.appendVarFlag('do_package_write_rpm', 'depends', ' %s:do_ar_configured' % pn)
 }
 
+do_ar_prepare[vardeps] += " \
+    ARCHIVER_MODE \
+    ARCHIVER_MIRROR_EXCLUDE \
+    COPYLEFT_LICENSE_EXCLUDE \
+    COPYLEFT_LICENSE_INCLUDE \
+    COPYLEFT_PN_EXCLUDE \
+    COPYLEFT_PN_INCLUDE \
+    COPYLEFT_RECIPE_TYPES \
+"
+do_ar_prepare[cleandirs] = "${ARCHIVER_TOPDIR}"
+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.
@@ -609,14 +623,15 @@ do_deploy_archives[sstate-inputdirs] = "${ARCHIVER_TOPDIR}"
 do_deploy_archives[sstate-outputdirs] = "${DEPLOY_DIR_SRC}"
 addtask do_deploy_archives_setscene
 
-addtask do_ar_original after do_unpack
-addtask do_unpack_and_patch after do_patch do_preconfigure
+addtask do_ar_prepare
+addtask do_ar_original after do_unpack do_ar_prepare
+addtask do_unpack_and_patch after do_patch do_preconfigure do_ar_prepare
 addtask do_ar_patched after do_unpack_and_patch
 addtask do_ar_configured after do_unpack_and_patch
-addtask do_ar_mirror after do_fetch
-addtask do_dumpdata
-addtask do_ar_recipe
-addtask do_deploy_archives
+addtask do_ar_mirror after do_fetch do_ar_prepare
+addtask do_dumpdata after do_ar_prepare
+addtask do_ar_recipe after do_ar_prepare
+addtask do_deploy_archives after do_ar_prepare
 do_build[recrdeptask] += "do_deploy_archives"
 do_rootfs[recrdeptask] += "do_deploy_archives"
 do_populate_sdk[recrdeptask] += "do_deploy_archives"
index 82b0293338a5548d837f7309942c9b255e5e2cc2..872504808a17ebb73fc5b5e32aa7f2dfdad899b0 100644 (file)
@@ -343,3 +343,41 @@ class Archiver(OESelftestTestCase):
         ]:
             target_path = os.path.join(bb_vars['DEPLOY_DIR_SRC'], 'mirror', target_file_name)
             self.assertTrue(os.path.exists(target_path))
+
+    def test_archiver_cleanup(self):
+        """
+        Test that the archiver removes no longer needed artifacts when its
+        configuration is modified.
+        """
+
+        target = 'selftest-ed-native'
+        target_file_name = 'selftest-ed-native-1.21.1-r0-showdata.dump'
+
+        def assert_dumpdata_present(expect_present):
+            bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'BUILD_SYS'])
+            glob_str = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['BUILD_SYS'], '%s-*' % target)
+            glob_result = glob.glob(glob_str)
+            self.assertTrue(glob_result, 'Missing archiver directory for %s' % target)
+
+            archive_path = os.path.join(glob_result[0], target_file_name)
+            if expect_present:
+                self.assertTrue(os.path.exists(archive_path),
+                                'Missing archive file %s' % target_file_name)
+            else:
+                self.assertFalse(os.path.exists(archive_path),
+                                 'Unexpected archive file %s' % target_file_name)
+
+        features = 'INHERIT += "archiver"\n'
+        self.write_config(features)
+        bitbake('-c deploy_archives %s -f' % target)
+        assert_dumpdata_present(False)
+
+        features += 'ARCHIVER_MODE[dumpdata] = "1"\n'
+        self.write_config(features)
+        bitbake('-c deploy_archives %s -f' % target)
+        assert_dumpdata_present(True)
+
+        features = 'INHERIT += "archiver"\n'
+        self.write_config(features)
+        bitbake('-c deploy_archives %s -f' % target)
+        assert_dumpdata_present(False)