Chromium Code Reviews| 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): 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_SRC_BASE = os.path.join(V8_BASE, 'src') |
|
Michael Achenbach
2016/09/19 15:09:37
So these would be unused now?
jochen (gone - plz use gerrit)
2016/09/19 15:11:46
right, will remove
| |
| 23 V8_TEST_BASE = os.path.join(V8_BASE, 'test') | 24 V8_TEST_BASE = os.path.join(V8_BASE, 'test') |
| 24 V8_INCLUDE_BASE = os.path.join(V8_BASE, 'include') | 25 V8_INCLUDE_BASE = os.path.join(V8_BASE, 'include') |
| 25 | 26 |
| 26 GYP_FILES = [ | 27 GYP_FILES = [ |
| 27 os.path.join(V8_BASE, 'src', 'd8.gyp'), | 28 os.path.join(V8_BASE, 'src', 'd8.gyp'), |
| 28 os.path.join(V8_BASE, 'src', 'v8.gyp'), | 29 os.path.join(V8_BASE, 'src', 'v8.gyp'), |
| 29 os.path.join(V8_BASE, 'src', 'inspector', 'inspector.gypi'), | 30 os.path.join(V8_BASE, 'src', 'inspector', 'inspector.gypi'), |
| 30 os.path.join(V8_BASE, 'src', 'third_party', 'vtune', 'v8vtune.gyp'), | 31 os.path.join(V8_BASE, 'src', 'third_party', 'vtune', 'v8vtune.gyp'), |
| 32 os.path.join(V8_BASE, 'samples', 'samples.gyp'), | |
| 31 os.path.join(V8_BASE, 'test', 'cctest', 'cctest.gyp'), | 33 os.path.join(V8_BASE, 'test', 'cctest', 'cctest.gyp'), |
| 32 os.path.join(V8_BASE, 'test', 'fuzzer', 'fuzzer.gyp'), | 34 os.path.join(V8_BASE, 'test', 'fuzzer', 'fuzzer.gyp'), |
| 33 os.path.join(V8_BASE, 'test', 'unittests', 'unittests.gyp'), | 35 os.path.join(V8_BASE, 'test', 'unittests', 'unittests.gyp'), |
| 36 os.path.join(V8_BASE, 'testing', 'gmock.gyp'), | |
|
Michael Achenbach
2016/09/19 15:08:21
Why do we need to list third_party gyp files?
jochen (gone - plz use gerrit)
2016/09/19 15:11:46
it's not third_party, but checked into v8
Michael Achenbach
2016/09/19 15:16:30
Acknowledged.
| |
| 37 os.path.join(V8_BASE, 'testing', 'gtest.gyp'), | |
| 34 os.path.join(V8_BASE, 'tools', 'parser-shell.gyp'), | 38 os.path.join(V8_BASE, 'tools', 'parser-shell.gyp'), |
| 35 ] | 39 ] |
| 36 | 40 |
| 41 ALL_GYP_PREFIXES = [ | |
| 42 '..', | |
| 43 'common', | |
| 44 os.path.join('src', 'third_party', 'vtune'), | |
| 45 'src', | |
| 46 'samples', | |
| 47 'testing', | |
| 48 'tools', | |
| 49 os.path.join('test', 'cctest'), | |
| 50 os.path.join('test', 'common'), | |
| 51 os.path.join('test', 'fuzzer'), | |
| 52 os.path.join('test', 'unittests'), | |
| 53 ] | |
| 54 | |
| 55 GYP_UNSUPPORTED_FEATURES = [ | |
| 56 'gcmole', | |
| 57 ] | |
| 58 | |
| 37 GN_FILES = [ | 59 GN_FILES = [ |
| 38 os.path.join(V8_BASE, 'BUILD.gn'), | 60 os.path.join(V8_BASE, 'BUILD.gn'), |
| 61 os.path.join(V8_BASE, 'build', 'secondary', 'testing', 'gmock', 'BUILD.gn'), | |
| 62 os.path.join(V8_BASE, 'build', 'secondary', 'testing', 'gtest', 'BUILD.gn'), | |
| 39 os.path.join(V8_BASE, 'src', 'inspector', 'BUILD.gn'), | 63 os.path.join(V8_BASE, 'src', 'inspector', 'BUILD.gn'), |
| 40 os.path.join(V8_BASE, 'test', 'cctest', 'BUILD.gn'), | 64 os.path.join(V8_BASE, 'test', 'cctest', 'BUILD.gn'), |
| 41 os.path.join(V8_BASE, 'test', 'unittests', 'BUILD.gn'), | 65 os.path.join(V8_BASE, 'test', 'unittests', 'BUILD.gn'), |
| 42 os.path.join(V8_BASE, 'tools', 'BUILD.gn'), | 66 os.path.join(V8_BASE, 'tools', 'BUILD.gn'), |
| 43 ] | 67 ] |
| 44 | 68 |
| 45 GN_UNSUPPORTED_FEATURES = [ | 69 GN_UNSUPPORTED_FEATURES = [ |
| 46 'aix', | 70 'aix', |
| 47 'cygwin', | 71 'cygwin', |
| 48 'freebsd', | 72 'freebsd', |
| 73 'gcmole', | |
| 49 'openbsd', | 74 'openbsd', |
| 50 'ppc', | 75 'ppc', |
| 51 'qnx', | 76 'qnx', |
| 52 'solaris', | 77 'solaris', |
| 78 'testing', | |
| 53 'vtune', | 79 'vtune', |
| 54 'x87', | 80 'x87', |
| 55 ] | 81 ] |
| 56 | 82 |
| 57 ALL_GN_PREFIXES = [ | 83 ALL_GN_PREFIXES = [ |
| 58 '..', | 84 '..', |
| 59 os.path.join('src', 'inspector'), | 85 os.path.join('src', 'inspector'), |
| 60 'src', | 86 'src', |
| 61 os.path.join('test', 'cctest'), | 87 os.path.join('test', 'cctest'), |
| 62 os.path.join('test', 'unittests'), | 88 os.path.join('test', 'unittests'), |
| 63 ] | 89 ] |
| 64 | 90 |
| 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): | 91 def pathsplit(path): |
| 77 return re.split('[/\\\\]', path) | 92 return re.split('[/\\\\]', path) |
| 78 | 93 |
| 79 def path_no_prefix(path, prefixes): | 94 def path_no_prefix(path, prefixes): |
| 80 for prefix in prefixes: | 95 for prefix in prefixes: |
| 81 if path.startswith(prefix + os.sep): | 96 if path.startswith(prefix + os.sep): |
| 82 return path_no_prefix(path[len(prefix) + 1:], prefixes) | 97 return path_no_prefix(path[len(prefix) + 1:], prefixes) |
| 83 return path | 98 return path |
| 84 | 99 |
| 85 | 100 |
| 86 def isources(directory, prefixes): | 101 def isources(prefixes): |
| 87 for root, dirs, files in os.walk(directory): | 102 cmd = ['git', 'ls-tree', '-r', 'HEAD', '--full-name', '--name-only'] |
|
Michael Achenbach
2016/09/19 15:12:48
This might now work on windows (not sure if that's
Michael Achenbach
2016/09/19 15:13:16
And with now I mean not :)
jochen (gone - plz use gerrit)
2016/09/19 15:14:39
Well, I developed this CL on windows... :)
but I'
Michael Achenbach
2016/09/19 15:16:30
Don't bother.
| |
| 88 for f in files: | 103 for f in subprocess.check_output(cmd).split('\n'): |
|
Michael Achenbach
2016/09/19 15:12:48
Unlikely that this fails after it first works, but
jochen (gone - plz use gerrit)
2016/09/19 15:14:39
ah, I guess I forgot to add universal_newlines=Tru
| |
| 89 if not (f.endswith('.h') or f.endswith('.cc')): | 104 if not (f.endswith('.h') or f.endswith('.cc')): |
| 90 continue | 105 continue |
| 91 yield path_no_prefix( | 106 yield path_no_prefix(os.path.join(*pathsplit(f)), prefixes) |
| 92 os.path.relpath(os.path.join(root, f), V8_BASE), prefixes) | |
| 93 | 107 |
| 94 | 108 |
| 95 def iflatten(obj): | 109 def iflatten(obj): |
| 96 if isinstance(obj, dict): | 110 if isinstance(obj, dict): |
| 97 for value in obj.values(): | 111 for value in obj.values(): |
| 98 for i in iflatten(value): | 112 for i in iflatten(value): |
| 99 yield i | 113 yield i |
| 100 elif isinstance(obj, list): | 114 elif isinstance(obj, list): |
| 101 for value in obj: | 115 for value in obj: |
| 102 for i in iflatten(value): | 116 for i in iflatten(value): |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 120 Iterates over all double quoted strings. | 134 Iterates over all double quoted strings. |
| 121 """ | 135 """ |
| 122 with open(gn_file) as f: | 136 with open(gn_file) as f: |
| 123 for line in f.read().splitlines(): | 137 for line in f.read().splitlines(): |
| 124 match = re.match(r'.*"([^"]*)".*', line) | 138 match = re.match(r'.*"([^"]*)".*', line) |
| 125 if match: | 139 if match: |
| 126 yield path_no_prefix( | 140 yield path_no_prefix( |
| 127 os.path.join(*pathsplit(match.group(1))), ALL_GN_PREFIXES) | 141 os.path.join(*pathsplit(match.group(1))), ALL_GN_PREFIXES) |
| 128 | 142 |
| 129 | 143 |
| 130 def icheck_values(values, prefixes, *source_dirs): | 144 def icheck_values(values, prefixes): |
| 131 for source_file in itertools.chain( | 145 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: | 146 if source_file not in values: |
| 135 yield source_file | 147 yield source_file |
| 136 | 148 |
| 137 | 149 |
| 138 def missing_gyp_files(): | 150 def missing_gyp_files(): |
| 139 gyp_values = set(itertools.chain( | 151 gyp_values = set(itertools.chain( |
| 140 *[iflatten_gyp_file(gyp_file) for gyp_file in GYP_FILES] | 152 *[iflatten_gyp_file(gyp_file) for gyp_file in GYP_FILES] |
| 141 )) | 153 )) |
| 142 return sorted(icheck_values( | 154 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)) | 155 return filter( |
| 156 lambda x: not any(i in x for i in GYP_UNSUPPORTED_FEATURES), gyp_files) | |
| 144 | 157 |
| 145 | 158 |
| 146 def missing_gn_files(): | 159 def missing_gn_files(): |
| 147 gn_values = set(itertools.chain( | 160 gn_values = set(itertools.chain( |
| 148 *[iflatten_gn_file(gn_file) for gn_file in GN_FILES] | 161 *[iflatten_gn_file(gn_file) for gn_file in GN_FILES] |
| 149 )) | 162 )) |
| 150 | 163 |
| 151 gn_files = sorted(icheck_values( | 164 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( | 165 return filter( |
| 154 lambda x: not any(i in x for i in GN_UNSUPPORTED_FEATURES), gn_files) | 166 lambda x: not any(i in x for i in GN_UNSUPPORTED_FEATURES), gn_files) |
| 155 | 167 |
| 156 | 168 |
| 157 def main(): | 169 def main(): |
| 158 print "----------- Files not in gyp: ------------" | 170 print "----------- Files not in gyp: ------------" |
| 159 for i in missing_gyp_files(): | 171 for i in missing_gyp_files(): |
| 160 print i | 172 print i |
| 161 | 173 |
| 162 print "\n----------- Files not in gn: -------------" | 174 print "\n----------- Files not in gn: -------------" |
| 163 for i in missing_gn_files(): | 175 for i in missing_gn_files(): |
| 164 print i | 176 print i |
| 165 return 0 | 177 return 0 |
| 166 | 178 |
| 167 if '__main__' == __name__: | 179 if '__main__' == __name__: |
| 168 sys.exit(main()) | 180 sys.exit(main()) |
| OLD | NEW |