OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright 2015 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 import os | |
7 import subprocess | |
8 import sys | |
9 import tempfile | |
10 | |
11 | |
12 _HERE_PATH = os.path.join(os.path.dirname(__file__)) | |
13 | |
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 | |
20 _RESOURCES_PATH = os.path.join(_SRC_PATH, 'ui', 'webui', 'resources') | |
21 | |
22 _CR_ELEMENTS_PATH = os.path.join(_RESOURCES_PATH, 'cr_elements') | |
23 _CSS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'css') | |
24 _HTML_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'html') | |
25 _JS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'js') | |
26 | |
27 _POLYMER_PATH = os.path.join( | |
28 _SRC_PATH, 'third_party', 'polymer', 'v1_0', 'components-chromium') | |
29 | |
30 _VULCANIZE_ARGS = [ | |
31 '--exclude', 'crisper.js', | |
32 | |
33 # These files are already combined and minified. | |
34 '--exclude', 'chrome://resources/html/polymer.html', | |
35 '--exclude', 'web-animations-next-lite.min.js', | |
36 | |
37 # These files are dynamically created by C++. | |
38 '--exclude', 'load_time_data.js', | |
39 '--exclude', 'strings.js', | |
40 '--exclude', 'text_defaults.css', | |
41 '--exclude', 'text_defaults_md.css', | |
42 | |
43 '--inline-css', | |
44 '--inline-scripts', | |
45 | |
46 '--redirect', 'chrome://downloads/|%s' % _HERE_PATH, | |
47 '--redirect', 'chrome://resources/cr_elements/|%s' % _CR_ELEMENTS_PATH, | |
48 '--redirect', 'chrome://resources/css/|%s' % _CSS_RESOURCES_PATH, | |
49 '--redirect', 'chrome://resources/html/|%s' % _HTML_RESOURCES_PATH, | |
50 '--redirect', 'chrome://resources/js/|%s' % _JS_RESOURCES_PATH, | |
51 '--redirect', 'chrome://resources/polymer/v1_0/|%s' % _POLYMER_PATH, | |
52 | |
53 '--strip-comments', | |
54 ] | |
55 | |
56 def main(): | |
57 def _run_cmd(cmd_parts, stdout=None): | |
58 cmd = "'" + "' '".join(cmd_parts) + "'" | |
59 process = subprocess.Popen( | |
60 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) | |
61 stdout, stderr = process.communicate() | |
62 | |
63 if stderr: | |
64 print >> sys.stderr, '%s failed: %s' % (cmd, stderr) | |
65 raise | |
66 | |
67 return stdout | |
68 | |
69 output = _run_cmd(['vulcanize'] + _VULCANIZE_ARGS + [_HTML_IN_PATH]) | |
70 | |
71 with tempfile.NamedTemporaryFile(mode='wt+', delete=False) as tmp: | |
72 tmp.write(output.replace( | |
73 '<include src="', '<include src="../../../../ui/webui/resources/js/')) | |
74 | |
75 try: | |
76 _run_cmd(['crisper', '--source', tmp.name, | |
77 '--script-in-head', 'false', | |
78 '--html', _HTML_OUT_PATH, | |
79 '--js', _JS_OUT_PATH]) | |
80 finally: | |
81 os.remove(tmp.name) | |
82 | |
83 | |
84 if __name__ == '__main__': | |
85 main() | |
OLD | NEW |