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

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

Issue 2179033002: Strip comments and whitespace from javascript resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix naming of GN variables, and rebase. Created 4 years, 4 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
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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 217
218 externs = filter(is_extern, externs_and_deps) 218 externs = filter(is_extern, externs_and_deps)
219 deps = filter(lambda f: not is_extern(f), externs_and_deps) 219 deps = filter(lambda f: not is_extern(f), externs_and_deps)
220 220
221 assert externs or deps or self._target 221 assert externs or deps or self._target
222 222
223 self._log_debug("Externs: %s" % externs) 223 self._log_debug("Externs: %s" % externs)
224 self._log_debug("Dependencies: %s" % deps) 224 self._log_debug("Dependencies: %s" % deps)
225 self._log_debug("Target: %s" % self._target) 225 self._log_debug("Target: %s" % self._target)
226 226
227 js_args = deps + [self._target] if self._target else [] 227 js_args = deps + ([self._target] if self._target else [])
228 228
229 if not custom_sources: 229 if not custom_sources:
230 # TODO(dbeam): compiler.jar automatically detects "@externs" in a --js arg 230 # TODO(dbeam): compiler.jar automatically detects "@externs" in a --js arg
231 # and moves these files to a different AST tree. However, because we use 231 # and moves these files to a different AST tree. However, because we use
232 # one big funky <include> meta-file, it thinks all the code is one big 232 # one big funky <include> meta-file, it thinks all the code is one big
233 # externs. Just use --js when <include> dies. 233 # externs. Just use --js when <include> dies.
234 234
235 cwd, tmp_dir = os.getcwd(), tempfile.gettempdir() 235 cwd, tmp_dir = os.getcwd(), tempfile.gettempdir()
236 rel_path = lambda f: os.path.join(os.path.relpath(cwd, tmp_dir), f) 236 rel_path = lambda f: os.path.join(os.path.relpath(cwd, tmp_dir), f)
237 contents = ['<include src="%s">' % rel_path(f) for f in js_args] 237 contents = ['<include src="%s">' % rel_path(f) for f in js_args]
(...skipping 25 matching lines...) Expand all
263 263
264 args_file = self._create_temp_file(args_file_content) 264 args_file = self._create_temp_file(args_file_content)
265 self._log_debug("Args file: %s" % args_file) 265 self._log_debug("Args file: %s" % args_file)
266 266
267 runner_args = ["--compiler-args-file=%s" % args_file] 267 runner_args = ["--compiler-args-file=%s" % args_file]
268 _, stderr = self._run_jar(self._runner_jar, runner_args) 268 _, stderr = self._run_jar(self._runner_jar, runner_args)
269 269
270 errors = stderr.strip().split("\n\n") 270 errors = stderr.strip().split("\n\n")
271 maybe_summary = errors.pop() 271 maybe_summary = errors.pop()
272 272
273 if re.search(".*error.*warning.*typed", maybe_summary): 273 summary = re.search("(?P<error_count>\d+).*error.*warning", maybe_summary)
274 if summary:
274 self._log_debug("Summary: %s" % maybe_summary) 275 self._log_debug("Summary: %s" % maybe_summary)
275 else: 276 else:
276 # Not a summary. Running the jar failed. Bail. 277 # Not a summary. Running the jar failed. Bail.
277 self._log_error(stderr) 278 self._log_error(stderr)
278 self._nuke_temp_files() 279 self._nuke_temp_files()
279 sys.exit(1) 280 sys.exit(1)
280 281
281 if errors and out_file: 282 if summary.group('error_count') != "0" and out_file:
282 if os.path.exists(out_file): 283 if os.path.exists(out_file):
283 os.remove(out_file) 284 os.remove(out_file)
284 if os.path.exists(self._MAP_FILE_FORMAT % out_file): 285 if os.path.exists(self._MAP_FILE_FORMAT % out_file):
285 os.remove(self._MAP_FILE_FORMAT % out_file) 286 os.remove(self._MAP_FILE_FORMAT % out_file)
286 287
287 if not custom_sources: 288 if not custom_sources:
288 filtered_errors = self._filter_errors(errors) 289 filtered_errors = self._filter_errors(errors)
289 errors = map(self._clean_up_error, filtered_errors) 290 errors = map(self._clean_up_error, filtered_errors)
290 output = self._format_errors(errors) 291 output = self._format_errors(errors)
291 292
(...skipping 25 matching lines...) Expand all
317 checker = Checker(verbose=opts.verbose) 318 checker = Checker(verbose=opts.verbose)
318 319
319 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file, 320 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file,
320 closure_args=opts.closure_args, 321 closure_args=opts.closure_args,
321 custom_sources=opts.custom_sources) 322 custom_sources=opts.custom_sources)
322 323
323 if found_errors: 324 if found_errors:
324 if opts.custom_sources: 325 if opts.custom_sources:
325 print stderr 326 print stderr
326 sys.exit(1) 327 sys.exit(1)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698