OLD | NEW |
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 |
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 pathsplit(path): |
| 78 return re.split('[/\\\\]', path) |
| 79 |
| 80 def path_no_prefix(path, prefixes): |
| 81 for prefix in prefixes: |
| 82 if path.startswith(prefix + os.sep): |
| 83 return path_no_prefix(path[len(prefix) + 1:], prefixes) |
61 return path | 84 return path |
62 | 85 |
63 | 86 |
64 def isources(directory): | 87 def isources(directory, prefixes): |
65 for root, dirs, files in os.walk(directory): | 88 for root, dirs, files in os.walk(directory): |
66 for f in files: | 89 for f in files: |
67 if not (f.endswith('.h') or f.endswith('.cc')): | 90 if not (f.endswith('.h') or f.endswith('.cc')): |
68 continue | 91 continue |
69 yield path_no_prefix(os.path.relpath(os.path.join(root, f), V8_BASE)) | 92 yield path_no_prefix( |
| 93 os.path.relpath(os.path.join(root, f), V8_BASE), prefixes) |
70 | 94 |
71 | 95 |
72 def iflatten(obj): | 96 def iflatten(obj): |
73 if isinstance(obj, dict): | 97 if isinstance(obj, dict): |
74 for value in obj.values(): | 98 for value in obj.values(): |
75 for i in iflatten(value): | 99 for i in iflatten(value): |
76 yield i | 100 yield i |
77 elif isinstance(obj, list): | 101 elif isinstance(obj, list): |
78 for value in obj: | 102 for value in obj: |
79 for i in iflatten(value): | 103 for i in iflatten(value): |
80 yield i | 104 yield i |
81 elif isinstance(obj, basestring): | 105 elif isinstance(obj, basestring): |
82 yield path_no_prefix(obj) | 106 yield path_no_prefix(os.path.join(*pathsplit(obj)), ALL_GYP_PREFIXES) |
83 | 107 |
84 | 108 |
85 def iflatten_gyp_file(gyp_file): | 109 def iflatten_gyp_file(gyp_file): |
86 """Overaproximates all values in the gyp file. | 110 """Overaproximates all values in the gyp file. |
87 | 111 |
88 Iterates over all string values recursively. Removes '../' path prefixes. | 112 Iterates over all string values recursively. Removes '../' path prefixes. |
89 """ | 113 """ |
90 with open(gyp_file) as f: | 114 with open(gyp_file) as f: |
91 return iflatten(eval(f.read())) | 115 return iflatten(eval(f.read())) |
92 | 116 |
93 | 117 |
94 def iflatten_gn_file(gn_file): | 118 def iflatten_gn_file(gn_file): |
95 """Overaproximates all values in the gn file. | 119 """Overaproximates all values in the gn file. |
96 | 120 |
97 Iterates over all double quoted strings. | 121 Iterates over all double quoted strings. |
98 """ | 122 """ |
99 with open(gn_file) as f: | 123 with open(gn_file) as f: |
100 for line in f.read().splitlines(): | 124 for line in f.read().splitlines(): |
101 match = re.match(r'.*"([^"]*)".*', line) | 125 match = re.match(r'.*"([^"]*)".*', line) |
102 if match: | 126 if match: |
103 yield path_no_prefix(match.group(1)) | 127 yield path_no_prefix( |
| 128 os.path.join(*pathsplit(match.group(1))), ALL_GN_PREFIXES) |
104 | 129 |
105 | 130 |
106 def icheck_values(values, *source_dirs): | 131 def icheck_values(values, prefixes, *source_dirs): |
107 for source_file in itertools.chain( | 132 for source_file in itertools.chain( |
108 *[isources(source_dir) for source_dir in source_dirs] | 133 *[isources(source_dir, prefixes) for source_dir in source_dirs] |
109 ): | 134 ): |
110 if source_file not in values: | 135 if source_file not in values: |
111 yield source_file | 136 yield source_file |
112 | 137 |
113 | 138 |
114 gyp_values = set(itertools.chain( | 139 def missing_gyp_files(): |
115 *[iflatten_gyp_file(gyp_file) for gyp_file in GYP_FILES] | 140 gyp_values = set(itertools.chain( |
116 )) | 141 *[iflatten_gyp_file(gyp_file) for gyp_file in GYP_FILES] |
| 142 )) |
| 143 return sorted(icheck_values( |
| 144 gyp_values, ALL_GYP_PREFIXES, V8_SRC_BASE, V8_INCLUDE_BASE, V8_TEST_BASE)) |
117 | 145 |
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 | 146 |
122 gn_values = set(itertools.chain( | 147 def missing_gn_files(): |
123 *[iflatten_gn_file(gn_file) for gn_file in GN_FILES] | 148 gn_values = set(itertools.chain( |
124 )) | 149 *[iflatten_gn_file(gn_file) for gn_file in GN_FILES] |
| 150 )) |
125 | 151 |
126 print "\n----------- Files not in gn: -------------" | 152 gn_files = sorted(icheck_values( |
127 for i in sorted(icheck_values(gn_values, V8_SRC_BASE, V8_INCLUDE_BASE)): | 153 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): | 154 return filter( |
| 155 lambda x: not any(i in x for i in GN_UNSUPPORTED_FEATURES), gn_files) |
| 156 |
| 157 |
| 158 def main(): |
| 159 print "----------- Files not in gyp: ------------" |
| 160 for i in missing_gyp_files(): |
129 print i | 161 print i |
| 162 |
| 163 print "\n----------- Files not in gn: -------------" |
| 164 for i in missing_gn_files(): |
| 165 print i |
| 166 return 0 |
| 167 |
| 168 if '__main__' == __name__: |
| 169 sys.exit(main()) |
OLD | NEW |