* [PATCH] kunit: tool: Build compile_commands.json
@ 2024-05-16 19:38 Brendan Jackman
2024-09-12 7:37 ` David Gow
2024-09-12 21:36 ` Justin Stitt
0 siblings, 2 replies; 5+ messages in thread
From: Brendan Jackman @ 2024-05-16 19:38 UTC (permalink / raw)
To: Brendan Higgins, David Gow, Rae Moar, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt
Cc: linux-kselftest, kunit-dev, linux-kernel, llvm, Brendan Jackman
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= to your
clangd args for it to be found.
[1] https://clangd.llvm.org/
[2] https://github.com/FlorentRevest/linux-kernel-vscode
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
tools/testing/kunit/kunit_kernel.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index 7254c110ff23..61931c4926fd 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -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:
---
base-commit: 3c999d1ae3c75991902a1a7dad0cb62c2a3008b4
change-id: 20240516-kunit-compile-commands-d994074fc2be
Best regards,
--
Brendan Jackman <jackmanb@google.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kunit: tool: Build compile_commands.json
2024-05-16 19:38 [PATCH] kunit: tool: Build compile_commands.json Brendan Jackman
@ 2024-09-12 7:37 ` David Gow
2024-09-12 21:36 ` Justin Stitt
1 sibling, 0 replies; 5+ messages in thread
From: David Gow @ 2024-09-12 7:37 UTC (permalink / raw)
To: Brendan Jackman
Cc: Brendan Higgins, Rae Moar, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, linux-kselftest, kunit-dev,
linux-kernel, llvm
[-- Attachment #1: Type: text/plain, Size: 2372 bytes --]
On Fri, 17 May 2024 at 03:38, Brendan Jackman <jackmanb@google.com> wrote:
>
> 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= to your
> clangd args for it to be found.
>
> [1] https://clangd.llvm.org/
> [2] https://github.com/FlorentRevest/linux-kernel-vscode
>
> Signed-off-by: Brendan Jackman <jackmanb@google.com>
> ---
Sorry for missing this earlier.
I'm happy with this. Having the compile_commands.json be in the .kunit
directory is annoying, but it actually ends up being less annoying for
the case where you have lots of out-of-tree builds, so I actually
prefer it.
Reviewed-by: David Gow <davidgow@google.com>
Cheers,
-- David
> tools/testing/kunit/kunit_kernel.py | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
> index 7254c110ff23..61931c4926fd 100644
> --- a/tools/testing/kunit/kunit_kernel.py
> +++ b/tools/testing/kunit/kunit_kernel.py
> @@ -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:
>
> ---
> base-commit: 3c999d1ae3c75991902a1a7dad0cb62c2a3008b4
> change-id: 20240516-kunit-compile-commands-d994074fc2be
>
> Best regards,
> --
> Brendan Jackman <jackmanb@google.com>
>
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5294 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kunit: tool: Build compile_commands.json
2024-05-16 19:38 [PATCH] kunit: tool: Build compile_commands.json Brendan Jackman
2024-09-12 7:37 ` David Gow
@ 2024-09-12 21:36 ` Justin Stitt
1 sibling, 0 replies; 5+ messages in thread
From: Justin Stitt @ 2024-09-12 21:36 UTC (permalink / raw)
To: Brendan Jackman
Cc: Brendan Higgins, David Gow, Rae Moar, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, linux-kselftest, kunit-dev,
linux-kernel, llvm
On Thu, May 16, 2024 at 12:38 PM Brendan Jackman <jackmanb@google.com> wrote:
>
> 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.
This is great!
>
> 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= to your
> clangd args for it to be found.
This is annoying for some. For my setup, the discovery of
compile_commands.json depends on where I open my editor from. So this
isn't really an issue as I can *choose* what compile_commands to use.
I think some folks may wish the compile_commands.json was also dumped
in the top-level directory so clangd can discover it easier.
>
> [1] https://clangd.llvm.org/
> [2] https://github.com/FlorentRevest/linux-kernel-vscode
>
> Signed-off-by: Brendan Jackman <jackmanb@google.com>
> ---
> tools/testing/kunit/kunit_kernel.py | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
> index 7254c110ff23..61931c4926fd 100644
> --- a/tools/testing/kunit/kunit_kernel.py
> +++ b/tools/testing/kunit/kunit_kernel.py
> @@ -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:
>
> ---
> base-commit: 3c999d1ae3c75991902a1a7dad0cb62c2a3008b4
> change-id: 20240516-kunit-compile-commands-d994074fc2be
>
> Best regards,
> --
> Brendan Jackman <jackmanb@google.com>
>
Reviewed-by: Justin Stitt <justinstitt@google.com>
Thanks
Justin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kunit: tool: Build compile_commands.json
2024-05-16 19:40 Brendan Jackman
@ 2024-05-17 18:32 ` Nathan Chancellor
0 siblings, 0 replies; 5+ messages in thread
From: Nathan Chancellor @ 2024-05-17 18:32 UTC (permalink / raw)
To: Brendan Jackman
Cc: Brendan Higgins, David Gow, Rae Moar, Nick Desaulniers,
Bill Wendling, Justin Stitt, linux-kselftest, kunit-dev,
linux-kernel, llvm
Hi Brendan,
On Thu, May 16, 2024 at 07:40:53PM +0000, Brendan Jackman wrote:
> 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>
This makes sense to do automatically in my opinion, as Python will
already be available (which is the only dependency of
gen_compile_commands.py as far as I am aware) and it should not take
that long to generate.
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
> ---
> tools/testing/kunit/kunit_kernel.py | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
> index 7254c110ff23..61931c4926fd 100644
> --- a/tools/testing/kunit/kunit_kernel.py
> +++ b/tools/testing/kunit/kunit_kernel.py
> @@ -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:
>
> ---
> base-commit: 3c999d1ae3c75991902a1a7dad0cb62c2a3008b4
> change-id: 20240516-kunit-compile-commands-d994074fc2be
>
> Best regards,
> --
> Brendan Jackman <jackmanb@google.com>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] kunit: tool: Build compile_commands.json
@ 2024-05-16 19:40 Brendan Jackman
2024-05-17 18:32 ` Nathan Chancellor
0 siblings, 1 reply; 5+ messages in thread
From: Brendan Jackman @ 2024-05-16 19:40 UTC (permalink / raw)
To: Brendan Higgins, David Gow, Rae Moar, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt
Cc: linux-kselftest, kunit-dev, linux-kernel, llvm, Brendan Jackman
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>
---
tools/testing/kunit/kunit_kernel.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index 7254c110ff23..61931c4926fd 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -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:
---
base-commit: 3c999d1ae3c75991902a1a7dad0cb62c2a3008b4
change-id: 20240516-kunit-compile-commands-d994074fc2be
Best regards,
--
Brendan Jackman <jackmanb@google.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-09-12 21:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-16 19:38 [PATCH] kunit: tool: Build compile_commands.json Brendan Jackman
2024-09-12 7:37 ` David Gow
2024-09-12 21:36 ` Justin Stitt
2024-05-16 19:40 Brendan Jackman
2024-05-17 18:32 ` Nathan Chancellor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®