OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium 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 from ast import literal_eval | 6 from ast import literal_eval |
7 import os | 7 import os |
8 | 8 |
9 | 9 |
10 _HERE = os.path.dirname(__file__) | 10 _HERE = os.path.dirname(__file__) |
11 _SRC_ROOT = os.path.join(_HERE, '..', '..', '..') | 11 _SRC_ROOT = os.path.join(_HERE, '..', '..', '..') |
12 _FROM_SRC = lambda p: os.path.abspath(os.path.join(_SRC_ROOT, p)) | 12 _FROM_SRC = lambda p: os.path.abspath(os.path.join(_SRC_ROOT, p)) |
13 | 13 |
14 | 14 |
15 from sys import path as sys_path | |
16 sys_path.insert(0, os.path.join(_HERE, '..')) | |
17 import processor | |
18 | |
19 | |
15 # High priority code to compile. | 20 # High priority code to compile. |
16 _NEED_TO_COMPILE = map(_FROM_SRC, [ | 21 _NEED_TO_COMPILE = map(_FROM_SRC, [ |
17 'chrome/browser/resources', | 22 'chrome/browser/resources', |
18 'chrome/browser/ui/webui', | 23 'chrome/browser/ui/webui', |
19 'ui/webui/resources/js', | 24 'ui/webui/resources/js', |
20 ]) | 25 ]) |
21 | 26 |
22 | 27 |
23 # Code that we'd eventually like to compile. | 28 # Code that we'd eventually like to compile. |
24 _WANT_TO_COMPILE = map(_FROM_SRC, [ | 29 _WANT_TO_COMPILE = map(_FROM_SRC, [ |
(...skipping 11 matching lines...) Expand all Loading... | |
36 | 41 |
37 _GIT_IGNORE = open(_FROM_SRC('.gitignore')).read().splitlines() | 42 _GIT_IGNORE = open(_FROM_SRC('.gitignore')).read().splitlines() |
38 _IGNORE_DIRS = tuple(map(_FROM_SRC, map(lambda p: p[1:], _GIT_IGNORE))) | 43 _IGNORE_DIRS = tuple(map(_FROM_SRC, map(lambda p: p[1:], _GIT_IGNORE))) |
39 _IGNORE_DIRS = filter(os.path.isdir, _IGNORE_DIRS) | 44 _IGNORE_DIRS = filter(os.path.isdir, _IGNORE_DIRS) |
40 _RELEVANT_JS = lambda f: f.endswith('.js') and not f.startswith(_IGNORE_DIRS) | 45 _RELEVANT_JS = lambda f: f.endswith('.js') and not f.startswith(_IGNORE_DIRS) |
41 | 46 |
42 | 47 |
43 def main(): | 48 def main(): |
44 line_cache = {} | 49 line_cache = {} |
45 | 50 |
46 def js_files_in_dir(js_dir): | 51 def js_files_and_deps_in_dir(js_dir): |
47 found_files = set() | 52 found_files = set() |
53 | |
48 for root, dirs, files in os.walk(js_dir): | 54 for root, dirs, files in os.walk(js_dir): |
49 abs_files = [os.path.abspath(os.path.join(root, f)) for f in files] | 55 abs_files = [os.path.abspath(os.path.join(root, f)) for f in files] |
50 found_files.update(filter(_RELEVANT_JS, abs_files)) | 56 relevant_files = filter(_RELEVANT_JS, abs_files) |
57 found_files.update(relevant_files) | |
58 for f in relevant_files: | |
59 found_files.update(processor.Processor(f).included_files) | |
60 | |
51 return found_files | 61 return found_files |
52 | 62 |
53 def num_lines(f): | 63 def num_lines(f): |
54 f = os.path.abspath(f) | 64 f = os.path.abspath(f) |
55 if f not in line_cache: | 65 if f not in line_cache: |
56 line_cache[f] = len(open(f, 'r').read().splitlines()) | 66 line_cache[f] = len(open(f, 'r').read().splitlines()) |
57 return line_cache[f] | 67 return line_cache[f] |
58 | 68 |
59 # All the files that are already compiled. | 69 # All the files that are already compiled. |
60 compiled = set() | 70 compiled = set() |
61 | 71 |
62 closure_dir = os.path.join(_HERE, '..') | 72 closure_dir = os.path.join(_HERE, '..') |
63 root_gyp = os.path.join(closure_dir, 'compiled_resources.gyp') | 73 root_gyp = os.path.join(closure_dir, 'compiled_resources.gyp') |
64 root_contents = open(root_gyp, 'r').read() | 74 root_contents = open(root_gyp, 'r').read() |
65 gyp_files = literal_eval(root_contents)['targets'][0]['dependencies'] | 75 gyp_files = literal_eval(root_contents)['targets'][0]['dependencies'] |
66 | 76 |
67 for g in gyp_files: | 77 for g in gyp_files: |
68 gyp_file = os.path.join(closure_dir, g.replace(':*', '')) | 78 gyp_file = os.path.join(closure_dir, g.replace(':*', '')) |
69 targets = literal_eval(open(gyp_file, 'r').read())['targets'] | 79 targets = literal_eval(open(gyp_file, 'r').read())['targets'] |
70 | 80 |
71 for target in targets: | 81 for target in targets: |
72 gyp_dir = os.path.dirname(gyp_file) | 82 gyp_dir = os.path.dirname(gyp_file) |
73 target_file = os.path.join(gyp_dir, target['target_name'] + '.js') | 83 target_file = os.path.join(gyp_dir, target['target_name'] + '.js') |
74 compiled.add(os.path.abspath(target_file)) | 84 compiled.add(os.path.abspath(target_file)) |
85 compiled.update(processor.Processor(target_file).included_files) | |
75 | 86 |
76 if 'variables' in target and 'depends' in target['variables']: | 87 if 'variables' in target and 'depends' in target['variables']: |
77 depends = target['variables']['depends'] | 88 depends = target['variables']['depends'] |
78 rel_depends = [os.path.join(gyp_dir, d) for d in depends] | 89 rel_depends = [os.path.join(gyp_dir, d) for d in depends] |
79 compiled.update([os.path.abspath(d) for d in rel_depends]) | 90 compiled.update([os.path.abspath(d) for d in rel_depends]) |
Vitaly Pavlenko
2014/09/16 01:11:16
Maybe
compiled.update([file for d in rel_depends f
Dan Beam
2014/09/16 01:13:43
this probably needs to recurse, though, no?
Dan Beam
2014/09/16 01:14:14
oh, nvm, it already should... yeah that'd probably
| |
80 | 91 |
81 compiled_lines = sum(map(num_lines, compiled)) | 92 compiled_lines = sum(map(num_lines, compiled)) |
82 print 'compiled: %d files, %d lines' % (len(compiled), compiled_lines) | 93 print 'compiled: %d files, %d lines' % (len(compiled), compiled_lines) |
83 | 94 |
84 # Find and calculate the line count of all .js files in the wanted or needed | 95 # Find and calculate the line count of all .js files in the wanted or needed |
85 # resource directories. | 96 # resource directories. |
86 files = set() | 97 files = set() |
87 | 98 |
88 for n in _NEED_TO_COMPILE: | 99 for n in _NEED_TO_COMPILE: |
89 files.update(js_files_in_dir(n)) | 100 files.update(js_files_and_deps_in_dir(n)) |
90 | 101 |
91 need_lines = sum(map(num_lines, files)) | 102 need_lines = sum(map(num_lines, files)) |
92 print 'need: %d files, %d lines' % (len(files), need_lines) | 103 print 'need: %d files, %d lines' % (len(files), need_lines) |
93 | 104 |
94 need_done = float(compiled_lines) / need_lines * 100 | 105 need_done = float(compiled_lines) / need_lines * 100 |
95 print '%.2f%% done with the code we need to compile' % need_done | 106 print '%.2f%% done with the code we need to compile' % need_done |
96 | 107 |
97 for w in _WANT_TO_COMPILE: | 108 for w in _WANT_TO_COMPILE: |
98 files.update(js_files_in_dir(w)) | 109 files.update(js_files_and_deps_in_dir(w)) |
99 | 110 |
100 want_lines = sum(map(num_lines, files)) | 111 want_lines = sum(map(num_lines, files)) |
101 print 'want: %d files, %d lines' % (len(files), want_lines) | 112 print 'want: %d files, %d lines' % (len(files), want_lines) |
102 | 113 |
103 want_done = float(compiled_lines) / want_lines * 100 | 114 want_done = float(compiled_lines) / want_lines * 100 |
104 print '%.2f%% done with the code we want to compile' % want_done | 115 print '%.2f%% done with the code we want to compile' % want_done |
105 | 116 |
106 | 117 |
107 if __name__ == '__main__': | 118 if __name__ == '__main__': |
108 main() | 119 main() |
OLD | NEW |