Browse Source

add clang tidy gh (#26)

pull/28/head
Yura Zarudniy 5 years ago
committed by GitHub
parent
commit
9047eae209
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      .clang-tidy
  2. 38
      .github/workflows/clang-tidy.yml
  3. 32
      housekeeping/clang-tidy.sh
  4. 19
      housekeeping/codecov.sh
  5. 81
      housekeeping/filter_compile_commands.py

6
.clang-tidy

@ -1,10 +1,10 @@
--- ---
Checks: '-*,clang-analyzer-*,clang-diagnostic-*,readability-*,modernize-*,boost-*,bugprone-*,cppcoreguidelines-*,google-*,hicpp-*,performance-*,readability-*,-google-readability-namespace-comments,-readability-inconsistent-declaration-parameter-name,-readability-braces-around-statements,-hicpp-signed-bitwise,-google-runtime-references,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-pro-type-vararg,-readability-magic-numbers,-hicpp-explicit-conversions,-hicpp-uppercase-literal-suffix,-hicpp-member-init,-readability-uppercase-literal-suffix,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-type-member-init,-hicpp-vararg,-hicpp-no-array-decay,-hicpp-static-assert,-hicpp-special-member-functions,-bugprone-narrowing-conversions,-modernize-use-nodiscard' Checks: '-*,clang-analyzer-*,clang-diagnostic-*,readability-*,modernize-*,-modernize-use-trailing-return-type,boost-*,bugprone-*,cppcoreguidelines-*,google-*,hicpp-*,performance-*,readability-*,-google-readability-namespace-comments,-readability-inconsistent-declaration-parameter-name,-readability-braces-around-statements,-hicpp-signed-bitwise,-google-runtime-references,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-readability-magic-numbers,-hicpp-explicit-conversions,-hicpp-uppercase-literal-suffix,-readability-uppercase-literal-suffix,-hicpp-no-array-decay,-hicpp-special-member-functions,-bugprone-narrowing-conversions,-modernize-use-nodiscard,-google-readability-braces-around-statements,-hicpp-braces-around-statements,-bugprone-suspicious-semicolon,-readability-named-parameter,-hicpp-named-parameter,-readability-identifier-naming'
WarningsAsErrors: 'modernize-*,cppcoreguidelines-*,boost-*,performance-*,google-build-using-namespace,readability-else-after-return,google-readability-todo' WarningsAsErrors: 'modernize-*,cppcoreguidelines-*,boost-*,performance-*,google-build-using-namespace,readability-else-after-return,google-readability-todo'
HeaderFilterRegex: 'libp2p/.*\.hpp' HeaderFilterRegex: 'libp2p/.*\.hpp'
AnalyzeTemporaryDtors: false AnalyzeTemporaryDtors: false
FormatStyle: .clang-format FormatStyle: .clang-format
User: bogdan User: user
CheckOptions: CheckOptions:
- key: bugprone-argument-comment.StrictMode - key: bugprone-argument-comment.StrictMode
value: '0' value: '0'
@ -260,5 +260,3 @@ CheckOptions:
value: '3' value: '3'
- key: cppcoreguidelines-macro-usage.CheckCapsOnly - key: cppcoreguidelines-macro-usage.CheckCapsOnly
value: '1' value: '1'
...

38
.github/workflows/clang-tidy.yml

@ -0,0 +1,38 @@
name: Clang Tidy
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: macOS-10.14
steps:
- uses: actions/checkout@v1
name: checkout
with:
submodules: true
clean: true
fetch-depth: 1
- name: install
run: |
brew install ninja llvm
sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install scikit-build cmake requests gitpython gcovr pyyaml
- name: run checks
run: |
#!/bin/bash
LLVM_DIR=/usr/local/Cellar/llvm
test -d $LLVM_DIR || echo $(echo "llvm is absent, cannot continue" && exit 1)
VER_COUNT=$(ls -1 ${LLVM_DIR} | wc -l)
test ${VER_COUNT} -eq 0 && echo "no llvm version detected" && exit 1
test $VER_COUNT -gt 1 && echo "wrong llvm installation" && exit 1
LLVM_VER=$(ls -1 ${LLVM_DIR})
export LLVM_ROOT=${LLVM_DIR}/${LLVM_VER}
export PATH=${LLVM_ROOT}/bin:${LLVM_ROOT}/share/clang:${PATH}
cmake . -GNinja -Bbuild
housekeeping/clang-tidy.sh build

32
housekeeping/clang-tidy.sh

@ -0,0 +1,32 @@
#!/bin/bash -xe
## on master branch: analyzes all cpp files
## on other branches: analyzes cpp files changed in this branch, in comparison to master
function get_abs_path(){
echo $(echo "$(cd "$(dirname "$1")"; pwd -P)/$(basename "$1")")
}
function get_files(){
local head=$(git rev-parse --abbrev-ref HEAD)
if [[ "${head}" = "master" ]]; then
echo $(find . -type f | grep "cpp")
else
echo $(git diff --name-only HEAD..origin/master | grep "cpp" | grep -v "test")
fi
}
BUILD_DIR=$(get_abs_path $1)
cd $(dirname $0)/..
# list of cpp files changed in this branch (in comparison to master); tests are ignored
FILES=$(get_files)
CLANG_TIDY=$(which clang-tidy)
RUN_CLANG_TIDY=$(which run-clang-tidy.py)
# filter compile_commands.json
echo ${FILES} | python3 ./housekeeping/filter_compile_commands.py -p ${BUILD_DIR}
# exec run-clang-tidy.py
python3 ${RUN_CLANG_TIDY} -clang-tidy-binary=${CLANG_TIDY} -p ${BUILD_DIR} -header-filter "core/.*\.hpp"

19
housekeeping/codecov.sh

@ -0,0 +1,19 @@
#!/bin/bash -xe
buildDir=$1
token=$2
which git
if [ -z "$buildDir" ]; then
echo "buildDir is empty"
exit 1
fi
if [ -z "$token" ]; then
echo "token arg is empty"
exit 2
fi
bash <(curl -s https://codecov.io/bash) -s $buildDir -t $token

81
housekeeping/filter_compile_commands.py

@ -0,0 +1,81 @@
#!/usr/bin/env python3
import sys
import json
import argparse
from pathlib import Path
import re
def remove_non_whitelist(wl):
def f(x):
for w in wl:
if w in x['file']:
print("selected for analysis: {}".format(w))
return True
return False
return f
def make_backup(src: Path):
dest = Path(src.absolute().__str__() + ".backup")
if dest.exists():
return # backup is already there
dest.touch()
dest.write_text(src.read_text()) # for text files
assert dest.exists()
def do(args) -> None:
builddir = args.p
if not builddir.exists():
raise Exception("build dir {} does not exist".format(builddir))
if not builddir.is_dir():
raise Exception("build dir {} is not dir".format(builddir))
p = Path(builddir, "compile_commands.json")
if not p.exists():
raise Exception("build dir {} does not contain compile_commands.json".format(builddir))
make_backup(p)
with p.open("r") as f:
data = f.read()
j = json.loads(data)
wl = read_whitelist()
j = filter(remove_non_whitelist(wl), j)
j = list(j)
s = json.dumps(j, indent=4)
with p.open("w") as w:
w.write(s)
print("success")
def read_whitelist():
whitelist = []
print("provide whitelisted files, one path on a single line")
for line in sys.stdin:
lines = re.split("[\s\n]+", line)
for l in lines:
if len(l) > 0:
whitelist.append(l)
return whitelist
if __name__ == '__main__':
parser = argparse.ArgumentParser(
prog="filter "
)
parser.add_argument("-p", help="path to build dir",
type=Path)
args = parser.parse_args()
do(args)
Loading…
Cancel
Save