| 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 |
| 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 |
| 13 tool won't be accurate for other sources in other directories (e.g. cctest). |
| 10 """ | 14 """ |
| 11 | 15 |
| 12 import itertools | 16 import itertools |
| 13 import re | 17 import re |
| 14 import os | 18 import os |
| 15 | 19 |
| 16 | 20 |
| 17 V8_BASE = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | 21 V8_BASE = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
| 18 V8_SRC_BASE = os.path.join(V8_BASE, 'src') | 22 V8_SRC_BASE = os.path.join(V8_BASE, 'src') |
| 19 V8_INCLUDE_BASE = os.path.join(V8_BASE, 'include') | 23 V8_INCLUDE_BASE = os.path.join(V8_BASE, 'include') |
| 20 | 24 |
| 21 GYP_FILES = [ | 25 GYP_FILES = [ |
| 22 os.path.join(V8_BASE, 'src', 'd8.gyp'), | 26 os.path.join(V8_BASE, 'src', 'd8.gyp'), |
| 23 os.path.join(V8_BASE, 'src', 'third_party', 'vtune', 'v8vtune.gyp'), | 27 os.path.join(V8_BASE, 'src', 'third_party', 'vtune', 'v8vtune.gyp'), |
| 24 os.path.join(V8_BASE, 'test', 'cctest', 'cctest.gyp'), | 28 os.path.join(V8_BASE, 'test', 'cctest', 'cctest.gyp'), |
| 25 os.path.join(V8_BASE, 'test', 'unittests', 'unittests.gyp'), | 29 os.path.join(V8_BASE, 'test', 'unittests', 'unittests.gyp'), |
| 26 os.path.join(V8_BASE, 'tools', 'gyp', 'v8.gyp'), | 30 os.path.join(V8_BASE, 'tools', 'gyp', 'v8.gyp'), |
| 27 os.path.join(V8_BASE, 'tools', 'parser-shell.gyp'), | 31 os.path.join(V8_BASE, 'tools', 'parser-shell.gyp'), |
| 28 ] | 32 ] |
| 29 | 33 |
| 30 | 34 |
| 31 def path_no_prefix(path): | 35 def path_no_prefix(path): |
| 32 if path.startswith('../'): | 36 if path.startswith('../'): |
| 33 return path_no_prefix(path[3:]) | 37 return path_no_prefix(path[3:]) |
| 38 elif path.startswith('src/'): |
| 39 return path_no_prefix(path[4:]) |
| 34 else: | 40 else: |
| 35 return path | 41 return path |
| 36 | 42 |
| 37 | 43 |
| 38 def isources(directory): | 44 def isources(directory): |
| 39 for root, dirs, files in os.walk(directory): | 45 for root, dirs, files in os.walk(directory): |
| 40 for f in files: | 46 for f in files: |
| 41 if not (f.endswith('.h') or f.endswith('.cc')): | 47 if not (f.endswith('.h') or f.endswith('.cc')): |
| 42 continue | 48 continue |
| 43 yield os.path.relpath(os.path.join(root, f), V8_BASE) | 49 yield path_no_prefix(os.path.relpath(os.path.join(root, f), V8_BASE)) |
| 44 | 50 |
| 45 | 51 |
| 46 def iflatten(obj): | 52 def iflatten(obj): |
| 47 if isinstance(obj, dict): | 53 if isinstance(obj, dict): |
| 48 for value in obj.values(): | 54 for value in obj.values(): |
| 49 for i in iflatten(value): | 55 for i in iflatten(value): |
| 50 yield i | 56 yield i |
| 51 elif isinstance(obj, list): | 57 elif isinstance(obj, list): |
| 52 for value in obj: | 58 for value in obj: |
| 53 for i in iflatten(value): | 59 for i in iflatten(value): |
| (...skipping 13 matching lines...) Expand all Loading... |
| 67 | 73 |
| 68 def iflatten_gn_file(gn_file): | 74 def iflatten_gn_file(gn_file): |
| 69 """Overaproximates all values in the gn file. | 75 """Overaproximates all values in the gn file. |
| 70 | 76 |
| 71 Iterates over all double quoted strings. | 77 Iterates over all double quoted strings. |
| 72 """ | 78 """ |
| 73 with open(gn_file) as f: | 79 with open(gn_file) as f: |
| 74 for line in f.read().splitlines(): | 80 for line in f.read().splitlines(): |
| 75 match = re.match(r'.*"([^"]*)".*', line) | 81 match = re.match(r'.*"([^"]*)".*', line) |
| 76 if match: | 82 if match: |
| 77 yield match.group(1) | 83 yield path_no_prefix(match.group(1)) |
| 78 | 84 |
| 79 | 85 |
| 80 def icheck_values(values, *source_dirs): | 86 def icheck_values(values, *source_dirs): |
| 81 for source_file in itertools.chain( | 87 for source_file in itertools.chain( |
| 82 *[isources(source_dir) for source_dir in source_dirs] | 88 *[isources(source_dir) for source_dir in source_dirs] |
| 83 ): | 89 ): |
| 84 if source_file not in values: | 90 if source_file not in values: |
| 85 yield source_file | 91 yield source_file |
| 86 | 92 |
| 87 | 93 |
| 88 gyp_values = set(itertools.chain( | 94 gyp_values = set(itertools.chain( |
| 89 *[iflatten_gyp_file(gyp_file) for gyp_file in GYP_FILES] | 95 *[iflatten_gyp_file(gyp_file) for gyp_file in GYP_FILES] |
| 90 )) | 96 )) |
| 91 | 97 |
| 92 print "----------- Files not in gyp: ------------" | 98 print "----------- Files not in gyp: ------------" |
| 93 for i in sorted(icheck_values(gyp_values, V8_SRC_BASE, V8_INCLUDE_BASE)): | 99 for i in sorted(icheck_values(gyp_values, V8_SRC_BASE, V8_INCLUDE_BASE)): |
| 94 print i | 100 print i |
| 95 | 101 |
| 96 gn_values = set(iflatten_gn_file(os.path.join(V8_BASE, 'BUILD.gn'))) | 102 gn_values = set(iflatten_gn_file(os.path.join(V8_BASE, 'BUILD.gn'))) |
| 97 | 103 |
| 98 print "\n----------- Files not in gn: -------------" | 104 print "\n----------- Files not in gn: -------------" |
| 99 for i in sorted(icheck_values(gn_values, V8_SRC_BASE, V8_INCLUDE_BASE)): | 105 for i in sorted(icheck_values(gn_values, V8_SRC_BASE, V8_INCLUDE_BASE)): |
| 100 print i | 106 print i |
| OLD | NEW |