| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 from bs4 import BeautifulSoup | |
| 7 from datetime import date | |
| 8 import os.path as path | |
| 9 import sys | |
| 10 | |
| 11 | |
| 12 _SRC = path.join(path.dirname(path.abspath(__file__)), "..", "..") | |
| 13 _COMPILE_JS = path.join( | |
| 14 _SRC, "third_party", "closure_compiler", "compile_js2.gypi") | |
| 15 _POLYMERS = ["polymer%s.html" % p for p in "", "-mini", "-micro"] | |
| 16 _COMPILED_RESOURCES_TEMPLATE = """ | |
| 17 # Copyright %d The Chromium Authors. All rights reserved. | |
| 18 # Use of this source code is governed by a BSD-style license that can be | |
| 19 # found in the LICENSE file. | |
| 20 # | |
| 21 # NOTE: Created with %s, please do not edit. | |
| 22 { | |
| 23 'targets': [ | |
| 24 %s | |
| 25 ], | |
| 26 } | |
| 27 """.strip() | |
| 28 | |
| 29 | |
| 30 def main(created_by, html_files): | |
| 31 targets = "" | |
| 32 | |
| 33 for html_file in html_files: | |
| 34 html_base = path.basename(html_file) | |
| 35 if html_base in _POLYMERS: | |
| 36 continue | |
| 37 | |
| 38 parsed = BeautifulSoup(open(html_file), "html.parser") | |
| 39 imports = set(i.get("href") for i in parsed.find_all("link", rel="import")) | |
| 40 | |
| 41 html_dir = path.dirname(html_file) | |
| 42 dependencies = [] | |
| 43 | |
| 44 for html_import in sorted(imports): | |
| 45 import_dir, import_base = path.split(html_import.encode("ascii")) | |
| 46 if import_base in _POLYMERS: | |
| 47 continue | |
| 48 | |
| 49 target = import_base[:-5] + "-extracted" | |
| 50 if not path.isfile(path.join(html_dir, import_dir, target + ".js")): | |
| 51 continue | |
| 52 | |
| 53 if import_dir: | |
| 54 target = "compiled_resources2.gyp:" + target | |
| 55 | |
| 56 dependencies.append(path.join(import_dir, target)) | |
| 57 | |
| 58 path_to_compile_js = path.relpath(_COMPILE_JS, html_dir) | |
| 59 | |
| 60 targets += "\n {" | |
| 61 targets += "\n 'target_name': '%s-extracted'," % html_base[:-5] | |
| 62 if dependencies: | |
| 63 targets += "\n 'dependencies': [" | |
| 64 targets += "\n '%s'," % "',\n '".join(dependencies) | |
| 65 targets += "\n ]," | |
| 66 targets += "\n 'includes': ['%s']," % path_to_compile_js | |
| 67 targets += "\n }," | |
| 68 | |
| 69 targets = targets.strip() | |
| 70 | |
| 71 if targets: | |
| 72 current_year = date.today().year | |
| 73 print _COMPILED_RESOURCES_TEMPLATE % (current_year, created_by, targets) | |
| 74 | |
| 75 | |
| 76 if __name__ == "__main__": | |
| 77 main(path.basename(sys.argv[0]), sys.argv[1:]) | |
| OLD | NEW |