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

Side by Side Diff: build/check_gn_headers.py

Issue 2510303002: Add check_gn_headers.py to find missing headers in GN (Closed)
Patch Set: Created 4 years, 1 month 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Find header files missing in GN.
7
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.
10 """
11
12 import argparse
13 import json
14 import os
15 import re
16 import subprocess
17 import sys
18
19
20 IGNORE_REGEX = re.compile('(^(third_party|build)\/)|(.*/gen/.*)')
stgao 2016/11/18 02:17:28 Just curious, why we ignore third_party?
wychen 2016/11/18 03:35:40 I guess we shouldn't.
21
22
23 def get_d_headers(out_dir):
24 """Return all the header files from ninja_deps"""
25 all_headers = set()
26
27 out = subprocess.check_output(['ninja', '-C', out_dir, '-t', 'deps'])
28 is_valid = False
29 for line in out.split('\n'):
30 if line.startswith(' '):
31 if is_valid and line.endswith('.h'):
stgao 2016/11/18 02:17:28 Some header files are with extension .hh
wychen 2016/11/18 03:35:40 Done.
32 f = os.path.normpath(os.path.join(out_dir, line.strip()))
stgao 2016/11/18 02:17:28 IIRC, normpath is platform-dependent, so path sepa
wychen 2016/11/18 03:35:40 Done.
33 if not IGNORE_REGEX.match(f):
34 all_headers.add(f)
35 else:
36 is_valid = line.endswith('(VALID)')
37
38 return all_headers
39
40
41 def get_gn_headers(out_dir):
42 """Return all the header files from GN"""
43 all_headers = set()
44
45 subprocess.check_call(['gn', 'gen', out_dir, '--ide=json'])
46
47 gn = json.load(open(os.path.join(out_dir, 'project.json')))
48 for target, properties in gn['targets'].iteritems():
49 if 'sources' in properties:
50 for f in properties['sources']:
stgao 2016/11/18 02:17:28 nit: properties.get('sources', [])?
51 if f.endswith('.h'):
52 all_headers.add(os.path.normpath('.' + f))
stgao 2016/11/18 02:17:28 same here for normpath
wychen 2016/11/18 03:35:40 Done.
53
54 return all_headers
55
56
57 def main():
58 parser = argparse.ArgumentParser()
59 parser.add_argument('--out-dir', default='out/Debug')
60 parser.add_argument('--whitelist')
61 parser.add_argument('args', nargs=argparse.REMAINDER)
62
63 args, extras = parser.parse_known_args()
64
65 d = get_d_headers(args.out_dir)
66 gn = get_gn_headers(args.out_dir)
67 missing = d - gn
68
69 if args.whitelist:
70 whitelist = set(open(args.whitelist).read().split('\n'))
71 missing -= whitelist
72
73 if len(missing) > 0:
74 for i in sorted(missing):
75 print(i)
76 return 1
77
78 if __name__ == '__main__':
79 try:
80 sys.exit(main())
81 except KeyboardInterrupt:
82 sys.stderr.write('interrupted\n')
83 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698