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 crisper_input = tempfile.NamedTemporaryFile(mode='wt+', delete=False) |
162 tmp.write(output) | 162 crisper_input.write(output) |
163 crisper_input.close() | |
164 | |
165 crisper_output = tempfile.NamedTemporaryFile(mode='wt+', delete=False) | |
166 crisper_output.close() | |
163 | 167 |
164 try: | 168 try: |
165 node.RunNode([node_modules.PathToCrisper(), | 169 node.RunNode([node_modules.PathToCrisper(), |
166 '--source', tmp.name, | 170 '--source', crisper_input.name, |
167 '--script-in-head', 'false', | 171 '--script-in-head', 'false', |
168 '--html', html_out_path, | 172 '--html', html_out_path, |
169 '--js', js_out_path]) | 173 '--js', crisper_output.name]) |
dpapad
2017/06/05 19:46:07
So this is causing a problem. Crisper substitutes
dpapad
2017/06/05 22:12:11
PTAL. I fixed this in patch#4 using approach #2 ab
| |
170 | 174 |
171 # Create an empty JS file if crisper did not create one. | 175 node.RunNode([node_modules.PathToUglifyJs(), 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/"', | 176 '--comments', '"/Copyright|license|LICENSE|\<\/?if/"', |
177 '--output', js_out_path]) | 177 '--output', js_out_path]) |
178 finally: | 178 finally: |
179 os.remove(tmp.name) | 179 if os.path.exists(crisper_input.name): |
180 os.remove(crisper_input.name) | |
181 if os.path.exists(crisper_output.name): | |
182 os.remove(crisper_output.name) | |
180 | 183 |
181 | 184 |
182 def main(argv): | 185 def main(argv): |
183 parser = argparse.ArgumentParser() | 186 parser = argparse.ArgumentParser() |
184 parser.add_argument('--depfile', required=True) | 187 parser.add_argument('--depfile', required=True) |
185 parser.add_argument('--exclude', nargs='*') | 188 parser.add_argument('--exclude', nargs='*') |
186 parser.add_argument('--host', required=True) | 189 parser.add_argument('--host', required=True) |
187 parser.add_argument('--html_in_file', required=True) | 190 parser.add_argument('--html_in_file', required=True) |
188 parser.add_argument('--html_out_file', required=True) | 191 parser.add_argument('--html_out_file', required=True) |
189 parser.add_argument('--input', required=True) | 192 parser.add_argument('--input', required=True) |
190 parser.add_argument('--insert_in_head') | 193 parser.add_argument('--insert_in_head') |
191 parser.add_argument('--js_out_file', required=True) | 194 parser.add_argument('--js_out_file', required=True) |
192 parser.add_argument('--out_folder', required=True) | 195 parser.add_argument('--out_folder', required=True) |
193 args = parser.parse_args(argv) | 196 args = parser.parse_args(argv) |
194 | 197 |
195 # NOTE(dbeam): on Windows, GN can send dirs/like/this. When joined, you might | 198 # 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 | 199 # get dirs/like/this\file.txt. This looks odd to windows. Normalize to right |
197 # the slashes. | 200 # the slashes. |
198 args.depfile = os.path.normpath(args.depfile) | 201 args.depfile = os.path.normpath(args.depfile) |
199 args.input = os.path.normpath(args.input) | 202 args.input = os.path.normpath(args.input) |
200 args.out_folder = os.path.normpath(args.out_folder) | 203 args.out_folder = os.path.normpath(args.out_folder) |
201 | 204 |
202 _vulcanize(args.input, args) | 205 _vulcanize(args.input, args) |
203 _update_dep_file(args.input, args) | 206 _update_dep_file(args.input, args) |
204 | 207 |
205 | 208 |
206 if __name__ == '__main__': | 209 if __name__ == '__main__': |
207 main(sys.argv[1:]) | 210 main(sys.argv[1:]) |
OLD | NEW |