Skip to content

Commit f5672b9

Browse files
add --force flag to precache (flutter#31278)
1 parent b275e11 commit f5672b9

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

packages/flutter_tools/lib/src/commands/precache.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class PrecacheCommand extends FlutterCommand {
1313
PrecacheCommand() {
1414
argParser.addFlag('all-platforms', abbr: 'a', negatable: false,
1515
help: 'Precache artifacts for all platforms.');
16+
argParser.addFlag('force', abbr: 'f', negatable: false,
17+
help: 'Force downloading of artifacts.');
1618
argParser.addFlag('android', negatable: true, defaultsTo: true,
1719
help: 'Precache artifacts for Android development');
1820
argParser.addFlag('ios', negatable: true, defaultsTo: true,
@@ -55,10 +57,11 @@ class PrecacheCommand extends FlutterCommand {
5557
requiredArtifacts.add(artifact);
5658
}
5759
}
58-
if (cache.isUpToDate()) {
59-
printStatus('Already up-to-date.');
60-
} else {
60+
final bool forceUpdate = argResults['force'];
61+
if (forceUpdate || !cache.isUpToDate()) {
6162
await cache.updateAll(requiredArtifacts);
63+
} else {
64+
printStatus('Already up-to-date.');
6265
}
6366
return null;
6467
}

packages/flutter_tools/test/commands/precache_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ void main() {
6363
Cache: () => cache,
6464
FlutterVersion: () => flutterVersion,
6565
});
66+
67+
testUsingContext('Downloads artifacts when --force is provided', () async {
68+
when(cache.isUpToDate()).thenReturn(true);
69+
// Release lock between test cases.
70+
Cache.releaseLockEarly();
71+
final PrecacheCommand command = PrecacheCommand();
72+
applyMocksToCommand(command);
73+
await createTestCommandRunner(command).run(const <String>['precache', '--force']);
74+
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
75+
DevelopmentArtifact.universal,
76+
DevelopmentArtifact.iOS,
77+
DevelopmentArtifact.android,
78+
}));
79+
}, overrides: <Type, Generator>{
80+
Cache: () => cache,
81+
FlutterVersion: () => flutterVersion,
82+
});
6683
});
6784
}
6885

0 commit comments

Comments
 (0)