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

Side by Side Diff: chrome/browser/resources/vulcanize_new.py

Issue 2569283002: WebUI: Add GN rules for Vulcanize. (Closed)
Patch Set: Update paths, fix presubmit warnings. Created 3 years, 11 months 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 2016 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 import argparse
11
12 # See //docs/vulcanize.md for instructions on installing prerequistes and
13 # running the vulcanize build.
14
15 _HERE_PATH = os.path.join(os.path.dirname(__file__))
16 _SRC_PATH = os.path.normpath(os.path.join(_HERE_PATH, '..', '..', '..'))
17
18 sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'node'))
19 import node
20 import node_modules
21
22 _NODE_BINARY = node.get_binary()
23
24 _RESOURCES_PATH = os.path.join(_SRC_PATH, 'ui', 'webui', 'resources')
25
26 _CR_ELEMENTS_PATH = os.path.join(_RESOURCES_PATH, 'cr_elements')
27 _CSS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'css')
28 _HTML_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'html')
29 _JS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'js')
30 _POLYMER_PATH = os.path.join(
31 _SRC_PATH, 'third_party', 'polymer', 'v1_0', 'components-chromium')
32
33 _VULCANIZE_BASE_ARGS = [
34 '--exclude', 'crisper.js',
35
36 # These files are already combined and minified.
37 '--exclude', 'chrome://resources/html/polymer.html',
38 '--exclude', 'web-animations-next-lite.min.js',
39
40 # These files are dynamically created by C++.
41 '--exclude', 'load_time_data.js',
42 '--exclude', 'strings.js',
43 '--exclude', 'text_defaults.css',
44 '--exclude', 'text_defaults_md.css',
45
46 '--inline-css',
47 '--inline-scripts',
48
49 '--redirect', 'chrome://resources/cr_elements/|%s' % _CR_ELEMENTS_PATH,
50 '--redirect', 'chrome://resources/css/|%s' % _CSS_RESOURCES_PATH,
51 '--redirect', 'chrome://resources/html/|%s' % _HTML_RESOURCES_PATH,
52 '--redirect', 'chrome://resources/js/|%s' % _JS_RESOURCES_PATH,
53 '--redirect', 'chrome://resources/polymer/v1_0/|%s' % _POLYMER_PATH,
54
55 '--strip-comments',
56 ]
57
58 def _run_cmd(cmd_parts, stdout=None):
59 cmd = "'" + "' '".join(cmd_parts) + "'"
60 process = subprocess.Popen(
61 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
62 stdout, stderr = process.communicate()
63
64 if stderr:
65 print >> sys.stderr, '%s failed: %s' % (cmd, stderr)
66 raise
67
68 return stdout
69
70 def _vulcanize(in_folder, out_folder, host, html_in_file,
71 html_out_file, js_out_file, extra_args=None):
72 #print 'Vulcanizing %s/%s' % (in_folder, html_in_file)
73
74 in_path = os.path.join(os.getcwd(), in_folder)
75 out_path = os.path.join(os.getcwd(), out_folder)
76
77 """print('------------------------');
78 print('cwd: ' + os.getcwd())
79 print('in_folder: ' + in_folder)
80 print('in_path: ' + in_path + ' ' + os.path.abspath(in_path))
81 print('out_path: ' + out_path)
82 print('------------------------')"""
83
84 html_in_path = os.path.join(in_path, html_in_file)
85 html_out_path = os.path.join(out_path, html_out_file)
86 js_out_path = os.path.join(out_path, js_out_file)
87 extra_args = extra_args or []
88
89 output = _run_cmd([_NODE_BINARY, node_modules.get_vulcanize_binary()] +
90 _VULCANIZE_BASE_ARGS + extra_args +
91 ['--redirect', '/|%s' % in_path,
92 '--redirect', 'chrome://%s/|%s' % (host, in_path),
93 os.path.join('/', html_in_file)])
94
95 with tempfile.NamedTemporaryFile(mode='wt+', delete=False) as tmp:
96 # Grit includes are not supported, use HTML imports instead.
97 tmp.write(output.replace(
98 '<include src="', '<include src-disabled="'))
99
100 try:
101 _run_cmd([_NODE_BINARY, node_modules.get_crisper_binary(),
102 '--source', tmp.name,
103 '--script-in-head', 'false',
104 '--html', html_out_path,
105 '--js', js_out_path])
106
107 # TODO(tsergeant): Remove when JS resources are minified by default:
108 # crbug.com/619091.
109 # Commented out because it blows up with "for of" loops.
110 _run_cmd([_NODE_BINARY, node_modules.get_uglifyjs_binary(), js_out_path,
111 '--comments', '/Copyright|license|LICENSE|\<\/?if/',
112 '--output', js_out_path])
113 finally:
114 os.remove(tmp.name)
115
116 def _css_build(out_folder, files):
117 out_path = os.path.join(os.getcwd(), out_folder)
118 paths = map(lambda f: os.path.join(out_path, f), files)
119
120 _run_cmd([_NODE_BINARY, node_modules.get_polymer_css_build_binary()] + paths)
121
122 def main():
123 parser = argparse.ArgumentParser()
124 parser.add_argument('--host')
125 parser.add_argument('--htmlInFile')
126 parser.add_argument('--htmlOutFile')
127 parser.add_argument('--inputType')
128 parser.add_argument('--input')
129 parser.add_argument('--jsOutFile')
130 parser.add_argument('--outFolder')
131 parser.add_argument('--depfile')
132 args = parser.parse_args()
133
134 vulcanize_input_folder = args.input;
135
136 # If a .pak file was specified, unpack that file first and pass the output to
137 # vulcanize.
138 if (args.inputType == 'PAK_FILE'):
139 import unpack_pak
140 input_folder = os.path.join(os.getcwd(), args.input)
141 output_folder = os.path.join(args.outFolder, 'flattened');
142 unpack_pak.unpack(args.input, output_folder)
143 vulcanize_input_folder = output_folder
144 # assert inputType == "FOLDER"
145
146 _vulcanize(vulcanize_input_folder, args.outFolder, args.host, args.htmlInFile,
147 args.htmlOutFile, args.jsOutFile);
148 _css_build(args.outFolder, files=[args.htmlOutFile])
149
150 # TODO(dpapad): Get a list of files from vulcanize.
151 f = open(os.path.join(os.getcwd(), args.depfile), 'w')
152
153 # Temporary hack, until vulcanize --list-files works.
154 if (args.host == 'downloads'):
155 dummy_input =
156 './../../chrome/browser/resources/md_downloads/i18n_setup.html'
157 else:
158 dummy_input = './../../chrome/browser/resources/settings/i18n_setup.html'
159
160 f.write(os.path.join(args.outFolder, 'vulcanized.html: ') + dummy_input);
161 f.close()
162
163 if __name__ == '__main__':
164 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698