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

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: Revert changes to screen.js (no longer needed for this CL) 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 218
219 externs = filter(is_extern, externs_and_deps) 219 externs = filter(is_extern, externs_and_deps)
220 deps = filter(lambda f: not is_extern(f), externs_and_deps) 220 deps = filter(lambda f: not is_extern(f), externs_and_deps)
221 221
222 assert externs or deps or self._target 222 assert externs or deps or self._target
223 223
224 self._log_debug("Externs: %s" % externs) 224 self._log_debug("Externs: %s" % externs)
225 self._log_debug("Dependencies: %s" % deps) 225 self._log_debug("Dependencies: %s" % deps)
226 self._log_debug("Target: %s" % self._target) 226 self._log_debug("Target: %s" % self._target)
227 227
228 js_args = deps + [self._target] if self._target else [] 228 js_args = deps + ([self._target] if self._target else [])
229 229
230 if not custom_sources: 230 if not custom_sources:
231 # TODO(dbeam): compiler.jar automatically detects "@externs" in a --js arg 231 # TODO(dbeam): compiler.jar automatically detects "@externs" in a --js arg
232 # and moves these files to a different AST tree. However, because we use 232 # and moves these files to a different AST tree. However, because we use
233 # one big funky <include> meta-file, it thinks all the code is one big 233 # one big funky <include> meta-file, it thinks all the code is one big
234 # externs. Just use --js when <include> dies. 234 # externs. Just use --js when <include> dies.
235 235
236 cwd, tmp_dir = os.getcwd(), tempfile.gettempdir() 236 cwd, tmp_dir = os.getcwd(), tempfile.gettempdir()
237 rel_path = lambda f: os.path.join(os.path.relpath(cwd, tmp_dir), f) 237 rel_path = lambda f: os.path.join(os.path.relpath(cwd, tmp_dir), f)
238 contents = ['<include src="%s">' % rel_path(f) for f in js_args] 238 contents = ['<include src="%s">' % rel_path(f) for f in js_args]
(...skipping 26 matching lines...) Expand all
265 args_file = self._create_temp_file(args_file_content) 265 args_file = self._create_temp_file(args_file_content)
266 self._log_debug("Args file: %s" % args_file) 266 self._log_debug("Args file: %s" % args_file)
267 267
268 runner_args = ["--%s" % arg for arg in runner_args or []] 268 runner_args = ["--%s" % arg for arg in runner_args or []]
269 runner_args += ["--compiler-args-file=%s" % args_file] 269 runner_args += ["--compiler-args-file=%s" % args_file]
270 _, stderr = self._run_jar(self._runner_jar, runner_args) 270 _, stderr = self._run_jar(self._runner_jar, runner_args)
271 271
272 errors = stderr.strip().split("\n\n") 272 errors = stderr.strip().split("\n\n")
273 maybe_summary = errors.pop() 273 maybe_summary = errors.pop()
274 274
275 if re.search(".*error.*warning.*typed", maybe_summary): 275 summary = re.search("(?P<error_count>\d+).*error.*warning", maybe_summary)
276 if summary:
276 self._log_debug("Summary: %s" % maybe_summary) 277 self._log_debug("Summary: %s" % maybe_summary)
277 else: 278 else:
278 # Not a summary. Running the jar failed. Bail. 279 # Not a summary. Running the jar failed. Bail.
279 self._log_error(stderr) 280 self._log_error(stderr)
280 self._nuke_temp_files() 281 self._nuke_temp_files()
281 sys.exit(1) 282 sys.exit(1)
282 283
283 if errors and out_file: 284 if summary.group('error_count') != "0" and out_file:
284 if os.path.exists(out_file): 285 if os.path.exists(out_file):
285 os.remove(out_file) 286 os.remove(out_file)
286 if os.path.exists(self._MAP_FILE_FORMAT % out_file): 287 if os.path.exists(self._MAP_FILE_FORMAT % out_file):
287 os.remove(self._MAP_FILE_FORMAT % out_file) 288 os.remove(self._MAP_FILE_FORMAT % out_file)
288 289
289 if not custom_sources: 290 if not custom_sources:
290 filtered_errors = self._filter_errors(errors) 291 filtered_errors = self._filter_errors(errors)
291 errors = map(self._clean_up_error, filtered_errors) 292 errors = map(self._clean_up_error, filtered_errors)
292 output = self._format_errors(errors) 293 output = self._format_errors(errors)
293 294
(...skipping 28 matching lines...) Expand all
322 323
323 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file, 324 found_errors, stderr = checker.check(opts.sources, out_file=opts.out_file,
324 closure_args=opts.closure_args, 325 closure_args=opts.closure_args,
325 runner_args=opts.runner_args, 326 runner_args=opts.runner_args,
326 custom_sources=opts.custom_sources) 327 custom_sources=opts.custom_sources)
327 328
328 if found_errors: 329 if found_errors:
329 if opts.custom_sources: 330 if opts.custom_sources:
330 print stderr 331 print stderr
331 sys.exit(1) 332 sys.exit(1)
OLDNEW
« no previous file with comments | « third_party/closure_compiler/closure_args.gni ('k') | third_party/closure_compiler/js_minify.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698