From 3d11dad786d5160e828faffb4216a9d1329b8828 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] kbuild: backend TuxMake: Add artifact discovery with
 --output-dir

TuxMake's --output-dir flag allows building directly to KernelCI's
artifact directory, eliminating the need to discover and copy from
TuxMake's cache directory. Combined with automatic artifact discovery
in verify_build(), this ensures all TuxMake-generated files (kernel
images, modules, metadata.json, logs, etc.) are discovered and uploaded
to storage.

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

diff --git a/kernelci/kbuild.py b/kernelci/kbuild.py
index c4b0157e0355..e01c5e790871 100644
--- a/kernelci/kbuild.py
+++ b/kernelci/kbuild.py
@@ -795,6 +795,7 @@ trap 'case $stage in
             "tuxmake --runtime=null",
             f"--target-arch={self._arch}",
             f"--toolchain={self._compiler}",
+            f"--output-dir={self._af_dir}",
         ]
 
         # Add --kconfig only if not using pre-created .config
@@ -813,19 +814,11 @@ trap 'case $stage in
 
         tuxmake_cmd = " ".join(cmd_parts)
         print(f"[_build_with_tuxmake] Command: {tuxmake_cmd}")
+        print(f"[_build_with_tuxmake] Output directory: {self._af_dir}")
         self.addcmd(tuxmake_cmd)
 
-        # Copy final .config to artifacts
-        self.addcmd(f"cp .config {self._af_dir}/")
-        self._artifacts.append(".config")
-
         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")
@@ -1024,6 +1017,23 @@ trap 'case $stage in
                         file = os.path.relpath(os.path.join(root, file),
                                                self._af_dir)
                         self._artifacts.append(file)
+        # Discover and add all TuxMake artifacts
+        if self._backend == 'tuxmake':
+            print("[verify_build] Discovering TuxMake artifacts")
+            discovered = []
+            for root, dirs, files in os.walk(self._af_dir):
+                for file in files:
+                    file_rel = os.path.relpath(os.path.join(root, file),
+                                               self._af_dir)
+                    if file_rel not in self._artifacts:
+                        self._artifacts.append(file_rel)
+                        discovered.append(file_rel)
+            if discovered:
+                print(f"[verify_build] Discovered {len(discovered)} additional TuxMake artifacts:")
+                for artifact in sorted(discovered):
+                    print(f"[verify_build]   - {artifact}")
+            else:
+                print("[verify_build] No additional TuxMake artifacts to discover")
         # Update manifest/metadata
         self._write_metadata()
         print("Artifacts verified")
-- 
2.51.0

