diff --git a/packages/flutter_tools/lib/src/commands/precache.dart b/packages/flutter_tools/lib/src/commands/precache.dart index 6854fb82e0..58b151b8ad 100644 --- a/packages/flutter_tools/lib/src/commands/precache.dart +++ b/packages/flutter_tools/lib/src/commands/precache.dart @@ -28,19 +28,19 @@ class PrecacheCommand extends FlutterCommand { help: 'Precache artifacts for all host platforms.'); argParser.addFlag('force', abbr: 'f', negatable: false, help: 'Force re-downloading of artifacts.'); - argParser.addFlag('android', negatable: true, defaultsTo: true, + argParser.addFlag('android', negatable: true, defaultsTo: false, help: 'Precache artifacts for Android development.', hide: verboseHelp); - argParser.addFlag('android_gen_snapshot', negatable: true, defaultsTo: true, + argParser.addFlag('android_gen_snapshot', negatable: true, defaultsTo: false, help: 'Precache gen_snapshot for Android development.', hide: !verboseHelp); - argParser.addFlag('android_maven', negatable: true, defaultsTo: true, + argParser.addFlag('android_maven', negatable: true, defaultsTo: false, help: 'Precache Gradle dependencies for Android development.', hide: !verboseHelp); argParser.addFlag('android_internal_build', negatable: true, defaultsTo: false, help: 'Precache dependencies for internal Android development.', hide: !verboseHelp); - argParser.addFlag('ios', negatable: true, defaultsTo: true, + argParser.addFlag('ios', negatable: true, defaultsTo: false, help: 'Precache artifacts for iOS development.'); argParser.addFlag('web', negatable: true, defaultsTo: false, help: 'Precache artifacts for web development.'); @@ -69,7 +69,9 @@ class PrecacheCommand extends FlutterCommand { final String name = 'precache'; @override - final String description = "Populate the Flutter tool's cache of binary artifacts."; + final String description = "Populate the Flutter tool's cache of binary artifacts.\n\n" + 'If no explicit platform flags are provided, this command will download the artifacts ' + 'for all currently enabled platforms'; @override bool get shouldUpdateCache => false; @@ -143,7 +145,12 @@ class PrecacheCommand extends FlutterCommand { if (boolArg('use-unsigned-mac-binaries')) { _cache.useUnsignedMacBinaries = true; } - _cache.platformOverrideArtifacts = _explicitArtifactSelections(); + final Set explicitlyEnabled = _explicitArtifactSelections(); + _cache.platformOverrideArtifacts = explicitlyEnabled; + + // If the user did not provide any artifact flags, then download + // all artifacts that correspond to an enabled platform. + final bool downloadDefaultArtifacts = explicitlyEnabled.isEmpty; final Map umbrellaForArtifact = _umbrellaForArtifactMap(); final Set requiredArtifacts = {}; for (final DevelopmentArtifact artifact in DevelopmentArtifact.values) { @@ -152,7 +159,7 @@ class PrecacheCommand extends FlutterCommand { } final String argumentName = umbrellaForArtifact[artifact.name] ?? artifact.name; - if (includeAllPlatforms || boolArg(argumentName)) { + if (includeAllPlatforms || boolArg(argumentName) || downloadDefaultArtifacts) { requiredArtifacts.add(artifact); } } diff --git a/packages/flutter_tools/test/commands.shard/hermetic/precache_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/precache_test.dart index 2a23db2b0d..c5396e7ff3 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/precache_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/precache_test.dart @@ -268,6 +268,7 @@ void main() { const [ 'precache', '--no-ios', + '--android', '--android_gen_snapshot', '--android_maven', '--android_internal_build', @@ -403,6 +404,34 @@ void main() { verify(cache.clearStampFiles()).called(1); }); + + testUsingContext('precache downloads all enabled platforms if no flags are provided.', () async { + final PrecacheCommand command = PrecacheCommand( + cache: cache, + logger: BufferLogger.test(), + featureFlags: TestFeatureFlags( + isWebEnabled: true, + isLinuxEnabled: true, + isWindowsEnabled: true, + isMacOSEnabled: true, + isIOSEnabled: false, + isAndroidEnabled: false, + ), + platform: FakePlatform(environment: {}), + ); + await createTestCommandRunner(command).run(const ['precache']); + + expect( + artifacts, + unorderedEquals({ + DevelopmentArtifact.web, + DevelopmentArtifact.macOS, + DevelopmentArtifact.windows, + DevelopmentArtifact.linux, + DevelopmentArtifact.universal, + // iOS and android specifically excluded + })); + }); } class MockCache extends Mock implements Cache {}