Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 42bd5f2

Browse files
author
Harry Terkelsen
authored
Download platform-agnostic Flutter Web SDK in the flutter_tool (#118654)
1 parent 1b779b6 commit 42bd5f2

File tree

2 files changed

+9
-88
lines changed

2 files changed

+9
-88
lines changed

packages/flutter_tools/lib/src/flutter_cache.dart

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class FlutterCache extends Cache {
3737
registerArtifact(AndroidGenSnapshotArtifacts(this, platform: platform));
3838
registerArtifact(AndroidInternalBuildArtifacts(this));
3939
registerArtifact(IOSEngineArtifacts(this, platform: platform));
40-
registerArtifact(FlutterWebSdk(this, platform: platform));
40+
registerArtifact(FlutterWebSdk(this));
4141
registerArtifact(FlutterSdk(this, platform: platform));
4242
registerArtifact(WindowsEngineArtifacts(this, platform: platform));
4343
registerArtifact(MacOSEngineArtifacts(this, platform: platform));
@@ -158,16 +158,13 @@ class MaterialFonts extends CachedArtifact {
158158
///
159159
/// This SDK references code within the regular Dart sdk to reduce download size.
160160
class FlutterWebSdk extends CachedArtifact {
161-
FlutterWebSdk(Cache cache, {required Platform platform})
162-
: _platform = platform,
163-
super(
161+
FlutterWebSdk(Cache cache)
162+
: super(
164163
'flutter_web_sdk',
165164
cache,
166165
DevelopmentArtifact.web,
167166
);
168167

169-
final Platform _platform;
170-
171168
@override
172169
Directory get location => cache.getWebSdkDirectory();
173170

@@ -180,15 +177,7 @@ class FlutterWebSdk extends CachedArtifact {
180177
FileSystem fileSystem,
181178
OperatingSystemUtils operatingSystemUtils,
182179
) async {
183-
String platformName = 'flutter-web-sdk-';
184-
if (_platform.isMacOS) {
185-
platformName += 'darwin-x64';
186-
} else if (_platform.isLinux) {
187-
platformName += 'linux-x64';
188-
} else if (_platform.isWindows) {
189-
platformName += 'windows-x64';
190-
}
191-
final Uri url = Uri.parse('${cache.storageBaseUrl}/flutter_infra_release/flutter/$version/$platformName.zip');
180+
final Uri url = Uri.parse('${cache.storageBaseUrl}/flutter_infra_release/flutter/$version/flutter-web-sdk.zip');
192181
ErrorHandlingFileSystem.deleteIfExists(location, recursive: true);
193182
await artifactUpdater.downloadZipArchive('Downloading Web SDK...', url, location);
194183
// This is a temporary work-around for not being able to safely download into a shared directory.
@@ -205,21 +194,6 @@ class FlutterWebSdk extends CachedArtifact {
205194
entity.copySync(newPath);
206195
}
207196
}
208-
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-
}
223197
}
224198
}
225199

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

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ void main() {
760760
final Cache cache = Cache.test(processManager: FakeProcessManager.any(), fileSystem: fileSystem);
761761
final Directory webCacheDirectory = cache.getWebSdkDirectory();
762762
final FakeArtifactUpdater artifactUpdater = FakeArtifactUpdater();
763-
final FlutterWebSdk webSdk = FlutterWebSdk(cache, platform: FakePlatform());
763+
final FlutterWebSdk webSdk = FlutterWebSdk(cache);
764764

765765
final List<String> messages = <String>[];
766766
final List<String> downloads = <String>[];
@@ -778,17 +778,14 @@ void main() {
778778

779779
expect(messages, <String>[
780780
'Downloading Web SDK...',
781-
'Downloading CanvasKit...',
782781
]);
783782

784783
expect(downloads, <String>[
785-
'https://storage.googleapis.com/flutter_infra_release/flutter/hijklmnop/flutter-web-sdk-linux-x64.zip',
786-
'https://chrome-infra-packages.appspot.com/dl/flutter/web/canvaskit_bundle/+/abcdefg',
784+
'https://storage.googleapis.com/flutter_infra_release/flutter/hijklmnop/flutter-web-sdk.zip',
787785
]);
788786

789787
expect(locations, <String>[
790788
'cache/bin/cache/flutter_web_sdk',
791-
'cache/bin/cache/flutter_web_sdk',
792789
]);
793790

794791
expect(webCacheDirectory.childFile('foo'), exists);
@@ -820,7 +817,7 @@ void main() {
820817
);
821818
final Directory webCacheDirectory = cache.getWebSdkDirectory();
822819
final FakeArtifactUpdater artifactUpdater = FakeArtifactUpdater();
823-
final FlutterWebSdk webSdk = FlutterWebSdk(cache, platform: FakePlatform());
820+
final FlutterWebSdk webSdk = FlutterWebSdk(cache);
824821

825822
final List<String> downloads = <String>[];
826823
final List<String> locations = <String>[];
@@ -835,57 +832,7 @@ void main() {
835832
await webSdk.updateInner(artifactUpdater, fileSystem, FakeOperatingSystemUtils());
836833

837834
expect(downloads, <String>[
838-
'https://flutter.storage.com/override/flutter_infra_release/flutter/hijklmnop/flutter-web-sdk-linux-x64.zip',
839-
'https://flutter.storage.com/override/flutter_infra_release/cipd/flutter/web/canvaskit_bundle/+/abcdefg',
840-
]);
841-
});
842-
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',
835+
'https://flutter.storage.com/override/flutter_infra_release/flutter/hijklmnop/flutter-web-sdk.zip',
889836
]);
890837
});
891838

@@ -895,7 +842,7 @@ void main() {
895842
final Cache cache = Cache.test(processManager: FakeProcessManager.any(), fileSystem: fileSystem);
896843
final Directory webCacheDirectory = cache.getWebSdkDirectory();
897844
final FakeArtifactUpdater artifactUpdater = FakeArtifactUpdater();
898-
final FlutterWebSdk webSdk = FlutterWebSdk(cache, platform: FakePlatform());
845+
final FlutterWebSdk webSdk = FlutterWebSdk(cache);
899846

900847
artifactUpdater.onDownloadZipArchive = (String message, Uri uri, Directory location) {
901848
location.createSync(recursive: true);

0 commit comments

Comments
 (0)