Chromium Code Reviews| 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 |
| 11 import re | 11 import re |
| 12 import subprocess | 12 import subprocess |
| 13 import sys | 13 import sys |
| 14 import tempfile | 14 import tempfile |
| 15 | 15 |
| 16 import build.inputs | |
| 17 import processor | 16 import processor |
| 18 import error_filter | 17 import error_filter |
| 19 | 18 |
| 20 | 19 |
| 21 _CURRENT_DIR = os.path.join(os.path.dirname(__file__)) | 20 _CURRENT_DIR = os.path.join(os.path.dirname(__file__)) |
| 22 | 21 |
| 23 | 22 |
| 24 class Checker(object): | 23 class Checker(object): |
| 25 """Runs the Closure compiler on given source files to typecheck them | 24 """Runs the Closure compiler on given source files to typecheck them |
| 26 and produce minified output.""" | 25 and produce minified output.""" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 | 181 |
| 183 Return: | 182 Return: |
| 184 The filepath of the newly created, written, and closed temporary file. | 183 The filepath of the newly created, written, and closed temporary file. |
| 185 """ | 184 """ |
| 186 with tempfile.NamedTemporaryFile(mode="wt", delete=False) as tmp_file: | 185 with tempfile.NamedTemporaryFile(mode="wt", delete=False) as tmp_file: |
| 187 self._temp_files.append(tmp_file.name) | 186 self._temp_files.append(tmp_file.name) |
| 188 tmp_file.write(contents) | 187 tmp_file.write(contents) |
| 189 return tmp_file.name | 188 return tmp_file.name |
| 190 | 189 |
| 191 def check(self, sources, out_file, closure_args=None, | 190 def check(self, sources, out_file, closure_args=None, |
| 192 custom_sources=True, custom_includes=False): | 191 custom_sources=False, custom_includes=False): |
|
dpapad
2017/05/20 02:12:10
Hm, so I guess currently the compilation succeeds,
Dan Beam
2017/05/20 03:03:45
this is always specified from the |opts| below
| |
| 193 """Closure compile |sources| while checking for errors. | 192 """Closure compile |sources| while checking for errors. |
| 194 | 193 |
| 195 Args: | 194 Args: |
| 196 sources: Files to check. sources[0] is the typically the target file. | 195 sources: Files to check. sources[0] is the typically the target file. |
| 197 sources[1:] are externs and dependencies in topological order. Order | 196 sources[1:] are externs and dependencies in topological order. Order |
| 198 is not guaranteed if custom_sources is True. | 197 is not guaranteed if custom_sources is True. |
| 199 out_file: A file where the compiled output is written to. | 198 out_file: A file where the compiled output is written to. |
| 200 closure_args: Arguments passed directly to the Closure compiler. | 199 closure_args: Arguments passed directly to the Closure compiler. |
| 201 custom_sources: Whether |sources| was customized by the target (e.g. not | 200 custom_sources: Whether |sources| was customized by the target (e.g. not |
| 202 in GYP dependency order). | 201 in GYP dependency order). |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 parser.add_argument("-c", "--closure_args", nargs=argparse.ZERO_OR_MORE, | 324 parser.add_argument("-c", "--closure_args", nargs=argparse.ZERO_OR_MORE, |
| 326 help="Arguments passed directly to the Closure compiler") | 325 help="Arguments passed directly to the Closure compiler") |
| 327 parser.add_argument("-v", "--verbose", action="store_true", | 326 parser.add_argument("-v", "--verbose", action="store_true", |
| 328 help="Show more information as this script runs") | 327 help="Show more information as this script runs") |
| 329 opts = parser.parse_args() | 328 opts = parser.parse_args() |
| 330 | 329 |
| 331 checker = Checker(verbose=opts.verbose) | 330 checker = Checker(verbose=opts.verbose) |
| 332 | 331 |
| 333 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, |
| 334 closure_args=opts.closure_args, | 333 closure_args=opts.closure_args, |
| 335 custom_sources=opts.custom_sources, | 334 custom_sources=opts.custom_sources, |
|
Dan Beam
2017/05/20 03:03:45
these are always false unless a flag is present
| |
| 336 custom_includes=opts.custom_includes) | 335 custom_includes=opts.custom_includes) |
| 337 | 336 |
| 338 if found_errors: | 337 if found_errors: |
| 339 if opts.custom_sources: | 338 if opts.custom_sources: |
| 340 print stderr | 339 print stderr |
| 341 sys.exit(1) | 340 sys.exit(1) |
| OLD | NEW |