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

Unified Diff: third_party/closure_compiler/compile.py

Issue 1152583011: Refactor compile_js.gypi to support script_args and closure_args (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: app_remoting_webapp gyp stuff Created 5 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 side-by-side diff with in-line comments
Download patch
Index: third_party/closure_compiler/compile.py
diff --git a/third_party/closure_compiler/compile.py b/third_party/closure_compiler/compile.py
index 0b1ddee32885bd9592d9fedfb2752f38fad6d442..66b93bb97359212294e17ec513ced7dbb7e0d2c2 100755
--- a/third_party/closure_compiler/compile.py
+++ b/third_party/closure_compiler/compile.py
@@ -25,67 +25,6 @@ class Checker(object):
"""Runs the Closure compiler on given source files to typecheck them
and produce minified output."""
- _COMMON_JSCOMP_ERRORS = [
- "accessControls",
- "ambiguousFunctionDecl",
- "checkStructDictInheritance",
- "checkTypes",
- "checkVars",
- "constantProperty",
- "deprecated",
- "externsValidation",
- "globalThis",
- "invalidCasts",
- "missingProperties",
- "missingReturn",
- "nonStandardJsDocs",
- "suspiciousCode",
- "undefinedNames",
- "undefinedVars",
- "unknownDefines",
- "uselessCode",
- "visibility",
- ]
-
- # Extra @jsDocAnnotations used when compiling polymer code.
- _POLYMER_EXTRA_ANNOTATIONS = [
- "attribute",
- "status",
- "element",
- "homepage",
- "submodule",
- "group",
- ]
-
- _COMMON_CLOSURE_ARGS = [
- "--accept_const_keyword",
- "--language_in=ECMASCRIPT5_STRICT",
- "--summary_detail_level=3",
- "--compilation_level=SIMPLE_OPTIMIZATIONS",
- "--source_map_format=V3",
- "--polymer_pass",
- ] + [
- "--jscomp_error=%s" % err for err in _COMMON_JSCOMP_ERRORS
- ] + [
- "--extra_annotation_name=%s" % a for a in _POLYMER_EXTRA_ANNOTATIONS
- ]
-
- # These are the extra flags used when compiling in strict mode.
- # Flags that are normally disabled are turned on for strict mode.
- _STRICT_CLOSURE_ARGS = [
- "--jscomp_error=reportUnknownTypes",
- "--jscomp_error=duplicate",
- "--jscomp_error=misplacedTypeAnnotation",
- ]
-
- _DISABLED_CLOSURE_ARGS = [
- # TODO(dbeam): happens when the same file is <include>d multiple times.
- "--jscomp_off=duplicate",
- # TODO(fukino): happens when cr.defineProperty() has a type annotation.
- # Avoiding parse-time warnings needs 2 pass compiling. crbug.com/421562.
Dan Beam 2015/06/12 21:45:06 where did these comments go?
Theresa 2015/06/12 22:12:15 Added back in closure_args.gypi.
- "--jscomp_off=misplacedTypeAnnotation",
- ]
-
_JAR_COMMAND = [
"java",
"-jar",
@@ -135,12 +74,6 @@ class Checker(object):
"""
print >> sys.stderr, "(ERROR) %s" % msg
- def _common_args(self):
- """Returns an array of the common closure compiler args."""
- if self._strict:
- return self._COMMON_CLOSURE_ARGS + self._STRICT_CLOSURE_ARGS
- return self._COMMON_CLOSURE_ARGS + self._DISABLED_CLOSURE_ARGS
-
def _run_jar(self, jar, args):
"""Runs a .jar from the command line with arguments.
@@ -253,15 +186,14 @@ class Checker(object):
return tmp_file.name
def _run_js_check(self, sources, out_file=None, externs=None,
- output_wrapper=None):
+ closure_args=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%.
+ closure_args: Arguments passed directly to the Closure compiler.
Returns:
(errors, stderr) A parsed list of errors (strings) found by the compiler
@@ -279,10 +211,11 @@ class Checker(object):
if externs:
args += ["--externs=%s" % e for e in externs]
- if output_wrapper:
- args += ['--output_wrapper="%s"' % output_wrapper]
+ if closure_args:
+ for arg in closure_args:
+ args += ["--%s" % arg]
Dan Beam 2015/06/12 21:45:06 args += ["--%s" % arg for arg in closure_args]
Theresa 2015/06/12 22:12:15 Done.
- args_file_content = " %s" % " ".join(self._common_args() + args)
+ args_file_content = " %s" % " ".join(args)
self._log_debug("Args: %s" % args_file_content.strip())
args_file = self._create_temp_file(args_file_content)
@@ -311,7 +244,7 @@ class Checker(object):
return errors, stderr
def check(self, source_file, out_file=None, depends=None, externs=None,
- output_wrapper=None):
+ closure_args=None):
"""Closure compiler |source_file| while checking for errors.
Args:
@@ -319,8 +252,7 @@ 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%.
+ closure_args: Arguments passed directly to the Closure compiler.
Returns:
(found_errors, stderr) A boolean indicating whether errors were found and
@@ -349,7 +281,7 @@ class Checker(object):
errors, stderr = self._run_js_check([self._expanded_file],
out_file=out_file, externs=externs,
- output_wrapper=output_wrapper)
+ closure_args=closure_args)
filtered_errors = self._filter_errors(errors)
cleaned_errors = map(self._clean_up_error, filtered_errors)
output = self._format_errors(cleaned_errors)
@@ -363,24 +295,23 @@ class Checker(object):
self._nuke_temp_files()
return bool(cleaned_errors), stderr
- def check_multiple(self, sources, out_file=None, output_wrapper=None,
- externs=None):
+ def check_multiple(self, sources, out_file=None, externs=None,
+ closure_args=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%.
externs: @extern files that inform the compiler about custom globals.
+ closure_args: Arguments passed directly to the Closure compiler.
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, out_file=out_file,
- output_wrapper=output_wrapper,
- externs=externs)
+ externs=externs,
+ closure_args=closure_args)
self._nuke_temp_files()
return bool(errors), stderr
@@ -399,17 +330,13 @@ if __name__ == "__main__":
help="Process all source files as a group")
parser.add_argument("-d", "--depends", nargs=argparse.ZERO_OR_MORE)
parser.add_argument("-e", "--externs", nargs=argparse.ZERO_OR_MORE)
- parser.add_argument("-o", "--out_file",
+ parser.add_argument("-o", "--out-file", dest="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("-c", "--closure-args", dest="closure_args",
+ nargs=argparse.ZERO_OR_MORE,
+ help="Arguments passed directly to the Closure compiler")
parser.add_argument("-v", "--verbose", action="store_true",
help="Show more information as this script runs")
- parser.add_argument("--strict", action="store_true",
- help="Enable strict type checking")
- parser.add_argument("--success-stamp",
- help="Timestamp file to update upon success")
parser.set_defaults(single_file=True, strict=False)
opts = parser.parse_args()
@@ -429,19 +356,15 @@ if __name__ == "__main__":
source, depends, externs)
found_errors, _ = checker.check(source, out_file=opts.out_file,
depends=depends, externs=externs,
- output_wrapper=opts.output_wrapper)
+ closure_args=opts.closure_args)
if found_errors:
sys.exit(1)
else:
found_errors, stderr = checker.check_multiple(
opts.sources,
out_file=opts.out_file,
- output_wrapper=opts.output_wrapper,
- externs=externs)
+ externs=externs,
+ closure_args=opts.closure_args)
if found_errors:
print stderr
sys.exit(1)
-
- if opts.success_stamp:
- with open(opts.success_stamp, "w"):
- os.utime(opts.success_stamp, None)

Powered by Google App Engine
This is Rietveld 408576698