OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 """Runs Closure compiler on JavaScript files to check for errors and produce | 6 """Runs Closure compiler on JavaScript files to check for errors and produce |
7 minified output.""" | 7 minified output.""" |
8 | 8 |
9 import argparse | 9 import argparse |
10 import os | 10 import os |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 process_includes = custom_includes or not custom_sources | 231 process_includes = custom_includes or not custom_sources |
232 if process_includes: | 232 if process_includes: |
233 # TODO(dbeam): compiler.jar automatically detects "@externs" in a --js arg | 233 # TODO(dbeam): compiler.jar automatically detects "@externs" in a --js arg |
234 # and moves these files to a different AST tree. However, because we use | 234 # and moves these files to a different AST tree. However, because we use |
235 # one big funky <include> meta-file, it thinks all the code is one big | 235 # one big funky <include> meta-file, it thinks all the code is one big |
236 # externs. Just use --js when <include> dies. | 236 # externs. Just use --js when <include> dies. |
237 | 237 |
238 cwd, tmp_dir = os.getcwd(), tempfile.gettempdir() | 238 cwd, tmp_dir = os.getcwd(), tempfile.gettempdir() |
239 rel_path = lambda f: os.path.join(os.path.relpath(cwd, tmp_dir), f) | 239 rel_path = lambda f: os.path.join(os.path.relpath(cwd, tmp_dir), f) |
240 contents = ['<include src="%s">' % rel_path(f) for f in js_args] | 240 contents = ['<include src="%s">' % rel_path(f) for f in js_args] |
241 meta_file = self._create_temp_file("\n".join(contents)) | 241 meta_file = self._create_temp_file("\n/** */\n".join(contents)) |
242 self._log_debug("Meta file: %s" % meta_file) | 242 self._log_debug("Meta file: %s" % meta_file) |
243 | 243 |
244 self._processor = processor.Processor(meta_file) | 244 self._processor = processor.Processor(meta_file) |
245 self._expanded_file = self._create_temp_file(self._processor.contents) | 245 self._expanded_file = self._create_temp_file(self._processor.contents) |
246 self._log_debug("Expanded file: %s" % self._expanded_file) | 246 self._log_debug("Expanded file: %s" % self._expanded_file) |
247 | 247 |
248 js_args = [self._expanded_file] | 248 js_args = [self._expanded_file] |
249 | 249 |
250 closure_args = closure_args or [] | 250 closure_args = closure_args or [] |
251 closure_args += ["summary_detail_level=3", "continue_after_errors"] | 251 closure_args += ["summary_detail_level=3", "continue_after_errors"] |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 331 |
332 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file, | 332 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file, |
333 closure_args=opts.closure_args, | 333 closure_args=opts.closure_args, |
334 custom_sources=opts.custom_sources, | 334 custom_sources=opts.custom_sources, |
335 custom_includes=opts.custom_includes) | 335 custom_includes=opts.custom_includes) |
336 | 336 |
337 if found_errors: | 337 if found_errors: |
338 if opts.custom_sources: | 338 if opts.custom_sources: |
339 print stderr | 339 print stderr |
340 sys.exit(1) | 340 sys.exit(1) |
OLD | NEW |