Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 from ast import literal_eval | |
| 7 import os | |
| 8 | |
| 9 | |
| 10 _NEED_TO_COMPILE = [ | |
| 11 'chrome/browser/resources', | |
|
Dan Beam
2014/08/26 05:04:51
^ this is likely to become more granular soon
| |
| 12 'chrome/browser/ui/webui', | |
| 13 'ui/webui/resources/js', | |
| 14 ] | |
| 15 | |
| 16 | |
| 17 _WANT_TO_COMPILE = [ | |
|
Tyler Breisacher (Chromium)
2014/08/26 16:23:42
What's the difference between need and want here?
Dan Beam
2014/08/26 17:58:47
yes, added clarifying comment
| |
| 18 'chrome/renderer/resources', | |
| 19 'chrome/test/data', | |
| 20 'content/renderer/resources', | |
| 21 'content/test/data', | |
| 22 'extensions/renderer', | |
| 23 'extensions/test/data', | |
| 24 'remoting', | |
| 25 'ui/file_manager', | |
| 26 'ui/keyboard', | |
| 27 ] | |
| 28 | |
| 29 | |
| 30 def main(): | |
| 31 here = os.path.dirname(__file__) | |
| 32 src_root = os.path.join(here, '..', '..', '..') | |
| 33 | |
| 34 line_cache = {} | |
| 35 | |
| 36 def js_files_in_dir(js_dir): | |
| 37 found_files = set() | |
| 38 for root, dirs, files in os.walk(js_dir): | |
| 39 js = filter(lambda f: f.endswith('.js'), files) | |
| 40 found_files.update([os.path.abspath(os.path.join(root, f)) for f in js]) | |
| 41 return found_files | |
| 42 | |
| 43 def num_lines(f): | |
| 44 if not f in line_cache: | |
|
Tyler Breisacher (Chromium)
2014/08/26 16:23:42
nit:
if f not in line_cache:
Dan Beam
2014/08/26 17:58:47
Done.
| |
| 45 line_cache[f] = len(open(f, 'r').read().splitlines()) | |
| 46 return line_cache[f] | |
| 47 | |
| 48 # All the files that are already compiled. | |
| 49 compiled = set() | |
| 50 | |
| 51 closure_dir = os.path.join(here, '..') | |
| 52 root_gyp = os.path.join(closure_dir, 'compiled_resources.gyp') | |
| 53 root_contents = open(root_gyp, 'r').read() | |
| 54 gyp_files = literal_eval(root_contents)['targets'][0]['dependencies'] | |
| 55 | |
| 56 for g in gyp_files: | |
| 57 src_to_closure = os.path.relpath(src_root, closure_dir) | |
| 58 rel_file = os.path.relpath(g.replace(':*', ''), src_to_closure) | |
| 59 abs_file = os.path.abspath(rel_file) | |
| 60 targets = literal_eval(open(abs_file, 'r').read())['targets'] | |
| 61 | |
| 62 for target in targets: | |
| 63 abs_dir = os.path.dirname(abs_file) | |
| 64 target_file = os.path.join(abs_dir, target['target_name'] + '.js') | |
| 65 compiled.add(target_file) | |
| 66 | |
| 67 if 'variables' in target and 'depends' in target['variables']: | |
| 68 depends = target['variables']['depends'] | |
| 69 rel_depends = [os.path.join(abs_dir, d) for d in depends] | |
| 70 compiled.update([os.path.abspath(d) for d in rel_depends]) | |
| 71 | |
| 72 compiled_lines = sum(map(num_lines, compiled)) | |
| 73 print 'compiled: %d files, %d lines' % (len(compiled), compiled_lines) | |
| 74 | |
| 75 # Find and calculate the line count of all .js files in the wanted or needed | |
| 76 # resource directories. | |
| 77 files = set() | |
| 78 | |
| 79 for n in _NEED_TO_COMPILE: | |
| 80 files.update(js_files_in_dir(os.path.join(src_root, n))) | |
| 81 | |
| 82 need_lines = sum(map(num_lines, files)) | |
| 83 print 'need: %d files, %d lines' % (len(files), need_lines) | |
| 84 | |
| 85 need_done = float(compiled_lines) / need_lines * 100 | |
| 86 print '%.2f%% done with the code we need to compile' % need_done | |
| 87 | |
| 88 for w in _WANT_TO_COMPILE: | |
| 89 files.update(js_files_in_dir(os.path.join(src_root, w))) | |
| 90 | |
| 91 want_lines = sum(map(num_lines, files)) | |
| 92 print 'want: %d files, %d lines' % (len(files), want_lines) | |
| 93 | |
| 94 want_done = float(compiled_lines) / want_lines * 100 | |
| 95 print '%.2f%% done with the code we want to compile' % want_done | |
| 96 | |
| 97 | |
| 98 if __name__ == '__main__': | |
| 99 main() | |
| OLD | NEW |