1- # Copyright 2014-2024 the openage authors. See copying.md for legal info.
1+ # Copyright 2014-2025 the openage authors. See copying.md for legal info.
22
33"""
44Entry point for the code compliance checker.
@@ -18,16 +18,24 @@ def parse_args():
1818 """ Returns the raw argument namespace. """
1919
2020 cli = argparse .ArgumentParser ()
21- cli .add_argument ("--fast" , action = "store_true" ,
22- help = "do all checks that can be performed quickly" )
23- cli .add_argument ("--all" , action = "store_true" ,
24- help = "do all checks, even the really slow ones" )
21+ check_types = cli .add_mutually_exclusive_group ()
22+ check_types .add_argument ("--fast" , action = "store_true" ,
23+ help = "do all checks that can be performed quickly" )
24+ check_types .add_argument ("--merge" , action = "store_true" ,
25+ help = "do all checks that are required before merges to master" )
26+ check_types .add_argument ("--all" , action = "store_true" ,
27+ help = "do all checks, even the really slow ones" )
28+
2529 cli .add_argument ("--only-changed-files" , metavar = 'GITREF' ,
2630 help = ("slow checks are only done on files that have "
2731 "changed since GITREF." ))
2832 cli .add_argument ("--authors" , action = "store_true" ,
2933 help = ("check whether all git authors are in copying.md. "
3034 "repo must be a git repository." ))
35+ cli .add_argument ("--clang-tidy" , action = "store_true" ,
36+ help = ("Check the C++ code with clang-tidy. Make sure you have build the "
37+ "project with ./configure --clang-tidy or have set "
38+ "CMAKE_CXX_CLANG_TIDY for your CMake build." ))
3139 cli .add_argument ("--cppstyle" , action = "store_true" ,
3240 help = "check the cpp code style" )
3341 cli .add_argument ("--cython" , action = "store_true" ,
@@ -76,7 +84,7 @@ def process_args(args, error):
7684 # set up log level
7785 log_setup (args .verbose - args .quiet )
7886
79- if args .fast or args .all :
87+ if args .fast or args .merge or args . all :
8088 # enable "fast" tests
8189 args .authors = True
8290 args .cppstyle = True
@@ -86,16 +94,19 @@ def process_args(args, error):
8694 args .filemodes = True
8795 args .textfiles = True
8896
89- if args .all :
90- # enable tests that take a bit longer
91-
97+ if args .merge or args .all :
98+ # enable tests that are required before merging to master
9299 args .pystyle = True
93100 args .pylint = True
94101 args .test_git_change_years = True
95102
103+ if args .all :
104+ # enable tests that take a bit longer
105+ args .clang_tidy = True
106+
96107 if not any ((args .headerguards , args .legal , args .authors , args .pystyle ,
97108 args .cppstyle , args .cython , args .test_git_change_years ,
98- args .pylint , args .filemodes , args .textfiles )):
109+ args .pylint , args .filemodes , args .textfiles , args . clang_tidy )):
99110 error ("no checks were specified" )
100111
101112 has_git = bool (shutil .which ('git' ))
@@ -128,6 +139,10 @@ def process_args(args, error):
128139 if not importlib .util .find_spec ('pylint' ):
129140 error ("pylint python module required for linting" )
130141
142+ if args .clang_tidy :
143+ if not shutil .which ('clang-tidy' ):
144+ error ("--clang-tidy requires clang-tidy to be installed" )
145+
131146
132147def get_changed_files (gitref ):
133148 """
@@ -264,6 +279,9 @@ def find_all_issues(args, check_files=None):
264279 from .modes import find_issues
265280 yield from find_issues (check_files , ('openage' , 'buildsystem' ,
266281 'libopenage' , 'etc/gdb_pretty' ))
282+ if args .clang_tidy :
283+ from .clangtidy import find_issues
284+ yield from find_issues (check_files , ('libopenage' , ))
267285
268286
269287if __name__ == '__main__' :
0 commit comments