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

Side by Side Diff: third_party/closure_compiler/compile2.py

Issue 2930773003: Closure compilation: Modify compile_js2.py to not swallow errors. (Closed)
Patch Set: Don't write to file on failure. Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 os.makedirs(out_dir) 236 os.makedirs(out_dir)
237 237
238 checks_only = 'checks_only' in closure_args 238 checks_only = 'checks_only' in closure_args
239 239
240 if not checks_only: 240 if not checks_only:
241 args += ["--js_output_file=%s" % out_file] 241 args += ["--js_output_file=%s" % out_file]
242 args += ["--create_source_map=%s" % (self._MAP_FILE_FORMAT % out_file)] 242 args += ["--create_source_map=%s" % (self._MAP_FILE_FORMAT % out_file)]
243 243
244 self._log_debug("Args: %s" % " ".join(args)) 244 self._log_debug("Args: %s" % " ".join(args))
245 245
246 _, stderr = self.run_jar(self._compiler_jar, args) 246 return_code, stderr = self.run_jar(self._compiler_jar, args)
247 247
248 errors = stderr.strip().split("\n\n") 248 errors = stderr.strip().split("\n\n")
249 maybe_summary = errors.pop() 249 maybe_summary = errors.pop()
250 250
251 summary = re.search("(?P<error_count>\d+).*error.*warning", maybe_summary) 251 summary = re.search("(?P<error_count>\d+).*error.*warning", maybe_summary)
252 if summary: 252 if summary:
253 self._log_debug("Summary: %s" % maybe_summary) 253 self._log_debug("Summary: %s" % maybe_summary)
254 else: 254 else:
255 # Not a summary. Running the jar failed. Bail. 255 # Not a summary. Running the jar failed. Bail.
256 self._log_error(stderr) 256 self._log_error(stderr)
257 self._nuke_temp_files() 257 self._nuke_temp_files()
258 sys.exit(1) 258 sys.exit(1)
259 259
260 if summary.group('error_count') != "0": 260 if summary.group('error_count') != "0":
261 if os.path.exists(out_file): 261 if os.path.exists(out_file):
262 os.remove(out_file) 262 os.remove(out_file)
263 if os.path.exists(self._MAP_FILE_FORMAT % out_file): 263 if os.path.exists(self._MAP_FILE_FORMAT % out_file):
264 os.remove(self._MAP_FILE_FORMAT % out_file) 264 os.remove(self._MAP_FILE_FORMAT % out_file)
265 elif checks_only: 265 elif checks_only and return_code == 0:
266 # Compile succeeded but --checks_only disables --js_output_file from 266 # Compile succeeded but --checks_only disables --js_output_file from
267 # actually writing a file. Write a file ourselves so incremental builds 267 # actually writing a file. Write a file ourselves so incremental builds
268 # still work. 268 # still work.
269 with open(out_file, 'w') as f: 269 with open(out_file, 'w') as f:
270 f.write('') 270 f.write('')
271 271
272 if process_includes: 272 if process_includes:
273 errors = map(self._clean_up_error, errors) 273 errors = map(self._clean_up_error, errors)
274 output = self._format_errors(errors) 274 output = self._format_errors(errors)
275 275
276 if errors: 276 if errors:
277 prefix = "\n" if output else "" 277 prefix = "\n" if output else ""
278 self._log_error("Error in: %s%s%s" % (self._target, prefix, output)) 278 self._log_error("Error in: %s%s%s" % (self._target, prefix, output))
279 elif output: 279 elif output:
280 self._log_debug("Output: %s" % output) 280 self._log_debug("Output: %s" % output)
281 281
282 self._nuke_temp_files() 282 self._nuke_temp_files()
283 return bool(errors), stderr 283 return bool(errors) or return_code > 0, stderr
284 284
285 285
286 if __name__ == "__main__": 286 if __name__ == "__main__":
287 parser = argparse.ArgumentParser( 287 parser = argparse.ArgumentParser(
288 description="Typecheck JavaScript using Closure compiler") 288 description="Typecheck JavaScript using Closure compiler")
289 parser.add_argument("sources", nargs=argparse.ONE_OR_MORE, 289 parser.add_argument("sources", nargs=argparse.ONE_OR_MORE,
290 help="Path to a source file to typecheck") 290 help="Path to a source file to typecheck")
291 parser.add_argument("--custom_sources", action="store_true", 291 parser.add_argument("--custom_sources", action="store_true",
292 help="Whether this rules has custom sources.") 292 help="Whether this rules has custom sources.")
293 parser.add_argument("--custom_includes", action="store_true", 293 parser.add_argument("--custom_includes", action="store_true",
(...skipping 11 matching lines...) Expand all
305 305
306 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file, 306 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file,
307 closure_args=opts.closure_args, 307 closure_args=opts.closure_args,
308 custom_sources=opts.custom_sources, 308 custom_sources=opts.custom_sources,
309 custom_includes=opts.custom_includes) 309 custom_includes=opts.custom_includes)
310 310
311 if found_errors: 311 if found_errors:
312 if opts.custom_sources: 312 if opts.custom_sources:
313 print stderr 313 print stderr
314 sys.exit(1) 314 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698