diff options
author | jlklein <jlklein@chromium.org> | 2015-05-12 13:38:18 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-12 20:38:29 +0000 |
commit | 0216cb3dd6369731c269304f04279914d0a39682 (patch) | |
tree | 019cb44efd265ec57448fc1e0b02454c80cc80f0 /third_party | |
parent | fbb6296bee4b2c8fe50ddc2df53ca580560815f6 (diff) | |
download | chromium_src-0216cb3dd6369731c269304f04279914d0a39682.zip chromium_src-0216cb3dd6369731c269304f04279914d0a39682.tar.gz chromium_src-0216cb3dd6369731c269304f04279914d0a39682.tar.bz2 |
Add a flag to the compiler for compiling polymer code.
Note that I did not add the checkbox compiled_resources.gyp to third_party/closure_compiler/compiled_resources.gyp because there are still some errors to dig through.
BUG=486240
Review URL: https://codereview.chromium.org/1112403006
Cr-Commit-Position: refs/heads/master@{#329476}
Diffstat (limited to 'third_party')
-rwxr-xr-x | third_party/closure_compiler/compile.py | 79 |
1 files changed, 54 insertions, 25 deletions
diff --git a/third_party/closure_compiler/compile.py b/third_party/closure_compiler/compile.py index b40dcfc..091a847 100755 --- a/third_party/closure_compiler/compile.py +++ b/third_party/closure_compiler/compile.py @@ -18,35 +18,56 @@ import processor import error_filter +_CURRENT_DIR = os.path.join(os.path.dirname(__file__)) + + 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", - "--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", + "--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. @@ -81,8 +102,7 @@ class Checker(object): verbose: Whether this class should output diagnostic messages. strict: Whether the Closure Compiler should be invoked more strictly. """ - 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 @@ -340,7 +360,8 @@ class Checker(object): self._nuke_temp_files() return bool(cleaned_errors), stderr - def check_multiple(self, sources, out_file=None, output_wrapper=None): + def check_multiple(self, sources, out_file=None, output_wrapper=None, + externs=None): """Closure compile a set of files and check for errors. Args: @@ -348,13 +369,15 @@ class Checker(object): 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. 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) + output_wrapper=output_wrapper, + externs=externs) self._nuke_temp_files() return bool(errors), stderr @@ -389,7 +412,12 @@ if __name__ == "__main__": opts = parser.parse_args() depends = opts.depends or [] - externs = opts.externs or set() + externs = set(opts.externs or []) + + polymer_externs = os.path.join(os.path.dirname(_CURRENT_DIR), 'polymer', + 'v0_8', 'components-chromium', + 'polymer-externs', 'polymer.externs.js') + externs.add(polymer_externs) if opts.out_file: out_dir = os.path.dirname(opts.out_file) @@ -410,7 +438,8 @@ if __name__ == "__main__": found_errors, stderr = checker.check_multiple( opts.sources, out_file=opts.out_file, - output_wrapper=opts.output_wrapper) + output_wrapper=opts.output_wrapper, + externs=externs) if found_errors: print stderr sys.exit(1) |