mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Revert "[web:tools] always use CanvasKit from the cache when building web apps (#93002)"
This commit is contained in:
parent
2a67bf78f0
commit
a9700ffdd5
@ -347,7 +347,7 @@ class Dart2WasmTarget extends Dart2WebTarget {
|
||||
/// Unpacks the dart2js or dart2wasm compilation and resources to a given
|
||||
/// output directory.
|
||||
class WebReleaseBundle extends Target {
|
||||
const WebReleaseBundle(this.webRenderer, this.isWasm);
|
||||
const WebReleaseBundle(this.webRenderer, {required this.isWasm});
|
||||
|
||||
final WebRendererMode webRenderer;
|
||||
final bool isWasm;
|
||||
@ -488,10 +488,9 @@ 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, this.cache, this.isWasm);
|
||||
const WebBuiltInAssets(this.fileSystem, {required this.isWasm});
|
||||
|
||||
final FileSystem fileSystem;
|
||||
final Cache cache;
|
||||
final bool isWasm;
|
||||
|
||||
@override
|
||||
@ -511,16 +510,13 @@ class WebBuiltInAssets extends Target {
|
||||
|
||||
@override
|
||||
Future<void> build(Environment environment) async {
|
||||
// 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');
|
||||
final Directory canvasKitDirectory = globals.fs.directory(
|
||||
globals.artifacts!.getArtifactPath(
|
||||
Artifact.canvasKitPath,
|
||||
platform: TargetPlatform.web_javascript,
|
||||
),
|
||||
);
|
||||
|
||||
for (final File file in canvasKitDirectory.listSync(recursive: true).whereType<File>()) {
|
||||
final String relativePath = fileSystem.path.relative(file.path, from: canvasKitDirectory.path);
|
||||
final String targetPath = fileSystem.path.join(environment.outputDir.path, 'canvaskit', relativePath);
|
||||
@ -543,10 +539,9 @@ class WebBuiltInAssets extends Target {
|
||||
|
||||
/// Generate a service worker for a web 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 Cache cache;
|
||||
final WebRendererMode webRenderer;
|
||||
final bool isWasm;
|
||||
|
||||
@ -556,8 +551,8 @@ class WebServiceWorker extends Target {
|
||||
@override
|
||||
List<Target> get dependencies => <Target>[
|
||||
if (isWasm) Dart2WasmTarget(webRenderer) else Dart2JSTarget(webRenderer),
|
||||
WebReleaseBundle(webRenderer, isWasm),
|
||||
WebBuiltInAssets(fileSystem, cache, isWasm),
|
||||
WebReleaseBundle(webRenderer, isWasm: isWasm),
|
||||
WebBuiltInAssets(fileSystem, isWasm: isWasm),
|
||||
];
|
||||
|
||||
@override
|
||||
|
@ -181,20 +181,6 @@ class FlutterWebSdk extends CachedArtifact {
|
||||
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.
|
||||
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 {
|
||||
required Logger logger,
|
||||
required Artifacts? artifacts,
|
||||
required ProcessManager processManager,
|
||||
required Cache cache,
|
||||
TestTimeRecorder? testTimeRecorder,
|
||||
}) : _fileSystem = fileSystem,
|
||||
_flutterToolPackageConfig = flutterToolPackageConfig,
|
||||
_chromiumLauncher = chromiumLauncher,
|
||||
_logger = logger,
|
||||
_artifacts = artifacts,
|
||||
_cache = cache {
|
||||
_artifacts = artifacts {
|
||||
final shelf.Cascade cascade = shelf.Cascade()
|
||||
.add(_webSocketHandler.handler)
|
||||
.add(createStaticHandler(
|
||||
@ -98,7 +96,6 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
final OneOffHandler _webSocketHandler = OneOffHandler();
|
||||
final AsyncMemoizer<void> _closeMemo = AsyncMemoizer<void>();
|
||||
final String _root;
|
||||
final Cache _cache;
|
||||
|
||||
/// 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
|
||||
@ -121,7 +118,6 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
required ChromiumLauncher chromiumLauncher,
|
||||
required Artifacts? artifacts,
|
||||
required ProcessManager processManager,
|
||||
required Cache cache,
|
||||
TestTimeRecorder? testTimeRecorder,
|
||||
}) async {
|
||||
final shelf_io.IOServer server = shelf_io.IOServer(await HttpMultiServer.loopback(0));
|
||||
@ -151,7 +147,6 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
logger: logger,
|
||||
nullAssertions: nullAssertions,
|
||||
processManager: processManager,
|
||||
cache: cache,
|
||||
testTimeRecorder: testTimeRecorder,
|
||||
);
|
||||
}
|
||||
@ -226,17 +221,12 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
));
|
||||
|
||||
File _canvasKitFile(String relativePath) {
|
||||
// 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 webSdkDirectory = _cache.getWebSdkDirectory();
|
||||
final String canvasKitPath = _artifacts!.getArtifactPath(
|
||||
Artifact.canvasKitPath,
|
||||
platform: TargetPlatform.web_javascript,
|
||||
);
|
||||
final File canvasKitFile = _fileSystem.file(_fileSystem.path.join(
|
||||
webSdkDirectory.path,
|
||||
canvasKitPath,
|
||||
relativePath,
|
||||
));
|
||||
return canvasKitFile;
|
||||
@ -388,12 +378,13 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
/// Serves a local build of CanvasKit, replacing the CDN build, which can
|
||||
/// cause test flakiness due to reliance on network.
|
||||
shelf.Response _localCanvasKitHandler(shelf.Request request) {
|
||||
final String path = _fileSystem.path.fromUri(request.url);
|
||||
if (!path.startsWith('canvaskit/')) {
|
||||
final String fullPath = _fileSystem.path.fromUri(request.url);
|
||||
if (!fullPath.startsWith('canvaskit/')) {
|
||||
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;
|
||||
switch (extension) {
|
||||
case '.js':
|
||||
@ -409,7 +400,7 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
}
|
||||
|
||||
return shelf.Response.ok(
|
||||
_canvasKitFile(path).openRead(),
|
||||
_canvasKitFile(relativePath).openRead(),
|
||||
headers: <String, Object>{
|
||||
HttpHeaders.contentTypeHeader: contentType,
|
||||
},
|
||||
|
@ -176,7 +176,6 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
||||
browserFinder: findChromeExecutable,
|
||||
logger: globals.logger,
|
||||
),
|
||||
cache: globals.cache,
|
||||
testTimeRecorder: testTimeRecorder,
|
||||
);
|
||||
},
|
||||
|
@ -54,7 +54,7 @@ Future<void> buildWeb(
|
||||
final Stopwatch sw = Stopwatch()..start();
|
||||
try {
|
||||
final BuildResult result = await globals.buildSystem.build(
|
||||
WebServiceWorker(globals.fs, globals.cache, buildInfo.webRenderer, isWasm),
|
||||
WebServiceWorker(globals.fs, buildInfo.webRenderer, isWasm: isWasm),
|
||||
Environment(
|
||||
projectDir: globals.fs.currentDirectory,
|
||||
outputDir: outputDirectory,
|
||||
|
@ -101,7 +101,7 @@ void main() {
|
||||
webResources.childFile('index.html')
|
||||
.createSync(recursive: true);
|
||||
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);
|
||||
}));
|
||||
@ -113,7 +113,7 @@ void main() {
|
||||
final Directory webResources = environment.projectDir.childDirectory('web');
|
||||
webResources.childFile('index.html').createSync(recursive: true);
|
||||
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
|
||||
.childFile('version.json')
|
||||
@ -131,7 +131,7 @@ void main() {
|
||||
<!DOCTYPE html><html><base href="$kBaseHrefPlaceholder"><head></head></html>
|
||||
''');
|
||||
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/'));
|
||||
}));
|
||||
@ -144,7 +144,7 @@ void main() {
|
||||
<!DOCTYPE html><html><head><base href='/basehreftest/'></head></html>
|
||||
''');
|
||||
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/'));
|
||||
}));
|
||||
@ -166,7 +166,7 @@ void main() {
|
||||
.writeAsStringSync('A');
|
||||
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')
|
||||
.readAsStringSync(), 'A');
|
||||
@ -178,7 +178,7 @@ void main() {
|
||||
// Update to arbitrary resource file triggers rebuild.
|
||||
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')
|
||||
.readAsStringSync(), 'B');
|
||||
@ -827,7 +827,7 @@ void main() {
|
||||
environment.outputDir.childDirectory('a').childFile('a.txt')
|
||||
..createSync(recursive: true)
|
||||
..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);
|
||||
// Contains file hash.
|
||||
@ -846,7 +846,7 @@ void main() {
|
||||
environment.outputDir
|
||||
.childFile('index.html')
|
||||
.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);
|
||||
// Contains file hash for both `/` and index.html.
|
||||
@ -864,7 +864,7 @@ void main() {
|
||||
environment.outputDir
|
||||
.childFile('main.dart.js.map')
|
||||
.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.
|
||||
expect(environment.outputDir.childFile('flutter_service_worker.js').readAsStringSync(),
|
||||
@ -896,7 +896,7 @@ void main() {
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('OL');
|
||||
|
||||
await WebBuiltInAssets(globals.fs, globals.cache, false).build(environment);
|
||||
await WebBuiltInAssets(globals.fs, isWasm: false).build(environment);
|
||||
|
||||
// No caching of source maps.
|
||||
final String fileGeneratorsPath = environment.artifacts
|
||||
@ -913,7 +913,7 @@ void main() {
|
||||
globals.fs.file('bin/cache/flutter_web_sdk/canvaskit/canvaskit.wasm')
|
||||
.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.childDirectory('canvaskit')
|
||||
|
Loading…
Reference in New Issue
Block a user