summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortwellington <twellington@chromium.org>2015-04-20 09:27:50 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-20 16:27:55 +0000
commit80cb4aa26112660ad65459ee618a1eac9fd5676b (patch)
tree76a033275f2e3dc3492e7a2f040147ab7053928d
parent1f550594c57c70c4e63c8c40093efe0018e38f3e (diff)
downloadchromium_src-80cb4aa26112660ad65459ee618a1eac9fd5676b.zip
chromium_src-80cb4aa26112660ad65459ee618a1eac9fd5676b.tar.gz
chromium_src-80cb4aa26112660ad65459ee618a1eac9fd5676b.tar.bz2
Add --output_wrapper support to checker.py and Runner.java
Modify Runner.java to understand quoted args and add optional --output_wrapper argument to checker.py BUG=393874 Review URL: https://codereview.chromium.org/1081073002 Cr-Commit-Position: refs/heads/master@{#325856}
-rw-r--r--remoting/app_remoting_webapp.gyp6
-rw-r--r--remoting/remoting_key_tester.gypi2
-rw-r--r--remoting/remoting_webapp_compile.gypi6
-rwxr-xr-xthird_party/closure_compiler/compile.py (renamed from third_party/closure_compiler/checker.py)42
-rw-r--r--third_party/closure_compiler/compile_js.gypi4
-rw-r--r--third_party/closure_compiler/runner/runner.jarbin18456 -> 19195 bytes
-rw-r--r--third_party/closure_compiler/runner/src/org/chromium/closure/compiler/Runner.java26
7 files changed, 66 insertions, 20 deletions
diff --git a/remoting/app_remoting_webapp.gyp b/remoting/app_remoting_webapp.gyp
index 9b0b04a..9c8add8 100644
--- a/remoting/app_remoting_webapp.gyp
+++ b/remoting/app_remoting_webapp.gyp
@@ -31,7 +31,7 @@
'<(success_stamp)',
],
'action': [
- 'python', '../third_party/closure_compiler/checker.py',
+ 'python', '../third_party/closure_compiler/compile.py',
'--strict',
'--no-single-file',
'--success-stamp', '<(success_stamp)',
@@ -54,7 +54,7 @@
'<(success_stamp)',
],
'action': [
- 'python', '../third_party/closure_compiler/checker.py',
+ 'python', '../third_party/closure_compiler/compile.py',
'--strict',
'--no-single-file',
'--success-stamp', '<(success_stamp)',
@@ -77,7 +77,7 @@
'<(success_stamp)',
],
'action': [
- 'python', '../third_party/closure_compiler/checker.py',
+ 'python', '../third_party/closure_compiler/compile.py',
'--strict',
'--no-single-file',
'--success-stamp', '<(success_stamp)',
diff --git a/remoting/remoting_key_tester.gypi b/remoting/remoting_key_tester.gypi
index 68db9b0..7eac507 100644
--- a/remoting/remoting_key_tester.gypi
+++ b/remoting/remoting_key_tester.gypi
@@ -62,7 +62,7 @@
'<(success_stamp)',
],
'action': [
- 'python', '../third_party/closure_compiler/checker.py',
+ 'python', '../third_party/closure_compiler/compile.py',
'--strict',
'--no-single-file',
'--success-stamp', '<(success_stamp)',
diff --git a/remoting/remoting_webapp_compile.gypi b/remoting/remoting_webapp_compile.gypi
index 094ff92..abae2d9 100644
--- a/remoting/remoting_webapp_compile.gypi
+++ b/remoting/remoting_webapp_compile.gypi
@@ -23,7 +23,7 @@
'<(success_stamp)',
],
'action': [
- 'python', '<(DEPTH)/third_party/closure_compiler/checker.py',
+ 'python', '<(DEPTH)/third_party/closure_compiler/compile.py',
'--strict',
'--no-single-file',
'--success-stamp', '<(success_stamp)',
@@ -44,7 +44,7 @@
'<(success_stamp_bt)',
],
'action': [
- 'python', '<(DEPTH)/third_party/closure_compiler/checker.py',
+ 'python', '<(DEPTH)/third_party/closure_compiler/compile.py',
'--strict',
'--no-single-file',
'--success-stamp', '<(success_stamp_bt)',
@@ -66,7 +66,7 @@
'<(success_stamp_ut)',
],
'action': [
- 'python', '<(DEPTH)/third_party/closure_compiler/checker.py',
+ 'python', '<(DEPTH)/third_party/closure_compiler/compile.py',
'--strict',
'--no-single-file',
'--success-stamp', '<(success_stamp_ut)',
diff --git a/third_party/closure_compiler/checker.py b/third_party/closure_compiler/compile.py
index 38473e9..2b2e7f8 100755
--- a/third_party/closure_compiler/checker.py
+++ b/third_party/closure_compiler/compile.py
@@ -3,7 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""Runs Closure compiler on a JavaScript file to check for errors."""
+"""Runs Closure compiler on JavaScript files to check for errors and produce
+minified output."""
import argparse
import os
@@ -18,7 +19,8 @@ import error_filter
class Checker(object):
- """Runs the Closure compiler on a given source file to typecheck it."""
+ """Runs the Closure compiler on given source files to typecheck them
+ and produce minified output."""
_COMMON_CLOSURE_ARGS = [
"--accept_const_keyword",
@@ -228,12 +230,16 @@ class Checker(object):
tmp_file.write(contents)
return tmp_file.name
- def _run_js_check(self, sources, out_file=None, externs=None):
+ def _run_js_check(self, sources, out_file=None, externs=None,
+ output_wrapper=None):
"""Check |sources| for type errors.
Args:
sources: Files to check.
+ out_file: A file where the compiled output is written to.
externs: @extern files that inform the compiler about custom globals.
+ output_wrapper: Wraps output into this string at the place denoted by the
+ marker token %output%.
Returns:
(errors, stderr) A parsed list of errors (strings) found by the compiler
@@ -248,6 +254,9 @@ class Checker(object):
if externs:
args += ["--externs=%s" % e for e in externs]
+ if output_wrapper:
+ args += ['--output_wrapper="%s"' % output_wrapper]
+
args_file_content = " %s" % " ".join(self._common_args() + args)
self._log_debug("Args: %s" % args_file_content.strip())
@@ -270,7 +279,8 @@ class Checker(object):
return errors, stderr
- def check(self, source_file, out_file=None, depends=None, externs=None):
+ def check(self, source_file, out_file=None, depends=None, externs=None,
+ output_wrapper=None):
"""Closure compiler |source_file| while checking for errors.
Args:
@@ -278,6 +288,8 @@ class Checker(object):
out_file: A file where the compiled output is written to.
depends: Files that |source_file| requires to run (e.g. earlier <script>).
externs: @extern files that inform the compiler about custom globals.
+ output_wrapper: Wraps output into this string at the place denoted by the
+ marker token %output%.
Returns:
(found_errors, stderr) A boolean indicating whether errors were found and
@@ -305,7 +317,8 @@ class Checker(object):
self._log_debug("Expanded file: %s" % self._expanded_file)
errors, stderr = self._run_js_check([self._expanded_file],
- out_file=out_file, externs=externs)
+ out_file=out_file, externs=externs,
+ output_wrapper=output_wrapper)
filtered_errors = self._filter_errors(errors)
fixed_errors = map(self._fix_up_error, filtered_errors)
output = self._format_errors(fixed_errors)
@@ -319,17 +332,21 @@ class Checker(object):
self._clean_up()
return bool(fixed_errors), stderr
- def check_multiple(self, sources):
+ def check_multiple(self, sources, out_file=None, output_wrapper=None):
"""Closure compile a set of files and check for errors.
Args:
sources: An array of files to check.
+ out_file: A file where the compiled output is written to.
+ output_wrapper: Wraps output into this string at the place denoted by the
+ marker token %output%.
Returns:
(found_errors, stderr) A boolean indicating whether errors were found and
the raw Closure Compiler stderr (as a string).
"""
- errors, stderr = self._run_js_check(sources, [])
+ errors, stderr = self._run_js_check(sources, out_file=out_file,
+ output_wrapper=output_wrapper)
self._clean_up()
return bool(errors), stderr
@@ -350,6 +367,9 @@ if __name__ == "__main__":
parser.add_argument("-e", "--externs", nargs=argparse.ZERO_OR_MORE)
parser.add_argument("-o", "--out_file",
help="A file where the compiled output is written to")
+ parser.add_argument("-w", "--output_wrapper",
+ help="Wraps output into this string at the place"
+ + " denoted by the marker token %output%")
parser.add_argument("-v", "--verbose", action="store_true",
help="Show more information as this script runs")
parser.add_argument("--strict", action="store_true",
@@ -374,11 +394,15 @@ if __name__ == "__main__":
depends, externs = build.inputs.resolve_recursive_dependencies(
source, depends, externs)
found_errors, _ = checker.check(source, out_file=opts.out_file,
- depends=depends, externs=externs)
+ depends=depends, externs=externs,
+ output_wrapper=opts.output_wrapper)
if found_errors:
sys.exit(1)
else:
- found_errors, stderr = checker.check_multiple(opts.sources)
+ found_errors, stderr = checker.check_multiple(
+ opts.sources,
+ out_file=opts.out_file,
+ output_wrapper=opts.output_wrapper)
if found_errors:
print stderr
sys.exit(1)
diff --git a/third_party/closure_compiler/compile_js.gypi b/third_party/closure_compiler/compile_js.gypi
index f1c73f5..b97b2ac 100644
--- a/third_party/closure_compiler/compile_js.gypi
+++ b/third_party/closure_compiler/compile_js.gypi
@@ -20,7 +20,7 @@
},
'inputs': [
'compile_js.gypi',
- '<(CLOSURE_DIR)/checker.py',
+ '<(CLOSURE_DIR)/compile.py',
'<(CLOSURE_DIR)/processor.py',
'<(CLOSURE_DIR)/build/inputs.py',
'<(CLOSURE_DIR)/build/outputs.py',
@@ -33,7 +33,7 @@
],
'action': [
'python',
- '<(CLOSURE_DIR)/checker.py',
+ '<(CLOSURE_DIR)/compile.py',
'<(source_file)',
'--depends', '<@(depends)',
'--externs', '<@(externs)',
diff --git a/third_party/closure_compiler/runner/runner.jar b/third_party/closure_compiler/runner/runner.jar
index 4688623..2412698 100644
--- a/third_party/closure_compiler/runner/runner.jar
+++ b/third_party/closure_compiler/runner/runner.jar
Binary files differ
diff --git a/third_party/closure_compiler/runner/src/org/chromium/closure/compiler/Runner.java b/third_party/closure_compiler/runner/src/org/chromium/closure/compiler/Runner.java
index c79d13a..77a03c2 100644
--- a/third_party/closure_compiler/runner/src/org/chromium/closure/compiler/Runner.java
+++ b/third_party/closure_compiler/runner/src/org/chromium/closure/compiler/Runner.java
@@ -19,6 +19,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
+import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -237,8 +238,29 @@ public class Runner {
}
private String[] prepareArgs() {
- // FIXME: This does not support quoted arguments.
- return descriptor.commandLine.split(" +");
+ Pattern quotedArgsPattern = Pattern.compile("(--\\S*=['\"][^'\"]*['\"])");
+ Matcher quotedArgsMatcher = quotedArgsPattern.matcher(descriptor.commandLine);
+
+ // Find all quoted args and add them to an ArrayList.
+ ArrayList<String> quotedArgs = new ArrayList<String>();
+ while (quotedArgsMatcher.find()) {
+ quotedArgs.add(quotedArgsMatcher.group());
+ }
+
+ // Remove all quoted args from the original descriptor.commandLine String.
+ String nonQuotedArgsString = quotedArgsMatcher.replaceAll("");
+
+ // Split the nonQuotedArgsString to create an ArrayList of the non-quoted args.
+ ArrayList<String> args = new ArrayList<String>(
+ Arrays.asList(nonQuotedArgsString.split(" +")));
+
+ // Add the quotedArgs to the args ArrayList (consolidate).
+ args.addAll(quotedArgs);
+
+ // Transform the args ArrayList into a String[] and return.
+ String[] result = new String[args.size()];
+ args.toArray(result);
+ return result;
}
}