Unverified Commit a9700ffd authored by Mouad Debbar's avatar Mouad Debbar Committed by GitHub

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

Revert "[web:tools] always use CanvasKit from the cache when building web apps (#93002)"
parent 2a67bf78
...@@ -347,7 +347,7 @@ class Dart2WasmTarget extends Dart2WebTarget { ...@@ -347,7 +347,7 @@ class Dart2WasmTarget extends Dart2WebTarget {
/// Unpacks the dart2js or dart2wasm compilation and resources to a given /// Unpacks the dart2js or dart2wasm compilation and resources to a given
/// output directory. /// output directory.
class WebReleaseBundle extends Target { class WebReleaseBundle extends Target {
const WebReleaseBundle(this.webRenderer, this.isWasm); const WebReleaseBundle(this.webRenderer, {required this.isWasm});
final WebRendererMode webRenderer; final WebRendererMode webRenderer;
final bool isWasm; final bool isWasm;
...@@ -488,10 +488,9 @@ class WebReleaseBundle extends Target { ...@@ -488,10 +488,9 @@ class WebReleaseBundle extends Target {
/// These assets can be cached forever and are only invalidated when the /// These assets can be cached forever and are only invalidated when the
/// Flutter SDK is upgraded to a new version. /// Flutter SDK is upgraded to a new version.
class WebBuiltInAssets extends Target { class WebBuiltInAssets extends Target {
const WebBuiltInAssets(this.fileSystem, this.cache, this.isWasm); const WebBuiltInAssets(this.fileSystem, {required this.isWasm});
final FileSystem fileSystem; final FileSystem fileSystem;
final Cache cache;
final bool isWasm; final bool isWasm;
@override @override
...@@ -511,16 +510,13 @@ class WebBuiltInAssets extends Target { ...@@ -511,16 +510,13 @@ class WebBuiltInAssets extends Target {
@override @override
Future<void> build(Environment environment) async { Future<void> build(Environment environment) async {
// TODO(yjbanov): https://github.com/flutter/flutter/issues/52588 final Directory canvasKitDirectory = globals.fs.directory(
// globals.artifacts!.getArtifactPath(
// Update this when we start building CanvasKit from sources. In the Artifact.canvasKitPath,
// meantime, get the Web SDK directory from cache rather than through platform: TargetPlatform.web_javascript,
// 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>()) { for (final File file in canvasKitDirectory.listSync(recursive: true).whereType<File>()) {
final String relativePath = fileSystem.path.relative(file.path, from: canvasKitDirectory.path); final String relativePath = fileSystem.path.relative(file.path, from: canvasKitDirectory.path);
final String targetPath = fileSystem.path.join(environment.outputDir.path, 'canvaskit', relativePath); final String targetPath = fileSystem.path.join(environment.outputDir.path, 'canvaskit', relativePath);
...@@ -543,10 +539,9 @@ class WebBuiltInAssets extends Target { ...@@ -543,10 +539,9 @@ class WebBuiltInAssets extends Target {
/// Generate a service worker for a web target. /// Generate a service worker for a web target.
class WebServiceWorker extends Target { class WebServiceWorker extends Target {
const WebServiceWorker(this.fileSystem, this.cache, this.webRenderer, this.isWasm); const WebServiceWorker(this.fileSystem, this.webRenderer, {required this.isWasm});
final FileSystem fileSystem; final FileSystem fileSystem;
final Cache cache;
final WebRendererMode webRenderer; final WebRendererMode webRenderer;
final bool isWasm; final bool isWasm;
...@@ -556,8 +551,8 @@ class WebServiceWorker extends Target { ...@@ -556,8 +551,8 @@ class WebServiceWorker extends Target {
@override @override
List<Target> get dependencies => <Target>[ List<Target> get dependencies => <Target>[
if (isWasm) Dart2WasmTarget(webRenderer) else Dart2JSTarget(webRenderer), if (isWasm) Dart2WasmTarget(webRenderer) else Dart2JSTarget(webRenderer),
WebReleaseBundle(webRenderer, isWasm), WebReleaseBundle(webRenderer, isWasm: isWasm),
WebBuiltInAssets(fileSystem, cache, isWasm), WebBuiltInAssets(fileSystem, isWasm: isWasm),
]; ];
@override @override
......
...@@ -181,20 +181,6 @@ class FlutterWebSdk extends CachedArtifact { ...@@ -181,20 +181,6 @@ class FlutterWebSdk extends CachedArtifact {
final Uri url = Uri.parse('${cache.storageBaseUrl}/flutter_infra_release/flutter/$version/flutter-web-sdk.zip'); final Uri url = Uri.parse('${cache.storageBaseUrl}/flutter_infra_release/flutter/$version/flutter-web-sdk.zip');
ErrorHandlingFileSystem.deleteIfExists(location, recursive: true); ErrorHandlingFileSystem.deleteIfExists(location, recursive: true);
await artifactUpdater.downloadZipArchive('Downloading Web SDK...', url, location); 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.
final FileSystem fileSystem = location.fileSystem;
for (final FileSystemEntity entity in location.listSync(recursive: true)) {
if (entity is File) {
final List<String> segments = fileSystem.path.split(entity.path);
segments.remove('flutter_web_sdk');
final String newPath = fileSystem.path.joinAll(segments);
final File newFile = fileSystem.file(newPath);
if (!newFile.existsSync()) {
newFile.createSync(recursive: true);
}
entity.copySync(newPath);
}
}
} }
} }
......
...@@ -51,14 +51,12 @@ class FlutterWebPlatform extends PlatformPlugin { ...@@ -51,14 +51,12 @@ class FlutterWebPlatform extends PlatformPlugin {
required Logger logger, required Logger logger,
required Artifacts? artifacts, required Artifacts? artifacts,
required ProcessManager processManager, required ProcessManager processManager,
required Cache cache,
TestTimeRecorder? testTimeRecorder, TestTimeRecorder? testTimeRecorder,
}) : _fileSystem = fileSystem, }) : _fileSystem = fileSystem,
_flutterToolPackageConfig = flutterToolPackageConfig, _flutterToolPackageConfig = flutterToolPackageConfig,
_chromiumLauncher = chromiumLauncher, _chromiumLauncher = chromiumLauncher,
_logger = logger, _logger = logger,
_artifacts = artifacts, _artifacts = artifacts {
_cache = cache {
final shelf.Cascade cascade = shelf.Cascade() final shelf.Cascade cascade = shelf.Cascade()
.add(_webSocketHandler.handler) .add(_webSocketHandler.handler)
.add(createStaticHandler( .add(createStaticHandler(
...@@ -98,7 +96,6 @@ class FlutterWebPlatform extends PlatformPlugin { ...@@ -98,7 +96,6 @@ class FlutterWebPlatform extends PlatformPlugin {
final OneOffHandler _webSocketHandler = OneOffHandler(); final OneOffHandler _webSocketHandler = OneOffHandler();
final AsyncMemoizer<void> _closeMemo = AsyncMemoizer<void>(); final AsyncMemoizer<void> _closeMemo = AsyncMemoizer<void>();
final String _root; final String _root;
final Cache _cache;
/// Allows only one test suite (typically one test file) to be loaded and run /// Allows only one test suite (typically one test file) to be loaded and run
/// at any given point in time. Loading more than one file at a time is known /// at any given point in time. Loading more than one file at a time is known
...@@ -121,7 +118,6 @@ class FlutterWebPlatform extends PlatformPlugin { ...@@ -121,7 +118,6 @@ class FlutterWebPlatform extends PlatformPlugin {
required ChromiumLauncher chromiumLauncher, required ChromiumLauncher chromiumLauncher,
required Artifacts? artifacts, required Artifacts? artifacts,
required ProcessManager processManager, required ProcessManager processManager,
required Cache cache,
TestTimeRecorder? testTimeRecorder, TestTimeRecorder? testTimeRecorder,
}) async { }) async {
final shelf_io.IOServer server = shelf_io.IOServer(await HttpMultiServer.loopback(0)); final shelf_io.IOServer server = shelf_io.IOServer(await HttpMultiServer.loopback(0));
...@@ -151,7 +147,6 @@ class FlutterWebPlatform extends PlatformPlugin { ...@@ -151,7 +147,6 @@ class FlutterWebPlatform extends PlatformPlugin {
logger: logger, logger: logger,
nullAssertions: nullAssertions, nullAssertions: nullAssertions,
processManager: processManager, processManager: processManager,
cache: cache,
testTimeRecorder: testTimeRecorder, testTimeRecorder: testTimeRecorder,
); );
} }
...@@ -226,17 +221,12 @@ class FlutterWebPlatform extends PlatformPlugin { ...@@ -226,17 +221,12 @@ class FlutterWebPlatform extends PlatformPlugin {
)); ));
File _canvasKitFile(String relativePath) { File _canvasKitFile(String relativePath) {
// TODO(yjbanov): https://github.com/flutter/flutter/issues/52588 final String canvasKitPath = _artifacts!.getArtifactPath(
// Artifact.canvasKitPath,
// Update this when we start building CanvasKit from sources. In the platform: TargetPlatform.web_javascript,
// 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 webSdkDirectory = _cache.getWebSdkDirectory();
final File canvasKitFile = _fileSystem.file(_fileSystem.path.join( final File canvasKitFile = _fileSystem.file(_fileSystem.path.join(
webSdkDirectory.path, canvasKitPath,
relativePath, relativePath,
)); ));
return canvasKitFile; return canvasKitFile;
...@@ -388,12 +378,13 @@ class FlutterWebPlatform extends PlatformPlugin { ...@@ -388,12 +378,13 @@ class FlutterWebPlatform extends PlatformPlugin {
/// Serves a local build of CanvasKit, replacing the CDN build, which can /// Serves a local build of CanvasKit, replacing the CDN build, which can
/// cause test flakiness due to reliance on network. /// cause test flakiness due to reliance on network.
shelf.Response _localCanvasKitHandler(shelf.Request request) { shelf.Response _localCanvasKitHandler(shelf.Request request) {
final String path = _fileSystem.path.fromUri(request.url); final String fullPath = _fileSystem.path.fromUri(request.url);
if (!path.startsWith('canvaskit/')) { if (!fullPath.startsWith('canvaskit/')) {
return shelf.Response.notFound('Not a CanvasKit file request'); return shelf.Response.notFound('Not a CanvasKit file request');
} }
final String extension = _fileSystem.path.extension(path); final String relativePath = fullPath.replaceFirst('canvaskit/', '');
final String extension = _fileSystem.path.extension(relativePath);
String contentType; String contentType;
switch (extension) { switch (extension) {
case '.js': case '.js':
...@@ -409,7 +400,7 @@ class FlutterWebPlatform extends PlatformPlugin { ...@@ -409,7 +400,7 @@ class FlutterWebPlatform extends PlatformPlugin {
} }
return shelf.Response.ok( return shelf.Response.ok(
_canvasKitFile(path).openRead(), _canvasKitFile(relativePath).openRead(),
headers: <String, Object>{ headers: <String, Object>{
HttpHeaders.contentTypeHeader: contentType, HttpHeaders.contentTypeHeader: contentType,
}, },
......
...@@ -176,7 +176,6 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner { ...@@ -176,7 +176,6 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
browserFinder: findChromeExecutable, browserFinder: findChromeExecutable,
logger: globals.logger, logger: globals.logger,
), ),
cache: globals.cache,
testTimeRecorder: testTimeRecorder, testTimeRecorder: testTimeRecorder,
); );
}, },
......
...@@ -54,7 +54,7 @@ Future<void> buildWeb( ...@@ -54,7 +54,7 @@ Future<void> buildWeb(
final Stopwatch sw = Stopwatch()..start(); final Stopwatch sw = Stopwatch()..start();
try { try {
final BuildResult result = await globals.buildSystem.build( final BuildResult result = await globals.buildSystem.build(
WebServiceWorker(globals.fs, globals.cache, buildInfo.webRenderer, isWasm), WebServiceWorker(globals.fs, buildInfo.webRenderer, isWasm: isWasm),
Environment( Environment(
projectDir: globals.fs.currentDirectory, projectDir: globals.fs.currentDirectory,
outputDir: outputDirectory, outputDir: outputDirectory,
......
...@@ -101,7 +101,7 @@ void main() { ...@@ -101,7 +101,7 @@ void main() {
webResources.childFile('index.html') webResources.childFile('index.html')
.createSync(recursive: true); .createSync(recursive: true);
environment.buildDir.childFile('main.dart.js').createSync(); environment.buildDir.childFile('main.dart.js').createSync();
await const WebReleaseBundle(WebRendererMode.autoDetect, false).build(environment); await const WebReleaseBundle(WebRendererMode.autoDetect, isWasm: false).build(environment);
expect(environment.outputDir.childFile('version.json'), exists); expect(environment.outputDir.childFile('version.json'), exists);
})); }));
...@@ -113,7 +113,7 @@ void main() { ...@@ -113,7 +113,7 @@ void main() {
final Directory webResources = environment.projectDir.childDirectory('web'); final Directory webResources = environment.projectDir.childDirectory('web');
webResources.childFile('index.html').createSync(recursive: true); webResources.childFile('index.html').createSync(recursive: true);
environment.buildDir.childFile('main.dart.js').createSync(); environment.buildDir.childFile('main.dart.js').createSync();
await const WebReleaseBundle(WebRendererMode.autoDetect, false).build(environment); await const WebReleaseBundle(WebRendererMode.autoDetect, isWasm: false).build(environment);
final String versionFile = environment.outputDir final String versionFile = environment.outputDir
.childFile('version.json') .childFile('version.json')
...@@ -131,7 +131,7 @@ void main() { ...@@ -131,7 +131,7 @@ void main() {
<!DOCTYPE html><html><base href="$kBaseHrefPlaceholder"><head></head></html> <!DOCTYPE html><html><base href="$kBaseHrefPlaceholder"><head></head></html>
'''); ''');
environment.buildDir.childFile('main.dart.js').createSync(); environment.buildDir.childFile('main.dart.js').createSync();
await const WebReleaseBundle(WebRendererMode.autoDetect, false).build(environment); await const WebReleaseBundle(WebRendererMode.autoDetect, isWasm: false).build(environment);
expect(environment.outputDir.childFile('index.html').readAsStringSync(), contains('/basehreftest/')); expect(environment.outputDir.childFile('index.html').readAsStringSync(), contains('/basehreftest/'));
})); }));
...@@ -144,7 +144,7 @@ void main() { ...@@ -144,7 +144,7 @@ void main() {
<!DOCTYPE html><html><head><base href='/basehreftest/'></head></html> <!DOCTYPE html><html><head><base href='/basehreftest/'></head></html>
'''); ''');
environment.buildDir.childFile('main.dart.js').createSync(); environment.buildDir.childFile('main.dart.js').createSync();
await const WebReleaseBundle(WebRendererMode.autoDetect, false).build(environment); await const WebReleaseBundle(WebRendererMode.autoDetect, isWasm: false).build(environment);
expect(environment.outputDir.childFile('index.html').readAsStringSync(), contains('/basehreftest/')); expect(environment.outputDir.childFile('index.html').readAsStringSync(), contains('/basehreftest/'));
})); }));
...@@ -166,7 +166,7 @@ void main() { ...@@ -166,7 +166,7 @@ void main() {
.writeAsStringSync('A'); .writeAsStringSync('A');
environment.buildDir.childFile('main.dart.js').createSync(); environment.buildDir.childFile('main.dart.js').createSync();
await const WebReleaseBundle(WebRendererMode.autoDetect, false).build(environment); await const WebReleaseBundle(WebRendererMode.autoDetect, isWasm: false).build(environment);
expect(environment.outputDir.childFile('foo.txt') expect(environment.outputDir.childFile('foo.txt')
.readAsStringSync(), 'A'); .readAsStringSync(), 'A');
...@@ -178,7 +178,7 @@ void main() { ...@@ -178,7 +178,7 @@ void main() {
// Update to arbitrary resource file triggers rebuild. // Update to arbitrary resource file triggers rebuild.
webResources.childFile('foo.txt').writeAsStringSync('B'); webResources.childFile('foo.txt').writeAsStringSync('B');
await const WebReleaseBundle(WebRendererMode.autoDetect, false).build(environment); await const WebReleaseBundle(WebRendererMode.autoDetect, isWasm: false).build(environment);
expect(environment.outputDir.childFile('foo.txt') expect(environment.outputDir.childFile('foo.txt')
.readAsStringSync(), 'B'); .readAsStringSync(), 'B');
...@@ -827,7 +827,7 @@ void main() { ...@@ -827,7 +827,7 @@ void main() {
environment.outputDir.childDirectory('a').childFile('a.txt') environment.outputDir.childDirectory('a').childFile('a.txt')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync('A'); ..writeAsStringSync('A');
await WebServiceWorker(globals.fs, globals.cache, WebRendererMode.autoDetect, false).build(environment); await WebServiceWorker(globals.fs, WebRendererMode.autoDetect, isWasm: false).build(environment);
expect(environment.outputDir.childFile('flutter_service_worker.js'), exists); expect(environment.outputDir.childFile('flutter_service_worker.js'), exists);
// Contains file hash. // Contains file hash.
...@@ -846,7 +846,7 @@ void main() { ...@@ -846,7 +846,7 @@ void main() {
environment.outputDir environment.outputDir
.childFile('index.html') .childFile('index.html')
.createSync(recursive: true); .createSync(recursive: true);
await WebServiceWorker(globals.fs, globals.cache, WebRendererMode.autoDetect, false).build(environment); await WebServiceWorker(globals.fs, WebRendererMode.autoDetect, isWasm: false).build(environment);
expect(environment.outputDir.childFile('flutter_service_worker.js'), exists); expect(environment.outputDir.childFile('flutter_service_worker.js'), exists);
// Contains file hash for both `/` and index.html. // Contains file hash for both `/` and index.html.
...@@ -864,7 +864,7 @@ void main() { ...@@ -864,7 +864,7 @@ void main() {
environment.outputDir environment.outputDir
.childFile('main.dart.js.map') .childFile('main.dart.js.map')
.createSync(recursive: true); .createSync(recursive: true);
await WebServiceWorker(globals.fs, globals.cache, WebRendererMode.autoDetect, false).build(environment); await WebServiceWorker(globals.fs, WebRendererMode.autoDetect, isWasm: false).build(environment);
// No caching of source maps. // No caching of source maps.
expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(), expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(),
...@@ -896,7 +896,7 @@ void main() { ...@@ -896,7 +896,7 @@ void main() {
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync('OL'); ..writeAsStringSync('OL');
await WebBuiltInAssets(globals.fs, globals.cache, false).build(environment); await WebBuiltInAssets(globals.fs, isWasm: false).build(environment);
// No caching of source maps. // No caching of source maps.
final String fileGeneratorsPath = environment.artifacts final String fileGeneratorsPath = environment.artifacts
...@@ -913,7 +913,7 @@ void main() { ...@@ -913,7 +913,7 @@ void main() {
globals.fs.file('bin/cache/flutter_web_sdk/canvaskit/canvaskit.wasm') globals.fs.file('bin/cache/flutter_web_sdk/canvaskit/canvaskit.wasm')
.createSync(recursive: true); .createSync(recursive: true);
await WebBuiltInAssets(globals.fs, globals.cache, true).build(environment); await WebBuiltInAssets(globals.fs, isWasm: true).build(environment);
expect(environment.outputDir.childFile('main.dart.js').existsSync(), true); expect(environment.outputDir.childFile('main.dart.js').existsSync(), true);
expect(environment.outputDir.childDirectory('canvaskit') expect(environment.outputDir.childDirectory('canvaskit')
......
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