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

Side by Side Diff: tools/verify_source_deps.py

Issue 1208573002: [tools] Add a tool to show potentially missing source deps. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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 | « no previous file | 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
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 """
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
9 and gn files. The latter inclusion is overapproximated.
10 """
11
12 import itertools
13 import re
14 import os
15
16
17 V8_BASE = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
18 V8_SRC_BASE = os.path.join(V8_BASE, 'src')
19 V8_INCLUDE_BASE = os.path.join(V8_BASE, 'include')
20
21 GYP_FILES = [
22 os.path.join(V8_BASE, 'src', 'd8.gyp'),
23 os.path.join(V8_BASE, 'src', 'third_party', 'vtune', 'v8vtune.gyp'),
24 os.path.join(V8_BASE, 'test', 'cctest', 'cctest.gyp'),
25 os.path.join(V8_BASE, 'test', 'unittests', 'unittests.gyp'),
26 os.path.join(V8_BASE, 'tools', 'gyp', 'v8.gyp'),
27 os.path.join(V8_BASE, 'tools', 'parser-shell.gyp'),
28 ]
29
30
31 def path_no_prefix(path):
32 if path.startswith('../'):
33 return path_no_prefix(path[3:])
34 else:
35 return path
36
37
38 def isources(directory):
39 for root, dirs, files in os.walk(directory):
40 for f in files:
41 if not (f.endswith('.h') or f.endswith('.cc')):
42 continue
43 yield os.path.relpath(os.path.join(root, f), V8_BASE)
44
45
46 def iflatten(obj):
47 if isinstance(obj, dict):
48 for value in obj.values():
49 for i in iflatten(value):
50 yield i
51 elif isinstance(obj, list):
52 for value in obj:
53 for i in iflatten(value):
54 yield i
55 elif isinstance(obj, basestring):
56 yield path_no_prefix(obj)
57
58
59 def iflatten_gyp_file(gyp_file):
60 """Overaproximates all values in the gyp file.
61
62 Iterates over all string values recursively. Removes '../' path prefixes.
63 """
64 with open(gyp_file) as f:
65 return iflatten(eval(f.read()))
66
67
68 def iflatten_gn_file(gn_file):
69 """Overaproximates all values in the gn file.
70
71 Iterates over all double quoted strings.
72 """
73 with open(gn_file) as f:
74 for line in f.read().splitlines():
75 match = re.match(r'.*"([^"]*)".*', line)
76 if match:
77 yield match.group(1)
78
79
80 def icheck_values(values, *source_dirs):
81 for source_file in itertools.chain(
82 *[isources(source_dir) for source_dir in source_dirs]
83 ):
84 if source_file not in values:
85 yield source_file
86
87
88 gyp_values = set(itertools.chain(
89 *[iflatten_gyp_file(gyp_file) for gyp_file in GYP_FILES]
90 ))
91
92 print "----------- Files not in gyp: ------------"
93 for i in sorted(icheck_values(gyp_values, V8_SRC_BASE, V8_INCLUDE_BASE)):
94 print i
95
96 gn_values = set(iflatten_gn_file(os.path.join(V8_BASE, 'BUILD.gn')))
97
98 print "\n----------- Files not in gn: -------------"
99 for i in sorted(icheck_values(gn_values, V8_SRC_BASE, V8_INCLUDE_BASE)):
100 print i
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698