Skip to content

Commit fa9895b

Browse files
bkonyidart-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[VM Service] Add service info file dumping and bind address support
Adds support for writing the active VM service connection URI to the file specified by `--write-service-info-to-file` and updates native bindings with the web server address on startups. TAG=agy CONV=ae3a29f5-e2c8-499c-b221-ff61e40f5f1f Change-Id: Ice85fda098031ef4ba1cd1120a917137aae97105 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505163 Auto-Submit: Ben Konyi <bkonyi@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com>
1 parent ad7c645 commit fa9895b

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

pkg/dart_runtime_service/lib/src/dart_runtime_service.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,15 @@ class DartRuntimeService {
240240
throw const DartRuntimeServiceServerAlreadyRunning();
241241
}
242242
final hostStr = config.host ?? InternetAddress.loopbackIPv4.host;
243-
final host =
244-
InternetAddress.tryParse(hostStr) ??
245-
(await InternetAddress.lookup(hostStr)).first;
243+
var parsedHost = InternetAddress.tryParse(hostStr);
244+
if (parsedHost == null) {
245+
final addresses = await InternetAddress.lookup(hostStr);
246+
parsedHost = addresses.firstWhere(
247+
(a) => a.type == InternetAddressType.IPv4,
248+
orElse: () => addresses.first,
249+
);
250+
}
251+
final host = parsedHost;
246252

247253
_logger.info('Starting the Dart Runtime Service.');
248254
late String errorMessage;

pkg/dart_runtime_service_vm/lib/dart_runtime_service_vm.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class DartRuntimeServiceVMBackend
3535
required Stream<VmRunningIsolate> runningIsolatesStream,
3636
required this.residentCompilerInfoFile,
3737
required this._ddsManager,
38+
this.serviceInfoFilename,
3839
}) : isolateManager = VmIsolateManager(
3940
runningIsolatesStream: runningIsolatesStream,
4041
);
@@ -89,6 +90,9 @@ class DartRuntimeServiceVMBackend
8990
/// Dart Development Service.
9091
final DartDevelopmentServiceManager _ddsManager;
9192

93+
/// The path to the file where VM service connection info should be written.
94+
final String? serviceInfoFilename;
95+
9296
@override
9397
UnmodifiableListView<ServiceRpcHandler> get rpcs => UnmodifiableListView([
9498
..._vmServiceRpcs.rpcs,
@@ -181,6 +185,22 @@ class DartRuntimeServiceVMBackend
181185
);
182186
}
183187
_nativeBindings.onServerAddressChange(httpUri.toString());
188+
189+
final serviceInfoFilenameLocal = serviceInfoFilename;
190+
if (serviceInfoFilenameLocal != null &&
191+
serviceInfoFilenameLocal.isNotEmpty) {
192+
await _dumpServiceInfoToFile(serviceInfoFilenameLocal, httpUri);
193+
}
194+
}
195+
196+
Future<void> _dumpServiceInfoToFile(String filename, Uri httpUri) async {
197+
final serviceInfo = <String, String>{'uri': httpUri.toString()};
198+
const kFileScheme = 'file://';
199+
final uri = filename.startsWith(kFileScheme)
200+
? Uri.parse(filename)
201+
: Uri.file(filename);
202+
final file = File.fromUri(uri);
203+
await file.writeAsString(json.encode(serviceInfo));
184204
}
185205

186206
@override

0 commit comments

Comments
 (0)