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

Side by Side Diff: chrome/browser/resources/settings/vulcanize.py

Issue 2513673005: Vulcanize Settings (Closed)
Patch Set: don't error on applied patch Created 4 years 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
OLDNEW
(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 # usage: vulcanize.py (linux|chromeos)
7
8 # note: first, run /patch_vulcanize.sh for $i18n{..} support
9
10 # TODO: ui/webui needs to be flattened, e.g. cr_elements/icons.html,
11 # css/roboto.css, md_select_css.html
12
13 import os
14 import re
15 import subprocess
16 import shutil
17 import sys
18 import tempfile
19 import flatten_settings
20
21 _HERE_PATH = os.path.join(os.path.dirname(__file__))
22
23 _HTML_OUT_PATH = os.path.join(_HERE_PATH, 'vulcanized.html')
24 _JS_OUT_PATH = os.path.join(_HERE_PATH, 'crisper.js')
25
26 _SRC_PATH = os.path.normpath(os.path.join(_HERE_PATH, '..', '..', '..', '..'))
27
28 _RESOURCES_PATH = os.path.join(_SRC_PATH, 'ui', 'webui', 'resources')
29
30 _CR_ELEMENTS_PATH = os.path.join(_RESOURCES_PATH, 'cr_elements')
31 _CSS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'css')
32 _HTML_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'html')
33 _JS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'js')
34
35 _POLYMER_PATH = os.path.join(
36 _SRC_PATH, 'third_party', 'polymer', 'v1_0', 'components-chromium')
37
38 def main():
39 def _run_cmd(cmd_parts, stdout=None):
40 cmd = "'" + "' '".join(cmd_parts) + "'"
41 process = subprocess.Popen(
42 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
43 stdout, stderr = process.communicate()
44
45 if stderr:
46 print >> sys.stderr, '%s failed: %s' % (cmd, stderr)
47 raise
48
49 return stdout
50
51 def _run_vulcanize(settings_dir):
52 _VULCANIZE_ARGS = [
53 '--exclude', 'crisper.js',
54
55 # These files are already combined and minified.
56 '--exclude', 'chrome://resources/html/polymer.html',
57 '--exclude', 'web-animations-next-lite.min.js',
58
59 # These files are dynamically created by C++.
60 '--exclude', 'load_time_data.js',
61 '--exclude', 'strings.js',
62 '--exclude', 'text_defaults.css',
63 '--exclude', 'text_defaults_md.css',
64
65 '--inline-css',
66 '--inline-scripts',
67
68 # last-to-first
69 '--redirect', '/|%s' % settings_dir,
70 '--redirect', 'chrome://md-settings/|%s' % settings_dir,
71 '--redirect', 'chrome://resources/cr_elements/|%s' % _CR_ELEMENTS_PATH,
72 '--redirect', 'chrome://resources/css/|%s' % _CSS_RESOURCES_PATH,
73 '--redirect', 'chrome://resources/html/|%s' % _HTML_RESOURCES_PATH,
74 '--redirect', 'chrome://resources/js/|%s' % _JS_RESOURCES_PATH,
75 '--redirect', 'chrome://resources/polymer/v1_0/|%s' % _POLYMER_PATH,
76
77 '--strip-comments',
78 ]
79
80 _HTML_IN_PATH = os.path.join('/settings.html')
81 output = _run_cmd(['vulcanize'] + _VULCANIZE_ARGS + [_HTML_IN_PATH])
82
83 with tempfile.NamedTemporaryFile(mode='wt+', delete=False) as tmp:
84 tmp.write(output.replace(
85 '<include src="', '<include src="../../../../ui/webui/resources/js/'))
86
87 try:
88 _run_cmd(['crisper', '--source', tmp.name,
89 '--script-in-head', 'false',
90 '--html', _HTML_OUT_PATH,
91 '--js', _JS_OUT_PATH])
92
93 # TODO: encoding issue breaking grit
94 with open(_HTML_OUT_PATH, 'r+') as outfile:
95 html_out = outfile.read().decode('utf-8').replace(u'\u2715', '&#x2715;') .encode('utf-8')
96 outfile.seek(0)
97 outfile.write(html_out)
98
99 finally:
100 os.remove(tmp.name)
101
102 chromeos = len(sys.argv) > 1 and sys.argv[1] == 'chromeos'
103 settings_dir = flatten_settings.flatten(sys.argv[1])
104 try:
105 _run_vulcanize(settings_dir)
106 finally:
107 shutil.rmtree(settings_dir)
108
109
110 if __name__ == '__main__':
111 main()
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/settings.html ('k') | chrome/browser/ui/webui/settings/md_settings_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698