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

Unified Diff: third_party/closure_compiler/checker.py

Issue 958383003: Output closure-compiled JavaScript files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Always generate source map if minified js is output Created 5 years, 10 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/checker.py
diff --git a/third_party/closure_compiler/checker.py b/third_party/closure_compiler/checker.py
index 2eb9e68a21f606fc41e3e6ba4859649483138d13..bdf4eca5842b3928d227ca984020b8280450d552 100755
--- a/third_party/closure_compiler/checker.py
+++ b/third_party/closure_compiler/checker.py
@@ -44,6 +44,7 @@ class Checker(object):
"--jscomp_error=visibility",
"--language_in=ECMASCRIPT5_STRICT",
"--summary_detail_level=3",
+ '--compilation_level=WHITESPACE_ONLY'
Dan Beam 2015/03/06 02:57:29 ' -> "
Dan Beam 2015/03/06 02:57:29 nit: trailing ,
Theresa 2015/03/06 18:09:19 Done.
Theresa 2015/03/06 18:09:19 Done.
]
# These are the extra flags used when compiling in 'strict' mode.
@@ -177,11 +178,18 @@ class Checker(object):
tmp_file.write(contents)
return tmp_file.name
- def run_js_check(self, sources, externs=None):
+ def run_js_check(self, sources, externs=None, out_file=None,
Dan Beam 2015/03/06 02:57:29 i think if the code will be modified, there should
Theresa 2015/03/06 03:07:19 Right now, the out_file is never empty. I'll look
Dan Beam 2015/03/06 03:41:38 why not just write the output for all files?
+ generate_output=False):
if not self._check_java_path():
return 1, ""
args = ["--js=%s" % s for s in sources]
+
+ if generate_output:
+ args += ["--js_output_file=%s" % out_file]
+ args += ["--source_map_format=V3"]
+ args += ["--create_source_map=%s.map" % out_file]
+
if externs:
args += ["--externs=%s" % e for e in externs]
args_file_content = " %s" % " ".join(self._common_args() + args)
@@ -201,7 +209,8 @@ class Checker(object):
return errors, stderr
- def check(self, source_file, depends=None, externs=None):
+ def check(self, source_file, depends=None, externs=None,
+ out_file=None, generate_output=False):
"""Closure compile a file and check for errors.
Args:
@@ -240,7 +249,8 @@ class Checker(object):
self._expanded_file = self._create_temp_file(self._processor.contents)
self._debug("Expanded file: %s" % self._expanded_file)
- errors, stderr = self.run_js_check([self._expanded_file], externs)
+ errors, stderr = self.run_js_check([self._expanded_file], externs,
+ out_file, generate_output)
# Filter out false-positive promise chain errors.
# See https://github.com/google/closure-compiler/issues/715 for details.
@@ -284,6 +294,8 @@ if __name__ == "__main__":
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", help="A place to output results")
+ parser.add_argument("-g", "--generate_output",
+ help="Whether or not an output file should be generated")
parser.add_argument("-v", "--verbose", action="store_true",
help="Show more information as this script runs")
parser.add_argument("--strict", action="store_true",
@@ -296,6 +308,16 @@ if __name__ == "__main__":
depends = opts.depends or []
externs = opts.externs or set()
+ generate_output = False if (opts.generate_output == '0') else True
Dan Beam 2015/03/06 02:57:29 False if (condition) else True => can always be sh
+
+ # Clean up intermediate folders that get created by output.py or create the dirs if needed
Dan Beam 2015/03/06 02:57:29 end with .
Dan Beam 2015/03/06 02:57:29 80 col wrap
+ out_dir = os.path.dirname(opts.out_file)
+ if not generate_output:
+ if os.path.exists(out_dir) and os.listdir(out_dir) == []:
Dan Beam 2015/03/06 02:57:29 why are we making empty directories?
Theresa 2015/03/06 03:07:19 I think output.py is creating them when it generat
+ os.removedirs(out_dir)
+ else:
+ if not os.path.exists(out_dir):
+ os.makedirs(out_dir)
Dan Beam 2015/03/06 02:57:28 so closure doesn't do this automatically? make a
Theresa 2015/03/06 03:07:19 It might. I'll try removing this. I had copied it
checker = Checker(verbose=opts.verbose, strict=opts.strict)
if opts.single_file:
@@ -304,16 +326,11 @@ if __name__ == "__main__":
source,
depends,
externs)
- has_errors, _ = checker.check(source, depends=depends, externs=externs)
+ has_errors, _ = checker.check(source, depends=depends, externs=externs,
+ out_file=opts.out_file, generate_output=generate_output)
Dan Beam 2015/03/06 02:57:29 80 col wrap
if has_errors:
sys.exit(1)
- if opts.out_file:
- out_dir = os.path.dirname(opts.out_file)
- if not os.path.exists(out_dir):
- os.makedirs(out_dir)
- # TODO(dbeam): write compiled file to |opts.out_file|.
- open(opts.out_file, "w").write("")
else:
has_errors, errors = checker.check_multiple(opts.sources)
if has_errors:

Powered by Google App Engine
This is Rietveld 408576698