Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(705)

Unified Diff: third_party/closure_compiler/build/inputs.py

Issue 599203003: Implement recursive gyp dependencies for Closure Compilation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@J_jsevalcontext
Patch Set: fixed nits, removed i18n_template config Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/closure_compiler/build/inputs.py
diff --git a/third_party/closure_compiler/build/inputs.py b/third_party/closure_compiler/build/inputs.py
index 356c77197140845d246c855a18ddc20466731977..9d561462d4772c4fa48ac9594658204568511291 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)

Powered by Google App Engine
This is Rietveld 408576698