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

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

Issue 2573943002: WebUI: Vulcanize MD Settings at compile time. (Closed)
Patch Set: Fix path to crisper.js to not be relative. Created 3 years, 10 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
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 argparse 6 import argparse
7 import itertools 7 import itertools
8 import os 8 import os
9 import platform 9 import platform
10 import re 10 import re
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 html_out_file, js_out_file): 137 html_out_file, js_out_file):
138 in_path = os.path.normpath(os.path.join(_CWD, in_folder)) 138 in_path = os.path.normpath(os.path.join(_CWD, in_folder))
139 out_path = os.path.join(_CWD, out_folder) 139 out_path = os.path.join(_CWD, out_folder)
140 140
141 html_out_path = os.path.join(out_path, html_out_file) 141 html_out_path = os.path.join(out_path, html_out_file)
142 js_out_path = os.path.join(out_path, js_out_file) 142 js_out_path = os.path.join(out_path, js_out_file)
143 143
144 output = _run_node( 144 output = _run_node(
145 [node_modules.PathToVulcanize()] + 145 [node_modules.PathToVulcanize()] +
146 _VULCANIZE_BASE_ARGS + _VULCANIZE_REDIRECT_ARGS + 146 _VULCANIZE_BASE_ARGS + _VULCANIZE_REDIRECT_ARGS +
147 ['--out-request-list', os.path.join(out_path, _REQUEST_LIST_FILE), 147 ['--out-request-list', os.path.normpath(
148 os.path.join(out_path, _REQUEST_LIST_FILE)),
148 '--redirect', '"/|%s"' % in_path, 149 '--redirect', '"/|%s"' % in_path,
149 '--redirect', '"chrome://%s/|%s"' % (host, in_path), 150 '--redirect', '"chrome://%s/|%s"' % (host, in_path),
150 # TODO(dpapad): Figure out why vulcanize treats the input path 151 # TODO(dpapad): Figure out why vulcanize treats the input path
151 # differently on Windows VS Linux/Mac. 152 # differently on Windows VS Linux/Mac.
152 os.path.join( 153 os.path.join(
153 in_path if platform.system() == 'Windows' else os.sep, 154 in_path if platform.system() == 'Windows' else os.sep,
154 html_in_file)]) 155 html_in_file)])
155 156
156 with tempfile.NamedTemporaryFile(mode='wt+', delete=False) as tmp: 157 with tempfile.NamedTemporaryFile(mode='wt+', delete=False) as tmp:
157 # Grit includes are not supported, use HTML imports instead. 158 # Grit includes are not supported, use HTML imports instead.
158 tmp.write(output.replace( 159 tmp.write(output.replace(
159 '<include src="', '<include src-disabled="')) 160 '<include src="', '<include src-disabled="'))
Dan Beam 2017/01/30 21:41:46 tmp.write(output .replace('<include src="', '<
dpapad 2017/02/10 22:53:38 Already done in previous CLs (that have landed now
160 161
161 try: 162 try:
162 _run_node([node_modules.PathToCrisper(), 163 _run_node([node_modules.PathToCrisper(),
163 '--source', tmp.name, 164 '--source', tmp.name,
164 '--script-in-head', 'false', 165 '--script-in-head', 'false',
165 '--html', html_out_path, 166 '--html', html_out_path,
166 '--js', js_out_path]) 167 '--js', js_out_path])
167 168
169 # Replace last line of vulcanized HTML to use an absolute path for
170 # crisper.js. TODO(dpapad): Is there a faster way to do this?
171 js_out_file = os.path.basename(js_out_path)
172 with open(html_out_path, 'r+') as f:
173 lines = f.readlines();
174 last_line = lines[-1]
175 updated_line = last_line.replace(
176 js_out_file, 'chrome://' + host + '/' + js_out_file)
177 lines[-1] = updated_line
178 f.seek(0)
179 f.write(''.join(lines))
180
168 # TODO(tsergeant): Remove when JS resources are minified by default: 181 # TODO(tsergeant): Remove when JS resources are minified by default:
169 # crbug.com/619091. 182 # crbug.com/619091.
170 _run_node([node_modules.PathToUglifyJs(), js_out_path, 183 _run_node([node_modules.PathToUglifyJs(), js_out_path,
171 '--comments', '"/Copyright|license|LICENSE|\<\/?if/"', 184 '--comments', '"/Copyright|license|LICENSE|\<\/?if/"',
172 '--output', js_out_path]) 185 '--output', js_out_path])
173 finally: 186 finally:
174 os.remove(tmp.name) 187 os.remove(tmp.name)
175 188
176 189
177 def _css_build(out_folder, files): 190 def _css_build(out_folder, files):
(...skipping 29 matching lines...) Expand all
207 220
208 _vulcanize(vulcanize_input_folder, args.out_folder, args.host, 221 _vulcanize(vulcanize_input_folder, args.out_folder, args.host,
209 args.html_in_file, args.html_out_file, args.js_out_file) 222 args.html_in_file, args.html_out_file, args.js_out_file)
210 _css_build(args.out_folder, files=[args.html_out_file]) 223 _css_build(args.out_folder, files=[args.html_out_file])
211 224
212 _update_dep_file(vulcanize_input_folder, args) 225 _update_dep_file(vulcanize_input_folder, args)
213 226
214 227
215 if __name__ == '__main__': 228 if __name__ == '__main__':
216 main() 229 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698