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

Side by Side Diff: tools/polymer/generate_compiled_resources_gn.py

Issue 2247353004: GN files for running Closure Compiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add script to generate polymer gn files Created 4 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 unified diff | Download patch
« no previous file with comments | « third_party/jstemplate/BUILD.gn ('k') | ui/webui/resources/js/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 from subprocess import call
10 import sys
11
12
13 _SRC = path.join(path.dirname(path.abspath(__file__)), '..', '..')
14 _COMPILE_JS = path.join(
15 _SRC, 'third_party', 'closure_compiler', 'compile_js2.gypi')
16 _POLYMERS = ['polymer%s.html' % p for p in '', '-mini', '-micro']
17 _WEB_ANIMATIONS_BASE = 'web-animations.html'
18 _WEB_ANIMATIONS_TARGET = 'web_animations.js'
19 _COMPILED_RESOURCES_TEMPLATE = '''
20 # Copyright %d The Chromium Authors. All rights reserved.
21 # Use of this source code is governed by a BSD-style license that can be
22 # found in the LICENSE file.
23 #
24 # NOTE: Created with %s, please do not edit.
25
26 import("//third_party/closure_compiler/compile_js2.gni")
27
28 %s
29
30 '''.strip()
31
32
33 def main(created_by, html_files):
34 targets = ''
35
36 def _target_name(target_file):
37 assert target_file.endswith('.html')
38 return path.basename(target_file)[:-len('.html')] + '-extracted'
39
40 for html_file in sorted(html_files, key=_target_name):
41 html_base = path.basename(html_file)
42 if html_base in _POLYMERS:
43 continue
44
45 parsed = BeautifulSoup(open(html_file), 'html.parser')
46 imports = set(i.get('href') for i in parsed.find_all('link', rel='import'))
47
48 html_dir = path.dirname(html_file)
49 dependencies = []
50 externs = []
51
52 for html_import in sorted(imports):
53 import_dir, import_base = path.split(html_import.encode('ascii'))
54 if import_base in _POLYMERS:
55 continue
56
57 if import_base == _WEB_ANIMATIONS_BASE:
58 externs.append(_WEB_ANIMATIONS_TARGET)
59 continue
60
61 target = _target_name(import_base)
62 if not path.isfile(path.join(html_dir, import_dir, target + '.js')):
63 continue
64
65 target = ':compile_' + target
66
67 dependencies.append(import_dir + target)
68
69 targets += '\ncompile_js("compile_%s-extracted") {' % html_base[:-5]
70 targets += '\nsource_files = ["%s-extracted.js"]' % html_base[:-5]
71 if dependencies:
72 targets += "\ndeps = ["
73 targets += '\n "%s",' % '",\n "'.join(dependencies)
74 targets += '\n ]'
75 if externs:
76 targets += "\nexterns = ["
77 targets += '\n "%s",' % '",\n "'.join(externs)
78 targets += '\n ]'
79 targets += "\n}"
80
81
82 targets = targets.strip()
83
84 if targets:
85 current_year = date.today().year
86 build_gn_path = path.join(html_dir, 'BUILD.gn')
87 print build_gn_path
88 with open(build_gn_path, 'w') as build_gn:
89 build_gn.write(_COMPILED_RESOURCES_TEMPLATE % (current_year, created_by, t argets))
90 call(['gn', 'format', build_gn_path])
91
92 if __name__ == '__main__':
93 main(path.basename(sys.argv[0]), sys.argv[1:])
OLDNEW
« no previous file with comments | « third_party/jstemplate/BUILD.gn ('k') | ui/webui/resources/js/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698