28 with open(fpath,
'r')
as f:
33 with open(fpath,
'w')
as f:
42 r'(using +|using +[A-Za-z_]+ *= *|namespace [A-Za-z_]+ *= *)::')
46 fcontents =
load(fpath)
48 for (i, line)
in enumerate(fcontents):
61 print(
"Found in %s:%d - %s" % (fpath, i, line.strip()))
64 save(fpath,
''.join(fcontents))
70 "src/cpp/common/core_codegen.cc",
75 "src/compiler/cpp_generator.cc",
77 "src/core/lib/gprpp/global_config_env.h",
78 "src/core/lib/profiling/timers.h",
82 ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),
'../..'))
86 argp = argparse.ArgumentParser(
87 description=
'c++ namespace full qualification checker')
88 argp.add_argument(
'-f',
'--fix', default=
False, action=
'store_true')
89 argp.add_argument(
'--precommit', default=
False, action=
'store_true')
90 args = argp.parse_args()
92 grep_filter =
r"grep -E '^(include|src|test).*\.(h|cc)$'"
94 git_command =
'git diff --name-only HEAD'
96 git_command =
'git ls-tree -r --name-only -r HEAD'
98 FILE_LIST_COMMAND =
' | '.join((git_command, grep_filter))
104 filename_list = subprocess.check_output(FILE_LIST_COMMAND,
105 shell=
True).
decode().splitlines()
107 filename_list = (f
for f
in filename_list
if os.path.isfile(f))
108 except subprocess.CalledProcessError:
113 for filename
in filename_list:
115 if (filename.endswith(
'.upb.h')
or filename.endswith(
'.upb.c')
or
116 filename.endswith(
'.upbdefs.h')
or
117 filename.endswith(
'.upbdefs.c')
or filename
in IGNORED_FILES):
119 ok = validator.check(filename, args.fix)
and ok
121 sys.exit(0
if ok
else 1)