1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
|
description: add upstream files mistakenly missing from the -lite tarball
author: Michael Gilbert <[email protected]>
--- /dev/null
+++ b/third_party/closure_compiler/js_library.py
@@ -0,0 +1,37 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""Generates a file describing the js_library to be used by js_binary action.
+
+This script takes in a list of sources and dependencies as described by a
+js_library action. It creates a file listing the sources and dependencies
+that can later be used by a js_binary action to compile the javascript.
+"""
+
+from argparse import ArgumentParser
+
+
+def main():
+ parser = ArgumentParser()
+ parser.add_argument('-s', '--sources', nargs='*', default=[],
+ help='List of js source files')
+ parser.add_argument('-e', '--externs', nargs='*', default=[],
+ help='List of js source files')
+ parser.add_argument('-o', '--output', help='Write list to output')
+ parser.add_argument('-d', '--deps', nargs='*', default=[],
+ help='List of js_library dependencies')
+ args = parser.parse_args()
+
+ with open(args.output, 'w') as out:
+ out.write('sources:\n')
+ for s in args.sources:
+ out.write('%s\n' % s)
+ out.write('deps:\n')
+ for d in args.deps:
+ out.write('%s\n' % d)
+ out.write('externs:\n')
+ for e in args.externs:
+ out.write('%s\n' % e)
+
+if __name__ == '__main__':
+ main()
--- /dev/null
+++ b/third_party/closure_compiler/compiler.py
@@ -0,0 +1,314 @@
+#!/usr/bin/python2
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Runs Closure compiler on JavaScript files to check for errors and produce
+minified output."""
+
+import argparse
+import os
+import re
+import subprocess
+import sys
+import tempfile
+
+import processor
+
+
+_CURRENT_DIR = os.path.join(os.path.dirname(__file__))
+_JAVA_BIN = "java"
+_JDK_PATH = os.path.join(_CURRENT_DIR, "..", "jdk", "current", "bin", _JAVA_BIN)
+_JAVA_PATH = _JDK_PATH if os.path.isfile(_JDK_PATH) else _JAVA_BIN
+
+
+class Compiler(object):
+ """Runs the Closure compiler on given source files to typecheck them
+ and produce minified output."""
+
+ _JAR_COMMAND = [
+ _JAVA_PATH,
+ "-jar",
+ "-Xms1024m",
+ "-client",
+ "-XX:+TieredCompilation",
+ ]
+
+ _POLYMER_EXTERNS = os.path.join(_CURRENT_DIR, "externs", "polymer-1.0.js")
+
+ def __init__(self, verbose=False):
+ """
+ Args:
+ verbose: Whether this class should output diagnostic messages.
+ """
+ self._compiler_jar = os.path.join(_CURRENT_DIR, "compiler", "compiler.jar")
+ self._target = None
+ self._temp_files = []
+ self._verbose = verbose
+
+ def _nuke_temp_files(self):
+ """Deletes any temp files this class knows about."""
+ if not self._temp_files:
+ return
+
+ self._log_debug("Deleting temp files: %s" % ", ".join(self._temp_files))
+ for f in self._temp_files:
+ os.remove(f)
+ self._temp_files = []
+
+ def _log_debug(self, msg, error=False):
+ """Logs |msg| to stdout if --verbose/-v is passed when invoking this script.
+
+ Args:
+ msg: A debug message to log.
+ """
+ if self._verbose:
+ print "(INFO) %s" % msg
+
+ def _log_error(self, msg):
+ """Logs |msg| to stderr regardless of --flags.
+
+ Args:
+ msg: An error message to log.
+ """
+ print >> sys.stderr, "(ERROR) %s" % msg
+
+ def run_jar(self, jar, args):
+ """Runs a .jar from the command line with arguments.
+
+ Args:
+ jar: A file path to a .jar file
+ args: A list of command line arguments to be passed when running the .jar.
+
+ Return:
+ (exit_code, stderr) The exit code of the command (e.g. 0 for success) and
+ the stderr collected while running |jar| (as a string).
+ """
+ shell_command = " ".join(self._JAR_COMMAND + [jar] + args)
+ self._log_debug("Running jar: %s" % shell_command)
+
+ devnull = open(os.devnull, "w")
+ kwargs = {"stdout": devnull, "stderr": subprocess.PIPE, "shell": True}
+ process = subprocess.Popen(shell_command, **kwargs)
+ _, stderr = process.communicate()
+ return process.returncode, stderr
+
+ def _get_line_number(self, match):
+ """When chrome is built, it preprocesses its JavaScript from:
+
+ <include src="blah.js">
+ alert(1);
+
+ to:
+
+ /* contents of blah.js inlined */
+ alert(1);
+
+ Because Closure Compiler requires this inlining already be done (as
+ <include> isn't valid JavaScript), this script creates temporary files to
+ expand all the <include>s.
+
+ When type errors are hit in temporary files, a developer doesn't know the
+ original source location to fix. This method maps from /tmp/file:300 back to
+ /original/source/file:100 so fixing errors is faster for developers.
+
+ Args:
+ match: A re.MatchObject from matching against a line number regex.
+
+ Returns:
+ The fixed up /file and :line number.
+ """
+ real_file = self._processor.get_file_from_line(match.group(1))
+ return "%s:%d" % (os.path.abspath(real_file.file), real_file.line_number)
+
+ def _clean_up_error(self, error):
+ """Reverse the effects that funky <include> preprocessing steps have on
+ errors messages.
+
+ Args:
+ error: A Closure compiler error (2 line string with error and source).
+
+ Return:
+ The fixed up error string.
+ """
+ assert self._target
+ assert self._expanded_file
+ expanded_file = self._expanded_file
+ fixed = re.sub("%s:(\d+)" % expanded_file, self._get_line_number, error)
+ return fixed.replace(expanded_file, os.path.abspath(self._target))
+
+ def _format_errors(self, errors):
+ """Formats Closure compiler errors to easily spot compiler output.
+
+ Args:
+ errors: A list of strings extracted from the Closure compiler's output.
+
+ Returns:
+ A formatted output string.
+ """
+ contents = "\n## ".join("\n\n".join(errors).splitlines())
+ return "## %s" % contents if contents else ""
+
+ def _create_temp_file(self, contents):
+ """Creates an owned temporary file with |contents|.
+
+ Args:
+ content: A string of the file contens to write to a temporary file.
+
+ Return:
+ The filepath of the newly created, written, and closed temporary file.
+ """
+ with tempfile.NamedTemporaryFile(mode="wt", delete=False) as tmp_file:
+ self._temp_files.append(tmp_file.name)
+ tmp_file.write(contents)
+ return tmp_file.name
+
+ def run(self, sources, out_file, closure_args=None,
+ custom_sources=False, custom_includes=False):
+ """Closure compile |sources| while checking for errors.
+
+ Args:
+ sources: Files to compile. sources[0] is the typically the target file.
+ sources[1:] are externs and dependencies in topological order. Order
+ is not guaranteed if custom_sources is True.
+ out_file: A file where the compiled output is written to.
+ closure_args: Arguments passed directly to the Closure compiler.
+ custom_sources: Whether |sources| was customized by the target (e.g. not
+ in GYP dependency order).
+ custom_includes: Whether <include>s are processed when |custom_sources|
+ is True.
+
+ Returns:
+ (found_errors, stderr) A boolean indicating whether errors were found and
+ the raw Closure compiler stderr (as a string).
+ """
+ is_extern = lambda f: 'externs' in f
+ externs_and_deps = [self._POLYMER_EXTERNS]
+
+ if custom_sources:
+ if custom_includes:
+ # TODO(dbeam): this is fairly hacky. Can we just remove custom_sources
+ # soon when all the things kept on life support using it die?
+ self._target = sources.pop()
+ externs_and_deps += sources
+ else:
+ self._target = sources[0]
+ externs_and_deps += sources[1:]
+
+ externs = filter(is_extern, externs_and_deps)
+ deps = filter(lambda f: not is_extern(f), externs_and_deps)
+
+ assert externs or deps or self._target
+
+ self._log_debug("Externs: %s" % externs)
+ self._log_debug("Dependencies: %s" % deps)
+ self._log_debug("Target: %s" % self._target)
+
+ js_args = deps + ([self._target] if self._target else [])
+
+ process_includes = custom_includes or not custom_sources
+ if process_includes:
+ # TODO(dbeam): compiler.jar automatically detects "@externs" in a --js arg
+ # and moves these files to a different AST tree. However, because we use
+ # one big funky <include> meta-file, it thinks all the code is one big
+ # externs. Just use --js when <include> dies.
+
+ cwd, tmp_dir = os.getcwd(), tempfile.gettempdir()
+ rel_path = lambda f: os.path.join(os.path.relpath(cwd, tmp_dir), f)
+ contents = ['<include src="%s">' % rel_path(f) for f in js_args]
+ meta_file = self._create_temp_file("\n".join(contents))
+ self._log_debug("Meta file: %s" % meta_file)
+
+ self._processor = processor.Processor(meta_file)
+ self._expanded_file = self._create_temp_file(self._processor.contents)
+ self._log_debug("Expanded file: %s" % self._expanded_file)
+
+ js_args = [self._expanded_file]
+
+ closure_args = closure_args or []
+ closure_args += ["summary_detail_level=3", "continue_after_errors"]
+
+ args = ["--externs=%s" % e for e in externs] + \
+ ["--js=%s" % s for s in js_args] + \
+ ["--%s" % arg for arg in closure_args]
+
+ assert out_file
+
+ out_dir = os.path.dirname(out_file)
+ if not os.path.exists(out_dir):
+ os.makedirs(out_dir)
+
+ checks_only = 'checks_only' in closure_args
+
+ if not checks_only:
+ args += ["--js_output_file=%s" % out_file]
+
+ self._log_debug("Args: %s" % " ".join(args))
+
+ return_code, stderr = self.run_jar(self._compiler_jar, args)
+
+ errors = stderr.strip().split("\n\n")
+ maybe_summary = errors.pop()
+
+ summary = re.search("(?P<error_count>\d+).*error.*warning", maybe_summary)
+ if summary:
+ self._log_debug("Summary: %s" % maybe_summary)
+ else:
+ # Not a summary. Running the jar failed. Bail.
+ self._log_error(stderr)
+ self._nuke_temp_files()
+ sys.exit(1)
+
+ if summary.group('error_count') != "0":
+ if os.path.exists(out_file):
+ os.remove(out_file)
+ elif checks_only and return_code == 0:
+ # Compile succeeded but --checks_only disables --js_output_file from
+ # actually writing a file. Write a file ourselves so incremental builds
+ # still work.
+ with open(out_file, 'w') as f:
+ f.write('')
+
+ if process_includes:
+ errors = map(self._clean_up_error, errors)
+ output = self._format_errors(errors)
+
+ if errors:
+ prefix = "\n" if output else ""
+ self._log_error("Error in: %s%s%s" % (self._target, prefix, output))
+ elif output:
+ self._log_debug("Output: %s" % output)
+
+ self._nuke_temp_files()
+ return bool(errors) or return_code > 0, stderr
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(
+ description="Typecheck JavaScript using Closure compiler")
+ parser.add_argument("sources", nargs=argparse.ONE_OR_MORE,
+ help="Path to a source file to typecheck")
+ parser.add_argument("--custom_sources", action="store_true",
+ help="Whether this rules has custom sources.")
+ parser.add_argument("--custom_includes", action="store_true",
+ help="If present, <include>s are processed when "
+ "using --custom_sources.")
+ parser.add_argument("-o", "--out_file", required=True,
+ help="A file where the compiled output is written to")
+ parser.add_argument("-c", "--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")
+ opts = parser.parse_args()
+
+ compiler = Compiler(verbose=opts.verbose)
+
+ found_errors, stderr = compiler.run(opts.sources, out_file=opts.out_file,
+ closure_args=opts.closure_args,
+ custom_sources=opts.custom_sources,
+ custom_includes=opts.custom_includes)
+
+ if found_errors:
+ if opts.custom_sources:
+ print stderr
+ sys.exit(1)
--- /dev/null
+++ b/third_party/closure_compiler/externs/mojo_core.js
@@ -0,0 +1,87 @@
+/**
+ * @fileoverview Closure definitions of Mojo core IDL objects only.
+ */
+
+const Mojo = {};
+
+/**
+ * @param {string} name
+ * @param {MojoHandle} handle
+ * @param {string=} scope
+ */
+Mojo.bindInterface = function(name, handle, scope) {};
+
+/** @typedef {number} */
+let MojoResult;
+
+/** @type {!MojoResult} */
+Mojo.RESULT_OK;
+
+/** @type {!MojoResult} */
+Mojo.RESULT_CANCELLED;
+
+/** @type {!MojoResult} */
+Mojo.RESULT_FAILED_PRECONDITION;
+
+/** @type {!MojoResult} */
+Mojo.RESULT_SHOULD_WAIT;
+
+/**
+ * @typedef {{
+ * result: MojoResult,
+ * buffer: !ArrayBuffer,
+ * handles: !Array<MojoHandle>
+ * }}
+ */
+let MojoReadMessageResult;
+
+class MojoWatcher {
+ /** @return {MojoResult} */
+ cancel() {}
+}
+
+/**
+ * @typedef {{
+ * readable: (?boolean|undefined),
+ * writable: (?boolean|undefined),
+ * peerClosed: (?boolean|undefined)
+ * }}
+ */
+let MojoHandleSignals;
+
+class MojoHandle {
+ close() {}
+
+ /**
+ * @return {!MojoReadMessageResult}
+ */
+ readMessage() {}
+
+ /**
+ * @param {!ArrayBuffer} buffer
+ * @param {!Array<MojoHandle>} handles
+ * @return {MojoResult}
+ */
+ writeMessage(buffer, handles) {}
+
+ /**
+ * @param {!MojoHandleSignals} signals
+ * @param {function(MojoResult)} handler
+ * @return {!MojoWatcher}
+ */
+ watch(signals, handler) {}
+};
+
+/**
+ * @typedef {{
+ * result: !MojoResult,
+ * handle0: !MojoHandle,
+ * handle1: !MojoHandle,
+ * }}
+ */
+let MojoCreateMessagePipeResult;
+
+/**
+ * @return {!MojoCreateMessagePipeResult}
+ */
+Mojo.createMessagePipe = function() {}
--- /dev/null
+++ b/third_party/closure_compiler/externs/pending.js
@@ -0,0 +1,85 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview Externs for stuff not added to the Closure compiler yet, but
+ * should get added.
+ * @externs
+ */
+
+/**
+ * TODO(dstockwell): Remove this once it is added to Closure Compiler itself.
+ * @see https://drafts.fxtf.org/geometry/#DOMMatrix
+ */
+class DOMMatrix {
+ /**
+ * @param {number} x
+ * @param {number} y
+ */
+ translateSelf(x, y) {}
+ /**
+ * @param {number} x
+ * @param {number} y
+ * @param {number} z
+ */
+ rotateSelf(x, y, z) {}
+ /**
+ * @param {number} x
+ * @param {number} y
+ */
+ scaleSelf(x, y) {}
+ /**
+ * @param {{x: number, y: number}} point
+ * @return {{x: number, y: number}}
+ */
+ transformPoint(point) {}
+}
+
+/**
+ * TODO(katie): Remove this once length is added to the Closure
+ * chrome_extensions.js.
+ * An event from the TTS engine to communicate the status of an utterance.
+ * @constructor
+ */
+function TtsEvent() {}
+
+/** @type {number} */
+TtsEvent.prototype.length;
+
+
+/**
+ * @see https://drafts.css-houdini.org/css-typed-om/#stylepropertymap
+ * @typedef {{set: function(string, *):void,
+ * append: function(string, *):void,
+ * delete: function(string):void,
+ * clear: function():void }}
+ * TODO(rbpotter): Remove this once it is added to Closure Compiler itself.
+ */
+class StylePropertyMap {
+ /**
+ * @param {string} property
+ * @param {*} values
+ */
+ set(property, values) {}
+
+ /**
+ * @param {string} property
+ * @param {*} values
+ */
+ append(property, values) {}
+
+ /** @param {string} property */
+ delete(property) {}
+
+ clear() {}
+}
+
+/** @type {!StylePropertyMap} */
+HTMLElement.prototype.attributeStyleMap;
+
+/** @return {!AnimationEffectTimingProperties} */
+AnimationEffect.prototype.getTiming = function() {};
+
+/** @return {!Array<!Object>} */
+AnimationEffect.prototype.getKeyframes = function() {};
|