Unverified Commit 77378934 authored by Yegor's avatar Yegor Committed by GitHub

[web:tools] always use CanvasKit from the cache when building web apps (#93002)

parent 6cd39cce
......@@ -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<void> 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<File>()) {
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<Target> get dependencies => <Target>[
const Dart2JSTarget(),
const WebReleaseBundle(),
WebBuiltInAssets(fileSystem),
WebBuiltInAssets(fileSystem, cache),
];
@override
......
......@@ -49,7 +49,7 @@ List<Target> _kDefaultTargets = <Target>[
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(),
......
......@@ -37,7 +37,7 @@ Future<void> 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
......
......@@ -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(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment