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 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 | 151 |
152 # Grit includes are not supported, use HTML imports instead. | 152 # Grit includes are not supported, use HTML imports instead. |
153 output = output.replace('<include src="', '<include src-disabled="') | 153 output = output.replace('<include src="', '<include src-disabled="') |
154 | 154 |
155 if args.insert_in_head: | 155 if args.insert_in_head: |
156 assert '<head>' in output | 156 assert '<head>' in output |
157 # NOTE(dbeam): Vulcanize eats <base> tags after processing. This undoes | 157 # NOTE(dbeam): Vulcanize eats <base> tags after processing. This undoes |
158 # that by adding a <base> tag to the (post-processed) generated output. | 158 # that by adding a <base> tag to the (post-processed) generated output. |
159 output = output.replace('<head>', '<head>' + args.insert_in_head) | 159 output = output.replace('<head>', '<head>' + args.insert_in_head) |
160 | 160 |
161 with tempfile.NamedTemporaryFile(mode='wt+', delete=False) as tmp: | 161 with tempfile.NamedTemporaryFile( |
162 tmp.write(output) | 162 mode='wt+', delete=False) as tmp_crisper_input: |
163 tmp_crisper_input.write(output) | |
Dan Beam
2017/06/03 01:19:05
nit:
crisper_input = tempfile.NamedTemporaryFile(
dpapad
2017/06/03 01:27:10
Done.
| |
164 | |
165 tmp_crisper_output = tempfile.NamedTemporaryFile(mode='wt+', delete=False) | |
163 | 166 |
164 try: | 167 try: |
165 node.RunNode([node_modules.PathToCrisper(), | 168 node.RunNode([node_modules.PathToCrisper(), |
166 '--source', tmp.name, | 169 '--source', tmp_crisper_input.name, |
167 '--script-in-head', 'false', | 170 '--script-in-head', 'false', |
168 '--html', html_out_path, | 171 '--html', html_out_path, |
169 '--js', js_out_path]) | 172 '--js', tmp_crisper_output.name]) |
170 | 173 |
171 # Create an empty JS file if crisper did not create one. | 174 node.RunNode([node_modules.PathToUglifyJs(), tmp_crisper_output.name, |
172 if not os.path.isfile(js_out_path): | |
173 open(js_out_path, 'w').close() | |
174 | |
175 node.RunNode([node_modules.PathToUglifyJs(), js_out_path, | |
176 '--comments', '"/Copyright|license|LICENSE|\<\/?if/"', | 175 '--comments', '"/Copyright|license|LICENSE|\<\/?if/"', |
177 '--output', js_out_path]) | 176 '--output', js_out_path]) |
178 finally: | 177 finally: |
179 os.remove(tmp.name) | 178 if os.path.exists(tmp_crisper_input.name): |
179 os.remove(tmp_crisper_input.name) | |
180 if os.path.exists(tmp_crisper_output.name): | |
181 os.remove(tmp_crisper_output.name) | |
180 | 182 |
181 | 183 |
182 def main(argv): | 184 def main(argv): |
183 parser = argparse.ArgumentParser() | 185 parser = argparse.ArgumentParser() |
184 parser.add_argument('--depfile', required=True) | 186 parser.add_argument('--depfile', required=True) |
185 parser.add_argument('--exclude', nargs='*') | 187 parser.add_argument('--exclude', nargs='*') |
186 parser.add_argument('--host', required=True) | 188 parser.add_argument('--host', required=True) |
187 parser.add_argument('--html_in_file', required=True) | 189 parser.add_argument('--html_in_file', required=True) |
188 parser.add_argument('--html_out_file', required=True) | 190 parser.add_argument('--html_out_file', required=True) |
189 parser.add_argument('--input', required=True) | 191 parser.add_argument('--input', required=True) |
190 parser.add_argument('--insert_in_head') | 192 parser.add_argument('--insert_in_head') |
191 parser.add_argument('--js_out_file', required=True) | 193 parser.add_argument('--js_out_file', required=True) |
192 parser.add_argument('--out_folder', required=True) | 194 parser.add_argument('--out_folder', required=True) |
193 args = parser.parse_args(argv) | 195 args = parser.parse_args(argv) |
194 | 196 |
195 # NOTE(dbeam): on Windows, GN can send dirs/like/this. When joined, you might | 197 # NOTE(dbeam): on Windows, GN can send dirs/like/this. When joined, you might |
196 # get dirs/like/this\file.txt. This looks odd to windows. Normalize to right | 198 # get dirs/like/this\file.txt. This looks odd to windows. Normalize to right |
197 # the slashes. | 199 # the slashes. |
198 args.depfile = os.path.normpath(args.depfile) | 200 args.depfile = os.path.normpath(args.depfile) |
199 args.input = os.path.normpath(args.input) | 201 args.input = os.path.normpath(args.input) |
200 args.out_folder = os.path.normpath(args.out_folder) | 202 args.out_folder = os.path.normpath(args.out_folder) |
201 | 203 |
202 _vulcanize(args.input, args) | 204 _vulcanize(args.input, args) |
203 _update_dep_file(args.input, args) | 205 _update_dep_file(args.input, args) |
204 | 206 |
205 | 207 |
206 if __name__ == '__main__': | 208 if __name__ == '__main__': |
207 main(sys.argv[1:]) | 209 main(sys.argv[1:]) |
OLD | NEW |