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:
@@ -8,6 +8,7 @@ import 'package:flutter_tools/src/features.dart';
|
||||
import 'package:flutter_tools/src/runner/flutter_command.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
@@ -270,6 +271,111 @@ void main() {
|
||||
FeatureFlags: () => TestFeatureFlags(isWebEnabled: false),
|
||||
});
|
||||
|
||||
testUsingContext('precache downloads iOS and Android artifacts by default', () async {
|
||||
final PrecacheCommand command = PrecacheCommand();
|
||||
applyMocksToCommand(command);
|
||||
|
||||
await createTestCommandRunner(command).run(
|
||||
const <String>[
|
||||
'precache',
|
||||
],
|
||||
);
|
||||
|
||||
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
|
||||
DevelopmentArtifact.universal,
|
||||
DevelopmentArtifact.iOS,
|
||||
DevelopmentArtifact.androidGenSnapshot,
|
||||
DevelopmentArtifact.androidMaven,
|
||||
DevelopmentArtifact.androidInternalBuild,
|
||||
}));
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => cache,
|
||||
});
|
||||
|
||||
testUsingContext('precache --all-platforms gets all artifacts', () async {
|
||||
final PrecacheCommand command = PrecacheCommand();
|
||||
applyMocksToCommand(command);
|
||||
|
||||
await createTestCommandRunner(command).run(
|
||||
const <String>[
|
||||
'precache',
|
||||
'--all-platforms',
|
||||
],
|
||||
);
|
||||
|
||||
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
|
||||
DevelopmentArtifact.universal,
|
||||
DevelopmentArtifact.iOS,
|
||||
DevelopmentArtifact.androidGenSnapshot,
|
||||
DevelopmentArtifact.androidMaven,
|
||||
DevelopmentArtifact.androidInternalBuild,
|
||||
DevelopmentArtifact.web,
|
||||
DevelopmentArtifact.macOS,
|
||||
DevelopmentArtifact.linux,
|
||||
DevelopmentArtifact.windows,
|
||||
DevelopmentArtifact.fuchsia,
|
||||
DevelopmentArtifact.flutterRunner,
|
||||
}));
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => cache,
|
||||
FeatureFlags: () => TestFeatureFlags(
|
||||
isWebEnabled: true,
|
||||
isLinuxEnabled: true,
|
||||
isMacOSEnabled: true,
|
||||
isWindowsEnabled: true,
|
||||
),
|
||||
FlutterVersion: () => masterFlutterVersion,
|
||||
});
|
||||
|
||||
testUsingContext('precache with default artifacts does not override platform filtering', () async {
|
||||
final PrecacheCommand command = PrecacheCommand();
|
||||
applyMocksToCommand(command);
|
||||
|
||||
await createTestCommandRunner(command).run(
|
||||
const <String>[
|
||||
'precache',
|
||||
],
|
||||
);
|
||||
|
||||
verify(cache.platformOverrideArtifacts = <String>{});
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => cache,
|
||||
FlutterVersion: () => masterFlutterVersion,
|
||||
});
|
||||
|
||||
testUsingContext('precache with explicit artifact options overrides platform filtering', () async {
|
||||
final PrecacheCommand command = PrecacheCommand();
|
||||
applyMocksToCommand(command);
|
||||
|
||||
await createTestCommandRunner(command).run(
|
||||
const <String>[
|
||||
'precache',
|
||||
'--no-ios',
|
||||
'--no-android',
|
||||
'--macos',
|
||||
],
|
||||
);
|
||||
|
||||
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
|
||||
DevelopmentArtifact.universal,
|
||||
DevelopmentArtifact.macOS,
|
||||
}));
|
||||
verify(cache.platformOverrideArtifacts = <String>{'macos'});
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => cache,
|
||||
FlutterVersion: () => masterFlutterVersion,
|
||||
FeatureFlags: () => TestFeatureFlags(
|
||||
isMacOSEnabled: true,
|
||||
),
|
||||
Platform: () => FakePlatform(
|
||||
operatingSystem: 'windows',
|
||||
environment: <String, String>{
|
||||
'FLUTTER_ROOT': 'flutter',
|
||||
'FLUTTER_ALREADY_LOCKED': 'true',
|
||||
},
|
||||
),
|
||||
});
|
||||
|
||||
testUsingContext('precache downloads artifacts when --force is provided', () async {
|
||||
when(cache.isUpToDate()).thenReturn(true);
|
||||
final PrecacheCommand command = PrecacheCommand();
|
||||
@@ -285,6 +391,9 @@ void main() {
|
||||
}, overrides: <Type, Generator>{
|
||||
Cache: () => cache,
|
||||
FlutterVersion: () => flutterVersion,
|
||||
FeatureFlags: () => TestFeatureFlags(
|
||||
isMacOSEnabled: true,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -520,7 +520,7 @@ void main() {
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
expect(artifacts.getBinaryDirs(), <List<String>>[<String>['linux-x64', 'linux-x64/font-subset.zip']]);
|
||||
}, overrides: <Type, Generator> {
|
||||
Platform: () => FakePlatform()..operatingSystem = 'linux',
|
||||
Platform: () => FakePlatform(operatingSystem: 'linux'),
|
||||
});
|
||||
|
||||
testUsingContext('FontSubset artifacts on windows', () {
|
||||
@@ -529,7 +529,7 @@ void main() {
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
expect(artifacts.getBinaryDirs(), <List<String>>[<String>['windows-x64', 'windows-x64/font-subset.zip']]);
|
||||
}, overrides: <Type, Generator> {
|
||||
Platform: () => FakePlatform()..operatingSystem = 'windows',
|
||||
Platform: () => FakePlatform(operatingSystem: 'windows'),
|
||||
});
|
||||
|
||||
testUsingContext('FontSubset artifacts on macos', () {
|
||||
@@ -538,7 +538,7 @@ void main() {
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
expect(artifacts.getBinaryDirs(), <List<String>>[<String>['darwin-x64', 'darwin-x64/font-subset.zip']]);
|
||||
}, overrides: <Type, Generator> {
|
||||
Platform: () => FakePlatform()..operatingSystem = 'macos',
|
||||
Platform: () => FakePlatform(operatingSystem: 'macos'),
|
||||
});
|
||||
|
||||
testUsingContext('FontSubset artifacts on fuchsia', () {
|
||||
@@ -547,7 +547,7 @@ void main() {
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
expect(() => artifacts.getBinaryDirs(), throwsToolExit(message: 'Unsupported operating system: ${globals.platform.operatingSystem}'));
|
||||
}, overrides: <Type, Generator> {
|
||||
Platform: () => FakePlatform()..operatingSystem = 'fuchsia',
|
||||
Platform: () => FakePlatform(operatingSystem: 'fuchsia'),
|
||||
});
|
||||
|
||||
testUsingContext('FontSubset artifacts for all platforms', () {
|
||||
@@ -560,7 +560,40 @@ void main() {
|
||||
<String>['windows-x64', 'windows-x64/font-subset.zip'],
|
||||
]);
|
||||
}, overrides: <Type, Generator> {
|
||||
Platform: () => FakePlatform()..operatingSystem = 'fuchsia',
|
||||
Platform: () => FakePlatform(operatingSystem: 'fuchsia'),
|
||||
});
|
||||
|
||||
testUsingContext('macOS desktop artifacts ignore filtering when requested', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final MacOSEngineArtifacts artifacts = MacOSEngineArtifacts(mockCache);
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
when(mockCache.platformOverrideArtifacts).thenReturn(<String>{'macos'});
|
||||
|
||||
expect(artifacts.getBinaryDirs(), isNotEmpty);
|
||||
}, overrides: <Type, Generator> {
|
||||
Platform: () => FakePlatform(operatingSystem: 'linux'),
|
||||
});
|
||||
|
||||
testUsingContext('Windows desktop artifacts ignore filtering when requested', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final WindowsEngineArtifacts artifacts = WindowsEngineArtifacts(mockCache);
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
when(mockCache.platformOverrideArtifacts).thenReturn(<String>{'windows'});
|
||||
|
||||
expect(artifacts.getBinaryDirs(), isNotEmpty);
|
||||
}, overrides: <Type, Generator> {
|
||||
Platform: () => FakePlatform(operatingSystem: 'linux'),
|
||||
});
|
||||
|
||||
testUsingContext('Linux desktop artifacts ignore filtering when requested', () {
|
||||
final MockCache mockCache = MockCache();
|
||||
final LinuxEngineArtifacts artifacts = LinuxEngineArtifacts(mockCache);
|
||||
when(mockCache.includeAllPlatforms).thenReturn(false);
|
||||
when(mockCache.platformOverrideArtifacts).thenReturn(<String>{'linux'});
|
||||
|
||||
expect(artifacts.getBinaryDirs(), isNotEmpty);
|
||||
}, overrides: <Type, Generator> {
|
||||
Platform: () => FakePlatform(operatingSystem: 'macos'),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -829,6 +829,9 @@ class FakeCache implements Cache {
|
||||
@override
|
||||
bool includeAllPlatforms;
|
||||
|
||||
@override
|
||||
Set<String> platformOverrideArtifacts;
|
||||
|
||||
@override
|
||||
bool useUnsignedMacBinaries;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user