diff options
author | dbeam <dbeam@chromium.org> | 2014-08-27 12:15:02 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-27 19:16:30 +0000 |
commit | 2e2ec7c150110d82d2134050724d254237c9fe44 (patch) | |
tree | 9c4e48e3c45f623b29c594a518234afc7664eb81 /third_party/closure_compiler/tools | |
parent | 42e82923357fd24d2bd0e028d13f317c0b9474a7 (diff) | |
download | chromium_src-2e2ec7c150110d82d2134050724d254237c9fe44.zip chromium_src-2e2ec7c150110d82d2134050724d254237c9fe44.tar.gz chromium_src-2e2ec7c150110d82d2134050724d254237c9fe44.tar.bz2 |
closure: make tracking script cwd-independent.
R=vitalyp@chromium.org,tbreisacher@chromium.org
BUG=393873
TEST=cd third_party/closure_compiler && ./tools/compile_coverage.py
NOTRY=true
Review URL: https://codereview.chromium.org/507953002
Cr-Commit-Position: refs/heads/master@{#292204}
Diffstat (limited to 'third_party/closure_compiler/tools')
-rwxr-xr-x | third_party/closure_compiler/tools/compile_coverage.py | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/third_party/closure_compiler/tools/compile_coverage.py b/third_party/closure_compiler/tools/compile_coverage.py index 67186e4..ad73d23 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))) +_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) |