]> git.dujemihanovic.xyz Git - linux.git/commitdiff
kunit: tool: Build compile_commands.json
authorBrendan Jackman <jackmanb@google.com>
Thu, 16 May 2024 19:40:53 +0000 (19:40 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Thu, 12 Sep 2024 15:52:36 +0000 (09:52 -0600)
compile_commands.json is used by clangd[1] to provide code navigation
and completion functionality to editors. See [2] for an example
configuration that includes this functionality for VSCode.

It can currently be built manually when using kunit.py, by running:

  ./scripts/clang-tools/gen_compile_commands.py -d .kunit

With this change however, it's built automatically so you don't need to
manually keep it up to date.

Unlike the manual approach, having make build the compile_commands.json
means that it appears in the build output tree instead of at the root of
the source tree, so you'll need to add --compile-commands-dir=.kunit to
your clangd args for it to be found. This might turn out to be pretty
annoying, I'm not sure yet. If so maybe we can later add some hackery to
kunit.py to work around it.

[1] https://clangd.llvm.org/
[2] https://github.com/FlorentRevest/linux-kernel-vscode

Signed-off-by: Brendan Jackman <jackmanb@google.com>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/kunit/kunit_kernel.py

index 7254c110ff23ab9a661ed1ca4d9dc789b8d8762f..61931c4926fd6645f2c62dd13f9842a432ec4167 100644 (file)
@@ -72,7 +72,8 @@ class LinuxSourceTreeOperations:
                        raise ConfigError(e.output.decode())
 
        def make(self, jobs: int, build_dir: str, make_options: Optional[List[str]]) -> None:
-               command = ['make', 'ARCH=' + self._linux_arch, 'O=' + build_dir, '--jobs=' + str(jobs)]
+               command = ['make', 'all', 'compile_commands.json', 'ARCH=' + self._linux_arch,
+                          'O=' + build_dir, '--jobs=' + str(jobs)]
                if make_options:
                        command.extend(make_options)
                if self._cross_compile: