Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: build/check_gn_headers.py

Issue 2846593007: Support checking and fixing non-existing header files in GN (Closed)
Patch Set: more naming Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/fix_gn_headers.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2017 The Chromium Authors. All rights reserved. 2 # Copyright 2017 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Find header files missing in GN. 6 """Find header files missing in GN.
7 7
8 This script gets all the header files from ninja_deps, which is from the true 8 This script gets all the header files from ninja_deps, which is from the true
9 dependency generated by the compiler, and report if they don't exist in GN. 9 dependency generated by the compiler, and report if they don't exist in GN.
10 """ 10 """
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 def ParseWhiteList(whitelist): 106 def ParseWhiteList(whitelist):
107 out = set() 107 out = set()
108 for line in whitelist.split('\n'): 108 for line in whitelist.split('\n'):
109 line = re.sub(r'#.*', '', line).strip() 109 line = re.sub(r'#.*', '', line).strip()
110 if line: 110 if line:
111 out.add(line) 111 out.add(line)
112 return out 112 return out
113 113
114 114
115 def FilterOutDepsedRepo(files, deps):
116 return {f for f in files if not any(f.startswith(d) for d in deps)}
117
118
119 def GetNonExistingFiles(lst):
120 out = set()
121 for f in lst:
122 if not os.path.isfile(f):
123 out.add(f)
124 return out
125
126
115 def main(): 127 def main():
116 parser = argparse.ArgumentParser() 128 parser = argparse.ArgumentParser()
117 parser.add_argument('--out-dir', default='out/Release') 129 parser.add_argument('--out-dir', default='out/Release')
118 parser.add_argument('--json') 130 parser.add_argument('--json')
119 parser.add_argument('--whitelist') 131 parser.add_argument('--whitelist')
120 parser.add_argument('args', nargs=argparse.REMAINDER) 132 parser.add_argument('args', nargs=argparse.REMAINDER)
121 133
122 args, _extras = parser.parse_known_args() 134 args, _extras = parser.parse_known_args()
123 135
124 d_q = Queue() 136 d_q = Queue()
125 d_p = Process(target=GetHeadersFromNinja, args=(args.out_dir, d_q,)) 137 d_p = Process(target=GetHeadersFromNinja, args=(args.out_dir, d_q,))
126 d_p.start() 138 d_p.start()
127 139
128 gn_q = Queue() 140 gn_q = Queue()
129 gn_p = Process(target=GetHeadersFromGN, args=(args.out_dir, gn_q,)) 141 gn_p = Process(target=GetHeadersFromGN, args=(args.out_dir, gn_q,))
130 gn_p.start() 142 gn_p.start()
131 143
132 deps_q = Queue() 144 deps_q = Queue()
133 deps_p = Process(target=GetDepsPrefixes, args=(deps_q,)) 145 deps_p = Process(target=GetDepsPrefixes, args=(deps_q,))
134 deps_p.start() 146 deps_p.start()
135 147
136 d = d_q.get() 148 d = d_q.get()
149 assert len(GetNonExistingFiles(d)) == 0, \
150 'Found non-existing files in ninja deps'
137 gn = gn_q.get() 151 gn = gn_q.get()
138 missing = d - gn 152 missing = d - gn
153 nonexisting = GetNonExistingFiles(gn)
139 154
140 deps = deps_q.get() 155 deps = deps_q.get()
141 missing = {m for m in missing if not any(m.startswith(d) for d in deps)} 156 missing = FilterOutDepsedRepo(missing, deps)
157 nonexisting = FilterOutDepsedRepo(nonexisting, deps)
142 158
143 d_p.join() 159 d_p.join()
144 gn_p.join() 160 gn_p.join()
145 deps_p.join() 161 deps_p.join()
146 162
147 if args.whitelist: 163 if args.whitelist:
148 whitelist = ParseWhiteList(open(args.whitelist).read()) 164 whitelist = ParseWhiteList(open(args.whitelist).read())
149 missing -= whitelist 165 missing -= whitelist
150 166
151 missing = sorted(missing) 167 missing = sorted(missing)
168 nonexisting = sorted(nonexisting)
152 169
153 if args.json: 170 if args.json:
154 with open(args.json, 'w') as f: 171 with open(args.json, 'w') as f:
155 json.dump(missing, f) 172 json.dump(missing, f)
156 173
157 if len(missing) == 0: 174 if len(missing) == 0 and len(nonexisting) == 0:
158 return 0 175 return 0
159 176
160 print 'The following files should be included in gn files:' 177 if len(missing) > 0:
161 for i in missing: 178 print '\nThe following files should be included in gn files:'
162 print i 179 for i in missing:
180 print i
181
182 if len(nonexisting) > 0:
183 print '\nThe following non-existing files should be removed from gn files:'
184 for i in nonexisting:
185 print i
186
163 return 1 187 return 1
164 188
165 189
166 if __name__ == '__main__': 190 if __name__ == '__main__':
167 sys.exit(main()) 191 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | build/fix_gn_headers.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698