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

Add clang-tidy to buildsystem checks #1063

Closed
wants to merge 1 commit into from
Closed
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
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)
simonsan marked this conversation as resolved.
Show resolved Hide resolved