[flutter_tools] flutter precache downloads all enabled platforms if no flags are provided (#73733)
This commit is contained in:
parent
7ed30cb7e5
commit
f7dc19eb23
@ -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<String> 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<String, String> umbrellaForArtifact = _umbrellaForArtifactMap();
|
||||
final Set<DevelopmentArtifact> requiredArtifacts = <DevelopmentArtifact>{};
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -268,6 +268,7 @@ void main() {
|
||||
const <String>[
|
||||
'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: <String, String>{}),
|
||||
);
|
||||
await createTestCommandRunner(command).run(const <String>['precache']);
|
||||
|
||||
expect(
|
||||
artifacts,
|
||||
unorderedEquals(<DevelopmentArtifact>{
|
||||
DevelopmentArtifact.web,
|
||||
DevelopmentArtifact.macOS,
|
||||
DevelopmentArtifact.windows,
|
||||
DevelopmentArtifact.linux,
|
||||
DevelopmentArtifact.universal,
|
||||
// iOS and android specifically excluded
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
class MockCache extends Mock implements Cache {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user