Chromium Code Reviews| Index: third_party/closure_compiler/tools/compile_coverage.py |
| diff --git a/third_party/closure_compiler/tools/compile_coverage.py b/third_party/closure_compiler/tools/compile_coverage.py |
| index 67186e4d021916a70ebb2c81865de2ad825f252a..ad73d233aeadd3cc395bdd63a9ea779b5e562c50 100755 |
| --- a/third_party/closure_compiler/tools/compile_coverage.py |
| +++ b/third_party/closure_compiler/tools/compile_coverage.py |
| @@ -7,16 +7,21 @@ from ast import literal_eval |
| import os |
| +_HERE = os.path.dirname(__file__) |
| +_SRC_ROOT = os.path.join(_HERE, '..', '..', '..') |
| +_FROM_SRC = lambda p: os.path.abspath(os.path.join(_SRC_ROOT, p)) |
| + |
| + |
| # High priority code to compile. |
| -_NEED_TO_COMPILE = [ |
| +_NEED_TO_COMPILE = map(_FROM_SRC, [ |
| 'chrome/browser/resources', |
| 'chrome/browser/ui/webui', |
| 'ui/webui/resources/js', |
| -] |
| +]) |
| # Code that we'd eventually like to compile. |
| -_WANT_TO_COMPILE = [ |
| +_WANT_TO_COMPILE = map(_FROM_SRC, [ |
| 'chrome/renderer/resources', |
| 'chrome/test/data', |
| 'content/renderer/resources', |
| @@ -26,23 +31,27 @@ _WANT_TO_COMPILE = [ |
| 'remoting', |
| 'ui/file_manager', |
| 'ui/keyboard', |
| -] |
| +]) |
| -def main(): |
| - here = os.path.dirname(__file__) |
| - src_root = os.path.join(here, '..', '..', '..') |
| +_GIT_IGNORE = open(_FROM_SRC('.gitignore')).read().splitlines() |
| +_IGNORE_DIRS = tuple(map(_FROM_SRC, map(lambda p: p[1:], _GIT_IGNORE))) |
|
Tyler Breisacher (Chromium)
2014/08/27 19:01:27
Why do you need to tuple-ize it? Seems like a list
Dan Beam
2014/08/27 19:03:59
https://docs.python.org/2/library/stdtypes.html#st
|
| +_IGNORE_DIRS = filter(os.path.isdir, _IGNORE_DIRS) |
| +_RELEVANT_JS = lambda f: f.endswith('.js') and not f.startswith(_IGNORE_DIRS) |
| + |
| +def main(): |
| line_cache = {} |
| def js_files_in_dir(js_dir): |
| found_files = set() |
| for root, dirs, files in os.walk(js_dir): |
| - js = filter(lambda f: f.endswith('.js'), files) |
| - found_files.update([os.path.abspath(os.path.join(root, f)) for f in js]) |
| + abs_files = [os.path.abspath(os.path.join(root, f)) for f in files] |
| + found_files.update(filter(_RELEVANT_JS, abs_files)) |
| return found_files |
| def num_lines(f): |
| + f = os.path.abspath(f) |
| if f not in line_cache: |
| line_cache[f] = len(open(f, 'r').read().splitlines()) |
| return line_cache[f] |
| @@ -50,25 +59,23 @@ def main(): |
| # All the files that are already compiled. |
| compiled = set() |
| - closure_dir = os.path.join(here, '..') |
| + closure_dir = os.path.join(_HERE, '..') |
| root_gyp = os.path.join(closure_dir, 'compiled_resources.gyp') |
| root_contents = open(root_gyp, 'r').read() |
| gyp_files = literal_eval(root_contents)['targets'][0]['dependencies'] |
| for g in gyp_files: |
| - src_to_closure = os.path.relpath(src_root, closure_dir) |
| - rel_file = os.path.relpath(g.replace(':*', ''), src_to_closure) |
| - abs_file = os.path.abspath(rel_file) |
| - targets = literal_eval(open(abs_file, 'r').read())['targets'] |
| + gyp_file = os.path.join(closure_dir, g.replace(':*', '')) |
| + targets = literal_eval(open(gyp_file, 'r').read())['targets'] |
| for target in targets: |
| - abs_dir = os.path.dirname(abs_file) |
| - target_file = os.path.join(abs_dir, target['target_name'] + '.js') |
| - compiled.add(target_file) |
| + gyp_dir = os.path.dirname(gyp_file) |
| + target_file = os.path.join(gyp_dir, target['target_name'] + '.js') |
| + compiled.add(os.path.abspath(target_file)) |
| if 'variables' in target and 'depends' in target['variables']: |
| depends = target['variables']['depends'] |
| - rel_depends = [os.path.join(abs_dir, d) for d in depends] |
| + rel_depends = [os.path.join(gyp_dir, d) for d in depends] |
| compiled.update([os.path.abspath(d) for d in rel_depends]) |
| compiled_lines = sum(map(num_lines, compiled)) |
| @@ -79,7 +86,7 @@ def main(): |
| files = set() |
| for n in _NEED_TO_COMPILE: |
| - files.update(js_files_in_dir(os.path.join(src_root, n))) |
| + files.update(js_files_in_dir(n)) |
| need_lines = sum(map(num_lines, files)) |
| print 'need: %d files, %d lines' % (len(files), need_lines) |
| @@ -88,7 +95,7 @@ def main(): |
| print '%.2f%% done with the code we need to compile' % need_done |
| for w in _WANT_TO_COMPILE: |
| - files.update(js_files_in_dir(os.path.join(src_root, w))) |
| + files.update(js_files_in_dir(w)) |
| want_lines = sum(map(num_lines, files)) |
| print 'want: %d files, %d lines' % (len(files), want_lines) |