From 543e5d6e5b6b8e61979558b8a32b69c02990c5fb 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 7/8] kbuild: backend TuxMake: Use --output-dir for direct
 artifact output

Use TuxMake's --output-dir flag to build directly to KernelCI's artifact
directory. For TuxMake backend, upload_artifacts() walks the artifacts
directory and uploads everything found, eliminating the need for artifact
discovery and list maintenance.

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

diff --git a/kernelci/kbuild.py b/kernelci/kbuild.py
index c4b0157e0355..843a2e100b01 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")
@@ -1068,9 +1061,19 @@ trap 'case $stage in
 
         # Prepare all artifacts for upload
         upload_tasks = []
-        for artifact in self._artifacts:
-            artifact_path = os.path.join(self._af_dir, artifact)
-            upload_tasks.append((artifact, artifact_path))
+        if self._backend == 'tuxmake':
+            # For TuxMake, upload everything in artifacts directory
+            print("[_upload_artifacts] TuxMake backend: discovering all files in artifacts directory")
+            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)
+                    artifact_path = os.path.join(self._af_dir, file_rel)
+                    upload_tasks.append((file_rel, artifact_path))
+        else:
+            # For make backend, upload only listed artifacts
+            for artifact in self._artifacts:
+                artifact_path = os.path.join(self._af_dir, artifact)
+                upload_tasks.append((artifact, artifact_path))
 
         # Function to handle a single artifact upload
         # args: (artifact, artifact_path)
-- 
2.51.0

