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 'dart:async';
|
||||||
|
|
||||||
|
import '../base/common.dart';
|
||||||
import '../cache.dart';
|
import '../cache.dart';
|
||||||
import '../features.dart';
|
import '../features.dart';
|
||||||
import '../globals.dart' as globals;
|
import '../globals.dart' as globals;
|
||||||
@ -57,6 +58,31 @@ class PrecacheCommand extends FlutterCommand {
|
|||||||
@override
|
@override
|
||||||
bool get shouldUpdateCache => false;
|
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
|
@override
|
||||||
Future<FlutterCommandResult> runCommand() async {
|
Future<FlutterCommandResult> runCommand() async {
|
||||||
if (boolArg('all-platforms')) {
|
if (boolArg('all-platforms')) {
|
||||||
@ -74,11 +100,26 @@ class PrecacheCommand extends FlutterCommand {
|
|||||||
if (artifact.feature != null && !featureFlags.isEnabled(artifact.feature)) {
|
if (artifact.feature != null && !featureFlags.isEnabled(artifact.feature)) {
|
||||||
continue;
|
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);
|
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);
|
requiredArtifacts.add(artifact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,6 @@ void main() {
|
|||||||
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
|
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
|
||||||
DevelopmentArtifact.universal,
|
DevelopmentArtifact.universal,
|
||||||
DevelopmentArtifact.web,
|
DevelopmentArtifact.web,
|
||||||
DevelopmentArtifact.androidGenSnapshot,
|
|
||||||
DevelopmentArtifact.androidMaven,
|
|
||||||
}));
|
}));
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: <Type, Generator>{
|
||||||
Cache: () => cache,
|
Cache: () => cache,
|
||||||
@ -59,14 +57,25 @@ void main() {
|
|||||||
|
|
||||||
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
|
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
|
||||||
DevelopmentArtifact.universal,
|
DevelopmentArtifact.universal,
|
||||||
DevelopmentArtifact.androidGenSnapshot,
|
|
||||||
DevelopmentArtifact.androidMaven,
|
|
||||||
}));
|
}));
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: <Type, Generator>{
|
||||||
Cache: () => cache,
|
Cache: () => cache,
|
||||||
FeatureFlags: () => TestFeatureFlags(isWebEnabled: false),
|
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 {
|
testUsingContext('precache adds artifact flags to requested artifacts', () async {
|
||||||
final PrecacheCommand command = PrecacheCommand();
|
final PrecacheCommand command = PrecacheCommand();
|
||||||
applyMocksToCommand(command);
|
applyMocksToCommand(command);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user