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

Side by Side Diff: build/check_gn_headers.py

Issue 2846593007: Support checking and fixing non-existing header files in GN (Closed)
Patch Set: 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 def ParseWhiteList(whitelist): 101 def ParseWhiteList(whitelist):
102 out = set() 102 out = set()
103 for line in whitelist.split('\n'): 103 for line in whitelist.split('\n'):
104 line = re.sub(r'#.*', '', line).strip() 104 line = re.sub(r'#.*', '', line).strip()
105 if line: 105 if line:
106 out.add(line) 106 out.add(line)
107 return out 107 return out
108 108
109 109
110 def FilterOutDepsedRepo(files, deps):
Nico 2017/04/28 20:31:19 a) isn't this slow? i would've thought that deps h
wychen 2017/04/28 22:04:43 This is asymptotically slow, but only takes <0.1se
111 return {f for f in files if not any(f.startswith(d) for d in deps)}
112
113
114 def GetNonExistingFiles(lst):
115 out = set()
116 for f in lst:
117 if not os.path.isfile(f):
118 out.add(f)
119 return out
120
121
110 def main(): 122 def main():
111 parser = argparse.ArgumentParser() 123 parser = argparse.ArgumentParser()
112 parser.add_argument('--out-dir', default='out/Release') 124 parser.add_argument('--out-dir', default='out/Release')
113 parser.add_argument('--json') 125 parser.add_argument('--json')
114 parser.add_argument('--whitelist') 126 parser.add_argument('--whitelist')
115 parser.add_argument('args', nargs=argparse.REMAINDER) 127 parser.add_argument('args', nargs=argparse.REMAINDER)
116 128
117 args, _extras = parser.parse_known_args() 129 args, _extras = parser.parse_known_args()
118 130
119 d_q = Queue() 131 d_q = Queue()
120 d_p = Process(target=GetHeadersFromNinja, args=(args.out_dir, d_q,)) 132 d_p = Process(target=GetHeadersFromNinja, args=(args.out_dir, d_q,))
121 d_p.start() 133 d_p.start()
122 134
123 gn_q = Queue() 135 gn_q = Queue()
124 gn_p = Process(target=GetHeadersFromGN, args=(args.out_dir, gn_q,)) 136 gn_p = Process(target=GetHeadersFromGN, args=(args.out_dir, gn_q,))
125 gn_p.start() 137 gn_p.start()
126 138
127 deps_q = Queue() 139 deps_q = Queue()
128 deps_p = Process(target=GetDepsPrefixes, args=(deps_q,)) 140 deps_p = Process(target=GetDepsPrefixes, args=(deps_q,))
129 deps_p.start() 141 deps_p.start()
130 142
131 d = d_q.get() 143 d = d_q.get()
144 assert len(GetNonExistingFiles(d)) == 0, \
145 'Found non-existing files in ninja deps'
132 gn = gn_q.get() 146 gn = gn_q.get()
133 missing = d - gn 147 missing = d - gn
148 extra = GetNonExistingFiles(gn)
134 149
135 deps = deps_q.get() 150 deps = deps_q.get()
136 missing = {m for m in missing if not any(m.startswith(d) for d in deps)} 151 missing = FilterOutDepsedRepo(missing, deps)
152 extra = FilterOutDepsedRepo(extra, deps)
137 153
138 d_p.join() 154 d_p.join()
139 gn_p.join() 155 gn_p.join()
140 deps_p.join() 156 deps_p.join()
141 157
142 if args.whitelist: 158 if args.whitelist:
143 whitelist = ParseWhiteList(open(args.whitelist).read()) 159 whitelist = ParseWhiteList(open(args.whitelist).read())
144 missing -= whitelist 160 missing -= whitelist
145 161
146 missing = sorted(missing) 162 missing = sorted(missing)
163 extra = sorted(extra)
147 164
148 if args.json: 165 if args.json:
149 with open(args.json, 'w') as f: 166 with open(args.json, 'w') as f:
150 json.dump(missing, f) 167 json.dump(missing, f)
151 168
152 if len(missing) == 0: 169 if len(missing) == 0 and len(extra) == 0:
153 return 0 170 return 0
154 171
155 print 'The following files should be included in gn files:' 172 if len(missing) > 0:
156 for i in missing: 173 print '\nThe following files should be included in gn files:'
157 print i 174 for i in missing:
175 print i
176
177 if len(extra) > 0:
178 print '\nThe following files should be removed from gn files:'
179 for i in extra:
180 print i
181
158 return 1 182 return 1
159 183
160 184
161 if __name__ == '__main__': 185 if __name__ == '__main__':
162 sys.exit(main()) 186 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