25 ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),
'../..'))
29 argp = argparse.ArgumentParser(description=
'include guard checker')
30 argp.add_argument(
'-f',
'--fix', default=
False, action=
'store_true')
31 args = argp.parse_args()
43 for subdir
in CHECK_SUBDIRS:
44 for root, dirs, files
in os.walk(subdir):
46 if f.endswith(
'.h')
or f.endswith(
'.cc'):
47 fpath = os.path.join(root, f)
48 output =
open(fpath,
'r').readlines()
50 for (i, line)
in enumerate(output):
51 m = re.match(
r'^#include "([^"]*)"(.*)', line)
57 expect_path = os.path.join(root, include)
59 if not os.path.exists(expect_path):
63 output[i] =
'#include "{0}"{1}\n'.
format(
64 expect_path, trailing)
65 print(
"Found naked include '{0}' in {1}".
format(
67 if changed
and args.fix:
68 open(fpath,
'w').writelines(output)
71 print(
'{} errors found.'.
format(errors))