[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>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
ad7c6453a6
commit
fa9895bdf6
@@ -240,9 +240,15 @@ class DartRuntimeService {
|
||||
throw const DartRuntimeServiceServerAlreadyRunning();
|
||||
}
|
||||
final hostStr = config.host ?? InternetAddress.loopbackIPv4.host;
|
||||
final host =
|
||||
InternetAddress.tryParse(hostStr) ??
|
||||
(await InternetAddress.lookup(hostStr)).first;
|
||||
var parsedHost = InternetAddress.tryParse(hostStr);
|
||||
if (parsedHost == null) {
|
||||
final addresses = await InternetAddress.lookup(hostStr);
|
||||
parsedHost = addresses.firstWhere(
|
||||
(a) => a.type == InternetAddressType.IPv4,
|
||||
orElse: () => addresses.first,
|
||||
);
|
||||
}
|
||||
final host = parsedHost;
|
||||
|
||||
_logger.info('Starting the Dart Runtime Service.');
|
||||
late String errorMessage;
|
||||
|
||||
@@ -35,6 +35,7 @@ class DartRuntimeServiceVMBackend
|
||||
required Stream<VmRunningIsolate> runningIsolatesStream,
|
||||
required this.residentCompilerInfoFile,
|
||||
required this._ddsManager,
|
||||
this.serviceInfoFilename,
|
||||
}) : isolateManager = VmIsolateManager(
|
||||
runningIsolatesStream: runningIsolatesStream,
|
||||
);
|
||||
@@ -89,6 +90,9 @@ class DartRuntimeServiceVMBackend
|
||||
/// Dart Development Service.
|
||||
final DartDevelopmentServiceManager _ddsManager;
|
||||
|
||||
/// The path to the file where VM service connection info should be written.
|
||||
final String? serviceInfoFilename;
|
||||
|
||||
@override
|
||||
UnmodifiableListView<ServiceRpcHandler> get rpcs => UnmodifiableListView([
|
||||
..._vmServiceRpcs.rpcs,
|
||||
@@ -181,6 +185,22 @@ class DartRuntimeServiceVMBackend
|
||||
);
|
||||
}
|
||||
_nativeBindings.onServerAddressChange(httpUri.toString());
|
||||
|
||||
final serviceInfoFilenameLocal = serviceInfoFilename;
|
||||
if (serviceInfoFilenameLocal != null &&
|
||||
serviceInfoFilenameLocal.isNotEmpty) {
|
||||
await _dumpServiceInfoToFile(serviceInfoFilenameLocal, httpUri);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _dumpServiceInfoToFile(String filename, Uri httpUri) async {
|
||||
final serviceInfo = <String, String>{'uri': httpUri.toString()};
|
||||
const kFileScheme = 'file://';
|
||||
final uri = filename.startsWith(kFileScheme)
|
||||
? Uri.parse(filename)
|
||||
: Uri.file(filename);
|
||||
final file = File.fromUri(uri);
|
||||
await file.writeAsString(json.encode(serviceInfo));
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user