2019-04-24 05:20:13 +00:00
|
|
|
|
---
|
|
|
|
|
title: "Статический анализ кода"
|
|
|
|
|
category: Программирование
|
|
|
|
|
tags: программирование, отладка, cppcheck, iwyu, clang-tidy, cpplint, clazy,
|
|
|
|
|
summary:
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
## Общее описание
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### clang-tidy
|
|
|
|
|
|
|
|
|
|
Установка:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
sudo apt-get install clang-tidy-6.0
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Использование:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
cmake "-DCMAKE_CXX_CLANG_TIDY=/usr/bin/clang-tidy-6.0;-checks=*" path/to/source
|
|
|
|
|
```
|
|
|
|
|
|
2019-04-24 13:57:04 +00:00
|
|
|
|
|
2019-04-24 05:20:13 +00:00
|
|
|
|
This will run `/usr/bin/clang-tidy-6.0 -checks=*` on each of the C++ source files in the project being built.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### CppCheck
|
|
|
|
|
|
|
|
|
|
Установка:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
sudo apt-get install cppcheck
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Использование:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
cmake "-DCMAKE_CXX_CPPCHECK=/usr/bin/cppcheck;--std=c++11" path/to/source
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
This will run /usr/bin/cppcheck;–std=c++11″ –source=/path/to/source/file.cxx on each c++ file in the project being built.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### CppLint
|
|
|
|
|
|
|
|
|
|
Установка:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
sudo apt-get install python3-cpplint
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Использование:
|
|
|
|
|
|
|
|
|
|
```sh
|
2019-04-24 13:57:04 +00:00
|
|
|
|
cmake "-DCMAKE_CXX_CPPLINT=/usr/bin/cpplint;--linelength=79" path/to/source
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
make -j24 2>&1 1>/dev/null | ../cpplint2tasks.pl > 222.tasks
|
2019-04-24 05:20:13 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
This will run /usr/local/bin/cpplint –linelength=79 on each c++ file in the project being built.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### IWYU
|
|
|
|
|
|
|
|
|
|
Установка:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
sudo apt-get install iwyu
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Использование:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
cmake "-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=/usr/bin/iwyu;--transitive_includes_only" ..
|
|
|
|
|
```
|
|
|
|
|
|
2019-04-24 13:57:04 +00:00
|
|
|
|
|
2019-04-24 05:20:13 +00:00
|
|
|
|
This will run /usr/bin/iwyu –transitive_includes_only on each c++ file in the project being built.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### LWYU
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
cmake -DCMAKE_LINK_WHAT_YOU_USE=TRUE ..
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Clazy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Установка:
|
|
|
|
|
|
|
|
|
|
```sh
|
2019-04-24 13:57:04 +00:00
|
|
|
|
sudo apt-get install clazy clang-6.0
|
2019-04-24 05:20:13 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Использование:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
CLAZY_CHECKS=level2 cmake -DCMAKE_CXX_COMPILER=clazy ..
|
2019-04-24 13:57:04 +00:00
|
|
|
|
CLANGXX=clang++-6.0 make
|
2019-04-24 05:20:13 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### PVS-Studio
|
|
|
|
|
|