diff mbox series

classes/retain: add ability to ignore certain tasks

Message ID 20260823234742.1170713-1-paul.eggleton@linux.microsoft.com
State New
Headers show
Series classes/retain: add ability to ignore certain tasks | expand

Commit Message

Paul Eggleton Aug. 23, 2026, 11:47 p.m. UTC
From: Paul Eggleton <paul.eggleton@microsoft.com>

If you have retain enabled and RETAIN_DIRS_ALWAYS set, then run certain
tasks by themselves (e.g. -c clean), it can be annoying to have that
trigger retention. Add a RETAIN_IGNORE_TASKS variable that enables
specifying tasks that should be ignored by this class, and set a
reasonable default.

Signed-off-by: Paul Eggleton <paul.eggleton@microsoft.com>
---
 meta/classes-global/retain.bbclass     | 8 +++++++-
 meta/lib/oeqa/selftest/cases/retain.py | 6 ++----
 2 files changed, 9 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-global/retain.bbclass b/meta/classes-global/retain.bbclass
index 46e8c256cf..d81446b8a1 100644
--- a/meta/classes-global/retain.bbclass
+++ b/meta/classes-global/retain.bbclass
@@ -46,6 +46,8 @@ 
 #   is writing out the data that you wish to save.
 # * The tarballs have the tarball name as a top-level directory so that
 #   multiple tarballs can be extracted side-by-side easily.
+# * Some tasks shouldn't by themselves trigger retention (e.g. do_clean).
+#   For that we have RETAIN_IGNORE_TASKS.
 #
 # Copyright (c) 2020, 2024 Microsoft Corporation
 #
@@ -59,6 +61,7 @@  RETAIN_DIRS_GLOBAL_FAILURE ?= ""
 RETAIN_DIRS_GLOBAL_ALWAYS ?= ""
 RETAIN_TARBALL_SUFFIX ?= "${DATETIME}.tar.gz"
 RETAIN_ENABLED ?= "1"
+RETAIN_IGNORE_TASKS ?= "do_clean do_cleansstate do_cleanall do_listtasks do_addto_recipe_sysroot"
 
 
 def retain_retain_dir(desc, tarprefix, path, tarbasepath, d):
@@ -99,6 +102,10 @@  python retain_task_handler() {
     if d.getVar('RETAIN_ENABLED') != '1':
         return
 
+    taskname = d.getVar('BB_CURRENTTASK')
+    if 'do_' + taskname in d.getVar('RETAIN_IGNORE_TASKS').split():
+        return
+
     dirs = d.getVar('RETAIN_DIRS_ALWAYS')
     if isinstance(e, bb.build.TaskFailed):
         dirs += ' ' + d.getVar('RETAIN_DIRS_FAILURE')
@@ -109,7 +116,6 @@  python retain_task_handler() {
         bb.utils.mkdirhier(outdir)
         dirlist_file = os.path.join(outdir, 'retain_dirs.list')
         pn = d.getVar('PN')
-        taskname = d.getVar('BB_CURRENTTASK')
         with open(dirlist_file, 'a') as f:
             for entry in dirs:
                 f.write('%s %s %s\n' % (pn, taskname, entry))
diff --git a/meta/lib/oeqa/selftest/cases/retain.py b/meta/lib/oeqa/selftest/cases/retain.py
index 892be45857..c6d0952085 100644
--- a/meta/lib/oeqa/selftest/cases/retain.py
+++ b/meta/lib/oeqa/selftest/cases/retain.py
@@ -39,10 +39,8 @@  class Retain(OESelftestTestCase):
             self.fail('RETAIN_OUTDIR value "%s" is invalid' % retain_outdir)
         if not oe.path.is_path_parent(tmpdir, retain_outdir):
             self.fail('RETAIN_OUTDIR (%s) is not underneath TMPDIR (%s)' % (retain_outdir, tmpdir))
-        try:
-            shutil.rmtree(retain_outdir)
-        except FileNotFoundError:
-            pass
+        if os.path.exists(retain_outdir) and os.listdir(retain_outdir):
+            self.fail('RETAIN_OUTDIR should be empty after -c clean')
 
         bitbake(test_recipe)
         if not glob.glob(os.path.join(retain_outdir, '%s_temp_*.tar.gz' % test_recipe)):