mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 15:23:25 +08:00
[pigeon] Fix tool hangs on verbose sub-processes (#6198)
The Pigeon tool hangs on Windows if you don't have the Java formatter on your path. Repro examples: ``` dart ./tool/generate.dart ``` ``` dart ./tool/test.dart -f windows_integration_tests ``` The root cause is that the tool runs sub-processes without consuming their stdout/stderr output. The sub-process blocks if these pipes get full. See: https://api.dart.dev/stable/3.3.0/dart-io/Process-class.html This change is untested. See: https://github.com/flutter/packages/pull/6198#issuecomment-1962186100 Needed for https://github.com/flutter/packages/pull/6196 Part of https://github.com/flutter/flutter/issues/144042
This commit is contained in:
@ -16,13 +16,29 @@ Future<int> runProcess(String command, List<String> arguments,
|
||||
mode:
|
||||
streamOutput ? ProcessStartMode.inheritStdio : ProcessStartMode.normal,
|
||||
);
|
||||
|
||||
if (streamOutput) {
|
||||
return process.exitCode;
|
||||
}
|
||||
|
||||
final List<int> stdoutBuffer = <int>[];
|
||||
final List<int> stderrBuffer = <int>[];
|
||||
final Future<void> stdoutFuture = process.stdout.forEach(stdoutBuffer.addAll);
|
||||
final Future<void> stderrFuture = process.stderr.forEach(stderrBuffer.addAll);
|
||||
final int exitCode = await process.exitCode;
|
||||
await Future.wait(<Future<void>>[
|
||||
stdoutFuture,
|
||||
stderrFuture,
|
||||
]);
|
||||
|
||||
if (exitCode != 0 && logFailure) {
|
||||
// ignore: avoid_print
|
||||
print('$command $arguments failed:');
|
||||
stdout.add(stdoutBuffer);
|
||||
stderr.add(stderrBuffer);
|
||||
await Future.wait(<Future<void>>[
|
||||
process.stdout.pipe(stdout),
|
||||
process.stderr.pipe(stderr),
|
||||
stdout.flush(),
|
||||
stderr.flush(),
|
||||
]);
|
||||
}
|
||||
return exitCode;
|
||||
|
Reference in New Issue
Block a user