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

Side by Side Diff: lib/src/runner/browser/compiler_pool.dart

Issue 983573002: Add support for running browser tests to the test runner. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library unittest.util.compiler_pool; 5 library unittest.util.compiler_pool;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:path/path.dart' as p; 11 import 'package:path/path.dart' as p;
12 import 'package:pool/pool.dart'; 12 import 'package:pool/pool.dart';
13 13
14 import '../../util/io.dart'; 14 import '../../util/io.dart';
15 import '../load_exception.dart'; 15 import '../load_exception.dart';
16 16
17 /// A pool of `dart2js` instances. 17 /// A pool of `dart2js` instances.
18 /// 18 ///
19 /// This limits the number of compiler instances running concurrently. It also 19 /// This limits the number of compiler instances running concurrently. It also
20 /// ensures that their output doesn't intermingle; only one instance is 20 /// ensures that their output doesn't intermingle; only one instance is
21 /// "visible" (that is, having its output printed) at a time, and the other 21 /// "visible" (that is, having its output printed) at a time, and the other
22 /// instances' output is buffered until it's their turn to be visible. 22 /// instances' output is buffered until it's their turn to be visible.
23 class CompilerPool { 23 class CompilerPool {
24 /// The internal pool that controls the number of process running at once. 24 /// The internal pool that controls the number of process running at once.
25 final Pool _pool; 25 final Pool _pool;
26 26
27 /// Whether to enable colors on dart2js.
28 final bool _color;
29
27 /// The currently-active compilers. 30 /// The currently-active compilers.
28 /// 31 ///
29 /// The first one is the only visible the compiler; the rest will become 32 /// The first one is the only visible the compiler; the rest will become
30 /// visible in queue order. Note that some of these processes may actually 33 /// visible in queue order. Note that some of these processes may actually
31 /// have already exited; they're kept around so that their output can be 34 /// have already exited; they're kept around so that their output can be
32 /// emitted once they become visible. 35 /// emitted once they become visible.
33 final _compilers = new Queue<_Compiler>(); 36 final _compilers = new Queue<_Compiler>();
34 37
35 /// Creates a compiler pool that runs up to [parallel] instances of `dart2js` 38 /// Creates a compiler pool that runs up to [parallel] instances of `dart2js`
36 /// at once. 39 /// at once.
37 /// 40 ///
38 /// If [parallel] isn't provided, it defaults to 4. 41 /// If [parallel] isn't provided, it defaults to 4.
39 CompilerPool({int parallel}) 42 ///
40 : _pool = new Pool(parallel == null ? 4 : parallel); 43 /// If [color] is true, `dart2js` will be run with colors enabled.
44 CompilerPool({int parallel, bool color: false})
45 : _pool = new Pool(parallel == null ? 4 : parallel),
46 _color = color;
41 47
42 /// Compile the Dart code at [dartPath] to [jsPath]. 48 /// Compile the Dart code at [dartPath] to [jsPath].
43 /// 49 ///
44 /// This wraps the Dart code in the standard browser-testing wrapper. If 50 /// This wraps the Dart code in the standard browser-testing wrapper. If
45 /// [packageRoot] is provided, it's used as the package root for the 51 /// [packageRoot] is provided, it's used as the package root for the
46 /// compilation. 52 /// compilation.
47 /// 53 ///
48 /// The returned [Future] will complete once the `dart2js` process completes 54 /// The returned [Future] will complete once the `dart2js` process completes
49 /// *and* all its output has been printed to the command line. 55 /// *and* all its output has been printed to the command line.
50 Future compile(String dartPath, String jsPath, {String packageRoot}) { 56 Future compile(String dartPath, String jsPath, {String packageRoot}) {
(...skipping 12 matching lines...) Expand all
63 69
64 var dart2jsPath = p.join(sdkDir, 'bin', 'dart2js'); 70 var dart2jsPath = p.join(sdkDir, 'bin', 'dart2js');
65 if (Platform.isWindows) dart2jsPath += '.bat'; 71 if (Platform.isWindows) dart2jsPath += '.bat';
66 72
67 var args = ["--checked", wrapperPath, "--out=$jsPath"]; 73 var args = ["--checked", wrapperPath, "--out=$jsPath"];
68 74
69 if (packageRoot != null) { 75 if (packageRoot != null) {
70 args.add("--package-root=${p.absolute(packageRoot)}"); 76 args.add("--package-root=${p.absolute(packageRoot)}");
71 } 77 }
72 78
73 if (canUseSpecialChars) { 79 if (_color) args.add("--enable-diagnostic-colors");
74 args.add("--enable-diagnostic-colors");
75 }
76 80
77 return Process.start(dart2jsPath, args).then((process) { 81 return Process.start(dart2jsPath, args).then((process) {
78 var compiler = new _Compiler(dartPath, process); 82 var compiler = new _Compiler(dartPath, process);
79 83
80 if (_compilers.isEmpty) _showProcess(compiler); 84 if (_compilers.isEmpty) _showProcess(compiler);
81 _compilers.add(compiler); 85 _compilers.add(compiler);
82 86
83 return compiler.onDone; 87 return compiler.onDone;
84 }); 88 });
85 }); 89 });
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 /// The underlying process. 129 /// The underlying process.
126 final Process process; 130 final Process process;
127 131
128 /// A future that will complete once this instance has finished running and 132 /// A future that will complete once this instance has finished running and
129 /// all its output has been printed. 133 /// all its output has been printed.
130 Future get onDone => onDoneCompleter.future; 134 Future get onDone => onDoneCompleter.future;
131 final onDoneCompleter = new Completer(); 135 final onDoneCompleter = new Completer();
132 136
133 _Compiler(this.path, this.process); 137 _Compiler(this.path, this.process);
134 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698