mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Download platform-agnostic Flutter Web SDK in the flutter_tool (#118654)
This commit is contained in:
parent
1b779b655e
commit
42bd5f2bd1
@ -37,7 +37,7 @@ class FlutterCache extends Cache {
|
||||
registerArtifact(AndroidGenSnapshotArtifacts(this, platform: platform));
|
||||
registerArtifact(AndroidInternalBuildArtifacts(this));
|
||||
registerArtifact(IOSEngineArtifacts(this, platform: platform));
|
||||
registerArtifact(FlutterWebSdk(this, platform: platform));
|
||||
registerArtifact(FlutterWebSdk(this));
|
||||
registerArtifact(FlutterSdk(this, platform: platform));
|
||||
registerArtifact(WindowsEngineArtifacts(this, platform: platform));
|
||||
registerArtifact(MacOSEngineArtifacts(this, platform: platform));
|
||||
@ -158,16 +158,13 @@ class MaterialFonts extends CachedArtifact {
|
||||
///
|
||||
/// This SDK references code within the regular Dart sdk to reduce download size.
|
||||
class FlutterWebSdk extends CachedArtifact {
|
||||
FlutterWebSdk(Cache cache, {required Platform platform})
|
||||
: _platform = platform,
|
||||
super(
|
||||
FlutterWebSdk(Cache cache)
|
||||
: super(
|
||||
'flutter_web_sdk',
|
||||
cache,
|
||||
DevelopmentArtifact.web,
|
||||
);
|
||||
|
||||
final Platform _platform;
|
||||
|
||||
@override
|
||||
Directory get location => cache.getWebSdkDirectory();
|
||||
|
||||
@ -180,15 +177,7 @@ class FlutterWebSdk extends CachedArtifact {
|
||||
FileSystem fileSystem,
|
||||
OperatingSystemUtils operatingSystemUtils,
|
||||
) async {
|
||||
String platformName = 'flutter-web-sdk-';
|
||||
if (_platform.isMacOS) {
|
||||
platformName += 'darwin-x64';
|
||||
} else if (_platform.isLinux) {
|
||||
platformName += 'linux-x64';
|
||||
} else if (_platform.isWindows) {
|
||||
platformName += 'windows-x64';
|
||||
}
|
||||
final Uri url = Uri.parse('${cache.storageBaseUrl}/flutter_infra_release/flutter/$version/$platformName.zip');
|
||||
final Uri url = Uri.parse('${cache.storageBaseUrl}/flutter_infra_release/flutter/$version/flutter-web-sdk.zip');
|
||||
ErrorHandlingFileSystem.deleteIfExists(location, recursive: true);
|
||||
await artifactUpdater.downloadZipArchive('Downloading Web SDK...', url, location);
|
||||
// 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 {
|
||||
entity.copySync(newPath);
|
||||
}
|
||||
}
|
||||
|
||||
// If the flutter_web_sdk folder doesn't already contain CanvasKit, then
|
||||
// download it from CIPD.
|
||||
// TODO(hterkelsen): This whole section can be removed when we are always building
|
||||
// CanvasKit as part of flutter_web_sdk. See https://github.com/flutter/flutter/issues/113073
|
||||
final File expectedCanvasKitFile = fileSystem.file(fileSystem.path.join(location.path, 'canvaskit', 'canvaskit.wasm'));
|
||||
if (!expectedCanvasKitFile.existsSync()) {
|
||||
final String canvasKitVersion = cache.getVersionFor('canvaskit')!;
|
||||
final String canvasKitUrl = '${cache.cipdBaseUrl}/flutter/web/canvaskit_bundle/+/$canvasKitVersion';
|
||||
return artifactUpdater.downloadZipArchive(
|
||||
'Downloading CanvasKit...',
|
||||
Uri.parse(canvasKitUrl),
|
||||
location,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -760,7 +760,7 @@ void main() {
|
||||
final Cache cache = Cache.test(processManager: FakeProcessManager.any(), fileSystem: fileSystem);
|
||||
final Directory webCacheDirectory = cache.getWebSdkDirectory();
|
||||
final FakeArtifactUpdater artifactUpdater = FakeArtifactUpdater();
|
||||
final FlutterWebSdk webSdk = FlutterWebSdk(cache, platform: FakePlatform());
|
||||
final FlutterWebSdk webSdk = FlutterWebSdk(cache);
|
||||
|
||||
final List<String> messages = <String>[];
|
||||
final List<String> downloads = <String>[];
|
||||
@ -778,17 +778,14 @@ void main() {
|
||||
|
||||
expect(messages, <String>[
|
||||
'Downloading Web SDK...',
|
||||
'Downloading CanvasKit...',
|
||||
]);
|
||||
|
||||
expect(downloads, <String>[
|
||||
'https://storage.googleapis.com/flutter_infra_release/flutter/hijklmnop/flutter-web-sdk-linux-x64.zip',
|
||||
'https://chrome-infra-packages.appspot.com/dl/flutter/web/canvaskit_bundle/+/abcdefg',
|
||||
'https://storage.googleapis.com/flutter_infra_release/flutter/hijklmnop/flutter-web-sdk.zip',
|
||||
]);
|
||||
|
||||
expect(locations, <String>[
|
||||
'cache/bin/cache/flutter_web_sdk',
|
||||
'cache/bin/cache/flutter_web_sdk',
|
||||
]);
|
||||
|
||||
expect(webCacheDirectory.childFile('foo'), exists);
|
||||
@ -820,7 +817,7 @@ void main() {
|
||||
);
|
||||
final Directory webCacheDirectory = cache.getWebSdkDirectory();
|
||||
final FakeArtifactUpdater artifactUpdater = FakeArtifactUpdater();
|
||||
final FlutterWebSdk webSdk = FlutterWebSdk(cache, platform: FakePlatform());
|
||||
final FlutterWebSdk webSdk = FlutterWebSdk(cache);
|
||||
|
||||
final List<String> downloads = <String>[];
|
||||
final List<String> locations = <String>[];
|
||||
@ -835,57 +832,7 @@ void main() {
|
||||
await webSdk.updateInner(artifactUpdater, fileSystem, FakeOperatingSystemUtils());
|
||||
|
||||
expect(downloads, <String>[
|
||||
'https://flutter.storage.com/override/flutter_infra_release/flutter/hijklmnop/flutter-web-sdk-linux-x64.zip',
|
||||
'https://flutter.storage.com/override/flutter_infra_release/cipd/flutter/web/canvaskit_bundle/+/abcdefg',
|
||||
]);
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterWebSdk does not download CanvasKit if it is already in flutter_web_sdk', () async {
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
final Directory internalDir = fileSystem.currentDirectory
|
||||
.childDirectory('cache')
|
||||
.childDirectory('bin')
|
||||
.childDirectory('internal');
|
||||
final File canvasKitVersionFile = internalDir.childFile('canvaskit.version');
|
||||
canvasKitVersionFile.createSync(recursive: true);
|
||||
canvasKitVersionFile.writeAsStringSync('abcdefg');
|
||||
|
||||
final File engineVersionFile = internalDir.childFile('engine.version');
|
||||
engineVersionFile.createSync(recursive: true);
|
||||
engineVersionFile.writeAsStringSync('hijklmnop');
|
||||
|
||||
final Cache cache = Cache.test(processManager: FakeProcessManager.any(), fileSystem: fileSystem);
|
||||
final FakeArtifactUpdater artifactUpdater = FakeArtifactUpdater();
|
||||
final FlutterWebSdk webSdk = FlutterWebSdk(cache, platform: FakePlatform());
|
||||
|
||||
final List<String> messages = <String>[];
|
||||
final List<String> downloads = <String>[];
|
||||
final List<String> locations = <String>[];
|
||||
artifactUpdater.onDownloadZipArchive = (String message, Uri uri, Directory location) {
|
||||
messages.add(message);
|
||||
downloads.add(uri.toString());
|
||||
locations.add(location.path);
|
||||
location.createSync(recursive: true);
|
||||
location.childDirectory('canvaskit').createSync();
|
||||
location.childDirectory('canvaskit').childFile('canvaskit.js').createSync();
|
||||
location.childDirectory('canvaskit').childFile('canvaskit.wasm').createSync();
|
||||
location.childDirectory('canvaskit').childDirectory('profiling').createSync();
|
||||
location.childDirectory('canvaskit').childDirectory('profiling').childFile('canvaskit.js').createSync();
|
||||
location.childDirectory('canvaskit').childDirectory('profiling').childFile('canvaskit.wasm').createSync();
|
||||
};
|
||||
|
||||
await webSdk.updateInner(artifactUpdater, fileSystem, FakeOperatingSystemUtils());
|
||||
|
||||
expect(messages, <String>[
|
||||
'Downloading Web SDK...',
|
||||
]);
|
||||
|
||||
expect(downloads, <String>[
|
||||
'https://storage.googleapis.com/flutter_infra_release/flutter/hijklmnop/flutter-web-sdk-linux-x64.zip',
|
||||
]);
|
||||
|
||||
expect(locations, <String>[
|
||||
'cache/bin/cache/flutter_web_sdk',
|
||||
'https://flutter.storage.com/override/flutter_infra_release/flutter/hijklmnop/flutter-web-sdk.zip',
|
||||
]);
|
||||
});
|
||||
|
||||
@ -895,7 +842,7 @@ void main() {
|
||||
final Cache cache = Cache.test(processManager: FakeProcessManager.any(), fileSystem: fileSystem);
|
||||
final Directory webCacheDirectory = cache.getWebSdkDirectory();
|
||||
final FakeArtifactUpdater artifactUpdater = FakeArtifactUpdater();
|
||||
final FlutterWebSdk webSdk = FlutterWebSdk(cache, platform: FakePlatform());
|
||||
final FlutterWebSdk webSdk = FlutterWebSdk(cache);
|
||||
|
||||
artifactUpdater.onDownloadZipArchive = (String message, Uri uri, Directory location) {
|
||||
location.createSync(recursive: true);
|
||||
|
Loading…
Reference in New Issue
Block a user