20 os.chdir(os.path.join(os.path.dirname(sys.argv[0]),
'../../..'))
25 for root, dirs, files
in os.walk(directory_root):
26 for filename
in files:
27 path = os.path.join(root, filename)
28 if os.path.splitext(path)[1]
not in [
'.c',
'.cc',
'.h']:
31 os.path.join(
'include',
'grpc',
'support',
33 os.path.join(
'include',
'grpc',
'impl',
'codegen',
37 if filename.endswith(
'.pb.h')
or filename.endswith(
'.pb.c'):
40 if (filename.endswith(
'.upb.h')
or filename.endswith(
'.upb.c')
or
41 filename.endswith(
'.upbdefs.h')
or
42 filename.endswith(
'.upbdefs.c')):
45 all_lines_in_file = f.readlines()
46 for index, l
in enumerate(all_lines_in_file):
48 if l
not in legal_list:
49 bad_files.append(path)
50 elif all_lines_in_file[index + 1] !=
'\n':
54 bad_files.append(path)
61 '#include <grpc/support/port_platform.h>\n',
65 '#include <grpc/support/port_platform.h>\n',
66 '#include <grpc/impl/codegen/port_platform.h>\n',
69 if sys.argv[1:] == [
'--fix']:
70 for path
in all_bad_files:
74 for l
in f.readlines():
75 if not found
and '#include' in l:
76 text +=
'#include <grpc/support/port_platform.h>\n\n'
79 with open(path,
'w')
as f:
82 if len(all_bad_files) > 0:
83 for f
in all_bad_files:
84 print(((
'port_platform.h is not the first included header or there '
85 'is not a blank line following its inclusion in %s') % f))