diff --git a/packages/flutter_tools/lib/src/build_system/targets/web.dart b/packages/flutter_tools/lib/src/build_system/targets/web.dart index a8c1a0d699..563d9a405e 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/web.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/web.dart @@ -410,9 +410,10 @@ class WebReleaseBundle extends Target { /// These assets can be cached forever and are only invalidated when the /// Flutter SDK is upgraded to a new version. class WebBuiltInAssets extends Target { - const WebBuiltInAssets(this.fileSystem); + const WebBuiltInAssets(this.fileSystem, this.cache); final FileSystem fileSystem; + final Cache cache; @override String get name => 'web_static_assets'; @@ -431,7 +432,15 @@ class WebBuiltInAssets extends Target { @override Future build(Environment environment) async { - final Directory flutterWebSdk = globals.artifacts.getHostArtifact(HostArtifact.flutterWebSdk) as Directory; + // TODO(yjbanov): https://github.com/flutter/flutter/issues/52588 + // + // Update this when we start building CanvasKit from sources. In the + // meantime, get the Web SDK directory from cache rather than through + // Artifacts. The latter is sensitive to `--local-engine`, which changes + // the directory to point to ENGINE/src/out. However, CanvasKit is not yet + // built as part of the engine, but fetched from CIPD, and so it won't be + // found in ENGINE/src/out. + final Directory flutterWebSdk = cache.getWebSdkDirectory(); final Directory canvasKitDirectory = flutterWebSdk.childDirectory('canvaskit'); for (final File file in canvasKitDirectory.listSync(recursive: true).whereType()) { final String relativePath = fileSystem.path.relative(file.path, from: canvasKitDirectory.path); @@ -443,9 +452,10 @@ class WebBuiltInAssets extends Target { /// Generate a service worker for a web target. class WebServiceWorker extends Target { - const WebServiceWorker(this.fileSystem); + const WebServiceWorker(this.fileSystem, this.cache); final FileSystem fileSystem; + final Cache cache; @override String get name => 'web_service_worker'; @@ -454,7 +464,7 @@ class WebServiceWorker extends Target { List get dependencies => [ const Dart2JSTarget(), const WebReleaseBundle(), - WebBuiltInAssets(fileSystem), + WebBuiltInAssets(fileSystem, cache), ]; @override diff --git a/packages/flutter_tools/lib/src/commands/assemble.dart b/packages/flutter_tools/lib/src/commands/assemble.dart index 2fc67cf81e..369a3c9df5 100644 --- a/packages/flutter_tools/lib/src/commands/assemble.dart +++ b/packages/flutter_tools/lib/src/commands/assemble.dart @@ -49,7 +49,7 @@ List _kDefaultTargets = [ const ReleaseBundleLinuxAssets(TargetPlatform.linux_x64), const ReleaseBundleLinuxAssets(TargetPlatform.linux_arm64), // Web targets - WebServiceWorker(globals.fs), + WebServiceWorker(globals.fs, globals.cache), const ReleaseAndroidApplication(), // This is a one-off rule for bundle and aot compat. const CopyFlutterBundle(), diff --git a/packages/flutter_tools/lib/src/web/compile.dart b/packages/flutter_tools/lib/src/web/compile.dart index 1a8cd8b36b..054c552aba 100644 --- a/packages/flutter_tools/lib/src/web/compile.dart +++ b/packages/flutter_tools/lib/src/web/compile.dart @@ -37,7 +37,7 @@ Future buildWeb( final Status status = globals.logger.startProgress('Compiling $target for the Web...'); final Stopwatch sw = Stopwatch()..start(); try { - final BuildResult result = await globals.buildSystem.build(WebServiceWorker(globals.fs), Environment( + final BuildResult result = await globals.buildSystem.build(WebServiceWorker(globals.fs, globals.cache), Environment( projectDir: globals.fs.currentDirectory, outputDir: outputDirectory, buildDir: flutterProject.directory diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart index 2313add2da..0be396a79c 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart @@ -637,7 +637,7 @@ void main() { environment.outputDir.childDirectory('a').childFile('a.txt') ..createSync(recursive: true) ..writeAsStringSync('A'); - await WebServiceWorker(globals.fs).build(environment); + await WebServiceWorker(globals.fs, globals.cache).build(environment); expect(environment.outputDir.childFile('flutter_service_worker.js'), exists); // Contains file hash. @@ -656,7 +656,7 @@ void main() { environment.outputDir .childFile('index.html') .createSync(recursive: true); - await WebServiceWorker(globals.fs).build(environment); + await WebServiceWorker(globals.fs, globals.cache).build(environment); expect(environment.outputDir.childFile('flutter_service_worker.js'), exists); // Contains file hash for both `/` and index.html. @@ -674,7 +674,7 @@ void main() { environment.outputDir .childFile('main.dart.js.map') .createSync(recursive: true); - await WebServiceWorker(globals.fs).build(environment); + await WebServiceWorker(globals.fs, globals.cache).build(environment); // No caching of source maps. expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(),