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

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

Issue 2009163003: Add support for --dart2js-path and --dart2js-args. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | lib/src/runner/browser/platform.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:async/async.dart'; 9 import 'package:async/async.dart';
10 import 'package:path/path.dart' as p; 10 import 'package:path/path.dart' as p;
11 import 'package:pool/pool.dart'; 11 import 'package:pool/pool.dart';
12 12
13 import '../../util/io.dart'; 13 import '../../util/io.dart';
14 import '../configuration.dart';
14 import '../load_exception.dart'; 15 import '../load_exception.dart';
15 16
16 /// A pool of `dart2js` instances. 17 /// A pool of `dart2js` instances.
17 /// 18 ///
18 /// This limits the number of compiler instances running concurrently. 19 /// This limits the number of compiler instances running concurrently.
19 class CompilerPool { 20 class CompilerPool {
20 /// The internal pool that controls the number of process running at once. 21 /// The internal pool that controls the number of process running at once.
21 final Pool _pool; 22 final Pool _pool;
22 23
23 /// Whether to enable colors on dart2js. 24 /// The test runner configuration.
24 final bool _color; 25 final Configuration _config;
25 26
26 /// The currently-active dart2js processes. 27 /// The currently-active dart2js processes.
27 final _processes = new Set<Process>(); 28 final _processes = new Set<Process>();
28 29
29 /// Whether [close] has been called. 30 /// Whether [close] has been called.
30 bool get _closed => _closeMemo.hasRun; 31 bool get _closed => _closeMemo.hasRun;
31 32
32 /// The memoizer for running [close] exactly once. 33 /// The memoizer for running [close] exactly once.
33 final _closeMemo = new AsyncMemoizer(); 34 final _closeMemo = new AsyncMemoizer();
34 35
35 /// Creates a compiler pool that runs up to [concurrency] instances of 36 /// Creates a compiler pool that multiple instances of `dart2js` at once.
36 /// `dart2js` at once. 37 CompilerPool(Configuration config)
37 /// 38 : _pool = new Pool(config.concurrency),
38 /// If [concurrency] isn't provided, it defaults to 4. 39 _config = config;
39 ///
40 /// If [color] is true, `dart2js` will be run with colors enabled.
41 CompilerPool({int concurrency, bool color: false})
42 : _pool = new Pool(concurrency == null ? 4 : concurrency),
43 _color = color;
44 40
45 /// Compile the Dart code at [dartPath] to [jsPath]. 41 /// Compile the Dart code at [dartPath] to [jsPath].
46 /// 42 ///
47 /// This wraps the Dart code in the standard browser-testing wrapper. If 43 /// This wraps the Dart code in the standard browser-testing wrapper. If
48 /// [packageRoot] is provided, it's used as the package root for the 44 /// [packageRoot] is provided, it's used as the package root for the
49 /// compilation. 45 /// compilation.
50 /// 46 ///
51 /// The returned [Future] will complete once the `dart2js` process completes 47 /// The returned [Future] will complete once the `dart2js` process completes
52 /// *and* all its output has been printed to the command line. 48 /// *and* all its output has been printed to the command line.
53 Future compile(String dartPath, String jsPath, {String packageRoot}) { 49 Future compile(String dartPath, String jsPath, {String packageRoot}) {
54 return _pool.withResource(() { 50 return _pool.withResource(() {
55 if (_closed) return null; 51 if (_closed) return null;
56 52
57 return withTempDir((dir) async { 53 return withTempDir((dir) async {
58 var wrapperPath = p.join(dir, "runInBrowser.dart"); 54 var wrapperPath = p.join(dir, "runInBrowser.dart");
59 new File(wrapperPath).writeAsStringSync(''' 55 new File(wrapperPath).writeAsStringSync('''
60 import "package:stream_channel/stream_channel.dart"; 56 import "package:stream_channel/stream_channel.dart";
61 57
62 import "package:test/src/runner/plugin/remote_platform_helpers.dart"; 58 import "package:test/src/runner/plugin/remote_platform_helpers.dart";
63 import "package:test/src/runner/browser/post_message_channel.dart"; 59 import "package:test/src/runner/browser/post_message_channel.dart";
64 60
65 import "${p.toUri(p.absolute(dartPath))}" as test; 61 import "${p.toUri(p.absolute(dartPath))}" as test;
66 62
67 main(_) async { 63 main(_) async {
68 var channel = serializeSuite(() => test.main, hidePrints: false); 64 var channel = serializeSuite(() => test.main, hidePrints: false);
69 postMessageChannel().pipe(channel); 65 postMessageChannel().pipe(channel);
70 } 66 }
71 '''); 67 ''');
72 68
73 var dart2jsPath = p.join(sdkDir, 'bin', 'dart2js'); 69 var dart2jsPath = _config.dart2jsPath;
74 if (Platform.isWindows) dart2jsPath += '.bat'; 70 if (Platform.isWindows) dart2jsPath += '.bat';
75 71
76 var args = ["--checked", wrapperPath, "--out=$jsPath"]; 72 var args = ["--checked", wrapperPath, "--out=$jsPath"]
73 ..addAll(_config.dart2jsArgs);
77 74
78 if (packageRoot != null) { 75 if (packageRoot != null) {
79 args.add("--package-root=${p.toUri(p.absolute(packageRoot))}"); 76 args.add("--package-root=${p.toUri(p.absolute(packageRoot))}");
80 } 77 }
81 78
82 if (_color) args.add("--enable-diagnostic-colors"); 79 if (_config.color) args.add("--enable-diagnostic-colors");
83 80
84 var process = await Process.start(dart2jsPath, args); 81 var process = await Process.start(dart2jsPath, args);
85 if (_closed) { 82 if (_closed) {
86 process.kill(); 83 process.kill();
87 return; 84 return;
88 } 85 }
89 86
90 _processes.add(process); 87 _processes.add(process);
91 88
92 /// Wait until the process is entirely done to print out any output. 89 /// Wait until the process is entirely done to print out any output.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 /// have been killed and all resources released. 142 /// have been killed and all resources released.
146 Future close() { 143 Future close() {
147 return _closeMemo.runOnce(() async { 144 return _closeMemo.runOnce(() async {
148 await Future.wait(_processes.map((process) async { 145 await Future.wait(_processes.map((process) async {
149 process.kill(); 146 process.kill();
150 await process.exitCode; 147 await process.exitCode;
151 })); 148 }));
152 }); 149 });
153 } 150 }
154 } 151 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/runner/browser/platform.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698