From db7e0acda0b001d0b33827769c0f6b50eed4406d Mon Sep 17 00:00:00 2001 From: Yusuf Efe <120668197+yuefdev@users.noreply.github.com> Date: Sun, 13 Sep 2026 19:04:13 +0300 Subject: [PATCH] fix: Isolate Bazel sources from CMake generation Signed-off-by: Yusuf Efe <120668197+yuefdev@users.noreply.github.com> --- scripts/generate_build_files.py | 4 +- scripts/tests/test_generate_build_files.py | 54 ++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 scripts/tests/test_generate_build_files.py diff --git a/scripts/generate_build_files.py b/scripts/generate_build_files.py index b5d18390494..086a403943a 100644 --- a/scripts/generate_build_files.py +++ b/scripts/generate_build_files.py @@ -298,10 +298,10 @@ def strip_prefix(filename, prefix = "src/"): if args.bazel: # 8562a4ec: Remove CommonGraphOptions from Utils target and warnings - graph_files += ["//utils:CommonGraphOptions.cpp"] + bazel_graph_files = graph_files + ["//utils:CommonGraphOptions.cpp"] bazel_build_string = build_from_template_bazel( - graph_files, lib_files_sve, lib_files_sve2, lib_files + lib_files_neon_fp16) + bazel_graph_files, lib_files_sve, lib_files_sve2, lib_files + lib_files_neon_fp16) with open("src/BUILD.bazel", "w") as fp: fp.write(bazel_build_string) diff --git a/scripts/tests/test_generate_build_files.py b/scripts/tests/test_generate_build_files.py new file mode 100644 index 00000000000..89f5ba04a4b --- /dev/null +++ b/scripts/tests/test_generate_build_files.py @@ -0,0 +1,54 @@ +# SPDX-FileCopyrightText: 2026 Yusuf Efe +# +# SPDX-License-Identifier: MIT + +"""Run with: python -m unittest discover -s scripts/tests -p test_generate_build_files.py -v.""" + +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[2] +SCRIPT = ROOT / "scripts" / "generate_build_files.py" + + +class GenerateBuildFilesTest(unittest.TestCase): + def generate(self, *flags): + with tempfile.TemporaryDirectory(prefix="acl build ") as directory: + root = Path(directory) + shutil.copyfile(ROOT / "filelist.json", root / "filelist.json") + graph = root / "src" / "graph" + graph.mkdir(parents=True) + (graph / "Graph.cpp").touch() + result = subprocess.run( + [sys.executable, str(SCRIPT), *flags], cwd=root, capture_output=True, text=True + ) + self.assertEqual(result.returncode, 0, result.stderr) + return { + name: (root / "src" / name).read_bytes() + for name in ("CMakeLists.txt", "BUILD.bazel") + if (root / "src" / name).exists() + } + + def test_combined_generation_matches_separate_invocations(self): + cmake = self.generate("--cmake") + bazel = self.generate("--bazel") + self.assertEqual(set(cmake), {"CMakeLists.txt"}) + self.assertEqual(set(bazel), {"BUILD.bazel"}) + for flags in (("--bazel", "--cmake"), ("--cmake", "--bazel")): + with self.subTest(flags=flags): + self.assertEqual(self.generate(*flags), {**cmake, **bazel}) + + def test_bazel_utility_label_stays_out_of_cmake(self): + outputs = self.generate("--bazel", "--cmake") + self.assertIn(b"//utils:CommonGraphOptions.cpp", outputs["BUILD.bazel"]) + self.assertNotIn(b"//utils:CommonGraphOptions.cpp", outputs["CMakeLists.txt"]) + self.assertIn(b"Graph.cpp", outputs["BUILD.bazel"]) + self.assertIn(b"Graph.cpp", outputs["CMakeLists.txt"]) + + +if __name__ == "__main__": + unittest.main()