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

Unified Diff: third_party/closure_compiler/compile.py

Issue 1112403006: Add a flag to the compiler for compiling polymer code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address dbeam's comments Created 5 years, 7 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
« no previous file with comments | « no previous file | third_party/closure_compiler/compile_js.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/closure_compiler/compile.py
diff --git a/third_party/closure_compiler/compile.py b/third_party/closure_compiler/compile.py
index b40dcfc962f0dae97c82b16825b4604e2f056f15..90c114fe5360f47615b30b964bcde49c87e0b0dd 100755
--- a/third_party/closure_compiler/compile.py
+++ b/third_party/closure_compiler/compile.py
@@ -17,36 +17,58 @@ import build.inputs
import processor
import error_filter
+CURRENT_DIR = os.path.join(os.path.dirname(__file__))
Dan Beam 2015/05/12 04:22:37 _CURRENT_DIR
Jeremy Klein 2015/05/12 04:47:49 Done.
+
class Checker(object):
"""Runs the Closure compiler on given source files to typecheck them
and produce minified output."""
+ _COMMON_JSCOMP_ERROR = [
Dan Beam 2015/05/12 04:22:37 I don't think you really need _COMMON unless there
Jeremy Klein 2015/05/12 04:47:49 There are a few in _STRICT_CLOSURE_ARGS. Worth do
+ "accessControls",
+ "ambiguousFunctionDecl",
+ "checkStructDictInheritance",
+ "checkTypes",
+ "checkVars",
+ "constantProperty",
+ "deprecated",
+ "externsValidation",
+ "globalThis",
+ "invalidCasts",
+ "missingProperties",
+ "missingReturn",
+ "nonStandardJsDocs",
+ "suspiciousCode",
+ "undefinedNames",
+ "undefinedVars",
+ "unknownDefines",
+ "uselessCode",
+ "visibility",
+ ]
+
_COMMON_CLOSURE_ARGS = [
"--accept_const_keyword",
- "--jscomp_error=accessControls",
- "--jscomp_error=ambiguousFunctionDecl",
- "--jscomp_error=checkStructDictInheritance",
- "--jscomp_error=checkTypes",
- "--jscomp_error=checkVars",
- "--jscomp_error=constantProperty",
- "--jscomp_error=deprecated",
- "--jscomp_error=externsValidation",
- "--jscomp_error=globalThis",
- "--jscomp_error=invalidCasts",
- "--jscomp_error=missingProperties",
- "--jscomp_error=missingReturn",
- "--jscomp_error=nonStandardJsDocs",
- "--jscomp_error=suspiciousCode",
- "--jscomp_error=undefinedNames",
- "--jscomp_error=undefinedVars",
- "--jscomp_error=unknownDefines",
- "--jscomp_error=uselessCode",
- "--jscomp_error=visibility",
"--language_in=ECMASCRIPT5_STRICT",
"--summary_detail_level=3",
"--compilation_level=SIMPLE_OPTIMIZATIONS",
"--source_map_format=V3",
+ ] + ["--jscomp_error=%s" % err for err in _COMMON_JSCOMP_ERROR]
+
+ # Extra flags used when compiling polymer code.
Dan Beam 2015/05/12 04:22:37 Extra @jsDocAnnotations used when compiling Polyme
Jeremy Klein 2015/05/12 04:47:49 Done.
+ _POLYMER_EXTRA_ANNOTATIONS = [
+ "attribute",
+ "status",
+ "element",
+ "homepage",
+ "submodule",
+ "group",
+ ]
+
+ _POLYMER_ARGS = [
+ "--polymer_pass",
+ ] + [
+ "--extra_annotation_name=%s" % annotation for annotation in
+ _POLYMER_EXTRA_ANNOTATIONS
Dan Beam 2015/05/12 04:22:37 2 "annotations" in the same line (e.g. "--extra
Jeremy Klein 2015/05/12 04:47:49 Done.
]
# These are the extra flags used when compiling in strict mode.
@@ -75,17 +97,18 @@ class Checker(object):
_MAP_FILE_FORMAT = "%s.map"
- def __init__(self, verbose=False, strict=False):
+ def __init__(self, verbose=False, strict=False, polymer=False):
"""
Args:
verbose: Whether this class should output diagnostic messages.
strict: Whether the Closure Compiler should be invoked more strictly.
+ polymer: Whether the Polymer pass is being run.
Dan Beam 2015/05/12 04:22:37 polymer: Whether the code requires Polymer support
Jeremy Klein 2015/05/12 04:47:49 Removed.
"""
- current_dir = os.path.join(os.path.dirname(__file__))
- self._runner_jar = os.path.join(current_dir, "runner", "runner.jar")
+ self._runner_jar = os.path.join(CURRENT_DIR, "runner", "runner.jar")
self._temp_files = []
self._verbose = verbose
self._strict = strict
+ self._polymer = polymer
self._error_filter = error_filter.PromiseErrorFilter()
def _nuke_temp_files(self):
@@ -259,6 +282,9 @@ class Checker(object):
if output_wrapper:
args += ['--output_wrapper="%s"' % output_wrapper]
+ if self._polymer:
+ args += self._POLYMER_ARGS
+
args_file_content = " %s" % " ".join(self._common_args() + args)
self._log_debug("Args: %s" % args_file_content.strip())
@@ -382,6 +408,8 @@ if __name__ == "__main__":
help="Show more information as this script runs")
parser.add_argument("--strict", action="store_true",
help="Enable strict type checking")
+ parser.add_argument("-p", "--polymer", type=int,
+ help="'1' to run polymer-specific checks.")
parser.add_argument("--success-stamp",
help="Timestamp file to update upon success")
@@ -389,14 +417,21 @@ if __name__ == "__main__":
opts = parser.parse_args()
depends = opts.depends or []
- externs = opts.externs or set()
+ externs = set(opts.externs) or set()
+
+ if opts.polymer:
+ polymer_externs = os.path.join(CURRENT_DIR, os.pardir, 'polymer',
+ 'v0_8', 'components-chromium',
+ 'polymer-externs', 'polymer.externs.js')
+ externs.add(os.path.abspath(polymer_externs))
if opts.out_file:
out_dir = os.path.dirname(opts.out_file)
if not os.path.exists(out_dir):
os.makedirs(out_dir)
- checker = Checker(verbose=opts.verbose, strict=opts.strict)
+ checker = Checker(verbose=opts.verbose, strict=opts.strict,
+ polymer=opts.polymer)
if opts.single_file:
for source in opts.sources:
depends, externs = build.inputs.resolve_recursive_dependencies(
« no previous file with comments | « no previous file | third_party/closure_compiler/compile_js.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698