-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Description Our current CI has a check for GCC warnings, but this is clearly not as deep as the tests done by clang tidy. I am adding a new CI step to check the code using clang tidy. Right now this will throw some warnings and errors which I will fix progressively. Testing This is actually adding tests, so I am using this PR as a testing environment. Code related list: Former-commit-id: 201d407
- Loading branch information
Showing
3 changed files
with
183 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,42 @@ | ||
# Settings file automatically used by clang-tidy | ||
# Heavily adapted from the deal.II clang-tidy file | ||
# | ||
# See ./contrib/utilities/run_clang_tidy.sh for details | ||
|
||
# We disable performance-inefficient-string-concatenation because we don't care about "a"+to_string(5)+... | ||
# | ||
# Rationale for disabling warnings: | ||
# | ||
# - selected modernize-* warnings: | ||
# Some of these produce a lot of noise for limited utility. | ||
# | ||
# - performance-inefficient-string-concatenation: | ||
# We don't care about "a"+to_string(5)+... | ||
# | ||
# - performance-no-automatic-move: | ||
# All modern compilers perform the return value optimization and we prefer | ||
# to keep things const. | ||
# | ||
|
||
Checks: "-*,cppcoreguidelines-pro-type-static-cast-downcast,google-readability-casting,modernize-*,-modernize-pass-by-value,-modernize-raw-string-literal,-modernize-use-auto,-modernize-use-override,-modernize-use-default-member-init,-modernize-use-transparent-functors,use-emplace,mpi-*,performance-*,-performance-inefficient-string-concatenation" | ||
Checks: > | ||
-*, | ||
cppcoreguidelines-pro-type-static-cast-downcast, | ||
modernize-*, | ||
-modernize-avoid-c-arrays, | ||
-modernize-concat-nested-namespaces, | ||
-modernize-pass-by-value, | ||
-modernize-raw-string-literal, | ||
-modernize-return-braced-init-list, | ||
-modernize-use-auto, | ||
-modernize-use-default-member-init, | ||
-modernize-use-nodiscard, | ||
-modernize-use-override, | ||
-modernize-use-trailing-return-type, | ||
-modernize-use-transparent-functors, | ||
mpi-*, | ||
performance-*, | ||
-performance-inefficient-string-concatenation, | ||
-performance-no-automatic-move, | ||
-performance-avoid-endl, | ||
readability-qualified-auto | ||
WarningsAsErrors: '*' |
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,69 @@ | ||
#Heavily inspired by the deal.II version of this workflow | ||
#https://github.com/dealii/dealii | ||
|
||
name: Clang tidy | ||
|
||
on: | ||
push: | ||
# Runs on every push on master branch | ||
branches: | ||
- master | ||
# Runs on every push on master branch. If a push contains multiple commits, it will be ran on the latest one. | ||
pull_request: | ||
paths-ignore: | ||
- 'doc/**' | ||
- 'contrib/**' | ||
|
||
# Cancels running instances when a pull request is updated by a commit | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
COMPILE_JOBS: 4 | ||
|
||
jobs: | ||
tidy: | ||
name: tidy | ||
runs-on: [ubuntu-22.04] | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
dealii_version: ["master"] | ||
|
||
# Run steps in container of dealii's master branch | ||
#container: | ||
# image: dealii/dealii:${{ matrix.dealii_version }}-focal | ||
# options: --user root | ||
|
||
steps: | ||
- name: Setup | ||
run: | | ||
# Since dealii image doesn't include Node.js, we'll install it | ||
sudo apt-get install -y software-properties-common | ||
sudo add-apt-repository ppa:ginggs/deal.ii-9.5.1-backports | ||
sudo apt-get update | ||
sudo apt-get install -y --no-install-recommends nodejs \ | ||
clang-12 \ | ||
clang-tidy-12 \ | ||
numdiff \ | ||
libboost-all-dev \ | ||
libcgal-dev \ | ||
libp4est-dev \ | ||
trilinos-all-dev \ | ||
petsc-dev \ | ||
libmetis-dev \ | ||
libhdf5-mpi-dev \ | ||
deal.ii | ||
# Checks-out Lethe with branch of triggering commit | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Tidy | ||
run: | | ||
mkdir build | ||
cd build | ||
export PATH=/usr/lib/llvm-12/share/clang/:$PATH | ||
../contrib/utilities/run_clang_tidy.sh .. |
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,79 @@ | ||
#!/bin/bash | ||
## ------------------------------------------------------------------------ | ||
## | ||
## SPDX-License-Identifier: LGPL-2.1-or-later | ||
## Copyright (C) 2018 - 2020 by the deal.II authors | ||
## | ||
## This file is part of the deal.II library. | ||
## | ||
## Part of the source code is dual licensed under Apache-2.0 WITH | ||
## LLVM-exception OR LGPL-2.1-or-later. Detailed license information | ||
## governing the source code and code contributions can be found in | ||
## LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. | ||
## | ||
## ------------------------------------------------------------------------ | ||
|
||
# | ||
# This script runs the clang-tidy tool on the deal.II code base. | ||
# | ||
# | ||
# Usage: | ||
# /contrib/utilities/run_clang_tidy.sh SRC_DIR OPTIONAL_CMAKE_ARGS | ||
# with: | ||
# SRC_DIR points to a deal.II source directory | ||
# OPTIONAL_CMAKE_ARGS are optional arguments to pass to CMake | ||
# make sure to run this script in an empty build directory | ||
# | ||
# Requirements: | ||
# Clang 5.0.1+ and have clang, clang++, and run-clang-tidy.py in | ||
# your path. | ||
|
||
# grab first argument and make relative path an absolute one: | ||
SRC=$1 | ||
SRC=$(cd "$SRC";pwd) | ||
shift | ||
|
||
if test ! -d "$SRC/source" -o ! -d "$SRC/include" -o ! -d "$SRC/examples" -o ! -f "$SRC/CMakeLists.txt" ; then | ||
echo "Usage:" | ||
echo " run_clang_tidy.sh /path/to/dealII" | ||
exit 1 | ||
fi | ||
echo "SRC-DIR=$SRC" | ||
|
||
# enable MPI (to get MPI warnings) | ||
# export compile commands (so that run-clang-tidy.py works) | ||
ARGS=("-D" "CMAKE_EXPORT_COMPILE_COMMANDS=ON" "-D" "CMAKE_BUILD_TYPE=Debug" "$@") | ||
|
||
# for a list of checks, see /.clang-tidy | ||
cat "$SRC/.clang-tidy" | ||
|
||
if ! [ -x "$(command -v run-clang-tidy.py)" ] || ! [ -x "$(command -v clang++)" ]; then | ||
echo "make sure clang, clang++, and run-clang-tidy.py (part of clang) are in the path" | ||
exit 2 | ||
fi | ||
|
||
CC=clang CXX=clang++ cmake "${ARGS[@]}" "$SRC" || (echo "cmake failed!"; false) || exit 2 | ||
|
||
cmake --build . -j4 | ||
|
||
# generate allheaders.h | ||
#(cd include; find . -name '*.h'; cd $SRC/include/; find . -name '*.h') | grep -v allheaders.h | grep -v undefine_macros.h | sed 's|^./|#include <|' | sed 's|$|>|' >include/deal.II/allheaders.h | ||
|
||
# finally run clang-tidy on lethe | ||
# | ||
# pipe away stderr (just contains nonsensical "x warnings generated") | ||
# pipe output to output.txt | ||
run-clang-tidy.py -p . -quiet -header-filter "$SRC/include/*" -extra-arg='-DCLANG_TIDY' 2>error.txt >output.txt | ||
|
||
# grep interesting errors and make sure we remove duplicates: | ||
grep -E '(warning|error): ' output.txt | sort | uniq >clang-tidy.log | ||
|
||
# if we have errors, report them and set exit status to failure | ||
if [ -s clang-tidy.log ]; then | ||
cat clang-tidy.log | ||
exit 4 | ||
fi | ||
|
||
echo "OK" | ||
exit 0 | ||
|