Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2016 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 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 | 32 |
| 33 # These files are dynamically created by C++. | 33 # These files are dynamically created by C++. |
| 34 '--exclude', 'load_time_data.js', | 34 '--exclude', 'load_time_data.js', |
| 35 '--exclude', 'strings.js', | 35 '--exclude', 'strings.js', |
| 36 '--exclude', 'text_defaults.css', | 36 '--exclude', 'text_defaults.css', |
| 37 '--exclude', 'text_defaults_md.css', | 37 '--exclude', 'text_defaults_md.css', |
| 38 | 38 |
| 39 '--inline-css', | 39 '--inline-css', |
| 40 '--inline-scripts', | 40 '--inline-scripts', |
| 41 | 41 |
| 42 '--redirect', 'chrome://resources/cr_elements/|%s' % _CR_ELEMENTS_PATH, | 42 '--redirect', '"chrome://resources/cr_elements/|%s"' % _CR_ELEMENTS_PATH, |
|
dpapad
2016/12/20 18:54:08
Perhaps add a comment explaining that this is nece
Dan Beam
2016/12/20 19:03:02
it's necessary for all platforms. there's a | in
| |
| 43 '--redirect', 'chrome://resources/css/|%s' % _CSS_RESOURCES_PATH, | 43 '--redirect', '"chrome://resources/css/|%s"' % _CSS_RESOURCES_PATH, |
| 44 '--redirect', 'chrome://resources/html/|%s' % _HTML_RESOURCES_PATH, | 44 '--redirect', '"chrome://resources/html/|%s"' % _HTML_RESOURCES_PATH, |
| 45 '--redirect', 'chrome://resources/js/|%s' % _JS_RESOURCES_PATH, | 45 '--redirect', '"chrome://resources/js/|%s"' % _JS_RESOURCES_PATH, |
| 46 '--redirect', 'chrome://resources/polymer/v1_0/|%s' % _POLYMER_PATH, | 46 '--redirect', '"chrome://resources/polymer/v1_0/|%s"' % _POLYMER_PATH, |
| 47 | 47 |
| 48 '--strip-comments', | 48 '--strip-comments', |
| 49 ] | 49 ] |
| 50 | 50 |
| 51 def _run_cmd(cmd_parts, stdout=None): | 51 def _run_cmd(cmd_parts, stdout=None): |
| 52 cmd = "'" + "' '".join(cmd_parts) + "'" | 52 cmd = " ".join(cmd_parts) |
| 53 process = subprocess.Popen( | 53 process = subprocess.Popen( |
| 54 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) | 54 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) |
| 55 stdout, stderr = process.communicate() | 55 stdout, stderr = process.communicate() |
| 56 | 56 |
| 57 if stderr: | 57 if stderr: |
| 58 print >> sys.stderr, '%s failed: %s' % (cmd, stderr) | 58 print >> sys.stderr, '%s failed: %s' % (cmd, stderr) |
| 59 raise | 59 raise |
| 60 | 60 |
| 61 return stdout | 61 return stdout |
| 62 | 62 |
| 63 def _vulcanize(directory, host, html_in_file, html_out_file='vulcanized.html', | 63 def _vulcanize(directory, host, html_in_file, html_out_file='vulcanized.html', |
| 64 js_out_file='crisper.js', extra_args=None): | 64 js_out_file='crisper.js', extra_args=None): |
| 65 print 'Vulcanizing %s/%s' % (directory, html_in_file) | 65 print 'Vulcanizing %s/%s' % (directory, html_in_file) |
| 66 | 66 |
| 67 target_path = os.path.join(_HERE_PATH, directory) | 67 target_path = os.path.join(_HERE_PATH, directory) |
| 68 html_in_path = os.path.join(target_path, html_in_file) | 68 html_in_path = os.path.join(target_path, html_in_file) |
| 69 html_out_path = os.path.join(target_path, html_out_file) | 69 html_out_path = os.path.join(target_path, html_out_file) |
| 70 js_out_path = os.path.join(target_path, js_out_file) | 70 js_out_path = os.path.join(target_path, js_out_file) |
| 71 extra_args = extra_args or [] | 71 extra_args = extra_args or [] |
| 72 | 72 |
| 73 output = _run_cmd(['vulcanize'] + _VULCANIZE_BASE_ARGS + extra_args + | 73 output = _run_cmd(['vulcanize'] + _VULCANIZE_BASE_ARGS + extra_args + |
| 74 ['--redirect', 'chrome://%s/|%s' % (host, target_path), | 74 ['--redirect', '"chrome://%s/|%s"' % (host, target_path), |
| 75 html_in_path]) | 75 html_in_path]) |
| 76 | 76 |
| 77 with tempfile.NamedTemporaryFile(mode='wt+', delete=False) as tmp: | 77 with tempfile.NamedTemporaryFile(mode='wt+', delete=False) as tmp: |
| 78 # Grit includes are not supported, use HTML imports instead. | 78 # Grit includes are not supported, use HTML imports instead. |
| 79 tmp.write(output.replace( | 79 tmp.write(output.replace( |
| 80 '<include src="', '<include src-disabled="')) | 80 '<include src="', '<include src-disabled="')) |
| 81 | 81 |
| 82 try: | 82 try: |
| 83 _run_cmd(['crisper', '--source', tmp.name, | 83 _run_cmd(['crisper', '--source', tmp.name, |
| 84 '--script-in-head', 'false', | 84 '--script-in-head', 'false', |
| 85 '--html', html_out_path, | 85 '--html', html_out_path, |
| 86 '--js', js_out_path]) | 86 '--js', js_out_path]) |
| 87 | 87 |
| 88 # TODO(tsergeant): Remove when JS resources are minified by default: | 88 # TODO(tsergeant): Remove when JS resources are minified by default: |
| 89 # crbug.com/619091. | 89 # crbug.com/619091. |
| 90 _run_cmd(['uglifyjs', js_out_path, | 90 _run_cmd(['uglifyjs', js_out_path, |
| 91 '--comments', '/Copyright|license|LICENSE|\<\/?if/', | 91 '--comments', '"/Copyright|license|LICENSE|\<\/?if/"', |
| 92 '--output', js_out_path]) | 92 '--output', js_out_path]) |
| 93 finally: | 93 finally: |
| 94 os.remove(tmp.name) | 94 os.remove(tmp.name) |
| 95 | 95 |
| 96 | 96 |
| 97 def _css_build(directory, files): | 97 def _css_build(directory, files): |
| 98 target_path = os.path.join(_HERE_PATH, directory) | 98 target_path = os.path.join(_HERE_PATH, directory) |
| 99 paths = map(lambda f: os.path.join(target_path, f), files) | 99 paths = map(lambda f: os.path.join(target_path, f), files) |
| 100 | 100 |
| 101 _run_cmd(['polymer-css-build'] + paths) | 101 _run_cmd(['polymer-css-build'] + paths) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 119 _vulcanize(directory='md_history', host='history', | 119 _vulcanize(directory='md_history', host='history', |
| 120 html_in_file='lazy_load.html', | 120 html_in_file='lazy_load.html', |
| 121 html_out_file='lazy_load.vulcanized.html', | 121 html_out_file='lazy_load.vulcanized.html', |
| 122 js_out_file='lazy_load.crisper.js', | 122 js_out_file='lazy_load.crisper.js', |
| 123 extra_args=history_extra_args + lazy_load_extra_args) | 123 extra_args=history_extra_args + lazy_load_extra_args) |
| 124 _css_build(directory='md_history', files=['app.vulcanized.html', | 124 _css_build(directory='md_history', files=['app.vulcanized.html', |
| 125 'lazy_load.vulcanized.html']) | 125 'lazy_load.vulcanized.html']) |
| 126 | 126 |
| 127 if __name__ == '__main__': | 127 if __name__ == '__main__': |
| 128 main() | 128 main() |
| OLD | NEW |