Chromium Code Reviews| Index: build/check_gn_headers.py |
| diff --git a/build/check_gn_headers.py b/build/check_gn_headers.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..3724b61d37d375d892a7fe32fa9f87f7c192f61e |
| --- /dev/null |
| +++ b/build/check_gn_headers.py |
| @@ -0,0 +1,83 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Find header files missing in GN. |
| + |
| +This script gets all the header files from ninja_deps, which is from the true |
| +dependency generated by the compiler, and report if they don't exist in GN. |
| +""" |
| + |
| +import argparse |
| +import json |
| +import os |
| +import re |
| +import subprocess |
| +import sys |
| + |
| + |
| +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.
|
| + |
| + |
| +def get_d_headers(out_dir): |
| + """Return all the header files from ninja_deps""" |
| + all_headers = set() |
| + |
| + out = subprocess.check_output(['ninja', '-C', out_dir, '-t', 'deps']) |
| + is_valid = False |
| + for line in out.split('\n'): |
| + if line.startswith(' '): |
| + 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.
|
| + 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.
|
| + if not IGNORE_REGEX.match(f): |
| + all_headers.add(f) |
| + else: |
| + is_valid = line.endswith('(VALID)') |
| + |
| + return all_headers |
| + |
| + |
| +def get_gn_headers(out_dir): |
| + """Return all the header files from GN""" |
| + all_headers = set() |
| + |
| + subprocess.check_call(['gn', 'gen', out_dir, '--ide=json']) |
| + |
| + gn = json.load(open(os.path.join(out_dir, 'project.json'))) |
| + for target, properties in gn['targets'].iteritems(): |
| + if 'sources' in properties: |
| + for f in properties['sources']: |
|
stgao
2016/11/18 02:17:28
nit: properties.get('sources', [])?
|
| + if f.endswith('.h'): |
| + 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.
|
| + |
| + return all_headers |
| + |
| + |
| +def main(): |
| + parser = argparse.ArgumentParser() |
| + parser.add_argument('--out-dir', default='out/Debug') |
| + parser.add_argument('--whitelist') |
| + parser.add_argument('args', nargs=argparse.REMAINDER) |
| + |
| + args, extras = parser.parse_known_args() |
| + |
| + d = get_d_headers(args.out_dir) |
| + gn = get_gn_headers(args.out_dir) |
| + missing = d - gn |
| + |
| + if args.whitelist: |
| + whitelist = set(open(args.whitelist).read().split('\n')) |
| + missing -= whitelist |
| + |
| + if len(missing) > 0: |
| + for i in sorted(missing): |
| + print(i) |
| + return 1 |
| + |
| +if __name__ == '__main__': |
| + try: |
| + sys.exit(main()) |
| + except KeyboardInterrupt: |
| + sys.stderr.write('interrupted\n') |
| + sys.exit(1) |