Fix flutter update-packages regression by fixing parameters in "pub get" runner (#116687)

* Make pub get runner respect printProgress and retry parameters

* Fix typo

* Add regression test

* Improve test

* Fix implementation and test

* Test to fix flutter_drone tests

* Revert test

* Attempt #2 to fix flutter_drone tests

* Revert attempt

* Hack: Force printProgress to debug Windows tests

* Use ProcessUtils.run to avoid dangling stdout and stderr

* Update documentation

* Clean up retry argument
This commit is contained in:
Nehal Patel
2023-01-05 16:08:05 -08:00
committed by GitHub
parent 4f3ed80400
commit de2a42497f
3 changed files with 105 additions and 28 deletions

View File

@@ -444,6 +444,7 @@ class UpdatePackagesCommand extends FlutterCommand {
upgrade: doUpgrade,
offline: boolArgDeprecated('offline'),
flutterRootOverride: temporaryFlutterSdk?.path,
printProgress: false,
);
if (doUpgrade) {

View File

@@ -349,7 +349,6 @@ class _DefaultPub implements Pub {
context: context,
directory: directory,
failureMessage: 'pub $command failed',
retry: !offline,
flutterRootOverride: flutterRootOverride,
printProgress: printProgress
);
@@ -379,7 +378,8 @@ class _DefaultPub implements Pub {
/// Uses [ProcessStartMode.normal] and [Pub._stdio] if [Pub.test] constructor
/// was used.
///
/// Prints the stdout and stderr of the whole run.
/// Prints the stdout and stderr of the whole run, unless silenced using
/// [printProgress].
///
/// Sends an analytics event.
Future<void> _runWithStdioInherited(
@@ -387,51 +387,74 @@ class _DefaultPub implements Pub {
required String command,
required bool printProgress,
required PubContext context,
required bool retry,
required String directory,
String failureMessage = 'pub failed',
String? flutterRootOverride,
}) async {
int exitCode;
if (printProgress) {
_logger.printStatus('Running "flutter pub $command" in ${_fileSystem.path.basename(directory)}...');
}
_logger.printStatus('Running "flutter pub $command" in ${_fileSystem.path.basename(directory)}...');
final List<String> pubCommand = _pubCommand(arguments);
final Map<String, String> pubEnvironment = await _createPubEnvironment(context, flutterRootOverride);
try {
final io.Process process;
final io.Stdio? stdio = _stdio;
if (printProgress) {
final io.Stdio? stdio = _stdio;
if (stdio == null) {
// Let pub inherit stdio and output directly to the tool's stdout and
// stderr handles.
final io.Process process = await _processUtils.start(
pubCommand,
workingDirectory: _fileSystem.path.current,
environment: pubEnvironment,
mode: ProcessStartMode.inheritStdio,
);
if (stdio != null) {
// Omit mode parameter and direct pub output to [Pub._stdio] for tests.
process = await _processUtils.start(
pubCommand,
workingDirectory: _fileSystem.path.current,
environment: pubEnvironment,
);
exitCode = await process.exitCode;
} else {
// Omit [mode] parameter to send output to [process.stdout] and
// [process.stderr].
final io.Process process = await _processUtils.start(
pubCommand,
workingDirectory: _fileSystem.path.current,
environment: pubEnvironment,
);
final StreamSubscription<List<int>> stdoutSubscription =
process.stdout.listen(stdio.stdout.add);
final StreamSubscription<List<int>> stderrSubscription =
process.stderr.listen(stdio.stderr.add);
// Direct pub output to [Pub._stdio] for tests.
final StreamSubscription<List<int>> stdoutSubscription =
process.stdout.listen(stdio.stdout.add);
final StreamSubscription<List<int>> stderrSubscription =
process.stderr.listen(stdio.stderr.add);
await Future.wait<void>(<Future<void>>[
stdoutSubscription.asFuture<void>(),
stderrSubscription.asFuture<void>(),
]);
await Future.wait<void>(<Future<void>>[
stdoutSubscription.asFuture<void>(),
stderrSubscription.asFuture<void>(),
]);
unawaited(stdoutSubscription.cancel());
unawaited(stderrSubscription.cancel());
unawaited(stdoutSubscription.cancel());
unawaited(stderrSubscription.cancel());
exitCode = await process.exitCode;
}
} else {
// Let pub inherit stdio for normal operation.
process = await _processUtils.start(
// Do not try to use [ProcessUtils.start] here, because it requires you
// to read all data out of the stdout and stderr streams. If you don't
// read the streams, it may appear to work fine on your platform but
// will block the tool's process on Windows.
// See https://api.dart.dev/stable/dart-io/Process/start.html
//
// [ProcessUtils.run] will send the output to [result.stdout] and
// [result.stderr], which we will ignore.
final RunResult result = await _processUtils.run(
pubCommand,
workingDirectory: _fileSystem.path.current,
environment: pubEnvironment,
mode: ProcessStartMode.inheritStdio,
);
}
exitCode = await process.exitCode;
exitCode = result.exitCode;
}
// The exception is rethrown, so don't catch only Exceptions.
} catch (exception) { // ignore: avoid_catches_without_on_clauses
if (exception is io.ProcessException) {