| OLD | NEW |
| 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 """ |
| 11 | 11 |
| 12 import argparse | 12 import argparse |
| 13 import json | 13 import json |
| 14 import os | 14 import os |
| 15 import re | 15 import re |
| 16 import subprocess | 16 import subprocess |
| 17 import sys | 17 import sys |
| 18 | 18 |
| 19 | 19 |
| 20 def GetHeadersFromNinja(out_dir): | 20 def GetHeadersFromNinja(out_dir): |
| 21 """Return all the header files from ninja_deps""" | 21 """Return all the header files from ninja_deps""" |
| 22 | 22 ninja_out = subprocess.check_output(['ninja', '-C', out_dir, '-t', 'deps']) |
| 23 def NinjaSource(): | |
| 24 cmd = ['ninja', '-C', out_dir, '-t', 'deps'] | |
| 25 # A negative bufsize means to use the system default, which usually | |
| 26 # means fully buffered. | |
| 27 popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=-1) | |
| 28 for line in iter(popen.stdout.readline, ''): | |
| 29 yield line | |
| 30 | |
| 31 popen.stdout.close() | |
| 32 return_code = popen.wait() | |
| 33 if return_code: | |
| 34 raise subprocess.CalledProcessError(return_code, cmd) | |
| 35 | |
| 36 ninja_out = NinjaSource() | |
| 37 return ParseNinjaDepsOutput(ninja_out) | 23 return ParseNinjaDepsOutput(ninja_out) |
| 38 | 24 |
| 39 | 25 |
| 40 def ParseNinjaDepsOutput(ninja_out): | 26 def ParseNinjaDepsOutput(ninja_out): |
| 41 """Parse ninja output and get the header files""" | 27 """Parse ninja output and get the header files""" |
| 42 all_headers = set() | 28 all_headers = set() |
| 43 | 29 |
| 44 prefix = '..' + os.sep + '..' + os.sep | 30 prefix = '..' + os.sep + '..' + os.sep |
| 45 | 31 |
| 46 is_valid = False | 32 is_valid = False |
| 47 for line in ninja_out: | 33 for line in ninja_out.split('\n'): |
| 48 if line.startswith(' '): | 34 if line.startswith(' '): |
| 49 if not is_valid: | 35 if not is_valid: |
| 50 continue | 36 continue |
| 51 if line.endswith('.h') or line.endswith('.hh'): | 37 if line.endswith('.h') or line.endswith('.hh'): |
| 52 f = line.strip() | 38 f = line.strip() |
| 53 if f.startswith(prefix): | 39 if f.startswith(prefix): |
| 54 f = f[6:] # Remove the '../../' prefix | 40 f = f[6:] # Remove the '../../' prefix |
| 55 # build/ only contains build-specific files like build_config.h | 41 # build/ only contains build-specific files like build_config.h |
| 56 # and buildflag.h, and system header files, so they should be | 42 # and buildflag.h, and system header files, so they should be |
| 57 # skipped. | 43 # skipped. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return 0 | 122 return 0 |
| 137 | 123 |
| 138 print 'The following files should be included in gn files:' | 124 print 'The following files should be included in gn files:' |
| 139 for i in missing: | 125 for i in missing: |
| 140 print i | 126 print i |
| 141 return 1 | 127 return 1 |
| 142 | 128 |
| 143 | 129 |
| 144 if __name__ == '__main__': | 130 if __name__ == '__main__': |
| 145 sys.exit(main()) | 131 sys.exit(main()) |
| OLD | NEW |