| Index: chrome/browser/resources/settings/vulcanize.py
|
| diff --git a/chrome/browser/resources/settings/vulcanize.py b/chrome/browser/resources/settings/vulcanize.py
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..889d7e943458390cb2c15395f113bbb0924d9fb1
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/settings/vulcanize.py
|
| @@ -0,0 +1,111 @@
|
| +#!/usr/bin/env python
|
| +# Copyright 2015 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +# usage: vulcanize.py (linux|chromeos)
|
| +
|
| +# note: first, run /patch_vulcanize.sh for $i18n{..} support
|
| +
|
| +# TODO: ui/webui needs to be flattened, e.g. cr_elements/icons.html,
|
| +# css/roboto.css, md_select_css.html
|
| +
|
| +import os
|
| +import re
|
| +import subprocess
|
| +import shutil
|
| +import sys
|
| +import tempfile
|
| +import flatten_settings
|
| +
|
| +_HERE_PATH = os.path.join(os.path.dirname(__file__))
|
| +
|
| +_HTML_OUT_PATH = os.path.join(_HERE_PATH, 'vulcanized.html')
|
| +_JS_OUT_PATH = os.path.join(_HERE_PATH, 'crisper.js')
|
| +
|
| +_SRC_PATH = os.path.normpath(os.path.join(_HERE_PATH, '..', '..', '..', '..'))
|
| +
|
| +_RESOURCES_PATH = os.path.join(_SRC_PATH, 'ui', 'webui', 'resources')
|
| +
|
| +_CR_ELEMENTS_PATH = os.path.join(_RESOURCES_PATH, 'cr_elements')
|
| +_CSS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'css')
|
| +_HTML_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'html')
|
| +_JS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'js')
|
| +
|
| +_POLYMER_PATH = os.path.join(
|
| + _SRC_PATH, 'third_party', 'polymer', 'v1_0', 'components-chromium')
|
| +
|
| +def main():
|
| + def _run_cmd(cmd_parts, stdout=None):
|
| + cmd = "'" + "' '".join(cmd_parts) + "'"
|
| + process = subprocess.Popen(
|
| + cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
| + stdout, stderr = process.communicate()
|
| +
|
| + if stderr:
|
| + print >> sys.stderr, '%s failed: %s' % (cmd, stderr)
|
| + raise
|
| +
|
| + return stdout
|
| +
|
| + def _run_vulcanize(settings_dir):
|
| + _VULCANIZE_ARGS = [
|
| + '--exclude', 'crisper.js',
|
| +
|
| + # These files are already combined and minified.
|
| + '--exclude', 'chrome://resources/html/polymer.html',
|
| + '--exclude', 'web-animations-next-lite.min.js',
|
| +
|
| + # These files are dynamically created by C++.
|
| + '--exclude', 'load_time_data.js',
|
| + '--exclude', 'strings.js',
|
| + '--exclude', 'text_defaults.css',
|
| + '--exclude', 'text_defaults_md.css',
|
| +
|
| + '--inline-css',
|
| + '--inline-scripts',
|
| +
|
| + # last-to-first
|
| + '--redirect', '/|%s' % settings_dir,
|
| + '--redirect', 'chrome://md-settings/|%s' % settings_dir,
|
| + '--redirect', 'chrome://resources/cr_elements/|%s' % _CR_ELEMENTS_PATH,
|
| + '--redirect', 'chrome://resources/css/|%s' % _CSS_RESOURCES_PATH,
|
| + '--redirect', 'chrome://resources/html/|%s' % _HTML_RESOURCES_PATH,
|
| + '--redirect', 'chrome://resources/js/|%s' % _JS_RESOURCES_PATH,
|
| + '--redirect', 'chrome://resources/polymer/v1_0/|%s' % _POLYMER_PATH,
|
| +
|
| + '--strip-comments',
|
| + ]
|
| +
|
| + _HTML_IN_PATH = os.path.join('/settings.html')
|
| + output = _run_cmd(['vulcanize'] + _VULCANIZE_ARGS + [_HTML_IN_PATH])
|
| +
|
| + with tempfile.NamedTemporaryFile(mode='wt+', delete=False) as tmp:
|
| + tmp.write(output.replace(
|
| + '<include src="', '<include src="../../../../ui/webui/resources/js/'))
|
| +
|
| + try:
|
| + _run_cmd(['crisper', '--source', tmp.name,
|
| + '--script-in-head', 'false',
|
| + '--html', _HTML_OUT_PATH,
|
| + '--js', _JS_OUT_PATH])
|
| +
|
| + # TODO: encoding issue breaking grit
|
| + with open(_HTML_OUT_PATH, 'r+') as outfile:
|
| + html_out = outfile.read().decode('utf-8').replace(u'\u2715', '✕').encode('utf-8')
|
| + outfile.seek(0)
|
| + outfile.write(html_out)
|
| +
|
| + finally:
|
| + os.remove(tmp.name)
|
| +
|
| + chromeos = len(sys.argv) > 1 and sys.argv[1] == 'chromeos'
|
| + settings_dir = flatten_settings.flatten(sys.argv[1])
|
| + try:
|
| + _run_vulcanize(settings_dir)
|
| + finally:
|
| + shutil.rmtree(settings_dir)
|
| +
|
| +
|
| +if __name__ == '__main__':
|
| + main()
|
|
|