diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index 7f3aa7a140..3da4de5c3e 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -24,6 +24,7 @@ class Cache { _artifacts.add(MaterialFonts(this)); _artifacts.add(FlutterEngine(this)); _artifacts.add(GradleWrapper(this)); + _artifacts.add(FlutterWebSdk(this)); } else { _artifacts.addAll(artifacts); } @@ -162,6 +163,12 @@ class Cache { return getCacheArtifacts().childDirectory(name); } + /// The web sdk has to be co-located with the dart-sdk so that they can share source + /// code. + Directory getWebSdkDirectory() { + return getRoot().childDirectory('flutter_web_sdk'); + } + String getVersionFor(String artifactName) { final File versionFile = fs.file(fs.path.join(_rootOverride?.path ?? flutterRoot, 'bin', 'internal', '$artifactName.version')); return versionFile.existsSync() ? versionFile.readAsStringSync().trim() : null; @@ -357,6 +364,34 @@ class MaterialFonts extends CachedArtifact { } } +/// A cached artifact containing the web dart:ui sources, platform dill files, +/// and libraries.json. +/// +/// This SDK references code within the regular Dart sdk to reduce download size. +class FlutterWebSdk extends CachedArtifact { + FlutterWebSdk(Cache cache) : super('flutter_web_sdk', cache); + + @override + Directory get location => cache.getWebSdkDirectory(); + + @override + String get version => cache.getVersionFor('engine'); + + @override + Future updateInner() { + 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('$_storageBaseUrl/flutter_infra/flutter/$version/$platformName.zip'); + return _downloadZipArchive('Downloading Web SDK...', url, location); + } +} + /// A cached artifact containing the Flutter engine binaries. class FlutterEngine extends CachedArtifact { FlutterEngine(Cache cache) : super('engine', cache);