| 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 ninja_out = subprocess.check_output(['ninja', '-C', out_dir, '-t', 'deps']) | 22 |
| 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() |
| 23 return ParseNinjaDepsOutput(ninja_out) | 37 return ParseNinjaDepsOutput(ninja_out) |
| 24 | 38 |
| 25 | 39 |
| 26 def ParseNinjaDepsOutput(ninja_out): | 40 def ParseNinjaDepsOutput(ninja_out): |
| 27 """Parse ninja output and get the header files""" | 41 """Parse ninja output and get the header files""" |
| 28 all_headers = set() | 42 all_headers = set() |
| 29 | 43 |
| 30 prefix = '..' + os.sep + '..' + os.sep | 44 prefix = '..' + os.sep + '..' + os.sep |
| 31 | 45 |
| 32 is_valid = False | 46 is_valid = False |
| 33 for line in ninja_out.split('\n'): | 47 for line in ninja_out: |
| 34 if line.startswith(' '): | 48 if line.startswith(' '): |
| 35 if not is_valid: | 49 if not is_valid: |
| 36 continue | 50 continue |
| 37 if line.endswith('.h') or line.endswith('.hh'): | 51 if line.endswith('.h') or line.endswith('.hh'): |
| 38 f = line.strip() | 52 f = line.strip() |
| 39 if f.startswith(prefix): | 53 if f.startswith(prefix): |
| 40 f = f[6:] # Remove the '../../' prefix | 54 f = f[6:] # Remove the '../../' prefix |
| 41 # build/ only contains build-specific files like build_config.h | 55 # build/ only contains build-specific files like build_config.h |
| 42 # and buildflag.h, and system header files, so they should be | 56 # and buildflag.h, and system header files, so they should be |
| 43 # skipped. | 57 # skipped. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 return 0 | 136 return 0 |
| 123 | 137 |
| 124 print 'The following files should be included in gn files:' | 138 print 'The following files should be included in gn files:' |
| 125 for i in missing: | 139 for i in missing: |
| 126 print i | 140 print i |
| 127 return 1 | 141 return 1 |
| 128 | 142 |
| 129 | 143 |
| 130 if __name__ == '__main__': | 144 if __name__ == '__main__': |
| 131 sys.exit(main()) | 145 sys.exit(main()) |
| OLD | NEW |