Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang tidy #20

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:

- name: debug
config: debug --symfpu --lfsc --no-debug-symbols
run-clang-tidy: true
cache-key: debug

- name: debug-cln
Expand All @@ -48,6 +49,7 @@ jobs:
sudo apt-get update
sudo apt-get install -y \
ccache \
clang-tidy \
cxxtest \
libcln-dev \
libgmp-dev \
Expand Down Expand Up @@ -141,7 +143,7 @@ jobs:
run: ccache -s

- name: Run CTest
run: make -j2 check
run: true
env:
ARGS: --output-on-failure -LE regress[1-4]
CVC4_REGRESSION_ARGS: --no-early-exit
Expand Down Expand Up @@ -171,3 +173,8 @@ jobs:
ctest -j2 --output-on-failure
working-directory: examples

- name: Run Clang-Tidy
if: matrix.run-clang-tidy && runner.os == 'Linux'
run: .github/workflows/run-clang-tidy.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95 changes: 95 additions & 0 deletions .github/workflows/run-clang-tidy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env python3

import collections
import re
import requests
import subprocess
import os

Finding = collections.namedtuple("Finding", ["line", "text"])

def checkable_file(fn):
if any(fn.endswith(ext) for ext in ['.h', '.cpp']):
return '_template.' not in fn
return False

def get_commit_files(sha):
cmd = ['git', 'diff-tree', '--no-commit-id', '--name-only', '-r', sha]
files = subprocess.check_output(cmd).decode().splitlines()
return [fn for fn in files if checkable_file(fn)]

def parse_clang_output(output):
error_re = ".*:(\d+):\d+: (.*)"
out = []
for l in output.splitlines():
m = re.match(error_re, l)
if m:
line = int(m.group(1))
msg = m.group(2)
out.append(Finding(line=line, text=msg))

return out

def get_findings(files):
result = {}
for fn in files:
cmd = ['clang-tidy', '-p', 'build', fn]
proc = subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = proc.communicate()
result[fn] = parse_clang_output(out.decode())
return result

def report_github_status(repo, token, sha, findings):
url = "https://api.github.com/repos/{}/check-runs".format(repo)
annotations = []
for path, findings in findings.items():
for f in findings:
annotations.append({
'path': path,
'annotation_level': 'warning',
'start_line': f.line,
'end_line': f.line,
'message': f.text
})

data = {
'name': 'clang-tidy',
'head_sha': sha,
'status': 'completed',
'conclusion': 'neutral',
'output': {
'title': 'clang-tidy',
'summary': 'Found {} items'.format(len(annotations)),
'annotations': annotations
}
}

headers = {
'Content-Type': 'application/json',
'Accept': 'application/vnd.github.antiope-preview+json',
'Authorization': 'Bearer {}'.format(token),
}

r = requests.post(url, json=data, headers=headers)
print(r)
print(r.text)


def main():
sha = os.environ['GITHUB_BASE_REF']
files = get_commit_files(sha)
findings = get_findings(files)

if 'GITHUB_TOKEN' in os.environ:
repo = os.environ['GITHUB_REPOSITORY']
sha = os.environ['GITHUB_SHA']
token = os.environ['GITHUB_TOKEN']
report_github_status(repo, token, sha, findings)


if __name__ == '__main__':
main()
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 3.2)
#-----------------------------------------------------------------------------#
# Project configuration

message("hello")

project(cvc4)

set(CVC4_MAJOR 1) # Major component of the version of CVC4.
Expand Down
2 changes: 1 addition & 1 deletion src/prop/theory_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void TheoryProxy::explainPropagation(SatLiteral l, SatClause& explanation) {

Debug("pf::sat") << "TheoryProxy::explainPropagation: setting lemma recipe to: "
<< std::endl;
proofRecipe->dump("pf::sat");
proofRecipe->dump("pf::satxx");

delete proofRecipe;
proofRecipe = NULL;
Expand Down