mirror of https://github.com/libp2p/cpp-libp2p.git
Yura Zarudniy
5 years ago
committed by
GitHub
5 changed files with 172 additions and 4 deletions
@ -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 |
@ -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" |
@ -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 |
@ -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…
Reference in new issue