Consume flutter.js from the engine artifacts. (#137113)

Work in progress... currently testing against presubmit.
This commit is contained in:
Jackson Gardner
2023-11-14 09:00:29 -08:00
committed by GitHub
parent 463c02daaf
commit 07d73630fb
7 changed files with 32 additions and 72 deletions

View File

@@ -81,6 +81,9 @@ enum HostArtifact {
/// The libraries JSON file for web release builds.
flutterWebLibrariesJson,
// The flutter.js bootstrapping file provided by the engine.
flutterJsDirectory,
/// Folder that contains platform dill files for the web sdk.
webPlatformKernelFolder,
@@ -232,6 +235,8 @@ String _hostArtifactToFileName(HostArtifact artifact, Platform platform) {
switch (artifact) {
case HostArtifact.flutterWebSdk:
return '';
case HostArtifact.flutterJsDirectory:
return 'flutter_js';
case HostArtifact.iosDeploy:
return 'ios-deploy';
case HostArtifact.idevicesyslog:
@@ -440,6 +445,9 @@ class CachedArtifacts implements Artifacts {
case HostArtifact.flutterWebLibrariesJson:
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), _hostArtifactToFileName(artifact, _platform));
return _fileSystem.file(path);
case HostArtifact.flutterJsDirectory:
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'flutter_js');
return _fileSystem.directory(path);
case HostArtifact.webPlatformKernelFolder:
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel');
return _fileSystem.file(path);
@@ -893,6 +901,9 @@ class CachedLocalEngineArtifacts implements Artifacts {
case HostArtifact.flutterWebLibrariesJson:
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), _hostArtifactToFileName(artifact, _platform));
return _fileSystem.file(path);
case HostArtifact.flutterJsDirectory:
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'flutter_js');
return _fileSystem.directory(path);
case HostArtifact.webPlatformKernelFolder:
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel');
return _fileSystem.file(path);
@@ -1205,6 +1216,9 @@ class CachedLocalWebSdkArtifacts implements Artifacts {
case HostArtifact.flutterWebLibrariesJson:
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), _hostArtifactToFileName(artifact, _platform));
return _fileSystem.file(path);
case HostArtifact.flutterJsDirectory:
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'flutter_js');
return _fileSystem.directory(path);
case HostArtifact.webPlatformKernelFolder:
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel');
return _fileSystem.file(path);

View File

@@ -20,7 +20,6 @@ import '../../globals.dart' as globals;
import '../../html_utils.dart';
import '../../project.dart';
import '../../web/compile.dart';
import '../../web/file_generators/flutter_js.dart' as flutter_js;
import '../../web/file_generators/flutter_service_worker_js.dart';
import '../../web/file_generators/main_dart.dart' as main_dart;
import '../../web/file_generators/wasm_bootstrap.dart' as wasm_bootstrap;
@@ -525,11 +524,12 @@ class WebBuiltInAssets extends Target {
}
// Write the flutter.js file
final File flutterJsFile = environment.outputDir.childFile('flutter.js');
final String fileGeneratorsPath =
environment.artifacts.getArtifactPath(Artifact.flutterToolsFileGenerators);
flutterJsFile.writeAsStringSync(
flutter_js.generateFlutterJsFile(fileGeneratorsPath));
final String flutterJsOut = fileSystem.path.join(environment.outputDir.path, 'flutter.js');
final File flutterJsFile = fileSystem.file(fileSystem.path.join(
globals.artifacts!.getHostArtifact(HostArtifact.flutterJsDirectory).path,
'flutter.js',
));
flutterJsFile.copySync(flutterJsOut);
}
}

View File

@@ -40,7 +40,6 @@ import '../vmservice.dart';
import '../web/bootstrap.dart';
import '../web/chrome.dart';
import '../web/compile.dart';
import '../web/file_generators/flutter_js.dart' as flutter_js;
import '../web/memory_fs.dart';
typedef DwdsLauncher = Future<Dwds> Function({
@@ -834,14 +833,11 @@ class WebDevFS implements DevFS {
final String entrypoint = globals.fs.path.basename(mainFile.path);
webAssetServer.writeBytes(entrypoint, mainFile.readAsBytesSync());
webAssetServer.writeBytes('require.js', requireJS.readAsBytesSync());
webAssetServer.writeBytes('flutter.js', flutterJs.readAsBytesSync());
webAssetServer.writeBytes(
'stack_trace_mapper.js', stackTraceMapper.readAsBytesSync());
webAssetServer.writeFile(
'manifest.json', '{"info":"manifest not generated in run mode."}');
final String fileGeneratorsPath = globals.artifacts!
.getArtifactPath(Artifact.flutterToolsFileGenerators);
webAssetServer.writeFile(
'flutter.js', flutter_js.generateFlutterJsFile(fileGeneratorsPath));
webAssetServer.writeFile('flutter_service_worker.js',
'// Service worker not loaded in run mode.');
webAssetServer.writeFile(
@@ -934,6 +930,12 @@ class WebDevFS implements DevFS {
'require.js',
));
@visibleForTesting
final File flutterJs = globals.fs.file(globals.fs.path.join(
globals.artifacts!.getHostArtifact(HostArtifact.flutterJsDirectory).path,
'flutter.js',
));
@visibleForTesting
final File stackTraceMapper = globals.fs.file(globals.fs.path.join(
globals.artifacts!.getArtifactPath(Artifact.engineDartSdkPath, platform: TargetPlatform.web_javascript),

View File

@@ -1,18 +0,0 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../../globals.dart' as globals;
/// Generates the flutter.js file.
///
/// flutter.js should be completely static, so **do not use any parameter or
/// environment variable to generate this file**.
String generateFlutterJsFile(String fileGeneratorsPath) {
final String flutterJsPath = globals.localFileSystem.path.join(
fileGeneratorsPath,
'js',
'flutter.js',
);
return globals.localFileSystem.file(flutterJsPath).readAsStringSync();
}