Skip to content

Commit 08118d4

Browse files
andrewkolosesouthren
authored andcommitted
reduce pub output from flutter create (flutter#118285)
* reduce pub output from flutter create * fix fake Pub implementations * fix tests * Update pub.dart * replace enum with simpler boolean * fix tests * Revert "fix tests" This reverts commit 8a3182d. * Revert "replace enum with simpler boolean" This reverts commit 445dbc4. * go back to using an enum
1 parent c20ab54 commit 08118d4

File tree

11 files changed

+48
-23
lines changed

11 files changed

+48
-23
lines changed

packages/flutter_tools/lib/src/commands/create.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ class CreateCommand extends CreateBase {
414414
context: pubContext,
415415
project: project,
416416
offline: boolArgDeprecated('offline'),
417+
outputMode: PubOutputMode.summaryOnly,
417418
);
418419
await project.ensureReadyForPlatformSpecificTooling(
419420
androidPlatform: includeAndroid,

packages/flutter_tools/lib/src/commands/update_packages.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ class UpdatePackagesCommand extends FlutterCommand {
444444
upgrade: doUpgrade,
445445
offline: boolArgDeprecated('offline'),
446446
flutterRootOverride: temporaryFlutterSdk?.path,
447-
printProgress: false,
447+
outputMode: PubOutputMode.none,
448448
);
449449

450450
if (doUpgrade) {
@@ -538,7 +538,7 @@ class UpdatePackagesCommand extends FlutterCommand {
538538
// All dependencies should already have been downloaded by the fake
539539
// package, so the concurrent checks can all happen offline.
540540
offline: true,
541-
printProgress: false,
541+
outputMode: PubOutputMode.none,
542542
);
543543
stopwatch.stop();
544544
final double seconds = stopwatch.elapsedMilliseconds / 1000.0;

packages/flutter_tools/lib/src/dart/pub.dart

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ class PubContext {
140140
}
141141
}
142142

143+
/// Describes the amount of output that should get printed from a `pub` command.
144+
/// [PubOutputMode.all] indicates that the complete output is printed. This is
145+
/// typically the default.
146+
/// [PubOutputMode.none] indicates that no output should be printed.
147+
/// [PubOutputMode.summaryOnly] indicates that only summary information should be printed.
148+
enum PubOutputMode {
149+
none,
150+
all,
151+
summaryOnly,
152+
}
153+
143154
/// A handle for interacting with the pub tool.
144155
abstract class Pub {
145156
/// Create a default [Pub] instance.
@@ -172,6 +183,14 @@ abstract class Pub {
172183
/// If [shouldSkipThirdPartyGenerator] is true, the overall pub get will be
173184
/// skipped if the package config file has a "generator" other than "pub".
174185
/// Defaults to true.
186+
///
187+
/// [outputMode] determines how verbose the output from `pub get` will be.
188+
/// If [PubOutputMode.all] is used, `pub get` will print its typical output
189+
/// which includes information about all changed dependencies. If
190+
/// [PubOutputMode.summaryOnly] is used, only summary information will be printed.
191+
/// This is useful for cases where the user is typically not interested in
192+
/// what dependencies were changed, such as when running `flutter create`.
193+
///
175194
/// Will also resolve dependencies in the example folder if present.
176195
Future<void> get({
177196
required PubContext context,
@@ -181,7 +200,7 @@ abstract class Pub {
181200
String? flutterRootOverride,
182201
bool checkUpToDate = false,
183202
bool shouldSkipThirdPartyGenerator = true,
184-
bool printProgress = true,
203+
PubOutputMode outputMode = PubOutputMode.all
185204
});
186205

187206
/// Runs pub in 'batch' mode.
@@ -221,7 +240,7 @@ abstract class Pub {
221240
required String command,
222241
bool touchesPackageConfig = false,
223242
bool generateSyntheticPackage = false,
224-
bool printProgress = true,
243+
PubOutputMode outputMode = PubOutputMode.all
225244
});
226245
}
227246

@@ -286,7 +305,7 @@ class _DefaultPub implements Pub {
286305
String? flutterRootOverride,
287306
bool checkUpToDate = false,
288307
bool shouldSkipThirdPartyGenerator = true,
289-
bool printProgress = true,
308+
PubOutputMode outputMode = PubOutputMode.all
290309
}) async {
291310
final String directory = project.directory.path;
292311
final File packageConfigFile = project.packageConfigFile;
@@ -358,7 +377,7 @@ class _DefaultPub implements Pub {
358377
directory: directory,
359378
failureMessage: 'pub $command failed',
360379
flutterRootOverride: flutterRootOverride,
361-
printProgress: printProgress
380+
outputMode: outputMode,
362381
);
363382
await _updateVersionAndPackageConfig(project);
364383
}
@@ -375,7 +394,7 @@ class _DefaultPub implements Pub {
375394
Future<void> _runWithStdioInherited(
376395
List<String> arguments, {
377396
required String command,
378-
required bool printProgress,
397+
required PubOutputMode outputMode,
379398
required PubContext context,
380399
required String directory,
381400
String failureMessage = 'pub failed',
@@ -384,10 +403,10 @@ class _DefaultPub implements Pub {
384403
int exitCode;
385404

386405
final List<String> pubCommand = _pubCommand(arguments);
387-
final Map<String, String> pubEnvironment = await _createPubEnvironment(context, flutterRootOverride);
406+
final Map<String, String> pubEnvironment = await _createPubEnvironment(context: context, flutterRootOverride: flutterRootOverride, summaryOnly: outputMode == PubOutputMode.summaryOnly);
388407

389408
try {
390-
if (printProgress) {
409+
if (outputMode != PubOutputMode.none) {
391410
final io.Stdio? stdio = _stdio;
392411
if (stdio == null) {
393412
// Let pub inherit stdio and output directly to the tool's stdout and
@@ -450,8 +469,7 @@ class _DefaultPub implements Pub {
450469
? 'exists'
451470
: 'does not exist';
452471
buffer.writeln('Working directory: "$directory" ($directoryExistsMessage)');
453-
final Map<String, String> env = await _createPubEnvironment(context, flutterRootOverride);
454-
buffer.write(_stringifyPubEnv(env));
472+
buffer.write(_stringifyPubEnv(pubEnvironment));
455473
throw io.ProcessException(
456474
exception.executable,
457475
exception.arguments,
@@ -517,7 +535,7 @@ class _DefaultPub implements Pub {
517535
if (showTraceForErrors) {
518536
arguments.insert(0, '--trace');
519537
}
520-
final Map<String, String> pubEnvironment = await _createPubEnvironment(context, flutterRootOverride);
538+
final Map<String, String> pubEnvironment = await _createPubEnvironment(context: context, flutterRootOverride: flutterRootOverride);
521539
final List<String> pubCommand = _pubCommand(arguments);
522540
final int code = await _processUtils.stream(
523541
pubCommand,
@@ -557,14 +575,14 @@ class _DefaultPub implements Pub {
557575
required String command,
558576
bool touchesPackageConfig = false,
559577
bool generateSyntheticPackage = false,
560-
bool printProgress = true,
578+
PubOutputMode outputMode = PubOutputMode.all
561579
}) async {
562580
await _runWithStdioInherited(
563581
arguments,
564582
command: command,
565583
directory: _fileSystem.currentDirectory.path,
566584
context: context,
567-
printProgress: printProgress,
585+
outputMode: outputMode,
568586
);
569587
if (touchesPackageConfig && project != null) {
570588
await _updateVersionAndPackageConfig(project);
@@ -697,10 +715,15 @@ class _DefaultPub implements Pub {
697715
///
698716
/// [context] provides extra information to package server requests to
699717
/// understand usage.
700-
Future<Map<String, String>> _createPubEnvironment(PubContext context, [ String? flutterRootOverride ]) async {
718+
Future<Map<String, String>> _createPubEnvironment({
719+
required PubContext context,
720+
String? flutterRootOverride,
721+
bool? summaryOnly = false,
722+
}) async {
701723
final Map<String, String> environment = <String, String>{
702724
'FLUTTER_ROOT': flutterRootOverride ?? Cache.flutterRoot!,
703725
_kPubEnvironmentKey: await _getPubEnvironmentValue(context),
726+
if (summaryOnly ?? false) 'PUB_SUMMARY_ONLY': '1',
704727
};
705728
final String? pubCache = _getPubCacheIfAvailable();
706729
if (pubCache != null) {

packages/flutter_tools/test/commands.shard/hermetic/create_usage_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FakePub extends Fake implements Pub {
3636
String? flutterRootOverride,
3737
bool checkUpToDate = false,
3838
bool shouldSkipThirdPartyGenerator = true,
39-
bool printProgress = true,
39+
PubOutputMode outputMode = PubOutputMode.all,
4040
}) async {
4141
project.directory.childFile('.packages').createSync();
4242
if (offline == true) {

packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ class FakePub extends Fake implements Pub {
486486
String? flutterRootOverride,
487487
bool checkUpToDate = false,
488488
bool shouldSkipThirdPartyGenerator = true,
489-
bool printProgress = true,
489+
PubOutputMode outputMode = PubOutputMode.all,
490490
}) async { }
491491
}
492492

packages/flutter_tools/test/commands.shard/hermetic/pub_get_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class FakePub extends Fake implements Pub {
190190
required String command,
191191
bool touchesPackageConfig = false,
192192
bool generateSyntheticPackage = false,
193-
bool printProgress = true,
193+
PubOutputMode outputMode = PubOutputMode.all,
194194
}) async {
195195
if (project != null) {
196196
fileSystem.directory(project.directory)

packages/flutter_tools/test/commands.shard/hermetic/update_packages_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class FakePub extends Fake implements Pub {
282282
String? flutterRootOverride,
283283
bool checkUpToDate = false,
284284
bool shouldSkipThirdPartyGenerator = true,
285-
bool printProgress = true,
285+
PubOutputMode outputMode = PubOutputMode.all,
286286
}) async {
287287
pubGetDirectories.add(project.directory.path);
288288
project.directory.childFile('pubspec.lock')

packages/flutter_tools/test/general.shard/cache_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,7 @@ class FakePub extends Fake implements Pub {
12151215
bool checkUpToDate = false,
12161216
bool shouldSkipThirdPartyGenerator = true,
12171217
bool printProgress = true,
1218+
PubOutputMode outputMode = PubOutputMode.all,
12181219
}) async {
12191220
calledGet += 1;
12201221
}

packages/flutter_tools/test/general.shard/dart/pub_get_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ exit code: 66
676676
await pub.get(
677677
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
678678
context: PubContext.flutterTests,
679-
printProgress: false
679+
outputMode: PubOutputMode.none,
680680
);
681681
} on ToolExit {
682682
// Ignore.

packages/flutter_tools/test/general.shard/runner/flutter_command_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ class FakePub extends Fake implements Pub {
956956
String? flutterRootOverride,
957957
bool checkUpToDate = false,
958958
bool shouldSkipThirdPartyGenerator = true,
959-
bool printProgress = true,
959+
PubOutputMode outputMode = PubOutputMode.all,
960960
}) async { }
961961
}
962962

packages/flutter_tools/test/src/throwing_pub.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ThrowingPub implements Pub {
2929
String? flutterRootOverride,
3030
bool checkUpToDate = false,
3131
bool shouldSkipThirdPartyGenerator = true,
32-
bool printProgress = true,
32+
PubOutputMode outputMode = PubOutputMode.all,
3333
}) {
3434
throw UnsupportedError('Attempted to invoke pub during test.');
3535
}
@@ -42,7 +42,7 @@ class ThrowingPub implements Pub {
4242
required String command,
4343
bool touchesPackageConfig = false,
4444
bool generateSyntheticPackage = false,
45-
bool printProgress = true,
45+
PubOutputMode outputMode = PubOutputMode.all,
4646
}) {
4747
throw UnsupportedError('Attempted to invoke pub during test.');
4848
}

0 commit comments

Comments
 (0)