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