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

Side by Side Diff: utils/testrunner/pipeline_utils.dart

Issue 11091070: Change Process.start to return a future that completes with a (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of pipeline; 5 part of pipeline;
6 6
7 List stdout, stderr, log; 7 List stdout, stderr, log;
8 var replyPort; 8 var replyPort;
9 int _procId = 1; 9 int _procId = 1;
10 Map _procs = {}; 10 Map _procs = {};
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 * If [procId] is non-zero (i.e. called from startProcess) then a reference 53 * If [procId] is non-zero (i.e. called from startProcess) then a reference
54 * to the [Process] will be put in a map with key [procId]; in this case 54 * to the [Process] will be put in a map with key [procId]; in this case
55 * the process can be terminated later by calling [stopProcess] and 55 * the process can be terminated later by calling [stopProcess] and
56 * passing in the [procId]. 56 * passing in the [procId].
57 * [outputMonitor] is an optional function that will be called back with each 57 * [outputMonitor] is an optional function that will be called back with each
58 * line of output from the process. 58 * line of output from the process.
59 * Returns a [Future] for when the process terminates. 59 * Returns a [Future] for when the process terminates.
60 */ 60 */
61 Future _processHelper(String command, List<String> args, 61 Future _processHelper(String command, List<String> args,
62 [int timeout = 300, int procId = 0, Function outputMonitor]) { 62 [int timeout = 300, int procId = 0, Function outputMonitor]) {
63 var completer = new Completer(); 63 var completer = procId == 0 ? new Completer() : null;
64 log.add('Running $command ${Strings.join(args, " ")}'); 64 log.add('Running $command ${Strings.join(args, " ")}');
65 var timer = null; 65 var timer = null;
66 var stdoutHandler, stderrHandler; 66 var stdoutHandler, stderrHandler;
67 var process = Process.start(command, args); 67 Process.start(command, args).then((process) {
68 if (procId != 0) {
69 _procs[procId] = process; 68 _procs[procId] = process;
70 } 69
71 process.onStart = () {
72 timer = new Timer(1000 * timeout, (t) { 70 timer = new Timer(1000 * timeout, (t) {
73 timer = null; 71 timer = null;
74 process.kill(); 72 process.kill();
75 }); 73 });
76 };
77 process.onExit = (exitCode) {
78 if (timer != null) {
79 timer.cancel();
80 }
81 process.close();
82 if (completer != null) {
83 completer.complete(exitCode);
84 }
85 };
86 process.onError = (e) {
87 stderr.add("Error starting process:");
88 stderr.add(" Command: $command");
89 stderr.add(" Error: $e");
90 completePipeline(-1);
91 };
92 74
93 _pipeStream(process.stdout, stdout, outputMonitor); 75 process.onExit = (exitCode) {
94 _pipeStream(process.stderr, stderr, outputMonitor); 76 if (timer != null) {
77 timer.cancel();
78 }
79 process.close();
80 if (completer != null) {
81 completer.complete(exitCode);
82 }
83 };
84 process.onError = (e) {
85 stderr.add("Error starting process:");
86 stderr.add(" Command: $command");
87 stderr.add(" Error: $e");
88 completePipeline(-1);
89 };
90
91 _pipeStream(process.stdout, stdout, outputMonitor);
92 _pipeStream(process.stderr, stderr, outputMonitor);
93 });
95 94
96 return completer.future; 95 return completer.future;
97 } 96 }
98 97
99 void _pipeStream(InputStream stream, List<String> destination, 98 void _pipeStream(InputStream stream, List<String> destination,
100 Function outputMonitor) { 99 Function outputMonitor) {
101 var source = new StringInputStream(stream); 100 var source = new StringInputStream(stream);
102 source.onLine = () { 101 source.onLine = () {
103 if (source.available() == 0) return; 102 if (source.available() == 0) return;
104 var line = source.readLine(); 103 var line = source.readLine();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 stderr = new List(); 177 stderr = new List();
179 log = new List(); 178 log = new List();
180 } 179 }
181 180
182 void completePipeline([exitCode = 0]) { 181 void completePipeline([exitCode = 0]) {
183 replyPort.send([stdout, stderr, log, exitCode]); 182 replyPort.send([stdout, stderr, log, exitCode]);
184 } 183 }
185 184
186 /** Utility function to log diagnostic messages. */ 185 /** Utility function to log diagnostic messages. */
187 void logMessage(msg) => log.add(msg); 186 void logMessage(msg) => log.add(msg);
OLDNEW
« utils/testrunner/layout_test_controller.dart ('K') | « utils/testrunner/layout_test_controller.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698