diff mbox series

[1/3] archiver.bbclass: Properly remove artifacts when configuration changes

Message ID 20260608175259.3238900-1-pkj@axis.com
State New
Headers show
Series [1/3] archiver.bbclass: Properly remove artifacts when configuration changes | expand

Commit Message

Peter Kjellerstedt June 8, 2026, 5:52 p.m. UTC
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>
---
 meta/classes/archiver.bbclass            | 27 +++++++++++++----
 meta/lib/oeqa/selftest/cases/archiver.py | 38 ++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes/archiver.bbclass b/meta/classes/archiver.bbclass
index 1f1ee45bd7..a3f8689b19 100644
--- a/meta/classes/archiver.bbclass
+++ b/meta/classes/archiver.bbclass
@@ -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"
diff --git a/meta/lib/oeqa/selftest/cases/archiver.py b/meta/lib/oeqa/selftest/cases/archiver.py
index 82b0293338..872504808a 100644
--- a/meta/lib/oeqa/selftest/cases/archiver.py
+++ b/meta/lib/oeqa/selftest/cases/archiver.py
@@ -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)