Unverified Commit c21bf45b authored by Derek Xu's avatar Derek Xu Committed by GitHub

Switch flutter_tools to run frontend server from AOT snapshot (#135255)

Co-authored-by: 's avatarChristopher Fujino <fujino@google.com>
parent 54678fdb
......@@ -190,7 +190,7 @@ String? _artifactToFileName(Artifact artifact, Platform hostPlatform, [ BuildMod
case Artifact.wasmOptBinary:
return 'wasm-opt$exe';
case Artifact.frontendServerSnapshotForEngineDartSdk:
return 'frontend_server.dart.snapshot';
return 'frontend_server_aot.dart.snapshot';
case Artifact.linuxDesktopPath:
return '';
case Artifact.linuxHeaders:
......
......@@ -132,6 +132,7 @@ class KernelSnapshot extends Target {
Source.pattern('{FLUTTER_ROOT}/packages/flutter_tools/lib/src/build_system/targets/common.dart'),
Source.artifact(Artifact.platformKernelDill),
Source.artifact(Artifact.engineDartBinary),
Source.artifact(Artifact.engineDartAotRuntime),
Source.artifact(Artifact.frontendServerSnapshotForEngineDartSdk),
];
......
......@@ -244,20 +244,10 @@ class KernelCompiler {
String? nativeAssets,
}) async {
final TargetPlatform? platform = targetModel == TargetModel.dartdevc ? TargetPlatform.web_javascript : null;
final String frontendServer = (frontendServerStarterPath == null || frontendServerStarterPath.isEmpty)
? _artifacts.getArtifactPath(
Artifact.frontendServerSnapshotForEngineDartSdk,
platform: platform,
)
: frontendServerStarterPath;
// This is a URI, not a file path, so the forward slash is correct even on Windows.
if (!sdkRoot.endsWith('/')) {
sdkRoot = '$sdkRoot/';
}
final String engineDartPath = _artifacts.getArtifactPath(Artifact.engineDartBinary, platform: platform);
if (!_processManager.canRun(engineDartPath)) {
throwToolExit('Unable to find Dart binary at $engineDartPath');
}
String? mainUri;
final File mainFile = _fileSystem.file(mainPath);
final Uri mainFileUri = mainFile.uri;
......@@ -282,10 +272,33 @@ class KernelCompiler {
toMultiRootPath(dartPluginRegistrantFileUri, _fileSystemScheme, _fileSystemRoots, _fileSystem.path.separator == r'\');
}
final List<String> command = <String>[
engineDartPath,
'--disable-dart-dev',
frontendServer,
final List<String> commandToStartFrontendServer;
if (frontendServerStarterPath != null && frontendServerStarterPath.isNotEmpty) {
final String engineDartPath = _artifacts.getArtifactPath(Artifact.engineDartBinary, platform: platform);
if (!_processManager.canRun(engineDartPath)) {
throwToolExit('Unable to find Dart binary at $engineDartPath');
}
commandToStartFrontendServer = <String>[
engineDartPath,
'--disable-dart-dev',
frontendServerStarterPath,
];
} else {
final String engineDartAotRuntimePath = _artifacts.getArtifactPath(Artifact.engineDartAotRuntime, platform: platform);
if (!_processManager.canRun(engineDartAotRuntimePath)) {
throwToolExit('Unable to find dartaotruntime binary at $engineDartAotRuntimePath');
}
commandToStartFrontendServer = <String>[
engineDartAotRuntimePath,
'--disable-dart-dev',
_artifacts.getArtifactPath(
Artifact.frontendServerSnapshotForEngineDartSdk,
platform: platform,
),
];
}
final List<String> command = commandToStartFrontendServer + <String>[
'--sdk-root',
sdkRoot,
'--target=$targetModel',
......@@ -777,16 +790,25 @@ class DefaultResidentCompiler implements ResidentCompiler {
String? nativeAssetsUri,
}) async {
final TargetPlatform? platform = (targetModel == TargetModel.dartdevc) ? TargetPlatform.web_javascript : null;
final String frontendServer = (frontendServerStarterPath == null || frontendServerStarterPath!.isEmpty)
? artifacts.getArtifactPath(
Artifact.frontendServerSnapshotForEngineDartSdk,
platform: platform,
)
: frontendServerStarterPath!;
final List<String> command = <String>[
artifacts.getArtifactPath(Artifact.engineDartBinary, platform: platform),
'--disable-dart-dev',
frontendServer,
late final List<String> commandToStartFrontendServer;
if (frontendServerStarterPath != null && frontendServerStarterPath!.isNotEmpty) {
commandToStartFrontendServer = <String>[
artifacts.getArtifactPath(Artifact.engineDartBinary, platform: platform),
'--disable-dart-dev',
frontendServerStarterPath!,
];
} else {
commandToStartFrontendServer = <String>[
artifacts.getArtifactPath(Artifact.engineDartAotRuntime, platform: platform),
'--disable-dart-dev',
artifacts.getArtifactPath(
Artifact.frontendServerSnapshotForEngineDartSdk,
platform: platform,
),
];
}
final List<String> command = commandToStartFrontendServer + <String>[
'--sdk-root',
sdkRoot,
'--incremental',
......
......@@ -143,7 +143,8 @@ void main() {
);
expect(
artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
fileSystem.path.join('root', 'bin', 'cache', 'dart-sdk', 'bin', 'snapshots', 'frontend_server.dart.snapshot')
fileSystem.path.join('root', 'bin', 'cache', 'dart-sdk', 'bin',
'snapshots', 'frontend_server_aot.dart.snapshot')
);
});
......@@ -325,7 +326,7 @@ void main() {
expect(
artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
fileSystem.path.join('/out', 'host_debug_unopt', 'dart-sdk', 'bin',
'snapshots', 'frontend_server.dart.snapshot')
'snapshots', 'frontend_server_aot.dart.snapshot')
);
......@@ -397,7 +398,7 @@ void main() {
Artifact.frontendServerSnapshotForEngineDartSdk,
platform: TargetPlatform.web_javascript),
fileSystem.path.join('/flutter', 'prebuilts', 'linux-x64', 'dart-sdk', 'bin',
'snapshots', 'frontend_server.dart.snapshot'),
'snapshots', 'frontend_server_aot.dart.snapshot'),
);
expect(
artifacts.getArtifactPath(
......
......@@ -94,7 +94,7 @@ native-assets: {}
);
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
artifacts.getArtifactPath(Artifact.engineDartBinary),
artifacts.getArtifactPath(Artifact.engineDartAotRuntime),
'--disable-dart-dev',
artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
'--sdk-root',
......@@ -139,7 +139,7 @@ native-assets: {}
);
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
artifacts.getArtifactPath(Artifact.engineDartBinary),
artifacts.getArtifactPath(Artifact.engineDartAotRuntime),
'--disable-dart-dev',
artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
'--sdk-root',
......@@ -185,7 +185,7 @@ native-assets: {}
);
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
artifacts.getArtifactPath(Artifact.engineDartBinary),
artifacts.getArtifactPath(Artifact.engineDartAotRuntime),
'--disable-dart-dev',
artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
'--sdk-root',
......@@ -279,7 +279,7 @@ native-assets: {}
);
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
artifacts.getArtifactPath(Artifact.engineDartBinary),
artifacts.getArtifactPath(Artifact.engineDartAotRuntime),
'--disable-dart-dev',
artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
'--sdk-root',
......@@ -328,7 +328,7 @@ native-assets: {}
);
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
artifacts.getArtifactPath(Artifact.engineDartBinary),
artifacts.getArtifactPath(Artifact.engineDartAotRuntime),
'--disable-dart-dev',
artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
'--sdk-root',
......@@ -375,7 +375,7 @@ native-assets: {}
);
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
artifacts.getArtifactPath(Artifact.engineDartBinary),
artifacts.getArtifactPath(Artifact.engineDartAotRuntime),
'--disable-dart-dev',
artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
'--sdk-root',
......@@ -434,7 +434,7 @@ native-assets: {}
);
processManager.addCommands(<FakeCommand>[
FakeCommand(command: <String>[
artifacts.getArtifactPath(Artifact.engineDartBinary),
artifacts.getArtifactPath(Artifact.engineDartAotRuntime),
'--disable-dart-dev',
artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
'--sdk-root',
......
......@@ -53,7 +53,7 @@ void main() {
logger: logger,
processManager: FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: const <String>[
'Artifact.engineDartBinary',
'Artifact.engineDartAotRuntime',
'--disable-dart-dev',
'Artifact.frontendServerSnapshotForEngineDartSdk',
'--sdk-root',
......@@ -99,7 +99,7 @@ void main() {
logger: logger,
processManager: FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: const <String>[
'Artifact.engineDartBinary',
'Artifact.engineDartAotRuntime',
'--disable-dart-dev',
'Artifact.frontendServerSnapshotForEngineDartSdk',
'--sdk-root',
......@@ -145,7 +145,7 @@ void main() {
logger: logger,
processManager: FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: const <String>[
'Artifact.engineDartBinary',
'Artifact.engineDartAotRuntime',
'--disable-dart-dev',
'Artifact.frontendServerSnapshotForEngineDartSdk',
'--sdk-root',
......@@ -191,7 +191,7 @@ void main() {
logger: logger,
processManager: FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: const <String>[
'Artifact.engineDartBinary',
'Artifact.engineDartAotRuntime',
'--disable-dart-dev',
'Artifact.frontendServerSnapshotForEngineDartSdk',
'--sdk-root',
......@@ -239,7 +239,7 @@ void main() {
logger: logger,
processManager: FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: const <String>[
'Artifact.engineDartBinary',
'Artifact.engineDartAotRuntime',
'--disable-dart-dev',
'Artifact.frontendServerSnapshotForEngineDartSdk',
'--sdk-root',
......@@ -287,7 +287,7 @@ void main() {
logger: logger,
processManager: FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: const <String>[
'Artifact.engineDartBinary',
'Artifact.engineDartAotRuntime',
'--disable-dart-dev',
'Artifact.frontendServerSnapshotForEngineDartSdk',
'--sdk-root',
......@@ -339,7 +339,7 @@ void main() {
logger: logger,
processManager: FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: const <String>[
'Artifact.engineDartBinary',
'Artifact.engineDartAotRuntime',
'--disable-dart-dev',
'Artifact.frontendServerSnapshotForEngineDartSdk',
'--sdk-root',
......@@ -389,7 +389,7 @@ void main() {
logger: logger,
processManager: FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: const <String>[
'Artifact.engineDartBinary',
'Artifact.engineDartAotRuntime',
'--disable-dart-dev',
'Artifact.frontendServerSnapshotForEngineDartSdk',
'--sdk-root',
......@@ -449,7 +449,7 @@ void main() {
logger: logger,
processManager: FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: const <String>[
'Artifact.engineDartBinary',
'Artifact.engineDartAotRuntime',
'--disable-dart-dev',
'Artifact.frontendServerSnapshotForEngineDartSdk',
'--sdk-root',
......
......@@ -30,7 +30,7 @@ void main() {
late FakeProcessManager fakeProcessManager;
const List<String> frontendServerCommand = <String>[
'Artifact.engineDartBinary',
'Artifact.engineDartAotRuntime',
'--disable-dart-dev',
'Artifact.frontendServerSnapshotForEngineDartSdk',
'--sdk-root',
......
......@@ -36,7 +36,7 @@ void main() {
);
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: <Pattern>[
'Artifact.engineDartBinary.TargetPlatform.web_javascript',
'Artifact.engineDartAotRuntime.TargetPlatform.web_javascript',
'--disable-dart-dev',
'Artifact.frontendServerSnapshotForEngineDartSdk.TargetPlatform.web_javascript',
'--sdk-root',
......
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