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

Side by Side Diff: tools/verify_source_deps.py

Issue 2346103002: Fix BUILD.gn files and add presubmit step (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
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): Gyp files in src will point to source files in src without a 11 TODO(machenbach): Gyp files in src will point to source files in src without a
Michael Achenbach 2016/09/19 09:35:33 I guess this TODO is somewhat resolved as we now c
jochen (gone - plz use gerrit) 2016/09/19 10:54:38 done
Michael Achenbach 2016/09/19 11:03:33 forgot to upload?
12 src/ prefix. For simplicity, all paths relative to src are stripped. But this 12 src/ prefix. For simplicity, all paths relative to src are stripped. But this
13 tool won't be accurate for other sources in other directories (e.g. cctest). 13 tool won't be accurate for other sources in other directories (e.g. cctest).
14 """ 14 """
15 15
16 import itertools 16 import itertools
17 import re 17 import re
18 import os 18 import os
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_SRC_BASE = os.path.join(V8_BASE, 'src')
24 V8_TEST_BASE = os.path.join(V8_BASE, 'test')
23 V8_INCLUDE_BASE = os.path.join(V8_BASE, 'include') 25 V8_INCLUDE_BASE = os.path.join(V8_BASE, 'include')
24 26
25 GYP_FILES = [ 27 GYP_FILES = [
26 os.path.join(V8_BASE, 'src', 'd8.gyp'), 28 os.path.join(V8_BASE, 'src', 'd8.gyp'),
27 os.path.join(V8_BASE, 'src', 'v8.gyp'), 29 os.path.join(V8_BASE, 'src', 'v8.gyp'),
28 os.path.join(V8_BASE, 'src', 'inspector', 'inspector.gyp'), 30 os.path.join(V8_BASE, 'src', 'inspector', 'inspector.gypi'),
29 os.path.join(V8_BASE, 'src', 'third_party', 'vtune', 'v8vtune.gyp'), 31 os.path.join(V8_BASE, 'src', 'third_party', 'vtune', 'v8vtune.gyp'),
30 os.path.join(V8_BASE, 'test', 'cctest', 'cctest.gyp'), 32 os.path.join(V8_BASE, 'test', 'cctest', 'cctest.gyp'),
33 os.path.join(V8_BASE, 'test', 'fuzzer', 'fuzzer.gyp'),
31 os.path.join(V8_BASE, 'test', 'unittests', 'unittests.gyp'), 34 os.path.join(V8_BASE, 'test', 'unittests', 'unittests.gyp'),
32 os.path.join(V8_BASE, 'tools', 'parser-shell.gyp'), 35 os.path.join(V8_BASE, 'tools', 'parser-shell.gyp'),
33 ] 36 ]
34 37
35 GN_FILES = [ 38 GN_FILES = [
36 os.path.join(V8_BASE, 'BUILD.gn'), 39 os.path.join(V8_BASE, 'BUILD.gn'),
37 os.path.join(V8_BASE, 'src', 'inspector', 'BUILD.gn'), 40 os.path.join(V8_BASE, 'src', 'inspector', 'BUILD.gn'),
38 os.path.join(V8_BASE, 'test', 'cctest', 'BUILD.gn'), 41 os.path.join(V8_BASE, 'test', 'cctest', 'BUILD.gn'),
39 os.path.join(V8_BASE, 'test', 'unittests', 'BUILD.gn'), 42 os.path.join(V8_BASE, 'test', 'unittests', 'BUILD.gn'),
40 os.path.join(V8_BASE, 'tools', 'BUILD.gn'), 43 os.path.join(V8_BASE, 'tools', 'BUILD.gn'),
41 ] 44 ]
42 45
43 GN_UNSUPPORTED_FEATURES = [ 46 GN_UNSUPPORTED_FEATURES = [
44 'aix', 47 'aix',
45 'cygwin', 48 'cygwin',
46 'freebsd', 49 'freebsd',
47 'openbsd', 50 'openbsd',
48 'ppc', 51 'ppc',
49 'qnx', 52 'qnx',
50 'solaris', 53 'solaris',
51 'valgrind',
52 'vtune', 54 'vtune',
53 'x87', 55 'x87',
54 ] 56 ]
55 57
58 ALL_GN_PREFIXES = [
59 '..',
60 os.path.join('src', 'inspector'),
61 'src',
62 os.path.join('test', 'cctest'),
63 os.path.join('test', 'unittests'),
64 ]
56 65
57 def path_no_prefix(path): 66 ALL_GYP_PREFIXES = [
58 for prefix in ['../', 'src/inspector/', 'src/']: 67 '..',
59 if path.startswith(prefix): 68 'common',
60 return path_no_prefix(path[len(prefix):]) 69 os.path.join('src', 'third_party', 'vtune'),
70 'src',
71 os.path.join('test', 'cctest'),
72 os.path.join('test', 'common'),
73 os.path.join('test', 'fuzzer'),
74 os.path.join('test', 'unittests'),
75 ]
76
77 def path_no_prefix(path, prefixes):
78 for prefix in prefixes:
79 if path.startswith(prefix + os.sep):
80 return path_no_prefix(path[len(prefix) + 1:], prefixes)
61 return path 81 return path
62 82
63 83
64 def isources(directory): 84 def isources(directory, prefixes):
65 for root, dirs, files in os.walk(directory): 85 for root, dirs, files in os.walk(directory):
66 for f in files: 86 for f in files:
67 if not (f.endswith('.h') or f.endswith('.cc')): 87 if not (f.endswith('.h') or f.endswith('.cc')):
68 continue 88 continue
69 yield path_no_prefix(os.path.relpath(os.path.join(root, f), V8_BASE)) 89 yield path_no_prefix(
90 os.path.relpath(os.path.join(root, f), V8_BASE), prefixes)
70 91
71 92
72 def iflatten(obj): 93 def iflatten(obj):
73 if isinstance(obj, dict): 94 if isinstance(obj, dict):
74 for value in obj.values(): 95 for value in obj.values():
75 for i in iflatten(value): 96 for i in iflatten(value):
76 yield i 97 yield i
77 elif isinstance(obj, list): 98 elif isinstance(obj, list):
78 for value in obj: 99 for value in obj:
79 for i in iflatten(value): 100 for i in iflatten(value):
80 yield i 101 yield i
81 elif isinstance(obj, basestring): 102 elif isinstance(obj, basestring):
82 yield path_no_prefix(obj) 103 yield path_no_prefix(os.path.join(*os.path.split(obj)), ALL_GYP_PREFIXES)
Michael Achenbach 2016/09/19 09:35:33 Should this not do a obj.split('/') instead of os.
jochen (gone - plz use gerrit) 2016/09/19 10:54:38 I fixed that in the latest patchset. os.path.spli
83 104
84 105
85 def iflatten_gyp_file(gyp_file): 106 def iflatten_gyp_file(gyp_file):
86 """Overaproximates all values in the gyp file. 107 """Overaproximates all values in the gyp file.
87 108
88 Iterates over all string values recursively. Removes '../' path prefixes. 109 Iterates over all string values recursively. Removes '../' path prefixes.
89 """ 110 """
90 with open(gyp_file) as f: 111 with open(gyp_file) as f:
91 return iflatten(eval(f.read())) 112 return iflatten(eval(f.read()))
92 113
93 114
94 def iflatten_gn_file(gn_file): 115 def iflatten_gn_file(gn_file):
95 """Overaproximates all values in the gn file. 116 """Overaproximates all values in the gn file.
96 117
97 Iterates over all double quoted strings. 118 Iterates over all double quoted strings.
98 """ 119 """
99 with open(gn_file) as f: 120 with open(gn_file) as f:
100 for line in f.read().splitlines(): 121 for line in f.read().splitlines():
101 match = re.match(r'.*"([^"]*)".*', line) 122 match = re.match(r'.*"([^"]*)".*', line)
102 if match: 123 if match:
103 yield path_no_prefix(match.group(1)) 124 yield path_no_prefix(
125 os.path.join(*os.path.split(match.group(1))), ALL_GN_PREFIXES)
104 126
105 127
106 def icheck_values(values, *source_dirs): 128 def icheck_values(values, prefixes, *source_dirs):
107 for source_file in itertools.chain( 129 for source_file in itertools.chain(
108 *[isources(source_dir) for source_dir in source_dirs] 130 *[isources(source_dir, prefixes) for source_dir in source_dirs]
109 ): 131 ):
110 if source_file not in values: 132 if source_file not in values:
111 yield source_file 133 yield source_file
112 134
113 135
114 gyp_values = set(itertools.chain( 136 def missing_gyp_files():
115 *[iflatten_gyp_file(gyp_file) for gyp_file in GYP_FILES] 137 gyp_values = set(itertools.chain(
116 )) 138 *[iflatten_gyp_file(gyp_file) for gyp_file in GYP_FILES]
139 ))
140 return sorted(icheck_values(
141 gyp_values, ALL_GYP_PREFIXES, V8_SRC_BASE, V8_INCLUDE_BASE, V8_TEST_BASE))
117 142
118 print "----------- Files not in gyp: ------------"
119 for i in sorted(icheck_values(gyp_values, V8_SRC_BASE, V8_INCLUDE_BASE)):
120 print i
121 143
122 gn_values = set(itertools.chain( 144 def missing_gn_files():
123 *[iflatten_gn_file(gn_file) for gn_file in GN_FILES] 145 gn_values = set(itertools.chain(
124 )) 146 *[iflatten_gn_file(gn_file) for gn_file in GN_FILES]
147 ))
125 148
126 print "\n----------- Files not in gn: -------------" 149 gn_files = sorted(icheck_values(
127 for i in sorted(icheck_values(gn_values, V8_SRC_BASE, V8_INCLUDE_BASE)): 150 gn_values, ALL_GN_PREFIXES, V8_SRC_BASE, V8_INCLUDE_BASE, V8_TEST_BASE))
128 if not any(f in i for f in GN_UNSUPPORTED_FEATURES): 151 return filter(
152 lambda x: not any(i in x for i in GN_UNSUPPORTED_FEATURES), gn_files)
153
154
155 def main():
156 print "----------- Files not in gyp: ------------"
157 for i in missing_gyp_files():
129 print i 158 print i
159
160 print "\n----------- Files not in gn: -------------"
161 for i in missing_gn_files():
162 print i
163 return 0
164
165 if '__main__' == __name__:
166 sys.exit(main())
OLDNEW
« test/cctest/test-slots-buffer.cc ('K') | « test/unittests/unittests.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698