@@ -349,7 +349,6 @@ class _DefaultPub implements Pub {
349
349
context: context,
350
350
directory: directory,
351
351
failureMessage: 'pub $command failed' ,
352
- retry: ! offline,
353
352
flutterRootOverride: flutterRootOverride,
354
353
printProgress: printProgress
355
354
);
@@ -379,59 +378,83 @@ class _DefaultPub implements Pub {
379
378
/// Uses [ProcessStartMode.normal] and [Pub._stdio] if [Pub.test] constructor
380
379
/// was used.
381
380
///
382
- /// Prints the stdout and stderr of the whole run.
381
+ /// Prints the stdout and stderr of the whole run, unless silenced using
382
+ /// [printProgress] .
383
383
///
384
384
/// Sends an analytics event.
385
385
Future <void > _runWithStdioInherited (
386
386
List <String > arguments, {
387
387
required String command,
388
388
required bool printProgress,
389
389
required PubContext context,
390
- required bool retry,
391
390
required String directory,
392
391
String failureMessage = 'pub failed' ,
393
392
String ? flutterRootOverride,
394
393
}) async {
395
394
int exitCode;
395
+ if (printProgress) {
396
+ _logger.printStatus ('Running "flutter pub $command " in ${_fileSystem .path .basename (directory )}...' );
397
+ }
396
398
397
- _logger.printStatus ('Running "flutter pub $command " in ${_fileSystem .path .basename (directory )}...' );
398
399
final List <String > pubCommand = _pubCommand (arguments);
399
400
final Map <String , String > pubEnvironment = await _createPubEnvironment (context, flutterRootOverride);
400
- try {
401
- final io.Process process;
402
- final io.Stdio ? stdio = _stdio;
403
-
404
- if (stdio != null ) {
405
- // Omit mode parameter and direct pub output to [Pub._stdio] for tests.
406
- process = await _processUtils.start (
407
- pubCommand,
408
- workingDirectory: _fileSystem.path.current,
409
- environment: pubEnvironment,
410
- );
411
401
412
- final StreamSubscription <List <int >> stdoutSubscription =
413
- process.stdout.listen (stdio.stdout.add);
414
- final StreamSubscription <List <int >> stderrSubscription =
415
- process.stderr.listen (stdio.stderr.add);
416
-
417
- await Future .wait <void >(< Future <void >> [
418
- stdoutSubscription.asFuture <void >(),
419
- stderrSubscription.asFuture <void >(),
420
- ]);
421
-
422
- unawaited (stdoutSubscription.cancel ());
423
- unawaited (stderrSubscription.cancel ());
402
+ try {
403
+ if (printProgress) {
404
+ final io.Stdio ? stdio = _stdio;
405
+ if (stdio == null ) {
406
+ // Let pub inherit stdio and output directly to the tool's stdout and
407
+ // stderr handles.
408
+ final io.Process process = await _processUtils.start (
409
+ pubCommand,
410
+ workingDirectory: _fileSystem.path.current,
411
+ environment: pubEnvironment,
412
+ mode: ProcessStartMode .inheritStdio,
413
+ );
414
+
415
+ exitCode = await process.exitCode;
416
+ } else {
417
+ // Omit [mode] parameter to send output to [process.stdout] and
418
+ // [process.stderr].
419
+ final io.Process process = await _processUtils.start (
420
+ pubCommand,
421
+ workingDirectory: _fileSystem.path.current,
422
+ environment: pubEnvironment,
423
+ );
424
+
425
+ // Direct pub output to [Pub._stdio] for tests.
426
+ final StreamSubscription <List <int >> stdoutSubscription =
427
+ process.stdout.listen (stdio.stdout.add);
428
+ final StreamSubscription <List <int >> stderrSubscription =
429
+ process.stderr.listen (stdio.stderr.add);
430
+
431
+ await Future .wait <void >(< Future <void >> [
432
+ stdoutSubscription.asFuture <void >(),
433
+ stderrSubscription.asFuture <void >(),
434
+ ]);
435
+
436
+ unawaited (stdoutSubscription.cancel ());
437
+ unawaited (stderrSubscription.cancel ());
438
+
439
+ exitCode = await process.exitCode;
440
+ }
424
441
} else {
425
- // Let pub inherit stdio for normal operation.
426
- process = await _processUtils.start (
442
+ // Do not try to use [ProcessUtils.start] here, because it requires you
443
+ // to read all data out of the stdout and stderr streams. If you don't
444
+ // read the streams, it may appear to work fine on your platform but
445
+ // will block the tool's process on Windows.
446
+ // See https://api.dart.dev/stable/dart-io/Process/start.html
447
+ //
448
+ // [ProcessUtils.run] will send the output to [result.stdout] and
449
+ // [result.stderr], which we will ignore.
450
+ final RunResult result = await _processUtils.run (
427
451
pubCommand,
428
452
workingDirectory: _fileSystem.path.current,
429
453
environment: pubEnvironment,
430
- mode: ProcessStartMode .inheritStdio,
431
454
);
432
- }
433
455
434
- exitCode = await process.exitCode;
456
+ exitCode = result.exitCode;
457
+ }
435
458
// The exception is rethrown, so don't catch only Exceptions.
436
459
} catch (exception) { // ignore: avoid_catches_without_on_clauses
437
460
if (exception is io.ProcessException ) {
0 commit comments