Commit 94f38d7f authored by Jens Petit's avatar Jens Petit
Browse files

clang-tidy with config file and gitlab CI

parent 3c975307
Pipeline #172882 passed with stages
in 21 minutes and 21 seconds
---
Checks: '-*,
performance-*,
ccpcoreguidelines-*,
llvm-namespace-comment,
modernize-*,
-modernize-use-nodiscard,
readability-*,
-readability-else-after-return,
-readability-braces-around-statements,
-readability-magic-numbers,
-readability-uppercase-literal-suffix,
-readability-isolate-declaration'
HeaderFilterRegex: 'elsa/elsa'
AnalyzeTemporaryDtors: false
CheckOptions:
- key: llvm-namespace-comment.ShortNamespaceLines
value: '10'
- key: llvm-namespace-comment.SpacesBeforeComments
value: '2'
# type names
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.UnionCase
value: CamelCase
# method names
- key: readability-identifier-naming.MethodCase
value: camelBack
# variable names
- key: readability-identifier-naming.VariableCase
value: camelBack
- key: readability-identifier-naming.ParameterCase
value: camelBack
- key: readability-identifier-naming.MemberPrefix
value: _
# const static or global variables are UPPER_CASE
- key: readability-identifier-naming.EnumConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.StaticConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.ClassConstantCase
value: UPPER_CASE
...
......@@ -41,7 +41,8 @@ stages:
artifacts:
reports:
junit: "build/test_reports/test_*.xml"
### static test ###
clang-format:
......@@ -54,6 +55,17 @@ clang-format:
- elsa
- clang
clang-tidy:
stage: static-test
image: elsa/cuda:9.2
script:
./tools/ci_scripts/clang-tidy.sh
tags:
- linux
- elsa
- clang
### compile jobs ###
build-ubuntu:
......
#!/bin/bash
exit_flag=false
# for compilation database
mkdir -p build
cd build
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cd ..
target_branch="master"
echo
echo "clang-tidy checking changed files compared to target branch ${target_branch}"
# function to check if C++ file (based on suffix)
function checkCPP(){
if [[ $1 == *.cpp ]];then
return 0
fi
return 1
}
apt-get update
apt-get install clang-tidy-8 -y
clang-tidy-8 --version
echo
# Retrieve list of files that were changed in source branch with respect to master (target branch)
filelist=`git diff origin/${target_branch} --name-only`
# check list of files
for f in $filelist; do
if checkCPP $f; then
echo "Checking matching file ${f}"
# apply the clang-format script
touch output.txt
clang-tidy-8 -p=build ${f} > output.txt
# decide if error or warning fail
if [[ -n $(grep "warning: " output.txt) ]] || [[ -n $(grep "error: " output.txt) ]]; then
echo ""
echo "You must pass the clang tidy checks before submitting a pull request"
echo ""
grep --color -E '^|warning: |error: ' output.txt
if [[ -n $(grep "error: " output.txt) ]]; then
exit_flag=true
fi
else
echo -e "\033[1;32m\xE2\x9C\x93 passed:\033[0m $1";
fi
rm output.txt
fi
done
if [ "$exit_flag" = true ]; then
exit -1
fi
echo "clang-tidy check passed"
exit 0
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment