Unverified Commit ee1c59d4 authored by Andrew Kolos's avatar Andrew Kolos Committed by GitHub

reduce pub output from flutter create (#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 8a3182d3b95d4f2bf337343cdb76e88c2f428ca8.

* Revert "replace enum with simpler boolean"

This reverts commit 445dbc443db4eb5ce284f76749f60e81208b8783.

* go back to using an enum
parent c7a3f0fe
...@@ -414,6 +414,7 @@ class CreateCommand extends CreateBase { ...@@ -414,6 +414,7 @@ class CreateCommand extends CreateBase {
context: pubContext, context: pubContext,
project: project, project: project,
offline: boolArgDeprecated('offline'), offline: boolArgDeprecated('offline'),
outputMode: PubOutputMode.summaryOnly,
); );
await project.ensureReadyForPlatformSpecificTooling( await project.ensureReadyForPlatformSpecificTooling(
androidPlatform: includeAndroid, androidPlatform: includeAndroid,
......
...@@ -444,7 +444,7 @@ class UpdatePackagesCommand extends FlutterCommand { ...@@ -444,7 +444,7 @@ class UpdatePackagesCommand extends FlutterCommand {
upgrade: doUpgrade, upgrade: doUpgrade,
offline: boolArgDeprecated('offline'), offline: boolArgDeprecated('offline'),
flutterRootOverride: temporaryFlutterSdk?.path, flutterRootOverride: temporaryFlutterSdk?.path,
printProgress: false, outputMode: PubOutputMode.none,
); );
if (doUpgrade) { if (doUpgrade) {
...@@ -538,7 +538,7 @@ class UpdatePackagesCommand extends FlutterCommand { ...@@ -538,7 +538,7 @@ class UpdatePackagesCommand extends FlutterCommand {
// All dependencies should already have been downloaded by the fake // All dependencies should already have been downloaded by the fake
// package, so the concurrent checks can all happen offline. // package, so the concurrent checks can all happen offline.
offline: true, offline: true,
printProgress: false, outputMode: PubOutputMode.none,
); );
stopwatch.stop(); stopwatch.stop();
final double seconds = stopwatch.elapsedMilliseconds / 1000.0; final double seconds = stopwatch.elapsedMilliseconds / 1000.0;
......
...@@ -140,6 +140,17 @@ class PubContext { ...@@ -140,6 +140,17 @@ class PubContext {
} }
} }
/// Describes the amount of output that should get printed from a `pub` command.
/// [PubOutputMode.all] indicates that the complete output is printed. This is
/// typically the default.
/// [PubOutputMode.none] indicates that no output should be printed.
/// [PubOutputMode.summaryOnly] indicates that only summary information should be printed.
enum PubOutputMode {
none,
all,
summaryOnly,
}
/// A handle for interacting with the pub tool. /// A handle for interacting with the pub tool.
abstract class Pub { abstract class Pub {
/// Create a default [Pub] instance. /// Create a default [Pub] instance.
...@@ -172,6 +183,14 @@ abstract class Pub { ...@@ -172,6 +183,14 @@ abstract class Pub {
/// If [shouldSkipThirdPartyGenerator] is true, the overall pub get will be /// If [shouldSkipThirdPartyGenerator] is true, the overall pub get will be
/// skipped if the package config file has a "generator" other than "pub". /// skipped if the package config file has a "generator" other than "pub".
/// Defaults to true. /// Defaults to true.
///
/// [outputMode] determines how verbose the output from `pub get` will be.
/// If [PubOutputMode.all] is used, `pub get` will print its typical output
/// which includes information about all changed dependencies. If
/// [PubOutputMode.summaryOnly] is used, only summary information will be printed.
/// This is useful for cases where the user is typically not interested in
/// what dependencies were changed, such as when running `flutter create`.
///
/// Will also resolve dependencies in the example folder if present. /// Will also resolve dependencies in the example folder if present.
Future<void> get({ Future<void> get({
required PubContext context, required PubContext context,
...@@ -181,7 +200,7 @@ abstract class Pub { ...@@ -181,7 +200,7 @@ abstract class Pub {
String? flutterRootOverride, String? flutterRootOverride,
bool checkUpToDate = false, bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true, bool shouldSkipThirdPartyGenerator = true,
bool printProgress = true, PubOutputMode outputMode = PubOutputMode.all
}); });
/// Runs pub in 'batch' mode. /// Runs pub in 'batch' mode.
...@@ -221,7 +240,7 @@ abstract class Pub { ...@@ -221,7 +240,7 @@ abstract class Pub {
required String command, required String command,
bool touchesPackageConfig = false, bool touchesPackageConfig = false,
bool generateSyntheticPackage = false, bool generateSyntheticPackage = false,
bool printProgress = true, PubOutputMode outputMode = PubOutputMode.all
}); });
} }
...@@ -286,7 +305,7 @@ class _DefaultPub implements Pub { ...@@ -286,7 +305,7 @@ class _DefaultPub implements Pub {
String? flutterRootOverride, String? flutterRootOverride,
bool checkUpToDate = false, bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true, bool shouldSkipThirdPartyGenerator = true,
bool printProgress = true, PubOutputMode outputMode = PubOutputMode.all
}) async { }) async {
final String directory = project.directory.path; final String directory = project.directory.path;
final File packageConfigFile = project.packageConfigFile; final File packageConfigFile = project.packageConfigFile;
...@@ -358,7 +377,7 @@ class _DefaultPub implements Pub { ...@@ -358,7 +377,7 @@ class _DefaultPub implements Pub {
directory: directory, directory: directory,
failureMessage: 'pub $command failed', failureMessage: 'pub $command failed',
flutterRootOverride: flutterRootOverride, flutterRootOverride: flutterRootOverride,
printProgress: printProgress outputMode: outputMode,
); );
await _updateVersionAndPackageConfig(project); await _updateVersionAndPackageConfig(project);
} }
...@@ -375,7 +394,7 @@ class _DefaultPub implements Pub { ...@@ -375,7 +394,7 @@ class _DefaultPub implements Pub {
Future<void> _runWithStdioInherited( Future<void> _runWithStdioInherited(
List<String> arguments, { List<String> arguments, {
required String command, required String command,
required bool printProgress, required PubOutputMode outputMode,
required PubContext context, required PubContext context,
required String directory, required String directory,
String failureMessage = 'pub failed', String failureMessage = 'pub failed',
...@@ -384,10 +403,10 @@ class _DefaultPub implements Pub { ...@@ -384,10 +403,10 @@ class _DefaultPub implements Pub {
int exitCode; int exitCode;
final List<String> pubCommand = _pubCommand(arguments); final List<String> pubCommand = _pubCommand(arguments);
final Map<String, String> pubEnvironment = await _createPubEnvironment(context, flutterRootOverride); final Map<String, String> pubEnvironment = await _createPubEnvironment(context: context, flutterRootOverride: flutterRootOverride, summaryOnly: outputMode == PubOutputMode.summaryOnly);
try { try {
if (printProgress) { if (outputMode != PubOutputMode.none) {
final io.Stdio? stdio = _stdio; final io.Stdio? stdio = _stdio;
if (stdio == null) { if (stdio == null) {
// Let pub inherit stdio and output directly to the tool's stdout and // Let pub inherit stdio and output directly to the tool's stdout and
...@@ -450,8 +469,7 @@ class _DefaultPub implements Pub { ...@@ -450,8 +469,7 @@ class _DefaultPub implements Pub {
? 'exists' ? 'exists'
: 'does not exist'; : 'does not exist';
buffer.writeln('Working directory: "$directory" ($directoryExistsMessage)'); buffer.writeln('Working directory: "$directory" ($directoryExistsMessage)');
final Map<String, String> env = await _createPubEnvironment(context, flutterRootOverride); buffer.write(_stringifyPubEnv(pubEnvironment));
buffer.write(_stringifyPubEnv(env));
throw io.ProcessException( throw io.ProcessException(
exception.executable, exception.executable,
exception.arguments, exception.arguments,
...@@ -517,7 +535,7 @@ class _DefaultPub implements Pub { ...@@ -517,7 +535,7 @@ class _DefaultPub implements Pub {
if (showTraceForErrors) { if (showTraceForErrors) {
arguments.insert(0, '--trace'); arguments.insert(0, '--trace');
} }
final Map<String, String> pubEnvironment = await _createPubEnvironment(context, flutterRootOverride); final Map<String, String> pubEnvironment = await _createPubEnvironment(context: context, flutterRootOverride: flutterRootOverride);
final List<String> pubCommand = _pubCommand(arguments); final List<String> pubCommand = _pubCommand(arguments);
final int code = await _processUtils.stream( final int code = await _processUtils.stream(
pubCommand, pubCommand,
...@@ -557,14 +575,14 @@ class _DefaultPub implements Pub { ...@@ -557,14 +575,14 @@ class _DefaultPub implements Pub {
required String command, required String command,
bool touchesPackageConfig = false, bool touchesPackageConfig = false,
bool generateSyntheticPackage = false, bool generateSyntheticPackage = false,
bool printProgress = true, PubOutputMode outputMode = PubOutputMode.all
}) async { }) async {
await _runWithStdioInherited( await _runWithStdioInherited(
arguments, arguments,
command: command, command: command,
directory: _fileSystem.currentDirectory.path, directory: _fileSystem.currentDirectory.path,
context: context, context: context,
printProgress: printProgress, outputMode: outputMode,
); );
if (touchesPackageConfig && project != null) { if (touchesPackageConfig && project != null) {
await _updateVersionAndPackageConfig(project); await _updateVersionAndPackageConfig(project);
...@@ -697,10 +715,15 @@ class _DefaultPub implements Pub { ...@@ -697,10 +715,15 @@ class _DefaultPub implements Pub {
/// ///
/// [context] provides extra information to package server requests to /// [context] provides extra information to package server requests to
/// understand usage. /// understand usage.
Future<Map<String, String>> _createPubEnvironment(PubContext context, [ String? flutterRootOverride ]) async { Future<Map<String, String>> _createPubEnvironment({
required PubContext context,
String? flutterRootOverride,
bool? summaryOnly = false,
}) async {
final Map<String, String> environment = <String, String>{ final Map<String, String> environment = <String, String>{
'FLUTTER_ROOT': flutterRootOverride ?? Cache.flutterRoot!, 'FLUTTER_ROOT': flutterRootOverride ?? Cache.flutterRoot!,
_kPubEnvironmentKey: await _getPubEnvironmentValue(context), _kPubEnvironmentKey: await _getPubEnvironmentValue(context),
if (summaryOnly ?? false) 'PUB_SUMMARY_ONLY': '1',
}; };
final String? pubCache = _getPubCacheIfAvailable(); final String? pubCache = _getPubCacheIfAvailable();
if (pubCache != null) { if (pubCache != null) {
......
...@@ -36,7 +36,7 @@ class FakePub extends Fake implements Pub { ...@@ -36,7 +36,7 @@ class FakePub extends Fake implements Pub {
String? flutterRootOverride, String? flutterRootOverride,
bool checkUpToDate = false, bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true, bool shouldSkipThirdPartyGenerator = true,
bool printProgress = true, PubOutputMode outputMode = PubOutputMode.all,
}) async { }) async {
project.directory.childFile('.packages').createSync(); project.directory.childFile('.packages').createSync();
if (offline == true) { if (offline == true) {
......
...@@ -486,7 +486,7 @@ class FakePub extends Fake implements Pub { ...@@ -486,7 +486,7 @@ class FakePub extends Fake implements Pub {
String? flutterRootOverride, String? flutterRootOverride,
bool checkUpToDate = false, bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true, bool shouldSkipThirdPartyGenerator = true,
bool printProgress = true, PubOutputMode outputMode = PubOutputMode.all,
}) async { } }) async { }
} }
......
...@@ -190,7 +190,7 @@ class FakePub extends Fake implements Pub { ...@@ -190,7 +190,7 @@ class FakePub extends Fake implements Pub {
required String command, required String command,
bool touchesPackageConfig = false, bool touchesPackageConfig = false,
bool generateSyntheticPackage = false, bool generateSyntheticPackage = false,
bool printProgress = true, PubOutputMode outputMode = PubOutputMode.all,
}) async { }) async {
if (project != null) { if (project != null) {
fileSystem.directory(project.directory) fileSystem.directory(project.directory)
......
...@@ -282,7 +282,7 @@ class FakePub extends Fake implements Pub { ...@@ -282,7 +282,7 @@ class FakePub extends Fake implements Pub {
String? flutterRootOverride, String? flutterRootOverride,
bool checkUpToDate = false, bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true, bool shouldSkipThirdPartyGenerator = true,
bool printProgress = true, PubOutputMode outputMode = PubOutputMode.all,
}) async { }) async {
pubGetDirectories.add(project.directory.path); pubGetDirectories.add(project.directory.path);
project.directory.childFile('pubspec.lock') project.directory.childFile('pubspec.lock')
......
...@@ -1215,6 +1215,7 @@ class FakePub extends Fake implements Pub { ...@@ -1215,6 +1215,7 @@ class FakePub extends Fake implements Pub {
bool checkUpToDate = false, bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true, bool shouldSkipThirdPartyGenerator = true,
bool printProgress = true, bool printProgress = true,
PubOutputMode outputMode = PubOutputMode.all,
}) async { }) async {
calledGet += 1; calledGet += 1;
} }
......
...@@ -676,7 +676,7 @@ exit code: 66 ...@@ -676,7 +676,7 @@ exit code: 66
await pub.get( await pub.get(
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory), project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
context: PubContext.flutterTests, context: PubContext.flutterTests,
printProgress: false outputMode: PubOutputMode.none,
); );
} on ToolExit { } on ToolExit {
// Ignore. // Ignore.
......
...@@ -956,7 +956,7 @@ class FakePub extends Fake implements Pub { ...@@ -956,7 +956,7 @@ class FakePub extends Fake implements Pub {
String? flutterRootOverride, String? flutterRootOverride,
bool checkUpToDate = false, bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true, bool shouldSkipThirdPartyGenerator = true,
bool printProgress = true, PubOutputMode outputMode = PubOutputMode.all,
}) async { } }) async { }
} }
......
...@@ -29,7 +29,7 @@ class ThrowingPub implements Pub { ...@@ -29,7 +29,7 @@ class ThrowingPub implements Pub {
String? flutterRootOverride, String? flutterRootOverride,
bool checkUpToDate = false, bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true, bool shouldSkipThirdPartyGenerator = true,
bool printProgress = true, PubOutputMode outputMode = PubOutputMode.all,
}) { }) {
throw UnsupportedError('Attempted to invoke pub during test.'); throw UnsupportedError('Attempted to invoke pub during test.');
} }
...@@ -42,7 +42,7 @@ class ThrowingPub implements Pub { ...@@ -42,7 +42,7 @@ class ThrowingPub implements Pub {
required String command, required String command,
bool touchesPackageConfig = false, bool touchesPackageConfig = false,
bool generateSyntheticPackage = false, bool generateSyntheticPackage = false,
bool printProgress = true, PubOutputMode outputMode = PubOutputMode.all,
}) { }) {
throw UnsupportedError('Attempted to invoke pub during test.'); throw UnsupportedError('Attempted to invoke pub during test.');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment