Static analysis is a way of analyzing source code without executing it. One of its applications is to find code smells and bugs.
Fuchsia uses Clang as its compiler. Clang has several tools to analyze the code statically. Fuchsia enables a large set of useful warning messages and compiles with warnings as errors.
Before you do static analysis, make sure you have the following:
clang-tidy
and Clang static analyzer. It is created at the root of your build directory automatically by fx set
.There is a more detailed guide available here.
Install scan-build-py
:
pip install scan-build --user
You might get a warning that ~/.local/bin
is not part of the PATH
. Either add it to your PATH
environment variable or install scan-build
globally (without the --user
flag).
From your Fuchsia directory, run the Clang static analyzer:
analyze-build --cdb compile_commands.json --use-analyzer path/to/checkout/prebuilt/third_party/clang/linux-x64/bin/clang --output path/to/output
View the results of Clang static analyzer with Chrome:
chrome path/to/output/scan-build-date-hash/index.html