Skip to content

Commit 39da457

Browse files
committed
kbuild: upload make backend dtbs from an archive
Archive uploads of dtbs are only used when both the extracted dtb files and a dtbs.tar.xz artifact are present. The tuxmake backend gets the archive for free, but _package_dtbs() only ever copies the dtbs_install output into the artifacts directory, so make backend builds upload every dtb as a separate request. That is 36 of the currently scheduled kbuild jobs, including the whole CIP set and the arm64 chromebook build. Pack the installed dtbs into dtbs.tar.xz with the same dtbs/ prefix inside as the tuxmake archive, so upload_artifacts() picks it up with no change. The archive is only created when at least one dtb was built, which leaves verify_build() to drop the artifact and the upload to fall back to individual files otherwise. Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent 8da35b4 commit 39da457

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

kernelci/kbuild.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,20 @@ def _package_dtbs(self):
12491249
self.addcmd(f"mkdir -p {self._af_dir}/dtbs")
12501250
# copy dtbs to artifacts
12511251
self.addcmd(f"cp -r _dtbs_/* {self._af_dir}/dtbs", False)
1252+
# Also pack them into a single archive, with the same dtbs/ prefix
1253+
# inside as the one tuxmake produces, so that upload_artifacts() can
1254+
# upload the whole set in one request instead of one per dtb file.
1255+
# Skipped when no dtb was built, so that verify_build() drops the
1256+
# artifact and the upload falls back to individual files.
1257+
# -print -quit stops at the first dtb found, no full traversal
1258+
find_dtb = f"find {self._af_dir}/dtbs -name '*.dtb' -print -quit"
1259+
self.addcmd(
1260+
f'if [ -n "$({find_dtb})" ]; then '
1261+
f"tar -C {self._af_dir} -cJf {self._af_dir}/dtbs.tar.xz dtbs; "
1262+
"fi"
1263+
)
12521264
self.addcmd("cd ..")
1265+
self._artifacts.append("dtbs.tar.xz")
12531266

12541267
def _write_metadata(self):
12551268
"""

tests/test_kbuild.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,54 @@ def test_tuxmake_dtbs_use_archive_upload(self, tmp_path):
163163
assert "dtbs/board-a.dtb" in kbuild._full_artifacts
164164
assert "dtbs/nested/board-b.dtb" in kbuild._full_artifacts
165165
assert node_af["dtbs/board-a_dtb"].endswith("dtbs/board-a.dtb")
166+
167+
def test_make_dtbs_use_archive_upload(self, tmp_path):
168+
kbuild = _kbuild(tmp_path, arch="arm64")
169+
kbuild._backend = "make"
170+
kbuild._dtbs_check = False
171+
af_dir = tmp_path / "artifacts"
172+
(af_dir / "dtbs" / "nested").mkdir(parents=True)
173+
(af_dir / "dtbs" / "board-a.dtb").write_bytes(b"dtb-a")
174+
(af_dir / "dtbs" / "nested" / "board-b.dtb").write_bytes(b"dtb-b")
175+
(af_dir / "dtbs.tar.xz").write_bytes(b"archive")
176+
kbuild._artifacts = ["dtbs.tar.xz"]
177+
kbuild.verify_build()
178+
179+
storage = FakeStorage()
180+
kbuild._get_storage = lambda: storage
181+
kbuild._apijobname = "kbuild-gcc-arm64"
182+
kbuild._node = {"id": "node123", "data": {}}
183+
kbuild._full_artifacts = {}
184+
185+
node_af = kbuild.upload_artifacts()
186+
187+
assert storage.single_uploads == []
188+
assert len(storage.archive_uploads) == 1
189+
archive_path, file_paths, _dest_path, archive_name = (
190+
storage.archive_uploads[0]
191+
)
192+
assert archive_path == str(af_dir / "dtbs.tar.xz")
193+
assert archive_name == "dtbs.tar.xz"
194+
assert sorted(file_dst for _file_src, file_dst in file_paths) == [
195+
"dtbs/board-a.dtb",
196+
"dtbs/nested/board-b.dtb",
197+
]
198+
assert node_af["dtbs/board-a_dtb"].endswith("dtbs/board-a.dtb")
199+
200+
201+
class TestPackageDtbs:
202+
def test_dtbs_are_packed_into_archive(self, tmp_path):
203+
kbuild = _kbuild(tmp_path, arch="arm64")
204+
kbuild._package_dtbs()
205+
steps = "\n".join(kbuild._steps)
206+
af_dir = kbuild._af_dir
207+
assert f"tar -C {af_dir} -cJf {af_dir}/dtbs.tar.xz dtbs" in steps
208+
# the archive is only built when at least one dtb was produced
209+
assert "-print -quit" in steps
210+
assert "dtbs.tar.xz" in kbuild._artifacts
211+
212+
def test_archive_dropped_when_no_dtbs_built(self, tmp_path):
213+
kbuild = _kbuild(tmp_path, arch="arm64")
214+
kbuild._package_dtbs()
215+
kbuild.verify_build()
216+
assert "dtbs.tar.xz" not in kbuild._artifacts

0 commit comments

Comments
 (0)