Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Clang-tidy] Run clang-tidy on modified code
- Loading branch information
1 parent
6452390
commit 0dc69f2
Showing
6 changed files
with
209 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env bash | ||
########################################################################### | ||
# docker-qgis-clangtidy.sh | ||
# --------------------- | ||
# Date : September 2022 | ||
# Copyright : (C) 2022 by Julien Cabieces | ||
# Email : julien dot cabieces at oslandia dot com | ||
########################################################################### | ||
# # | ||
# This program is free software; you can redistribute it and/or modify # | ||
# it under the terms of the GNU General Public License as published by # | ||
# the Free Software Foundation; either version 2 of the License, or # | ||
# (at your option) any later version. # | ||
# # | ||
########################################################################### | ||
|
||
set -e | ||
|
||
SRCDIR=${CTEST_SOURCE_DIR-/root/QGIS} | ||
cd ${SRCDIR} | ||
|
||
# This is needed for `git status` to work, see | ||
# https://github.com/qgis/QGIS/runs/6733585841?check_suite_focus=true#step:13:89 | ||
git config --global --add safe.directory ${SRCDIR} | ||
|
||
echo "::group::Install cland tidy" | ||
apt install -y \ | ||
clang-tidy | ||
echo "::endgroup::" | ||
|
||
cd ${SRCDIR} | ||
|
||
echo "::group::Download clang-tidy-diff" | ||
curl -XGET https://raw.githubusercontent.com/llvm/llvm-project/llvmorg-14.0.6/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py -o clang-tidy-diff.py | ||
echo "::endgroup::" | ||
|
||
echo "${bold}Run clang-tidy on modifications...${endbold}" | ||
CLANG_TIDY_CHECKS=$(cat tests/code_layout/clangtidy_checks.txt | grep -ve "^#" | grep -ve "^$" | tr -d '\n') | ||
git diff -U0 HEAD^ | python3 clang-tidy-diff.py -p1 -path=${CTEST_BUILD_DIR} -use-color -checks="$CLANG_TIDY_CHECKS" | tee clang-tidy.log | ||
|
||
echo -e "\e[1;34mTo reproduce locally:" | ||
echo -e "\e[1;34m - launch cmake with option -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" | ||
echo -e "\e[1;34m - update build by calling Ninja" | ||
echo -e "\e[1;34m - launch command ./scripts/clang-tidy.sh -p <your_build_dir> <source_file>" | ||
|
||
exit $(grep "warning:" clang-tidy.log | wc -l) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env bash | ||
########################################################################### | ||
# clang-tidy.sh | ||
# --------------------- | ||
# Date : September 2022 | ||
# Copyright : (C) 2022 by Julien Cabieces | ||
# Email : julien dot cabieces at oslandia dot com | ||
########################################################################### | ||
# # | ||
# This program is free software; you can redistribute it and/or modify # | ||
# it under the terms of the GNU General Public License as published by # | ||
# the Free Software Foundation; either version 2 of the License, or # | ||
# (at your option) any later version. # | ||
# # | ||
########################################################################### | ||
|
||
set -e | ||
|
||
usage() { | ||
echo 'Usage: '$(basename $0)' [-p <build_dir>] [-a] [-m <module_name>] [source_files] | ||
-a : run clang-tidy on all source files | ||
-m <module> : run clang-tidy on all module source files (core, gui, analysis...) | ||
Use either -a or -m, or source files' 1>&2; exit 1; } | ||
|
||
SCRIPT_DIR=$(dirname $0)/.. | ||
SOURCE_DIR=$(realpath $SCRIPT_DIR) | ||
|
||
BUILD_DIR=$(pwd) | ||
while getopts "p:am:" o; do | ||
case "${o}" in | ||
p) | ||
BUILD_DIR=${OPTARG} | ||
;; | ||
a) | ||
if [[ ! -z "$FILE_OPT" ]]; then | ||
usage | ||
fi | ||
FILE_OPT="ALL" | ||
;; | ||
m) | ||
if [[ ! -z "$FILE_OPT" ]]; then | ||
usage | ||
fi | ||
FILE_OPT=${OPTARG} | ||
;; | ||
*) | ||
usage | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND-1)) | ||
|
||
CLANG_TIDY_CHECKS=$(cat ${SOURCE_DIR}/tests/code_layout/clangtidy_checks.txt | grep -ve "^#" | grep -ve "^$" | tr -d '\n') | ||
|
||
if [[ ! -f "$BUILD_DIR/compile_commands.json" ]]; then | ||
echo "compile_commands.json file is missing, you need to add -DCMAKE_EXPORT_COMPILE_COMMANDS=ON when you run cmake to generate it." | ||
exit 1 | ||
fi | ||
|
||
if [[ -z "$FILE_OPT" ]]; then | ||
if [[ $# -lt 1 ]]; then | ||
echo "Missing files" | ||
usage | ||
else | ||
FILES=$* | ||
fi | ||
else | ||
if [[ $# -gt 0 ]]; then | ||
usage | ||
elif [[ "$FILE_OPT" = "ALL" ]]; then | ||
FILES=$(find $SOURCE_DIR/src -name "*.cpp" -o -name "*.h") | ||
else | ||
FILES=$(find $SOURCE_DIR/src/$FILE_OPT -name "*.cpp" -o -name "*.h") | ||
fi | ||
fi | ||
|
||
set +e | ||
|
||
for file in $FILES; | ||
do | ||
clang-tidy -p=$BUILD_DIR -checks="$CLANG_TIDY_CHECKS" $file | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
bugprone-*, | ||
|
||
# Those we don't want to fix | ||
-bugprone-easily-swappable-parameters, | ||
-bugprone-virtual-near-miss |