diff options
author | vitalyp <vitalyp@chromium.org> | 2014-09-29 17:06:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-30 00:07:37 +0000 |
commit | 982046410eb61c3c6d4a0c52b44109a0c4a9d77b (patch) | |
tree | e4f8ab9922c1593dbd089cb82c7b3be9f4b817a1 /third_party | |
parent | 118b86758e6c1b7072a6dc9dcc1504f3fce1bf9b (diff) | |
download | chromium_src-982046410eb61c3c6d4a0c52b44109a0c4a9d77b.zip chromium_src-982046410eb61c3c6d4a0c52b44109a0c4a9d77b.tar.gz chromium_src-982046410eb61c3c6d4a0c52b44109a0c4a9d77b.tar.bz2 |
Implement recursive gyp dependencies for Closure Compilation
BUG=78368
R=dbeam@chromium.org
TEST=GYP_GENERATORS=ninja gyp --depth . third_party/closure_compiler/compiled_resources.gyp && ninja -C out/Default
Review URL: https://codereview.chromium.org/599203003
Cr-Commit-Position: refs/heads/master@{#297314}
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/closure_compiler/build/__init__.py | 0 | ||||
-rwxr-xr-x | third_party/closure_compiler/build/inputs.py | 68 | ||||
-rwxr-xr-x | third_party/closure_compiler/checker.py | 10 |
3 files changed, 74 insertions, 4 deletions
diff --git a/third_party/closure_compiler/build/__init__.py b/third_party/closure_compiler/build/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/third_party/closure_compiler/build/__init__.py diff --git a/third_party/closure_compiler/build/inputs.py b/third_party/closure_compiler/build/inputs.py index 356c771..9d561462 100755 --- a/third_party/closure_compiler/build/inputs.py +++ b/third_party/closure_compiler/build/inputs.py @@ -4,6 +4,8 @@ # found in the LICENSE file. import argparse +import ast +import collections import os import sys @@ -12,17 +14,79 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) import processor +def remove_duplicates_with_order(has_duplicates): + return list(collections.OrderedDict.fromkeys(has_duplicates)) + + +def expand_depends(source, dep): + if ":" not in dep: + return [dep], {} + + gyp_relative_path, target = dep.split(":") + gyp_path = os.path.join(os.path.dirname(source), gyp_relative_path) + gyp_content = ast.literal_eval(open(gyp_path).read()) + + for target_description in gyp_content["targets"]: + if target_description["target_name"] == target: + break + else: + raise ValueError("Target '%s' not found in file '%s'" % + (target, gyp_path)) + + depends = [] + externs = [] + if "variables" in target_description: + depends = target_description["variables"].get("depends", []) + externs = target_description["variables"].get("externs", []) + + def attach_gyp_dir(relative_path): + return os.path.join(os.path.dirname(gyp_path), relative_path) + + target_source = attach_gyp_dir(target + ".js") + expanded_depends, expanded_externs = resolve_recursive_dependencies( + target_source, + depends, + externs) + + expanded_depends = map(attach_gyp_dir, expanded_depends) + expanded_externs = set(map(attach_gyp_dir, expanded_externs)) + + expanded_depends.append(target_source) + + return expanded_depends, expanded_externs + + +def resolve_recursive_dependencies(source, input_depends, depends_externs): + output_depends = [] + output_externs = set(depends_externs) + + for depends in input_depends: + expanded_depends, expanded_externs = expand_depends(source, depends) + output_depends.extend(expanded_depends) + output_externs.update(expanded_externs) + + output_depends = remove_duplicates_with_order(output_depends) + + return output_depends, output_externs + + def GetInputs(args): parser = argparse.ArgumentParser() - parser.add_argument("sources", nargs=argparse.ONE_OR_MORE) + parser.add_argument("source", nargs=1) parser.add_argument("-d", "--depends", nargs=argparse.ZERO_OR_MORE, default=[]) parser.add_argument("-e", "--externs", nargs=argparse.ZERO_OR_MORE, default=[]) opts = parser.parse_args(args) + source = opts.source[0] + depends, externs = resolve_recursive_dependencies( + source, + opts.depends, + opts.externs) + files = set() - for file in opts.sources + opts.depends + opts.externs: + for file in {source} | set(depends) | externs: files.add(file) files.update(processor.Processor(file).included_files) diff --git a/third_party/closure_compiler/checker.py b/third_party/closure_compiler/checker.py index 5b21583..b471c76 100755 --- a/third_party/closure_compiler/checker.py +++ b/third_party/closure_compiler/checker.py @@ -11,6 +11,8 @@ import re import subprocess import sys import tempfile + +import build.inputs import processor @@ -168,7 +170,7 @@ class Checker(object): and its output (as a string). """ depends = depends or [] - externs = externs or [] + externs = externs or set() if not self._check_java_path(): return 1, "" @@ -233,7 +235,11 @@ if __name__ == "__main__": checker = Checker(verbose=opts.verbose) for source in opts.sources: - exit, _ = checker.check(source, depends=opts.depends, externs=opts.externs) + depends, externs = build.inputs.resolve_recursive_dependencies( + source, + opts.depends, + opts.externs) + exit, _ = checker.check(source, depends=depends, externs=externs) if exit != 0: sys.exit(exit) |