Chromium Code Reviews| Index: pkg/dev_compiler/bin/dartdevc.dart |
| diff --git a/pkg/dev_compiler/bin/dartdevc.dart b/pkg/dev_compiler/bin/dartdevc.dart |
| index 4a0ccbe410fcfff622ed5501e292d2d7a0246e5c..f26eb5b562e0742f0a6924d43facdedbd68ca25a 100755 |
| --- a/pkg/dev_compiler/bin/dartdevc.dart |
| +++ b/pkg/dev_compiler/bin/dartdevc.dart |
| @@ -3,40 +3,13 @@ |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| -/// Command line entry point for Dart Development Compiler (dartdevc). |
| -/// |
| -/// Supported commands are |
| -/// * compile: builds a collection of dart libraries into a single JS module |
| -/// |
| -/// Additionally, these commands are being considered |
| -/// * link: combines several JS modules into a single JS file |
| -/// * build: compiles & links a set of code, automatically determining |
| -/// appropriate groupings of libraries to combine into JS modules |
| -/// * watch: watch a directory and recompile build units automatically |
| -/// * serve: uses `watch` to recompile and exposes a simple static file server |
| -/// for local development |
| -/// |
| -/// These commands are combined so we have less names to expose on the PATH, |
| -/// and for development simplicity while the precise UI has not been determined. |
| -/// |
| -/// A more typical structure for web tools is simply to have the compiler with |
| -/// "watch" as an option. The challenge for us is: |
| -/// |
| -/// * Dart used to assume whole-program compiles, so we don't have a |
| -/// user-declared unit of building, and neither "libraries" or "packages" will |
| -/// work, |
| -/// * We do not assume a `node` JS installation, so we cannot easily reuse |
| -/// existing tools for the "link" step, or assume users have a local |
| -/// file server, |
| -/// * We didn't have a file watcher API at first, |
| -/// * We had no conventions about where compiled output should go (or even |
| -/// that we would be compiling at all, vs running on an in-browser Dart VM), |
| -/// * We wanted a good first impression with our simple examples, so we used |
| -/// local file servers, and users have an expectation of it now, even though |
| -/// it doesn't scale to typical apps that need their own real servers. |
| +/// Command line entry point for Dart Development Compiler (dartdevc), used to |
| +/// compile a collection of dart libraries into a single JS module |
| import 'dart:async'; |
| +import 'dart:convert'; |
| import 'dart:io'; |
| +import 'dart:isolate'; |
| import 'package:analyzer/file_system/physical_file_system.dart'; |
| import 'package:analyzer/src/command_line/arguments.dart'; |
| import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine; |
| @@ -48,7 +21,9 @@ Future main(List<String> args) async { |
| args = preprocessArgs(PhysicalResourceProvider.INSTANCE, args); |
| if (args.contains('--persistent_worker')) { |
| - new _CompilerWorker(args..remove('--persistent_worker')).run(); |
| + await new _CompilerWorker(args..remove('--persistent_worker')).run(); |
| + } else if (args.isNotEmpty && args.last == "--batch") { |
| + await runBatch(args.sublist(0, args.length - 1)); |
| } else { |
| exitCode = compile(args); |
| } |
| @@ -73,3 +48,30 @@ class _CompilerWorker extends AsyncWorkerLoop { |
| ..output = output.toString(); |
| } |
| } |
| + |
| +Future runBatch(List<String> batchArgs) async { |
| + int totalTests = 0; |
| + int testsFailed = 0; |
| + var watch = new Stopwatch()..start(); |
| + print('>>> BATCH START'); |
| + Stream input = stdin.transform(UTF8.decoder).transform(new LineSplitter()); |
|
Bob Nystrom
2017/08/03 18:28:04
Can this stream be typed more precisely, or inferr
Jennifer Messerly
2017/08/03 19:43:05
I just copy+pasted this from the other impls of ba
Bob Nystrom
2017/08/03 20:19:48
It was added much later in dart:io's evolution tha
|
| + await for (String line in input) { |
| + if (line.isEmpty) { |
| + int time = watch.elapsedMilliseconds; |
| + print('>>> BATCH END ' |
| + '(${totalTests - testsFailed})/$totalTests ${time}ms'); |
| + break; |
| + } |
| + ++totalTests; |
|
Bob Nystrom
2017/08/03 18:28:04
Random nit: Maybe it's just me, but I tend to thin
Jennifer Messerly
2017/08/03 19:43:06
again this is just copied code. I don't mind chang
|
| + var args = batchArgs.toList()..addAll(line.split(new RegExp(r'\s+'))); |
| + |
| + // We don't try/catch here, since `compile` should handle that. |
| + var compileExitCode = compile(args); |
| + AnalysisEngine.instance.clearCaches(); |
| + stderr.writeln('>>> EOF STDERR'); |
| + var outcome = compileExitCode == 0 |
| + ? 'PASS' |
| + : compileExitCode == 70 ? 'CRASH' : 'FAIL'; |
| + print('>>> TEST $outcome ${watch.elapsedMilliseconds}ms'); |
| + } |
| +} |