In January 2021 we will introduce a 10 GB quota for project repositories. Higher limits for individual projects will be available on request. Please see https://doku.lrz.de/display/PUBLIC/GitLab for more information.

Commit 939f1176 authored by David Frank's avatar David Frank Committed by Tobias Lasser

#90 Update clang-format and clang-tidy to version 10

- Update CI stage to reflect update
- Update ci_scripts to reflect update
- Reformate code with clang-format-10
- Update contribution guide
parent 6887ba84
Pipeline #370503 passed with stages
in 27 minutes and 59 seconds
......@@ -10,7 +10,7 @@ stages:
### variables ###
variables:
CLANG_FORMAT_IMAGE: "elsa/clang-format:8"
CLANG_FORMAT_IMAGE: "elsa/clang-format:10"
CLANG_TIDY_IMAGE: "elsa/clang-tidy:8"
GCC_IMAGE: "elsa/gcc-pybinds:10"
CLANG9_IMAGE: "elsa/clang-pybinds:9"
......
......@@ -62,10 +62,12 @@ We use the tool `clang-format` to autoformat our code with the [given style
file](.clang-format). Please make sure that your code is formatted accordingly, otherwise the CI
will fail in the first stage. You can either execute
```
find elsa/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' | xargs clang-format-8 -i -style=file $1
find elsa/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' | xargs clang-format-10 -i -style=file $1
find examples/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' | xargs clang-format-10 -i -style=file $1
find benchmark/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' | xargs clang-format-10 -i -style=file $1
```
in the root folder, setup a git hook or integrate `clang-format` into your IDE. Note that we
currently use version 8.0.0, different versions might produce errors.
currently use version 10.0.0, different versions might produce errors.
## Linting
We use `clang-tidy` with the enabled checks specified in [the configuration file](.clang-tidy). Note
......
......@@ -437,7 +437,7 @@ namespace elsa
/// User-defined template argument deduction guide for the expression based constructor
template <typename Source>
DataContainer(Source const& source)->DataContainer<typename Source::data_t>;
DataContainer(Source const& source) -> DataContainer<typename Source::data_t>;
/// Collects callable lambdas for later dispatch
template <typename... Ts>
......@@ -447,7 +447,7 @@ namespace elsa
/// Class template deduction guide
template <typename... Ts>
Callables(Ts...)->Callables<Ts...>;
Callables(Ts...) -> Callables<Ts...>;
/// Multiplying two operands (including scalars)
template <typename LHS, typename RHS, typename = std::enable_if_t<isBinaryOpOk<LHS, RHS>>>
......
......@@ -179,8 +179,8 @@ namespace elsa
}
template <typename data_t>
DataHandlerMapCPU<data_t>& DataHandlerMapCPU<data_t>::
operator=(const DataHandlerMapCPU<data_t>& v)
DataHandlerMapCPU<data_t>&
DataHandlerMapCPU<data_t>::operator=(const DataHandlerMapCPU<data_t>& v)
{
if (v.getSize() != getSize())
throw std::invalid_argument("DataHandler: assignment argument has wrong size");
......
......@@ -184,8 +184,8 @@ namespace elsa
}
template <typename data_t>
DataHandlerMapGPU<data_t>& DataHandlerMapGPU<data_t>::
operator=(const DataHandlerMapGPU<data_t>& v)
DataHandlerMapGPU<data_t>&
DataHandlerMapGPU<data_t>::operator=(const DataHandlerMapGPU<data_t>& v)
{
if (v.getSize() != getSize())
throw std::invalid_argument("DataHandler: assignment argument has wrong size");
......
......@@ -324,7 +324,7 @@ namespace elsa
operator Vector() const { return _vec; }
/// Conversion operator to Vector&& (rvalue reference)
operator Vector &&() { return std::move(_vec); }
operator Vector&&() { return std::move(_vec); }
/// Access to vector (const reference)
const Vector& get() & { return _vec; }
......
......@@ -17,8 +17,8 @@ namespace elsa
}
template <typename data_t>
RegularizationTerm<data_t>& RegularizationTerm<data_t>::
operator=(const RegularizationTerm<data_t>& other)
RegularizationTerm<data_t>&
RegularizationTerm<data_t>::operator=(const RegularizationTerm<data_t>& other)
{
if (this != &other) {
_weight = other._weight;
......@@ -35,8 +35,8 @@ namespace elsa
}
template <typename data_t>
RegularizationTerm<data_t>& RegularizationTerm<data_t>::
operator=(RegularizationTerm<data_t>&& other) noexcept
RegularizationTerm<data_t>&
RegularizationTerm<data_t>::operator=(RegularizationTerm<data_t>&& other) noexcept
{
_weight = std::move(other._weight);
_functional = std::move(other._functional);
......
......@@ -14,20 +14,20 @@ fi
echo
if type clang-format-8 2>/dev/null; then
if type clang-format-10 2>/dev/null; then
echo "Checking formatting using the following clang-format version:"
clang-format-8 --version
clang-format-10 --version
else
echo "clang-format-8 not correctly installed"
echo "clang-format-10 not correctly installed"
exit 1
fi
echo
# perform clang-format on all cpp-files
find elsa/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' -or -name '*.cu' -or -name '*.cuh' | xargs clang-format-8 -i -style=file $1
find benchmarks/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' -or -name '*.cu' -or -name '*.cuh' | xargs clang-format-8 -i -style=file $1
find examples/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' -or -name '*.cu' -or -name '*.cuh' | xargs clang-format-8 -i -style=file $1
find elsa/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' -or -name '*.cu' -or -name '*.cuh' | xargs clang-format-10 -i -style=file $1
find benchmarks/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' -or -name '*.cu' -or -name '*.cuh' | xargs clang-format-10 -i -style=file $1
find examples/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' -or -name '*.cu' -or -name '*.cuh' | xargs clang-format-10 -i -style=file $1
# check if something was modified
notcorrectlist=`git status --porcelain | grep '^ M' | cut -c4-`
......@@ -41,9 +41,9 @@ else
git diff --stat $notcorrectlist
echo "Please run"
echo
echo "find elsa/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' -or -name '*.cu' -or -name '*.cuh' | xargs clang-format-8 -i -style=file $1"
echo "find benchmarks/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' -or -name '*.cu' -or -name '*.cuh' | xargs clang-format -i -style=file $1"
echo "find examples/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' -or -name '*.cu' -or -name '*.cuh' | xargs clang-format -i -style=file $1"
echo "find elsa/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' -or -name '*.cu' -or -name '*.cuh' | xargs clang-format-10 -i -style=file $1"
echo "find benchmarks/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' -or -name '*.cu' -or -name '*.cuh' | xargs clang-format-10 -i -style=file $1"
echo "find examples/ -name '*.h' -or -name '*.hpp' -or -name '*.cpp' -or -name '*.cu' -or -name '*.cuh' | xargs clang-format-10 -i -style=file $1"
echo
echo "to solve the issue."
# cleanup changes in git
......
#!/bin/bash
# set exit on error
# set -e
exit_flag=false
target_branch="master"
......@@ -14,13 +17,14 @@ if [[ "${#filelist[@]}" -eq "0" ]]; then
exit 0
else
echo "==> Found ${#filelist[@]} cpp files"
echo "==> ${filelist[*]}"
echo "==> Let's start our clang-tidy check"
fi
# for compilation database
mkdir -p build
cd build
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DELSA_CUDA_VECTOR=ON -DELSA_BENCHMARKS=ON
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DELSA_CUDA_VECTOR=ON -DELSA_BENCHMARKS=ON -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_EXE_LINKER_FLAGS="-lc++abi"
cd ..
echo
......@@ -41,12 +45,13 @@ echo
filesWithErrors=()
# check list of files
for f in $filelist; do
for f in ${filelist[*]}; do
# check if .cpp file and in compilation DB
if checkCPP $f && [[ -n $(grep $f build/compile_commands.json) ]]; then
echo "Checking matching file ${f}"
touch output.txt
clang-tidy-8 -p=build ${f} --extra-arg=--cuda-host-only > output.txt
# decide if error or warning fail
if [[ -n $(grep "warning: " output.txt) ]] || [[ -n $(grep "error: " output.txt) ]]; then
echo ""
......@@ -56,11 +61,16 @@ for f in $filelist; do
if [[ -n $(grep "error: " output.txt) ]]; then
exit_flag=true
filesWithErrors=( "${filesWithErrors[@]}" $f )
echo -e "\033[1;31m\xE2\x9C\x98 failed file $f\033[0m $1";
else
echo -e "\033[1;33m\xE2\x9C\x93 passed file $f with warnings\033[0m $1";
fi
else
echo -e "\033[1;32m\xE2\x9C\x93 passed file $f\033[0m $1";
fi
rm output.txt
else
echo "$f not a C++ file or not in compilation database (compile_commands.json)"
fi
done
......
Markdown is supported
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