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 """ |
(...skipping 30 matching lines...) Expand all Loading... | |
41 ans = ParseNinjaDepsOutput(NinjaSource()) | 41 ans = ParseNinjaDepsOutput(NinjaSource()) |
42 except Exception as e: | 42 except Exception as e: |
43 err = str(e) | 43 err = str(e) |
44 q.put((ans, err)) | 44 q.put((ans, err)) |
45 | 45 |
46 | 46 |
47 def ParseNinjaDepsOutput(ninja_out): | 47 def ParseNinjaDepsOutput(ninja_out): |
48 """Parse ninja output and get the header files""" | 48 """Parse ninja output and get the header files""" |
49 all_headers = set() | 49 all_headers = set() |
50 | 50 |
51 prefix = '..' + os.sep + '..' + os.sep | 51 # Ninja always use "/", even on Windows. |
brucedawson
2017/06/12 17:38:40
use-> uses
wychen
2017/06/12 21:45:45
Done.
| |
52 prefix = '../../' | |
52 | 53 |
53 is_valid = False | 54 is_valid = False |
54 for line in ninja_out: | 55 for line in ninja_out: |
55 if line.startswith(' '): | 56 if line.startswith(' '): |
56 if not is_valid: | 57 if not is_valid: |
57 continue | 58 continue |
58 if line.endswith('.h') or line.endswith('.hh'): | 59 if line.endswith('.h') or line.endswith('.hh'): |
59 f = line.strip() | 60 f = line.strip() |
60 if f.startswith(prefix): | 61 if f.startswith(prefix): |
61 f = f[6:] # Remove the '../../' prefix | 62 f = f[6:] # Remove the '../../' prefix |
62 # build/ only contains build-specific files like build_config.h | 63 # build/ only contains build-specific files like build_config.h |
63 # and buildflag.h, and system header files, so they should be | 64 # and buildflag.h, and system header files, so they should be |
64 # skipped. | 65 # skipped. |
65 if not f.startswith('build'): | 66 if not f.startswith('build'): |
66 all_headers.add(f) | 67 all_headers.add(f) |
67 else: | 68 else: |
68 is_valid = line.endswith('(VALID)') | 69 is_valid = line.endswith('(VALID)') |
69 | 70 |
70 return all_headers | 71 return all_headers |
71 | 72 |
72 | 73 |
73 def GetHeadersFromGN(out_dir, q): | 74 def GetHeadersFromGN(out_dir, q): |
74 """Return all the header files from GN""" | 75 """Return all the header files from GN""" |
75 | 76 |
76 tmp = None | 77 tmp = None |
77 ans, err = set(), None | 78 ans, err = set(), None |
78 try: | 79 try: |
79 tmp = tempfile.mkdtemp() | 80 # Argument |dir| is needed to make sure it's on the same drive on Windows. |
81 # dir='' means dir='.', but doesn't introduce an unneeded prefix. | |
82 tmp = tempfile.mkdtemp(dir='') | |
80 shutil.copy2(os.path.join(out_dir, 'args.gn'), | 83 shutil.copy2(os.path.join(out_dir, 'args.gn'), |
81 os.path.join(tmp, 'args.gn')) | 84 os.path.join(tmp, 'args.gn')) |
82 # Do "gn gen" in a temp dir to prevent dirtying |out_dir|. | 85 # Do "gn gen" in a temp dir to prevent dirtying |out_dir|. |
83 subprocess.check_call(['gn', 'gen', tmp, '--ide=json', '-q']) | 86 GN_EXE = 'gn.bat' if sys.platform == 'win32' else 'gn' |
brucedawson
2017/06/12 17:38:40
Why upper-case for GN_EXE and GCLIENT_EXE? Doesn't
wychen
2017/06/12 21:45:45
Done.
| |
87 subprocess.check_call([GN_EXE, 'gen', tmp, '--ide=json', '-q']) | |
84 gn_json = json.load(open(os.path.join(tmp, 'project.json'))) | 88 gn_json = json.load(open(os.path.join(tmp, 'project.json'))) |
85 ans = ParseGNProjectJSON(gn_json, out_dir, tmp) | 89 ans = ParseGNProjectJSON(gn_json, out_dir, tmp) |
86 except Exception as e: | 90 except Exception as e: |
87 err = str(e) | 91 err = str(e) |
88 finally: | 92 finally: |
89 if tmp: | 93 if tmp: |
90 shutil.rmtree(tmp) | 94 shutil.rmtree(tmp) |
91 q.put((ans, err)) | 95 q.put((ans, err)) |
92 | 96 |
93 | 97 |
(...skipping 15 matching lines...) Expand all Loading... | |
109 f = out_dir + f[len(tmp_out):] | 113 f = out_dir + f[len(tmp_out):] |
110 all_headers.add(f) | 114 all_headers.add(f) |
111 | 115 |
112 return all_headers | 116 return all_headers |
113 | 117 |
114 | 118 |
115 def GetDepsPrefixes(q): | 119 def GetDepsPrefixes(q): |
116 """Return all the folders controlled by DEPS file""" | 120 """Return all the folders controlled by DEPS file""" |
117 prefixes, err = set(), None | 121 prefixes, err = set(), None |
118 try: | 122 try: |
123 GCLIENT_EXE = 'gclient.bat' if sys.platform == 'win32' else 'gclient' | |
119 gclient_out = subprocess.check_output( | 124 gclient_out = subprocess.check_output( |
120 ['gclient', 'recurse', '--no-progress', '-j1', | 125 [GCLIENT_EXE, 'recurse', '--no-progress', '-j1', |
121 'python', '-c', 'import os;print os.environ["GCLIENT_DEP_PATH"]']) | 126 'python', '-c', 'import os;print os.environ["GCLIENT_DEP_PATH"]'], |
127 universal_newlines = True) | |
122 for i in gclient_out.split('\n'): | 128 for i in gclient_out.split('\n'): |
123 if i.startswith('src/'): | 129 if i.startswith('src/'): |
124 i = i[4:] | 130 i = i[4:] |
125 prefixes.add(i) | 131 prefixes.add(i) |
126 except Exception as e: | 132 except Exception as e: |
127 err = str(e) | 133 err = str(e) |
128 q.put((prefixes, err)) | 134 q.put((prefixes, err)) |
129 | 135 |
130 | 136 |
131 def ParseWhiteList(whitelist): | 137 def ParseWhiteList(whitelist): |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 if len(nonexisting) > 0: | 231 if len(nonexisting) > 0: |
226 print '\nThe following non-existing files should be removed from gn files:' | 232 print '\nThe following non-existing files should be removed from gn files:' |
227 for i in nonexisting: | 233 for i in nonexisting: |
228 print i | 234 print i |
229 | 235 |
230 return 1 | 236 return 1 |
231 | 237 |
232 | 238 |
233 if __name__ == '__main__': | 239 if __name__ == '__main__': |
234 sys.exit(main()) | 240 sys.exit(main()) |
OLD | NEW |