Skip to content

Commit

Permalink
Add clang-tidy to buildsystem checks
Browse files Browse the repository at this point in the history
  • Loading branch information
kev946 committed Oct 20, 2018
1 parent 6768a3a commit e20ec3f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
14 changes: 13 additions & 1 deletion buildsystem/codecompliance/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def parse_args():
cli.add_argument("--test-git-change-years", action="store_true",
help=("when doing legal checks, test whether the "
"copyright year matches the git history."))
cli.add_argument("--clangtidy", action="store_true",
help="check the cpp code with clang-tidy")

cli.add_argument("--fix", action="store_true",
help=("try to automatically fix the found issues"))
Expand Down Expand Up @@ -79,10 +81,11 @@ def process_args(args, error):
args.pystyle = True
args.pylint = True
args.test_git_change_years = True
args.clangtidy = True

if not any((args.headerguards, args.legal, args.authors, args.pystyle,
args.cppstyle, args.test_git_change_years, args.pylint,
args.filemodes, args.textfiles)):
args.filemodes, args.textfiles, args.clangtidy)):
error("no checks were specified")

has_git = bool(shutil.which('git'))
Expand Down Expand Up @@ -115,6 +118,11 @@ def process_args(args, error):
if not importlib.util.find_spec('pylint'):
error("pylint python module required for linting")

if args.clangtidy:
has_clangtidy = bool(shutil.which('clang-tidy'))
if not has_clangtidy:
error("--clang-tidy requires clang-tidy")


def get_changed_files(gitref):
"""
Expand Down Expand Up @@ -248,6 +256,10 @@ def find_all_issues(args, check_files=None):
yield from find_issues(check_files, ('openage', 'buildsystem',
'libopenage'))

if args.clangtidy:
from .clangtidy import find_issues
yield from find_issues(check_files, ('libopenage',))


if __name__ == '__main__':
if main(parse_args()):
Expand Down
27 changes: 27 additions & 0 deletions buildsystem/codecompliance/clangtidy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2015-2018 the openage authors. See copying.md for legal info.

import subprocess

from .cppstyle import filter_file_list
from .util import findfiles


def find_issues(check_files, dirnames):
""" Invokes the external clang-tidy tool. """

invocation = ['clang-tidy', '-checks=-*,readability-*']

if check_files is not None:
filenames = filter_file_list(check_files, dirnames)
else:
filenames = filter_file_list(findfiles(dirnames), dirnames)

invocation.extend(filenames)

try:
retcode = subprocess.check_call(invocation)
except subprocess.CalledProcessError as exc:
retcode = exc.returncode

if retcode:
yield ("clang-tidy issue", f"clang-tidy exited with return code {retcode}", None)

0 comments on commit e20ec3f

Please sign in to comment.