Re: [PATCH v7] Makefile: Add clang-tidy and static analyzer support to makefile

From: Masahiro Yamada
Date: Wed Aug 12 2020 - 13:48:51 EST


On Wed, Aug 12, 2020 at 10:24 AM 'Nathan Huckleberry' via Clang Built
Linux <clang-built-linux@xxxxxxxxxxxxxxxx> wrote:
>
> Sounds good. Do you think this patch is ready to land then?


I do not think so.

I pointed out the CC=clang check was not working.
I see false positive errors from GCC commands.



This patch does not use the benefit of Makefile.

Makefile is used to describe the dependency
between a target and its prerequisites,
and how to update the target.

Make compares the timestamps between the
targets and prerequisites, then determines
which targets need updating.


See your code.


clang-tidy:
ifdef CONFIG_CC_IS_CLANG
$(PYTHON3) scripts/clang-tools/gen_compile_commands.py
$(PYTHON3) scripts/clang-tools/run-clang-tools.py clang-tidy
compile_commands.json
else
$(error clang-tidy requires CC=clang)
endif


This always runs two commands sequentially.
It rebuilds compile_commands.json even if
nothing in the source tree has been changed.

If you do this, there is no strong reason to use Make,
and actually you can rewrite it in a shell script:


clang_tidy () {
if [ "$CONFIG_CC_IS_CLANG = "y" ]; then
$PYTHON3 scripts/clang-tools/gen_compile_commands.py
$PYTHON3 scripts/clang-tools/run-clang-tools.py clang-tidy
compile_commands.json
else
echo "clang-tidy requires CC=clang"
exit 1
fi
}




I changed the rules to Makefile-ish style.

https://patchwork.kernel.org/project/linux-kbuild/list/?series=331893


I will wait for comments for the new version.


--
Best Regards
Masahiro Yamada