Skip to content

Commit 27c127d

Browse files
nateboschcommit-bot@chromium.org
authored andcommitted
Use Process.start in ddb
Allows us to use `inheritStdio` and see output as it comes in rather than waiting until the entire process has finished to see the output. Refactor to support https://dart-review.googlesource.com/c/sdk/+/117595 Change-Id: Ic940d11b6b24c12aa23052c224d72c5365486ae5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117860 Auto-Submit: Nate Bosch <[email protected]> Reviewed-by: Nicholas Shahan <[email protected]> Commit-Queue: Nate Bosch <[email protected]>
1 parent 7305ae6 commit 27c127d

File tree

1 file changed

+23
-27
lines changed
  • pkg/dev_compiler/tool

1 file changed

+23
-27
lines changed

pkg/dev_compiler/tool/ddb

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void main(List<String> args) async {
106106
var ddcPath = p.dirname(p.dirname(toolPath));
107107
var dartCheckoutPath = p.dirname(p.dirname(ddcPath));
108108

109-
ProcessResult runDdc(String command, List<String> args) {
109+
Future<void> runDdc(String command, List<String> args) async {
110110
if (debug) {
111111
// Use unbuilt script. This only works from a source checkout.
112112
args.insertAll(
@@ -116,18 +116,9 @@ void main(List<String> args) async {
116116
// Use built snapshot.
117117
command = p.join(dartSdk, 'bin', command);
118118
}
119-
return Process.runSync(command, args);
120-
}
121-
122-
/// Writes stdout and stderr from [result] to this process.
123-
///
124-
/// Will exit with the exit code from [result] when it's not zero.
125-
void echoResult(ProcessResult result) async {
126-
stdout.write(result.stdout);
127-
await stdout.flush();
128-
stderr.write(result.stderr);
129-
await stderr.flush();
130-
if (result.exitCode != 0) exit(result.exitCode);
119+
var process =
120+
await Process.start(command, args, mode: ProcessStartMode.inheritStdio);
121+
if (await process.exitCode != 0) exit(await process.exitCode);
131122
}
132123

133124
String mod;
@@ -163,7 +154,6 @@ void main(List<String> args) async {
163154
ddcSdk = p.join(
164155
dartSdk, 'lib', '_internal', kernel ? 'ddc_sdk.dill' : 'ddc_sdk.sum');
165156

166-
ProcessResult result;
167157
if (compile) {
168158
var ddcArgs = [
169159
if (kernel) '--kernel',
@@ -181,8 +171,7 @@ void main(List<String> args) async {
181171
entry
182172
];
183173

184-
result = runDdc('dartdevc', ddcArgs);
185-
await echoResult(result);
174+
await runDdc('dartdevc', ddcArgs);
186175
}
187176

188177
if (run) {
@@ -222,13 +211,17 @@ void main(List<String> args) async {
222211
File(htmlFile).writeAsStringSync(html);
223212
var tmp = p.join(Directory.systemTemp.path, 'ddc');
224213

225-
result = Process.runSync(chromeBinary, [
226-
'--auto-open-devtools-for-tabs',
227-
'--allow-file-access-from-files',
228-
'--remote-debugging-port=$port',
229-
'--user-data-dir=$tmp',
230-
htmlFile
231-
]);
214+
var process = await Process.start(
215+
chromeBinary,
216+
[
217+
'--auto-open-devtools-for-tabs',
218+
'--allow-file-access-from-files',
219+
'--remote-debugging-port=$port',
220+
'--user-data-dir=$tmp',
221+
htmlFile
222+
],
223+
mode: ProcessStartMode.inheritStdio);
224+
if (await process.exitCode != 0) exit(await process.exitCode);
232225
} else if (node) {
233226
var nodePath = '$sdkJsPath:$libRoot';
234227
var runjs = '''
@@ -253,9 +246,11 @@ try {
253246
var nodeFile = p.setExtension(entry, '.run.js');
254247
File(nodeFile).writeAsStringSync(runjs);
255248
var nodeBinary = binary ?? 'node';
256-
result = Process.runSync(
249+
var process = await Process.start(
257250
nodeBinary, ['--inspect=localhost:$port', nodeFile],
258-
environment: {'NODE_PATH': nodePath});
251+
environment: {'NODE_PATH': nodePath},
252+
mode: ProcessStartMode.inheritStdio);
253+
if (await process.exitCode != 0) exit(await process.exitCode);
259254
} else if (d8) {
260255
// Fix SDK import. `d8` doesn't let us set paths, so we need a full path
261256
// to the SDK.
@@ -280,9 +275,10 @@ try {
280275
var d8File = p.setExtension(entry, '.d8.js');
281276
File(d8File).writeAsStringSync(runjs);
282277
var d8Binary = binary ?? p.join(dartCheckoutPath, _d8executable);
283-
result = Process.runSync(d8Binary, ['--module', d8File]);
278+
var process = await Process.start(d8Binary, ['--module', d8File],
279+
mode: ProcessStartMode.inheritStdio);
280+
if (await process.exitCode != 0) exit(await process.exitCode);
284281
}
285-
await echoResult(result);
286282
}
287283
}
288284

0 commit comments

Comments
 (0)