Don't pre-cache Android artifacts with --no-android flag (#49009)
This commit is contained in:
parent
975bb08a62
commit
ac7b307803
@ -4,6 +4,7 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import '../base/common.dart';
|
||||
import '../cache.dart';
|
||||
import '../features.dart';
|
||||
import '../globals.dart' as globals;
|
||||
@ -57,6 +58,31 @@ class PrecacheCommand extends FlutterCommand {
|
||||
@override
|
||||
bool get shouldUpdateCache => false;
|
||||
|
||||
/// Some flags are umbrella names that expand to include multiple artifacts.
|
||||
static const Map<String, List<String>> _expandedArtifacts = <String, List<String>>{
|
||||
'android': <String>[
|
||||
'android_gen_snapshot',
|
||||
'android_maven',
|
||||
'android_internal_build',
|
||||
]
|
||||
};
|
||||
|
||||
@override
|
||||
Future<void> validateCommand() {
|
||||
_expandedArtifacts.forEach((String umbrellaName, List<String> childArtifactNames) {
|
||||
if (!argResults.arguments.contains('--no-$umbrellaName')) {
|
||||
return;
|
||||
}
|
||||
for (final String childArtifactName in childArtifactNames) {
|
||||
if (argResults.arguments.contains('--$childArtifactName')) {
|
||||
throwToolExit('--$childArtifactName requires --$umbrellaName');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return super.validateCommand();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
if (boolArg('all-platforms')) {
|
||||
@ -74,11 +100,26 @@ class PrecacheCommand extends FlutterCommand {
|
||||
if (artifact.feature != null && !featureFlags.isEnabled(artifact.feature)) {
|
||||
continue;
|
||||
}
|
||||
if (boolArg(artifact.name)) {
|
||||
|
||||
bool expandedArtifactProcessed = false;
|
||||
_expandedArtifacts.forEach((String umbrellaName, List<String> childArtifactNames) {
|
||||
if (!childArtifactNames.contains(artifact.name)) {
|
||||
return;
|
||||
}
|
||||
expandedArtifactProcessed = true;
|
||||
|
||||
// Expanded artifacts options are true by default.
|
||||
// Explicitly ignore them if umbrella name is excluded.
|
||||
// Example: --no-android [--android_gen_snapshot]
|
||||
if (!boolArg(umbrellaName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Example: --android [--android_gen_snapshot]
|
||||
requiredArtifacts.add(artifact);
|
||||
}
|
||||
// The `android` flag expands to android_gen_snapshot, android_maven, android_internal_build.
|
||||
if (artifact.name.startsWith('android_') && boolArg('android')) {
|
||||
});
|
||||
|
||||
if (!expandedArtifactProcessed && boolArg(artifact.name)) {
|
||||
requiredArtifacts.add(artifact);
|
||||
}
|
||||
}
|
||||
|
@ -44,8 +44,6 @@ void main() {
|
||||
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
|
||||
DevelopmentArtifact.universal,
|
||||
DevelopmentArtifact.web,
|
||||
DevelopmentArtifact.androidGenSnapshot,
|
||||
DevelopmentArtifact.androidMaven,
|
||||
}));
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => cache,
|
||||
@ -59,14 +57,25 @@ void main() {
|
||||
|
||||
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
|
||||
DevelopmentArtifact.universal,
|
||||
DevelopmentArtifact.androidGenSnapshot,
|
||||
DevelopmentArtifact.androidMaven,
|
||||
}));
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => cache,
|
||||
FeatureFlags: () => TestFeatureFlags(isWebEnabled: false),
|
||||
});
|
||||
|
||||
testUsingContext('precache exits if requesting mismatched artifacts.', () async {
|
||||
final PrecacheCommand command = PrecacheCommand();
|
||||
applyMocksToCommand(command);
|
||||
|
||||
expect(createTestCommandRunner(command).run(const <String>['precache',
|
||||
'--no-android',
|
||||
'--android_gen_snapshot',
|
||||
]), throwsToolExit(message: '--android_gen_snapshot requires --android'));
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => cache,
|
||||
FeatureFlags: () => TestFeatureFlags(isWebEnabled: false),
|
||||
});
|
||||
|
||||
testUsingContext('precache adds artifact flags to requested artifacts', () async {
|
||||
final PrecacheCommand command = PrecacheCommand();
|
||||
applyMocksToCommand(command);
|
||||
|
Loading…
x
Reference in New Issue
Block a user