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

Side by Side Diff: tools/verify_source_deps.py

Issue 2343423002: Use git ls-tree to collect source files instead of walking the fs (Closed)
Patch Set: updates Created 4 years, 3 months 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 | « tools/oom_dump/oom_dump.cc ('k') | 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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 the V8 project authors. All rights reserved. 2 # Copyright 2015 the V8 project 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 """ 6 """
7 Script to print potentially missing source dependencies based on the actual 7 Script to print potentially missing source dependencies based on the actual
8 .h and .cc files in the source tree and which files are included in the gyp 8 .h and .cc files in the source tree and which files are included in the gyp
9 and gn files. The latter inclusion is overapproximated. 9 and gn files. The latter inclusion is overapproximated.
10 10
11 TODO(machenbach): If two source files with the same name exist, but only one 11 TODO(machenbach): If two source files with the same name exist, but only one
12 is referenced from a gyp/gn file, we won't necessarily detect it. 12 is referenced from a gyp/gn file, we won't necessarily detect it.
13 """ 13 """
14 14
15 import itertools 15 import itertools
16 import re 16 import re
17 import os 17 import os
18 import subprocess
18 import sys 19 import sys
19 20
20 21
21 V8_BASE = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 22 V8_BASE = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
22 V8_SRC_BASE = os.path.join(V8_BASE, 'src')
23 V8_TEST_BASE = os.path.join(V8_BASE, 'test')
24 V8_INCLUDE_BASE = os.path.join(V8_BASE, 'include')
25 23
26 GYP_FILES = [ 24 GYP_FILES = [
27 os.path.join(V8_BASE, 'src', 'd8.gyp'), 25 os.path.join(V8_BASE, 'src', 'd8.gyp'),
28 os.path.join(V8_BASE, 'src', 'v8.gyp'), 26 os.path.join(V8_BASE, 'src', 'v8.gyp'),
29 os.path.join(V8_BASE, 'src', 'inspector', 'inspector.gypi'), 27 os.path.join(V8_BASE, 'src', 'inspector', 'inspector.gypi'),
30 os.path.join(V8_BASE, 'src', 'third_party', 'vtune', 'v8vtune.gyp'), 28 os.path.join(V8_BASE, 'src', 'third_party', 'vtune', 'v8vtune.gyp'),
29 os.path.join(V8_BASE, 'samples', 'samples.gyp'),
31 os.path.join(V8_BASE, 'test', 'cctest', 'cctest.gyp'), 30 os.path.join(V8_BASE, 'test', 'cctest', 'cctest.gyp'),
32 os.path.join(V8_BASE, 'test', 'fuzzer', 'fuzzer.gyp'), 31 os.path.join(V8_BASE, 'test', 'fuzzer', 'fuzzer.gyp'),
33 os.path.join(V8_BASE, 'test', 'unittests', 'unittests.gyp'), 32 os.path.join(V8_BASE, 'test', 'unittests', 'unittests.gyp'),
33 os.path.join(V8_BASE, 'testing', 'gmock.gyp'),
34 os.path.join(V8_BASE, 'testing', 'gtest.gyp'),
34 os.path.join(V8_BASE, 'tools', 'parser-shell.gyp'), 35 os.path.join(V8_BASE, 'tools', 'parser-shell.gyp'),
35 ] 36 ]
36 37
38 ALL_GYP_PREFIXES = [
39 '..',
40 'common',
41 os.path.join('src', 'third_party', 'vtune'),
42 'src',
43 'samples',
44 'testing',
45 'tools',
46 os.path.join('test', 'cctest'),
47 os.path.join('test', 'common'),
48 os.path.join('test', 'fuzzer'),
49 os.path.join('test', 'unittests'),
50 ]
51
52 GYP_UNSUPPORTED_FEATURES = [
53 'gcmole',
54 ]
55
37 GN_FILES = [ 56 GN_FILES = [
38 os.path.join(V8_BASE, 'BUILD.gn'), 57 os.path.join(V8_BASE, 'BUILD.gn'),
58 os.path.join(V8_BASE, 'build', 'secondary', 'testing', 'gmock', 'BUILD.gn'),
59 os.path.join(V8_BASE, 'build', 'secondary', 'testing', 'gtest', 'BUILD.gn'),
39 os.path.join(V8_BASE, 'src', 'inspector', 'BUILD.gn'), 60 os.path.join(V8_BASE, 'src', 'inspector', 'BUILD.gn'),
40 os.path.join(V8_BASE, 'test', 'cctest', 'BUILD.gn'), 61 os.path.join(V8_BASE, 'test', 'cctest', 'BUILD.gn'),
41 os.path.join(V8_BASE, 'test', 'unittests', 'BUILD.gn'), 62 os.path.join(V8_BASE, 'test', 'unittests', 'BUILD.gn'),
42 os.path.join(V8_BASE, 'tools', 'BUILD.gn'), 63 os.path.join(V8_BASE, 'tools', 'BUILD.gn'),
43 ] 64 ]
44 65
45 GN_UNSUPPORTED_FEATURES = [ 66 GN_UNSUPPORTED_FEATURES = [
46 'aix', 67 'aix',
47 'cygwin', 68 'cygwin',
48 'freebsd', 69 'freebsd',
70 'gcmole',
49 'openbsd', 71 'openbsd',
50 'ppc', 72 'ppc',
51 'qnx', 73 'qnx',
52 'solaris', 74 'solaris',
53 'vtune', 75 'vtune',
54 'x87', 76 'x87',
55 ] 77 ]
56 78
57 ALL_GN_PREFIXES = [ 79 ALL_GN_PREFIXES = [
58 '..', 80 '..',
59 os.path.join('src', 'inspector'), 81 os.path.join('src', 'inspector'),
60 'src', 82 'src',
83 'testing',
61 os.path.join('test', 'cctest'), 84 os.path.join('test', 'cctest'),
62 os.path.join('test', 'unittests'), 85 os.path.join('test', 'unittests'),
63 ] 86 ]
64 87
65 ALL_GYP_PREFIXES = [
66 '..',
67 'common',
68 os.path.join('src', 'third_party', 'vtune'),
69 'src',
70 os.path.join('test', 'cctest'),
71 os.path.join('test', 'common'),
72 os.path.join('test', 'fuzzer'),
73 os.path.join('test', 'unittests'),
74 ]
75
76 def pathsplit(path): 88 def pathsplit(path):
77 return re.split('[/\\\\]', path) 89 return re.split('[/\\\\]', path)
78 90
79 def path_no_prefix(path, prefixes): 91 def path_no_prefix(path, prefixes):
80 for prefix in prefixes: 92 for prefix in prefixes:
81 if path.startswith(prefix + os.sep): 93 if path.startswith(prefix + os.sep):
82 return path_no_prefix(path[len(prefix) + 1:], prefixes) 94 return path_no_prefix(path[len(prefix) + 1:], prefixes)
83 return path 95 return path
84 96
85 97
86 def isources(directory, prefixes): 98 def isources(prefixes):
87 for root, dirs, files in os.walk(directory): 99 cmd = ['git', 'ls-tree', '-r', 'HEAD', '--full-name', '--name-only']
88 for f in files: 100 for f in subprocess.check_output(cmd, universal_newlines=True).split('\n'):
89 if not (f.endswith('.h') or f.endswith('.cc')): 101 if not (f.endswith('.h') or f.endswith('.cc')):
90 continue 102 continue
91 yield path_no_prefix( 103 yield path_no_prefix(os.path.join(*pathsplit(f)), prefixes)
92 os.path.relpath(os.path.join(root, f), V8_BASE), prefixes)
93 104
94 105
95 def iflatten(obj): 106 def iflatten(obj):
96 if isinstance(obj, dict): 107 if isinstance(obj, dict):
97 for value in obj.values(): 108 for value in obj.values():
98 for i in iflatten(value): 109 for i in iflatten(value):
99 yield i 110 yield i
100 elif isinstance(obj, list): 111 elif isinstance(obj, list):
101 for value in obj: 112 for value in obj:
102 for i in iflatten(value): 113 for i in iflatten(value):
(...skipping 17 matching lines...) Expand all
120 Iterates over all double quoted strings. 131 Iterates over all double quoted strings.
121 """ 132 """
122 with open(gn_file) as f: 133 with open(gn_file) as f:
123 for line in f.read().splitlines(): 134 for line in f.read().splitlines():
124 match = re.match(r'.*"([^"]*)".*', line) 135 match = re.match(r'.*"([^"]*)".*', line)
125 if match: 136 if match:
126 yield path_no_prefix( 137 yield path_no_prefix(
127 os.path.join(*pathsplit(match.group(1))), ALL_GN_PREFIXES) 138 os.path.join(*pathsplit(match.group(1))), ALL_GN_PREFIXES)
128 139
129 140
130 def icheck_values(values, prefixes, *source_dirs): 141 def icheck_values(values, prefixes):
131 for source_file in itertools.chain( 142 for source_file in isources(prefixes):
132 *[isources(source_dir, prefixes) for source_dir in source_dirs]
133 ):
134 if source_file not in values: 143 if source_file not in values:
135 yield source_file 144 yield source_file
136 145
137 146
138 def missing_gyp_files(): 147 def missing_gyp_files():
139 gyp_values = set(itertools.chain( 148 gyp_values = set(itertools.chain(
140 *[iflatten_gyp_file(gyp_file) for gyp_file in GYP_FILES] 149 *[iflatten_gyp_file(gyp_file) for gyp_file in GYP_FILES]
141 )) 150 ))
142 return sorted(icheck_values( 151 gyp_files = sorted(icheck_values(gyp_values, ALL_GYP_PREFIXES))
143 gyp_values, ALL_GYP_PREFIXES, V8_SRC_BASE, V8_INCLUDE_BASE, V8_TEST_BASE)) 152 return filter(
153 lambda x: not any(i in x for i in GYP_UNSUPPORTED_FEATURES), gyp_files)
144 154
145 155
146 def missing_gn_files(): 156 def missing_gn_files():
147 gn_values = set(itertools.chain( 157 gn_values = set(itertools.chain(
148 *[iflatten_gn_file(gn_file) for gn_file in GN_FILES] 158 *[iflatten_gn_file(gn_file) for gn_file in GN_FILES]
149 )) 159 ))
150 160
151 gn_files = sorted(icheck_values( 161 gn_files = sorted(icheck_values(gn_values, ALL_GN_PREFIXES))
152 gn_values, ALL_GN_PREFIXES, V8_SRC_BASE, V8_INCLUDE_BASE, V8_TEST_BASE))
153 return filter( 162 return filter(
154 lambda x: not any(i in x for i in GN_UNSUPPORTED_FEATURES), gn_files) 163 lambda x: not any(i in x for i in GN_UNSUPPORTED_FEATURES), gn_files)
155 164
156 165
157 def main(): 166 def main():
158 print "----------- Files not in gyp: ------------" 167 print "----------- Files not in gyp: ------------"
159 for i in missing_gyp_files(): 168 for i in missing_gyp_files():
160 print i 169 print i
161 170
162 print "\n----------- Files not in gn: -------------" 171 print "\n----------- Files not in gn: -------------"
163 for i in missing_gn_files(): 172 for i in missing_gn_files():
164 print i 173 print i
165 return 0 174 return 0
166 175
167 if '__main__' == __name__: 176 if '__main__' == __name__:
168 sys.exit(main()) 177 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/oom_dump/oom_dump.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698