From cf0125e54cb1a84d8690ddc188da49b7c0157bab Mon Sep 17 00:00:00 2001
From: Anders Roxell <anders.roxell@linaro.org>
Date: Tue, 9 Dec 2025 10:49:21 +0100
Subject: [PATCH 6/8] kbuild: Use TuxMake cache directory for artifact
 collection

TuxMake with --runtime=null places build artifacts in its own cache
directory at ~/.cache/tuxmake/builds/<ID>/, but we need these artifacts
in KernelCI's artifact directory for publishing to storage.

After TuxMake completes, automatically discover the single build
directory under ~/.cache/tuxmake/builds/, assert there is exactly one
directory, and copy all artifacts from it to KernelCI's artifact root.
This preserves file names exactly as TuxMake produced them and uses
TuxMake's artifact directory as the source of truth.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 kernelci/kbuild.py | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/kernelci/kbuild.py b/kernelci/kbuild.py
index c4b0157e0355..d79201afad16 100644
--- a/kernelci/kbuild.py
+++ b/kernelci/kbuild.py
@@ -815,17 +815,30 @@ trap 'case $stage in
         print(f"[_build_with_tuxmake] Command: {tuxmake_cmd}")
         self.addcmd(tuxmake_cmd)
 
-        # Copy final .config to artifacts
-        self.addcmd(f"cp .config {self._af_dir}/")
-        self._artifacts.append(".config")
+        # Discover TuxMake's build directory and copy artifacts
+        print("[_build_with_tuxmake] Discovering and copying TuxMake artifacts")
+        self.addcmd('# Discover TuxMake build directory')
+        self.addcmd('TUXCACHE="$HOME/.cache/tuxmake/builds"')
+        self.addcmd('if [ ! -d "$TUXCACHE" ]; then')
+        self.addcmd('    echo "ERROR: TuxMake produced no builds directory at $TUXCACHE" >&2')
+        self.addcmd('    exit 1')
+        self.addcmd('fi')
+        self.addcmd('')
+        self.addcmd('dirs=( "$TUXCACHE"/* )')
+        self.addcmd('if [ "${#dirs[@]}" -ne 1 ]; then')
+        self.addcmd('    echo "ERROR: Expected exactly one TuxMake build dir, found ${#dirs[@]}" >&2')
+        self.addcmd('    exit 1')
+        self.addcmd('fi')
+        self.addcmd('')
+        self.addcmd('TUXDIR="${dirs[0]}"')
+        self.addcmd('echo "Found TuxMake build directory: $TUXDIR"')
+        self.addcmd('')
+        self.addcmd('# Copy all artifacts from TuxMake build directory')
+        self.addcmd(f'cp -a "$TUXDIR"/. {self._af_dir}/')
+        self.addcmd('echo "Artifacts copied to artifacts directory"')
 
         self.addcmd("cd ..")
 
-        # Package artifacts using existing methods
-        print("[_build_with_tuxmake] Packaging kernel image and modules")
-        self._package_kimage()
-        self._package_modules()
-
     def _build_kernel(self):
         """ Add kernel build steps """
         self.startjob("build_kernel")
-- 
2.51.0

