Re: [PATCH v1] clang_tools:gen_compile_commands: Change the default source directory

From: Stephen Zhang
Date: Sun Feb 14 2021 - 06:51:08 EST


Masahiro Yamada <masahiroy@xxxxxxxxxx> 于2021年2月13日周六 下午8:46写道:
> This is the steps I tested.
>
>
> masahiro@oscar:~/ref/linux$ make O=build defconfig all -j24
> [ snip ]
> masahiro@oscar:~/ref/linux$
> ./scripts/clang-tools/gen_compile_commands.py -d build
> masahiro@oscar:~/ref/linux$ grep '"file":' compile_commands.json |
> grep scripts/ | head -n5
> "file": "/home/masahiro/ref/linux/scripts/mod/empty.c"
> "file": "/home/masahiro/ref/linux/scripts/mod/sumversion.c"
> "file": "/home/masahiro/ref/linux/scripts/mod/file2alias.c"
> "file": "/home/masahiro/ref/linux/scripts/mod/modpost.c"
> "file": "/home/masahiro/ref/linux/build/scripts/kconfig/parser.tab.c"
>
> --
> Best Regards
> Masahiro Yamada

Thanks. Nathan had a detailed description about this:

> $ make O=build
>
> will work with '-d .' because the .cmd files are in '.' and the source
> files will be placed relative to '.', which is correct. Your command
> does not work for two reasons:
>
> 1. You are using a build directory that is not a subpath of the source
> directory. In other words, this script would not work for
>
> $ make O=/tmp/build
>
> because '-d /tmp/build' needs to be used to find the .cmd files but then
> the relative path of the source files is messed up, as you point out.

This may help you reproduce the problem. So you shoud try:

>masahiro@oscar:~/ref/linux$ make O=/tmp/build defconfig all -j24

where the build directory is not a subpath of the source directory.

--
Best Regards
Stephen Zhang