Skip to content

Commit 529184b

Browse files
author
Harry Terkelsen
authored
[flutter_tool] Don't download CanvasKit if it's already in flutter_web_sdk (#113072)
1 parent f36b9c5 commit 529184b

File tree

2 files changed

+63
-7
lines changed

2 files changed

+63
-7
lines changed

packages/flutter_tools/lib/src/flutter_cache.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,20 @@ class FlutterWebSdk extends CachedArtifact {
206206
}
207207
}
208208

209-
final String canvasKitVersion = cache.getVersionFor('canvaskit')!;
210-
final String canvasKitUrl = '${cache.cipdBaseUrl}/flutter/web/canvaskit_bundle/+/$canvasKitVersion';
211-
return artifactUpdater.downloadZipArchive(
212-
'Downloading CanvasKit...',
213-
Uri.parse(canvasKitUrl),
214-
location,
215-
);
209+
// If the flutter_web_sdk folder doesn't already contain CanvasKit, then
210+
// download it from CIPD.
211+
// TODO(hterkelsen): This whole section can be removed when we are always building
212+
// CanvasKit as part of flutter_web_sdk. See https://github.com/flutter/flutter/issues/113073
213+
final File expectedCanvasKitFile = fileSystem.file(fileSystem.path.join(location.path, 'canvaskit', 'canvaskit.wasm'));
214+
if (!expectedCanvasKitFile.existsSync()) {
215+
final String canvasKitVersion = cache.getVersionFor('canvaskit')!;
216+
final String canvasKitUrl = '${cache.cipdBaseUrl}/flutter/web/canvaskit_bundle/+/$canvasKitVersion';
217+
return artifactUpdater.downloadZipArchive(
218+
'Downloading CanvasKit...',
219+
Uri.parse(canvasKitUrl),
220+
location,
221+
);
222+
}
216223
}
217224
}
218225

packages/flutter_tools/test/general.shard/cache_test.dart

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,55 @@ void main() {
840840
]);
841841
});
842842

843+
testWithoutContext('FlutterWebSdk does not download CanvasKit if it is already in flutter_web_sdk', () async {
844+
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
845+
final Directory internalDir = fileSystem.currentDirectory
846+
.childDirectory('cache')
847+
.childDirectory('bin')
848+
.childDirectory('internal');
849+
final File canvasKitVersionFile = internalDir.childFile('canvaskit.version');
850+
canvasKitVersionFile.createSync(recursive: true);
851+
canvasKitVersionFile.writeAsStringSync('abcdefg');
852+
853+
final File engineVersionFile = internalDir.childFile('engine.version');
854+
engineVersionFile.createSync(recursive: true);
855+
engineVersionFile.writeAsStringSync('hijklmnop');
856+
857+
final Cache cache = Cache.test(processManager: FakeProcessManager.any(), fileSystem: fileSystem);
858+
final FakeArtifactUpdater artifactUpdater = FakeArtifactUpdater();
859+
final FlutterWebSdk webSdk = FlutterWebSdk(cache, platform: FakePlatform());
860+
861+
final List<String> messages = <String>[];
862+
final List<String> downloads = <String>[];
863+
final List<String> locations = <String>[];
864+
artifactUpdater.onDownloadZipArchive = (String message, Uri uri, Directory location) {
865+
messages.add(message);
866+
downloads.add(uri.toString());
867+
locations.add(location.path);
868+
location.createSync(recursive: true);
869+
location.childDirectory('canvaskit').createSync();
870+
location.childDirectory('canvaskit').childFile('canvaskit.js').createSync();
871+
location.childDirectory('canvaskit').childFile('canvaskit.wasm').createSync();
872+
location.childDirectory('canvaskit').childDirectory('profiling').createSync();
873+
location.childDirectory('canvaskit').childDirectory('profiling').childFile('canvaskit.js').createSync();
874+
location.childDirectory('canvaskit').childDirectory('profiling').childFile('canvaskit.wasm').createSync();
875+
};
876+
877+
await webSdk.updateInner(artifactUpdater, fileSystem, FakeOperatingSystemUtils());
878+
879+
expect(messages, <String>[
880+
'Downloading Web SDK...',
881+
]);
882+
883+
expect(downloads, <String>[
884+
'https://storage.googleapis.com/flutter_infra_release/flutter/hijklmnop/flutter-web-sdk-linux-x64.zip',
885+
]);
886+
887+
expect(locations, <String>[
888+
'cache/bin/cache/flutter_web_sdk',
889+
]);
890+
});
891+
843892
testWithoutContext('FlutterWebSdk uses tryToDelete to handle directory edge cases', () async {
844893
final FileExceptionHandler handler = FileExceptionHandler();
845894
final MemoryFileSystem fileSystem = MemoryFileSystem.test(opHandle: handler.opHandle);

0 commit comments

Comments
 (0)