From 2ef257b8fa77e0e8ae784e21a27e0809eac549d8 Mon Sep 17 00:00:00 2001 From: Derek Xu Date: Tue, 24 Oct 2023 13:39:46 -0400 Subject: [PATCH 1/4] Make FrontendServerClient start the frontend server from AOT snapshot by default --- .../lib/src/frontend_server_client.dart | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/frontend_server_client/lib/src/frontend_server_client.dart b/frontend_server_client/lib/src/frontend_server_client.dart index cd91511d5..563ea446a 100644 --- a/frontend_server_client/lib/src/frontend_server_client.dart +++ b/frontend_server_client/lib/src/frontend_server_client.dart @@ -40,6 +40,15 @@ class FrontendServerClient { /// The [outputDillPath] determines where the primary output should be, and /// some targets may output additional files based on that file name (by /// adding file extensions for instance). + /// + /// When the [frontendServerPath] argument is provided, the frontend server + /// will be started from the specified file. The specified file can either be + /// a Dart source file or an AppJIT snapshot. + /// + /// When the [frontendServerPath] argument is provided, setting [debug] to + /// true permits debuggers to attach to the frontend server. When the + /// [frontendServerPath] argument is omitted, the value of the [debug] + /// argument is ignored. static Future start( String entrypoint, String outputDillPath, @@ -60,9 +69,7 @@ class FrontendServerClient { List additionalSources = const [], String? nativeAssets, }) async { - var feServer = await Process.start(Platform.resolvedExecutable, [ - if (debug) '--observe', - frontendServerPath ?? _feServerPath, + final commonArguments = [ '--sdk-root', sdkRoot ?? sdkDir, '--platform=$platformKernel', @@ -90,7 +97,34 @@ class FrontendServerClient { '--native-assets', nativeAssets, ], - ]); + ]; + late final Process feServer; + if (frontendServerPath != null) { + feServer = await Process.start( + Platform.resolvedExecutable, + [ + if (debug) '--observe', + frontendServerPath, + ] + + commonArguments, + ); + } else if (File(_feServerAotSnapshotPath).existsSync()) { + feServer = await Process.start( + _dartAotRuntimePath, + [_feServerAotSnapshotPath] + commonArguments, + ); + } else { + // AOT snapshots cannot be generated on IA32, so we need this fallback + // branch until support for IA32 is dropped (https://dartbug.com/49969). + feServer = await Process.start( + Platform.resolvedExecutable, + [ + if (debug) '--observe', + _feServerAppJitSnapshotPath, + ] + + commonArguments, + ); + } var feServerStdoutLines = StreamQueue(feServer.stdout .transform(utf8.decoder) .transform(const LineSplitter())); @@ -407,5 +441,10 @@ enum _RejectState { done, } -final _feServerPath = +final _dartAotRuntimePath = p.join(sdkDir, 'bin', 'dartaotruntime'); + +final _feServerAppJitSnapshotPath = p.join(sdkDir, 'bin', 'snapshots', 'frontend_server.dart.snapshot'); + +final _feServerAotSnapshotPath = + p.join(sdkDir, 'bin', 'snapshots', 'frontend_server_aot.dart.snapshot'); From 521e9c8d100c8ba171427f026ee9d1e3f72aee54 Mon Sep 17 00:00:00 2001 From: Derek Xu Date: Mon, 13 Nov 2023 14:13:31 -0500 Subject: [PATCH 2/4] Update --- frontend_server_client/CHANGELOG.md | 9 ++++++++- .../lib/src/frontend_server_client.dart | 8 ++++++-- frontend_server_client/pubspec.yaml | 2 +- frontend_server_common/CHANGELOG.md | 4 ++++ test_common/lib/test_sdk_layout.dart | 2 +- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/frontend_server_client/CHANGELOG.md b/frontend_server_client/CHANGELOG.md index baedcf926..eccbcfca5 100644 --- a/frontend_server_client/CHANGELOG.md +++ b/frontend_server_client/CHANGELOG.md @@ -1,4 +1,11 @@ -## 3.3.0-wip +## 4.0.0-wip + +- By default, start the frontend server from the AOT snapshot shipped in the + Dart SDK. +- Throw an `ArgumentError` when `FrontendServerClient.start` is called with the + `frontendServerPath` argument omitted and the `debug` argument set to true. + +## 3.3.0 - Update Dart SDK constraint to `>=3.0.0 <4.0.0`. - Support changes in the SDK layout for Dart 3.0. diff --git a/frontend_server_client/lib/src/frontend_server_client.dart b/frontend_server_client/lib/src/frontend_server_client.dart index 563ea446a..cd8110247 100644 --- a/frontend_server_client/lib/src/frontend_server_client.dart +++ b/frontend_server_client/lib/src/frontend_server_client.dart @@ -47,8 +47,8 @@ class FrontendServerClient { /// /// When the [frontendServerPath] argument is provided, setting [debug] to /// true permits debuggers to attach to the frontend server. When the - /// [frontendServerPath] argument is omitted, the value of the [debug] - /// argument is ignored. + /// [frontendServerPath] argument is omitted, setting [debug] to true will + /// cause an [ArgumentError] to be thrown. static Future start( String entrypoint, String outputDillPath, @@ -109,6 +109,10 @@ class FrontendServerClient { commonArguments, ); } else if (File(_feServerAotSnapshotPath).existsSync()) { + if (debug) { + throw ArgumentError('The debug argument cannot be set to true when the ' + 'frontendServerPath argument is omitted.'); + } feServer = await Process.start( _dartAotRuntimePath, [_feServerAotSnapshotPath] + commonArguments, diff --git a/frontend_server_client/pubspec.yaml b/frontend_server_client/pubspec.yaml index 5ef52a2f2..4b70bd14e 100644 --- a/frontend_server_client/pubspec.yaml +++ b/frontend_server_client/pubspec.yaml @@ -1,5 +1,5 @@ name: frontend_server_client -version: 3.3.0-wip +version: 4.0.0-wip description: >- Client code to start and interact with the frontend_server compiler from the Dart SDK. diff --git a/frontend_server_common/CHANGELOG.md b/frontend_server_common/CHANGELOG.md index aa64921d0..6704b3872 100644 --- a/frontend_server_common/CHANGELOG.md +++ b/frontend_server_common/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.2 + +- Start the frontend server from the AOT snapshot shipped in the Dart SDK. + ## 0.2.1 - Doe not pass `-debugger-module-names` flag to the frontend server. diff --git a/test_common/lib/test_sdk_layout.dart b/test_common/lib/test_sdk_layout.dart index 072bd3f1f..49a2c7c08 100644 --- a/test_common/lib/test_sdk_layout.dart +++ b/test_common/lib/test_sdk_layout.dart @@ -94,7 +94,7 @@ class TestSdkLayout { sdkLayout.sdkDirectory, 'bin', 'snapshots', - 'frontend_server.dart.snapshot', + 'frontend_server_aot.dart.snapshot', ), dartdevcSnapshotPath: sdkLayout.dartdevcSnapshotPath, kernelWorkerSnapshotPath: p.join( From 94c05398417bc28275aef984c68f80749621d9da Mon Sep 17 00:00:00 2001 From: Derek Xu Date: Tue, 21 Nov 2023 14:41:00 -0500 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Jacob MacDonald --- .../lib/src/frontend_server_client.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend_server_client/lib/src/frontend_server_client.dart b/frontend_server_client/lib/src/frontend_server_client.dart index cd8110247..13fedb898 100644 --- a/frontend_server_client/lib/src/frontend_server_client.dart +++ b/frontend_server_client/lib/src/frontend_server_client.dart @@ -105,8 +105,8 @@ class FrontendServerClient { [ if (debug) '--observe', frontendServerPath, - ] + - commonArguments, + ...commonArguments, + ], ); } else if (File(_feServerAotSnapshotPath).existsSync()) { if (debug) { @@ -115,7 +115,7 @@ class FrontendServerClient { } feServer = await Process.start( _dartAotRuntimePath, - [_feServerAotSnapshotPath] + commonArguments, + [_feServerAotSnapshotPath, ...commonArguments], ); } else { // AOT snapshots cannot be generated on IA32, so we need this fallback @@ -125,8 +125,8 @@ class FrontendServerClient { [ if (debug) '--observe', _feServerAppJitSnapshotPath, - ] + - commonArguments, + ...commonArguments, + ], ); } var feServerStdoutLines = StreamQueue(feServer.stdout From 1c7c9f119892fd8b6d9fd94fb3a69d3c81d80359 Mon Sep 17 00:00:00 2001 From: Derek Xu Date: Mon, 11 Dec 2023 10:15:00 -0500 Subject: [PATCH 4/4] Defer changes in v3.3.0-wip to v4.0.0-wip --- dwds/lib/src/debugging/location.dart | 2 +- frontend_server_client/CHANGELOG.md | 8 +++----- .../lib/src/frontend_server_client.dart | 16 ++++++++-------- frontend_server_client/pubspec.yaml | 2 +- .../lib/src/frontend_server_client.dart | 2 +- test_common/lib/test_sdk_layout.dart | 7 +++++++ .../test/test_sdk_configuration_test.dart | 1 + 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/dwds/lib/src/debugging/location.dart b/dwds/lib/src/debugging/location.dart index 26c954ed2..161573c6e 100644 --- a/dwds/lib/src/debugging/location.dart +++ b/dwds/lib/src/debugging/location.dart @@ -78,7 +78,7 @@ class DartLocation { int get hashCode => Object.hashAll([uri, line, column]); @override - bool operator ==(Object? other) { + bool operator ==(Object other) { if (other is! DartLocation) { return false; } diff --git a/frontend_server_client/CHANGELOG.md b/frontend_server_client/CHANGELOG.md index eccbcfca5..047c86e8a 100644 --- a/frontend_server_client/CHANGELOG.md +++ b/frontend_server_client/CHANGELOG.md @@ -1,14 +1,12 @@ ## 4.0.0-wip +- Update Dart SDK constraint to `^3.0.0`. +- Support changes in the SDK layout for Dart 3.0. - By default, start the frontend server from the AOT snapshot shipped in the Dart SDK. - Throw an `ArgumentError` when `FrontendServerClient.start` is called with the `frontendServerPath` argument omitted and the `debug` argument set to true. - -## 3.3.0 - -- Update Dart SDK constraint to `>=3.0.0 <4.0.0`. -- Support changes in the SDK layout for Dart 3.0. +- Update `package:vm_service` constraint to `^14.0.0`. ## 3.2.0 diff --git a/frontend_server_client/lib/src/frontend_server_client.dart b/frontend_server_client/lib/src/frontend_server_client.dart index 13fedb898..3a62274a4 100644 --- a/frontend_server_client/lib/src/frontend_server_client.dart +++ b/frontend_server_client/lib/src/frontend_server_client.dart @@ -103,10 +103,10 @@ class FrontendServerClient { feServer = await Process.start( Platform.resolvedExecutable, [ - if (debug) '--observe', - frontendServerPath, - ...commonArguments, - ], + if (debug) '--observe', + frontendServerPath, + ...commonArguments, + ], ); } else if (File(_feServerAotSnapshotPath).existsSync()) { if (debug) { @@ -123,10 +123,10 @@ class FrontendServerClient { feServer = await Process.start( Platform.resolvedExecutable, [ - if (debug) '--observe', - _feServerAppJitSnapshotPath, - ...commonArguments, - ], + if (debug) '--observe', + _feServerAppJitSnapshotPath, + ...commonArguments, + ], ); } var feServerStdoutLines = StreamQueue(feServer.stdout diff --git a/frontend_server_client/pubspec.yaml b/frontend_server_client/pubspec.yaml index 4b70bd14e..7f0657b70 100644 --- a/frontend_server_client/pubspec.yaml +++ b/frontend_server_client/pubspec.yaml @@ -20,4 +20,4 @@ dev_dependencies: test: ^1.16.0 test_descriptor: ^2.0.0 test_process: ^2.0.0 - vm_service: ^8.0.0 + vm_service: ^14.0.0 diff --git a/frontend_server_common/lib/src/frontend_server_client.dart b/frontend_server_common/lib/src/frontend_server_client.dart index aba399997..18b15b53e 100644 --- a/frontend_server_common/lib/src/frontend_server_client.dart +++ b/frontend_server_common/lib/src/frontend_server_client.dart @@ -398,7 +398,7 @@ class ResidentCompiler { _logger.info(args.join(' ')); final workingDirectory = projectDirectory.toFilePath(); - _server = await Process.start(sdkLayout.dartPath, args, + _server = await Process.start(sdkLayout.dartAotRuntimePath, args, workingDirectory: workingDirectory); var server = _server!; diff --git a/test_common/lib/test_sdk_layout.dart b/test_common/lib/test_sdk_layout.dart index 49a2c7c08..9064ce8e9 100644 --- a/test_common/lib/test_sdk_layout.dart +++ b/test_common/lib/test_sdk_layout.dart @@ -90,6 +90,11 @@ class TestSdkLayout { 'bin', Platform.isWindows ? 'dart.exe' : 'dart', ), + dartAotRuntimePath: p.join( + sdkLayout.sdkDirectory, + 'bin', + Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime', + ), frontendServerSnapshotPath: p.join( sdkLayout.sdkDirectory, 'bin', @@ -137,6 +142,7 @@ class TestSdkLayout { final String stackTraceMapperPath; final String dartPath; + final String dartAotRuntimePath; final String frontendServerSnapshotPath; final String dartdevcSnapshotPath; final String kernelWorkerSnapshotPath; @@ -155,6 +161,7 @@ class TestSdkLayout { required this.requireJsPath, required this.stackTraceMapperPath, required this.dartPath, + required this.dartAotRuntimePath, required this.frontendServerSnapshotPath, required this.dartdevcSnapshotPath, required this.kernelWorkerSnapshotPath, diff --git a/test_common/test/test_sdk_configuration_test.dart b/test_common/test/test_sdk_configuration_test.dart index 8a701fc45..1ff60ddee 100644 --- a/test_common/test/test_sdk_configuration_test.dart +++ b/test_common/test/test_sdk_configuration_test.dart @@ -70,6 +70,7 @@ void main() { expect(sdkLayout.stackTraceMapperPath, _fileExists); expect(sdkLayout.dartPath, _fileExists); + expect(sdkLayout.dartAotRuntimePath, _fileExists); expect(sdkLayout.frontendServerSnapshotPath, _fileExists); expect(sdkLayout.dartdevcSnapshotPath, _fileExists); expect(sdkLayout.kernelWorkerSnapshotPath, _fileExists);