Precache platform filter change (#53701)
Makes the following changes to the behavior of precache: - The --all-platforms flags now fetches all artifacts, rather than just turning off platform filtering of selected artifacts. - Explicitly requested artifacts are no longer subject to platform filtering. E.g., 'precache --ios' will download iOS artifacts on Windows and Linux (but 'precache' without an 'ios' flag will still only download iOS artifacts on macOS). - Desktop platform artifacts now respect the bypassing of platform filtering. Fixes #53272
This commit is contained in:
@@ -156,6 +156,10 @@ class Cache {
|
||||
// artifacts for the current platform.
|
||||
bool includeAllPlatforms = false;
|
||||
|
||||
// Names of artifacts which should be cached even if they would normally
|
||||
// be filtered out for the current platform.
|
||||
Set<String> platformOverrideArtifacts;
|
||||
|
||||
// Whether to cache the unsigned mac binaries. Defaults to caching the signed binaries.
|
||||
bool useUnsignedMacBinaries = false;
|
||||
|
||||
@@ -523,6 +527,12 @@ abstract class CachedArtifact extends ArtifactSet {
|
||||
@visibleForTesting
|
||||
final List<File> downloadedFiles = <File>[];
|
||||
|
||||
// Whether or not to bypass normal platform filtering for this artifact.
|
||||
bool get ignorePlatformFiltering {
|
||||
return cache.includeAllPlatforms ||
|
||||
(cache.platformOverrideArtifacts != null && cache.platformOverrideArtifacts.contains(developmentArtifact.name));
|
||||
}
|
||||
|
||||
@override
|
||||
bool isUpToDate() {
|
||||
if (!location.existsSync()) {
|
||||
@@ -859,7 +869,7 @@ class MacOSEngineArtifacts extends EngineCachedArtifact {
|
||||
|
||||
@override
|
||||
List<List<String>> getBinaryDirs() {
|
||||
if (globals.platform.isMacOS) {
|
||||
if (globals.platform.isMacOS || ignorePlatformFiltering) {
|
||||
return _macOSDesktopBinaryDirs;
|
||||
}
|
||||
return const <List<String>>[];
|
||||
@@ -881,7 +891,7 @@ class WindowsEngineArtifacts extends EngineCachedArtifact {
|
||||
|
||||
@override
|
||||
List<List<String>> getBinaryDirs() {
|
||||
if (globals.platform.isWindows) {
|
||||
if (globals.platform.isWindows || ignorePlatformFiltering) {
|
||||
return _windowsDesktopBinaryDirs;
|
||||
}
|
||||
return const <List<String>>[];
|
||||
@@ -903,7 +913,7 @@ class LinuxEngineArtifacts extends EngineCachedArtifact {
|
||||
|
||||
@override
|
||||
List<List<String>> getBinaryDirs() {
|
||||
if (globals.platform.isLinux) {
|
||||
if (globals.platform.isLinux || ignorePlatformFiltering) {
|
||||
return _linuxDesktopBinaryDirs;
|
||||
}
|
||||
return const <List<String>>[];
|
||||
@@ -1020,14 +1030,14 @@ class IOSEngineArtifacts extends EngineCachedArtifact {
|
||||
@override
|
||||
List<List<String>> getBinaryDirs() {
|
||||
return <List<String>>[
|
||||
if (globals.platform.isMacOS || cache.includeAllPlatforms)
|
||||
if (globals.platform.isMacOS || ignorePlatformFiltering)
|
||||
..._iosBinaryDirs,
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
List<String> getLicenseDirs() {
|
||||
if (cache.includeAllPlatforms || globals.platform.isMacOS) {
|
||||
if (globals.platform.isMacOS || ignorePlatformFiltering) {
|
||||
return const <String>['ios', 'ios-profile', 'ios-release'];
|
||||
}
|
||||
return const <String>[];
|
||||
@@ -1302,7 +1312,7 @@ class IosUsbArtifacts extends CachedArtifact {
|
||||
|
||||
@override
|
||||
Future<void> updateInner() {
|
||||
if (!globals.platform.isMacOS && !cache.includeAllPlatforms) {
|
||||
if (!globals.platform.isMacOS && !ignorePlatformFiltering) {
|
||||
return Future<void>.value();
|
||||
}
|
||||
if (location.existsSync()) {
|
||||
|
||||
@@ -66,6 +66,33 @@ class PrecacheCommand extends FlutterCommand {
|
||||
]
|
||||
};
|
||||
|
||||
/// Returns a reverse mapping of _expandedArtifacts, from child artifact name
|
||||
/// to umbrella name.
|
||||
Map<String, String> _umbrellaForArtifactMap() {
|
||||
return <String, String>{
|
||||
for (final MapEntry<String, List<String>> entry in _expandedArtifacts.entries)
|
||||
for (final String childArtifactName in entry.value)
|
||||
childArtifactName: entry.key
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns the name of all artifacts that were explicitly chosen via flags.
|
||||
///
|
||||
/// If an umbrella is chosen, its children will be included as well.
|
||||
Set<String> _explicitArtifactSelections() {
|
||||
final Map<String, String> umbrellaForArtifact = _umbrellaForArtifactMap();
|
||||
final Set<String> selections = <String>{};
|
||||
bool explicitlySelected(String name) => boolArg(name) && argResults.wasParsed(name);
|
||||
for (final DevelopmentArtifact artifact in DevelopmentArtifact.values) {
|
||||
final String umbrellaName = umbrellaForArtifact[artifact.name];
|
||||
if (explicitlySelected(artifact.name) ||
|
||||
(umbrellaName != null && explicitlySelected(umbrellaName))) {
|
||||
selections.add(artifact.name);
|
||||
}
|
||||
}
|
||||
return selections;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> validateCommand() {
|
||||
_expandedArtifacts.forEach((String umbrellaName, List<String> childArtifactNames) {
|
||||
@@ -84,12 +111,15 @@ class PrecacheCommand extends FlutterCommand {
|
||||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
if (boolArg('all-platforms')) {
|
||||
final bool includeAllPlatforms = boolArg('all-platforms');
|
||||
if (includeAllPlatforms) {
|
||||
globals.cache.includeAllPlatforms = true;
|
||||
}
|
||||
if (boolArg('use-unsigned-mac-binaries')) {
|
||||
globals.cache.useUnsignedMacBinaries = true;
|
||||
}
|
||||
globals.cache.platformOverrideArtifacts = _explicitArtifactSelections();
|
||||
final Map<String, String> umbrellaForArtifact = _umbrellaForArtifactMap();
|
||||
final Set<DevelopmentArtifact> requiredArtifacts = <DevelopmentArtifact>{};
|
||||
for (final DevelopmentArtifact artifact in DevelopmentArtifact.values) {
|
||||
// Don't include unstable artifacts on stable branches.
|
||||
@@ -100,25 +130,8 @@ class PrecacheCommand extends FlutterCommand {
|
||||
continue;
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
if (!expandedArtifactProcessed && boolArg(artifact.name)) {
|
||||
final String argumentName = umbrellaForArtifact[artifact.name] ?? artifact.name;
|
||||
if (includeAllPlatforms || boolArg(argumentName)) {
|
||||
requiredArtifacts.add(artifact);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user