Skip to contentSkip to conversation

Makefile: add $(srctree) to dependency of compile_commands.json target

PATCH Superseded Alexandre Courbot 2 participants 4 messages Aug 3, 2024 – Aug 5, 2024 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: add $(srctree) to dependency of compile_commands.json target

When trying to build the compile_commands.json target from an external module's directory, the following error is displayed:

make[1]: *** No rule to make target 'scripts/clang-tools/gen_compile_commands.py', needed by 'compile_commands.json'. Stop.

This appears to be because gen_compile_commands.py is looked up using relative path, which doesn't exist from the module's source tree. Prefixing the dependency with $(srctree) fixes the problem.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 8ad55d6e7b60..52d7dfe4212a 100644
@@ -1980,7 +1980,7 @@ nsdeps: modules
 quiet_cmd_gen_compile_commands = GEN     $@
       cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
 
-$(extmod_prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \
+$(extmod_prefix)compile_commands.json: $(srctree)/scripts/clang-tools/gen_compile_commands.py \
 	$(if $(KBUILD_EXTMOD),, vmlinux.a $(KBUILD_VMLINUX_LIBS)) \
 	$(if $(CONFIG_MODULES), $(MODORDER)) FORCE
 	$(call if_changed,gen_compile_commands)
Signature · 1 line
2.46.0
#1 lore raw
Quoted 6 lines · Alexandre Courbot

When trying to build the compile_commands.json target from an external module's directory, the following error is displayed:

make[1]: *** No rule to make target 'scripts/clang-tools/gen_compile_commands.py', needed by 'compile_commands.json'. Stop.

Good catch.

But, to reproduce this, O= option is also needed, right?

e.g.

  $ make O=path/to/build/dir M=path/to/external/module/dir
Quoted 2 lines

This appears to be because gen_compile_commands.py is looked up using relative path, which doesn't exist from the module's source tree.

The phrase "appears to be ..." is somewhat modest.

You can reword this to pin-point the first bad commit.

For example:

gen_compile_commands.py was previously looked up using a relative path to $(srctree), but commit b1992c3772e6 ("kbuild: use $(src) instead of $(srctree)/$(src) for source directory") stopped defining VPATH for external module builds.

Quoted 1 line

Prefixing the dependency with $(srctree) fixes the problem.

This needs back-porting.

Please add this:

Fixes b1992c3772e6 ("kbuild: use $(src) instead of $(srctree)/$(src)

for source directory")

Thanks.

Quoted 19 lines
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -2
index 8ad55d6e7b60..52d7dfe4212a 100644
@@ -1980,7 +1980,7 @@ nsdeps: modules
 quiet_cmd_gen_compile_commands = GEN     $@
       cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
 
-$(extmod_prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \
+$(extmod_prefix)compile_commands.json: $(srctree)/scripts/clang-tools/gen_compile_commands.py \
        $(if $(KBUILD_EXTMOD),, vmlinux.a $(KBUILD_VMLINUX_LIBS)) \
        $(if $(CONFIG_MODULES), $(MODORDER)) FORCE
        $(call if_changed,gen_compile_commands)
--
Quoted 2 lines

2.46.0

--
Best Regards

Masahiro Yamada

#2 lore raw
Quoted 10 lines · Masahiro Yamada
Quoted 6 lines · Alexandre Courbot

When trying to build the compile_commands.json target from an external module's directory, the following error is displayed:

make[1]: *** No rule to make target 'scripts/clang-tools/gen_compile_commands.py', needed by 'compile_commands.json'. Stop.

Quoted 7 lines

Good catch.

But, to reproduce this, O= option is also needed, right?

e.g.

  $ make O=path/to/build/dir M=path/to/external/module/dir

I am building the module as follows:

$ make -C ../linux/build M=$PWD modules compile_commands.json

The kernel itself was built with O=build though.

Quoted 10 lines
Quoted 2 lines

This appears to be because gen_compile_commands.py is looked up using relative path, which doesn't exist from the module's source tree.

The phrase "appears to be ..." is somewhat modest.

You can reword this to pin-point the first bad commit.

Quoted 6 lines

For example:

gen_compile_commands.py was previously looked up using a relative path to $(srctree), but commit b1992c3772e6 ("kbuild: use $(src) instead of $(srctree)/$(src) for source directory") stopped defining VPATH for external module builds.

Thanks, that's much better. I should indeed have bisected to find the source of the regression.

Quoted 7 lines
Quoted 4 lines

Prefixing the dependency with $(srctree) fixes the problem.

Quoted 7 lines

This needs back-porting.

Please add this:

Fixes b1992c3772e6 ("kbuild: use $(src) instead of $(srctree)/$(src)

for source directory")

Done, and sent v2 as well.

Thank you!
Alex.

#3 lore raw
Quoted 16 lines · Alexandre Courbot
Quoted 14 lines · Masahiro Yamada
Quoted 6 lines · Alexandre Courbot

When trying to build the compile_commands.json target from an external module's directory, the following error is displayed:

make[1]: *** No rule to make target 'scripts/clang-tools/gen_compile_commands.py', needed by 'compile_commands.json'. Stop.

Good catch.

But, to reproduce this, O= option is also needed, right?

Quoted 7 lines
Quoted 3 lines

e.g.

  $ make O=path/to/build/dir M=path/to/external/module/dir

I am building the module as follows:

$ make -C ../linux/build M=$PWD modules compile_commands.json

OK, this is equivalent to the command I gave. You are building your external module
against the kernel built in a separate output directory.

Signature · 2 lines
Best Regards
Masahiro Yamada