[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:
Loïc Sharma
2024-02-26 11:02:41 -08:00
committed by GitHub
parent 0aff69f746
commit 6e835062a1

View File

@ -16,13 +16,29 @@ Future<int> runProcess(String command, List<String> arguments,
mode: mode:
streamOutput ? ProcessStartMode.inheritStdio : ProcessStartMode.normal, 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; final int exitCode = await process.exitCode;
await Future.wait(<Future<void>>[
stdoutFuture,
stderrFuture,
]);
if (exitCode != 0 && logFailure) { if (exitCode != 0 && logFailure) {
// ignore: avoid_print // ignore: avoid_print
print('$command $arguments failed:'); print('$command $arguments failed:');
stdout.add(stdoutBuffer);
stderr.add(stderrBuffer);
await Future.wait(<Future<void>>[ await Future.wait(<Future<void>>[
process.stdout.pipe(stdout), stdout.flush(),
process.stderr.pipe(stderr), stderr.flush(),
]); ]);
} }
return exitCode; return exitCode;