[PATCH 2/2] kunit: tool: Create missing build directory before build
From: Pavee Zheng via B4 Relay
Date: Fri Dec 04 2026 - 20:17:31 EST
From: Pavee Zheng <pavee.zheng@xxxxxxxxx>
Commit 1ee2ba89bea8 ("kunit: tool: make `build` subcommand also
reconfigure if needed") made kunit.py build run configuration before
building, so it can be used standalone without first running
kunit.py config. However, unlike run_handler() and config_handler(),
build_handler() does not create build_dir before calling
tree_from_args(). Because LinuxSourceTree.__init__() copies the default
.kunitconfig into build_dir when no --kunitconfig is given, running
kunit.py build on a clean checkout or with a non-existent build
directory fails with FileNotFoundError before configuring or building
the kernel.
Create cli_args.build_dir with os.makedirs(..., exist_ok=True) when
non-empty in build_handler() before calling tree_from_args(), matching
config_handler(). Extend test_commands_create_nested_builddir to cover
the build subcommand.
Fixes: 1ee2ba89bea8 ("kunit: tool: make `build` subcommand also reconfigure if needed")
Signed-off-by: Pavee Zheng <pavee.zheng@xxxxxxxxx>
---
tools/testing/kunit/kunit.py | 3 +++
tools/testing/kunit/kunit_tool_test.py | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index 5070a831e4e8..312e184f1a52 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -564,6 +564,9 @@ def config_handler(cli_args: argparse.Namespace) -> None:
def build_handler(cli_args: argparse.Namespace) -> None:
+ if cli_args.build_dir:
+ os.makedirs(cli_args.build_dir, exist_ok=True)
+
linux = tree_from_args(cli_args)
request = KunitBuildRequest(build_dir=cli_args.build_dir,
make_options=cli_args.make_options,
diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index 95809cdec7d2..921907c5771a 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -901,7 +901,7 @@ class KUnitMainTest(unittest.TestCase):
self.mock_linux_init.side_effect = init_linux
with tempfile.TemporaryDirectory() as tmpdir:
- for command in ('config', 'run'):
+ for command in ('config', 'build', 'run'):
with self.subTest(command=command):
self.mock_linux_init.reset_mock()
build_dir = os.path.join(tmpdir, command, 'arm64')
--
Git-157)