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

Unified Diff: tools/polymer/generate_compiled_resources_gyp.py

Issue 1702553002: Generate compiled_resources2.gyp for Polymer based on <link rel=import>s (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: \ls Created 4 years, 10 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
« no previous file with comments | « third_party/polymer/v1_0/reproduce.sh ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/polymer/generate_compiled_resources_gyp.py
diff --git a/tools/polymer/generate_compiled_resources_gyp.py b/tools/polymer/generate_compiled_resources_gyp.py
new file mode 100755
index 0000000000000000000000000000000000000000..391974efc760bacf5d7f1e1d70c50baeb0a77e3f
--- /dev/null
+++ b/tools/polymer/generate_compiled_resources_gyp.py
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from bs4 import BeautifulSoup
+from datetime import date
+import os.path as path
+import sys
+
+
+_SRC = path.join(path.dirname(path.abspath(__file__)), "..", "..")
+_COMPILE_JS = path.join(
+ _SRC, "third_party", "closure_compiler", "compile_js2.gypi")
+_POLYMERS = ["polymer%s.html" % p for p in "", "-mini", "-micro"]
+_COMPILED_RESOURCES_TEMPLATE = """
+# Copyright %d The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# NOTE: Created with %s, please do not edit.
+{
+ 'targets': [
+ %s
+ ],
+}
+""".strip()
+
+
+def main(created_by, html_files):
+ targets = ""
+
+ for html_file in html_files:
+ html_base = path.basename(html_file)
+ if html_base in _POLYMERS:
+ continue
+
+ parsed = BeautifulSoup(open(html_file), "html.parser")
+ imports = set(i.get("href") for i in parsed.find_all("link", rel="import"))
+
+ html_dir = path.dirname(html_file)
+ dependencies = []
+
+ for html_import in sorted(imports):
+ import_dir, import_base = path.split(html_import.encode("ascii"))
+ if import_base in _POLYMERS:
+ continue
+
+ target = import_base[:-5] + "-extracted"
+ if not path.isfile(path.join(html_dir, import_dir, target + ".js")):
+ continue
+
+ if import_dir:
+ target = "compiled_resources2.gyp:" + target
+
+ dependencies.append(path.join(import_dir, target))
+
+ path_to_compile_js = path.relpath(_COMPILE_JS, html_dir)
+
+ targets += "\n {"
+ targets += "\n 'target_name': '%s-extracted'," % html_base[:-5]
+ if dependencies:
+ targets += "\n 'dependencies': ["
+ targets += "\n '%s'," % "',\n '".join(dependencies)
+ targets += "\n ],"
+ targets += "\n 'includes': ['%s']," % path_to_compile_js
+ targets += "\n },"
+
+ targets = targets.strip()
+
+ if targets:
+ current_year = date.today().year
+ print _COMPILED_RESOURCES_TEMPLATE % (current_year, created_by, targets)
+
+
+if __name__ == "__main__":
+ main(path.basename(sys.argv[0]), sys.argv[1:])
« no previous file with comments | « third_party/polymer/v1_0/reproduce.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698