OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 import subprocess | 7 import subprocess |
8 import sys | 8 import sys |
9 import tempfile | 9 import tempfile |
10 | 10 |
11 # See //docs/vulcanize.md for instructions on installing prerequistes and | |
12 # running the vulcanize build. | |
11 | 13 |
12 _HERE_PATH = os.path.join(os.path.dirname(__file__)) | 14 _HERE_PATH = os.path.join(os.path.dirname(__file__)) |
13 | 15 _SRC_PATH = os.path.normpath(os.path.join(_HERE_PATH, '..', '..', '..')) |
14 _HTML_IN_PATH = os.path.join(_HERE_PATH, 'downloads.html') | |
15 _HTML_OUT_PATH = os.path.join(_HERE_PATH, 'vulcanized.html') | |
16 _JS_OUT_PATH = os.path.join(_HERE_PATH, 'crisper.js') | |
17 | |
18 _SRC_PATH = os.path.normpath(os.path.join(_HERE_PATH, '..', '..', '..', '..')) | |
19 | 16 |
20 _RESOURCES_PATH = os.path.join(_SRC_PATH, 'ui', 'webui', 'resources') | 17 _RESOURCES_PATH = os.path.join(_SRC_PATH, 'ui', 'webui', 'resources') |
21 | 18 |
22 _CR_ELEMENTS_PATH = os.path.join(_RESOURCES_PATH, 'cr_elements') | 19 _CR_ELEMENTS_PATH = os.path.join(_RESOURCES_PATH, 'cr_elements') |
23 _CSS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'css') | 20 _CSS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'css') |
24 _HTML_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'html') | 21 _HTML_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'html') |
25 _JS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'js') | 22 _JS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'js') |
26 | |
27 _POLYMER_PATH = os.path.join( | 23 _POLYMER_PATH = os.path.join( |
28 _SRC_PATH, 'third_party', 'polymer', 'v1_0', 'components-chromium') | 24 _SRC_PATH, 'third_party', 'polymer', 'v1_0', 'components-chromium') |
29 | 25 |
30 _VULCANIZE_ARGS = [ | 26 _VULCANIZE_BASE_ARGS = [ |
31 '--exclude', 'crisper.js', | 27 '--exclude', 'crisper.js', |
32 | 28 |
33 # These files are already combined and minified. | 29 # These files are already combined and minified. |
34 '--exclude', 'chrome://resources/html/polymer.html', | 30 '--exclude', 'chrome://resources/html/polymer.html', |
35 '--exclude', 'web-animations-next-lite.min.js', | 31 '--exclude', 'web-animations-next-lite.min.js', |
36 | 32 |
37 # These files are dynamically created by C++. | 33 # These files are dynamically created by C++. |
38 '--exclude', 'load_time_data.js', | 34 '--exclude', 'load_time_data.js', |
39 '--exclude', 'strings.js', | 35 '--exclude', 'strings.js', |
40 '--exclude', 'text_defaults.css', | 36 '--exclude', 'text_defaults.css', |
41 '--exclude', 'text_defaults_md.css', | 37 '--exclude', 'text_defaults_md.css', |
42 | 38 |
43 '--inline-css', | 39 '--inline-css', |
44 '--inline-scripts', | 40 '--inline-scripts', |
45 | 41 |
46 '--redirect', 'chrome://downloads/|%s' % _HERE_PATH, | |
47 '--redirect', 'chrome://resources/cr_elements/|%s' % _CR_ELEMENTS_PATH, | 42 '--redirect', 'chrome://resources/cr_elements/|%s' % _CR_ELEMENTS_PATH, |
48 '--redirect', 'chrome://resources/css/|%s' % _CSS_RESOURCES_PATH, | 43 '--redirect', 'chrome://resources/css/|%s' % _CSS_RESOURCES_PATH, |
49 '--redirect', 'chrome://resources/html/|%s' % _HTML_RESOURCES_PATH, | 44 '--redirect', 'chrome://resources/html/|%s' % _HTML_RESOURCES_PATH, |
50 '--redirect', 'chrome://resources/js/|%s' % _JS_RESOURCES_PATH, | 45 '--redirect', 'chrome://resources/js/|%s' % _JS_RESOURCES_PATH, |
51 '--redirect', 'chrome://resources/polymer/v1_0/|%s' % _POLYMER_PATH, | 46 '--redirect', 'chrome://resources/polymer/v1_0/|%s' % _POLYMER_PATH, |
52 | 47 |
53 '--strip-comments', | 48 '--strip-comments', |
54 ] | 49 ] |
55 | 50 |
56 def main(): | 51 |
52 def _vulcanize(directory, host, html_in_file, html_out_file='vulcanized.html', | |
53 js_out_file='crisper.js', extra_args=None): | |
Dan Beam
2016/08/11 05:44:34
can we me all of these keywords? looking at the c
tsergeant
2016/08/15 05:54:18
Done. I can just use them as keyword arguments fro
| |
57 def _run_cmd(cmd_parts, stdout=None): | 54 def _run_cmd(cmd_parts, stdout=None): |
58 cmd = "'" + "' '".join(cmd_parts) + "'" | 55 cmd = "'" + "' '".join(cmd_parts) + "'" |
59 process = subprocess.Popen( | 56 process = subprocess.Popen( |
60 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) | 57 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) |
61 stdout, stderr = process.communicate() | 58 stdout, stderr = process.communicate() |
62 | 59 |
63 if stderr: | 60 if stderr: |
64 print >> sys.stderr, '%s failed: %s' % (cmd, stderr) | 61 print >> sys.stderr, '%s failed: %s' % (cmd, stderr) |
65 raise | 62 raise |
66 | 63 |
67 return stdout | 64 return stdout |
68 | 65 |
69 output = _run_cmd(['vulcanize'] + _VULCANIZE_ARGS + [_HTML_IN_PATH]) | 66 print 'Vulcanizing %s' % directory |
67 | |
68 target_path = os.path.join(_HERE_PATH, directory) | |
69 html_in_path = os.path.join(target_path, html_in_file) | |
70 html_out_path = os.path.join(target_path, html_out_file) | |
71 js_out_path = os.path.join(target_path, js_out_file) | |
72 extra_args = extra_args or [] | |
73 | |
74 output = _run_cmd(['vulcanize'] + _VULCANIZE_BASE_ARGS + extra_args + | |
75 ['--redirect', 'chrome://%s/|%s' % (host, target_path), | |
76 html_in_path]) | |
70 | 77 |
71 with tempfile.NamedTemporaryFile(mode='wt+', delete=False) as tmp: | 78 with tempfile.NamedTemporaryFile(mode='wt+', delete=False) as tmp: |
79 # Grit includes are not supported, use HTML imports instead. | |
72 tmp.write(output.replace( | 80 tmp.write(output.replace( |
73 '<include src="', '<include src="../../../../ui/webui/resources/js/')) | 81 '<include src="', '<include src-disabled="')) |
74 | 82 |
75 try: | 83 try: |
76 _run_cmd(['crisper', '--source', tmp.name, | 84 _run_cmd(['crisper', '--source', tmp.name, |
77 '--script-in-head', 'false', | 85 '--script-in-head', 'false', |
78 '--html', _HTML_OUT_PATH, | 86 '--html', html_out_path, |
79 '--js', _JS_OUT_PATH]) | 87 '--js', js_out_path]) |
80 finally: | 88 finally: |
81 os.remove(tmp.name) | 89 os.remove(tmp.name) |
82 | 90 |
83 | 91 |
92 def main(): | |
93 _vulcanize('md_downloads', 'downloads', 'downloads.html') | |
Dan Beam
2016/08/11 05:44:34
and then from each callsite use the keywords becau
tsergeant
2016/08/15 05:54:18
Done.
| |
94 | |
95 # Already loaded by history.html: | |
96 history_extra_args = ['--exclude', 'chrome://resources/html/util.html', | |
97 '--exclude', 'chrome://history/constants.html'] | |
98 _vulcanize('md_history', 'history', 'app.html', 'app.vulcanized.html', | |
99 'app.crisper.js', history_extra_args) | |
100 | |
101 | |
84 if __name__ == '__main__': | 102 if __name__ == '__main__': |
85 main() | 103 main() |
OLD | NEW |