Skip to content

Commit

Permalink
Switch flutter_tools to run frontend server from AOT snapshot (#135255)
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher Fujino <fujino@google.com>
  • Loading branch information
derekxu16 and christopherfujino authored Sep 26, 2023
1 parent 54678fd commit c21bf45
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/artifacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
];

Expand Down
70 changes: 46 additions & 24 deletions packages/flutter_tools/lib/src/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
7 changes: 4 additions & 3 deletions packages/flutter_tools/test/general.shard/artifacts_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
});

Expand Down Expand Up @@ -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')
);


Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit c21bf45

Please sign in to comment.