Skip to content

Commit e39a98e

Browse files
bkonyiCommit Queue
authored andcommitted
[ DDS ] Ensure existing DevTools server URIs are reported correctly
Due to variable shadowing and lazy initialization of the DevTools URI within DDS, the DevTools URI reported by DDS did not include the `uri` query parameter used to automatically establish connection to the current DDS instance. This change updates variable names to avoid shadowing and also fixes issues where the DevTools URI would be reported even if DevTools was not enabled in the DDS configuration. Change-Id: I1ab0f5c58ee7e583e6eb4f4fb7381cddc29629b1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448480 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Ryan Macnak <[email protected]> Auto-Submit: Ben Konyi <[email protected]>
1 parent ca5c636 commit e39a98e

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

pkg/dds/lib/src/dds_impl.dart

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,6 @@ class DartDevelopmentServiceImpl implements DartDevelopmentService {
413413
devtoolsExtensionsManager: ExtensionsManager(),
414414
) as FutureOr<Response> Function(Request);
415415
}
416-
// Otherwise, set the DevTools URI to point to the externally hosted
417-
// DevTools instance.
418-
_devToolsUri = existingDevToolsAddress;
419416
}
420417

421418
// Otherwise, DevTools may be served externally, or not at all.
@@ -454,35 +451,35 @@ class DartDevelopmentServiceImpl implements DartDevelopmentService {
454451
return pathSegments;
455452
}
456453

457-
Uri? _toWebSocket(Uri? uri) {
458-
if (uri == null) {
454+
Uri? _toWebSocket(Uri? hostedUri) {
455+
if (hostedUri == null) {
459456
return null;
460457
}
461-
final pathSegments = _cleanupPathSegments(uri);
458+
final pathSegments = _cleanupPathSegments(hostedUri);
462459
pathSegments.add('ws');
463-
return uri.replace(scheme: 'ws', pathSegments: pathSegments);
460+
return hostedUri.replace(scheme: 'ws', pathSegments: pathSegments);
464461
}
465462

466-
Uri? _toSse(Uri? uri) {
467-
if (uri == null) {
463+
Uri? _toSse(Uri? hostedUri) {
464+
if (hostedUri == null) {
468465
return null;
469466
}
470-
final pathSegments = _cleanupPathSegments(uri);
467+
final pathSegments = _cleanupPathSegments(hostedUri);
471468
pathSegments.add(kSseHandlerPath);
472-
return uri.replace(scheme: 'sse', pathSegments: pathSegments);
469+
return hostedUri.replace(scheme: 'sse', pathSegments: pathSegments);
473470
}
474471

475472
@visibleForTesting
476-
Uri? toDevTools(Uri? uri) {
473+
Uri? toDevTools(Uri? hostedUri, {bool externallyServed = false}) {
477474
return Uri(
478475
scheme: 'http',
479-
host: uri!.host,
480-
port: uri.port,
476+
host: hostedUri!.host,
477+
port: hostedUri.port,
481478
pathSegments: [
482-
...uri.pathSegments.where(
479+
...hostedUri.pathSegments.where(
483480
(e) => e.isNotEmpty,
484481
),
485-
'devtools',
482+
if (!externallyServed) 'devtools',
486483
// Includes a trailing slash by adding an empty string to the end of the
487484
// path segments list.
488485
'',
@@ -522,8 +519,12 @@ class DartDevelopmentServiceImpl implements DartDevelopmentService {
522519

523520
@override
524521
Uri? get devToolsUri {
525-
_devToolsUri ??=
526-
_devToolsConfiguration?.enable ?? false ? toDevTools(_uri) : null;
522+
if (_devToolsUri == null && (_devToolsConfiguration?.enable ?? false)) {
523+
Uri? existingDevToolsUri = _devToolsConfiguration!.devToolsServerAddress;
524+
_devToolsUri = existingDevToolsUri != null
525+
? toDevTools(existingDevToolsUri, externallyServed: true)
526+
: toDevTools(_uri);
527+
}
527528
return _devToolsUri;
528529
}
529530

pkg/dds/test/launcher_smoke_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ void main() {
6666
);
6767
}
6868

69+
test(
70+
'External DevTools address is reported correctly',
71+
() async {
72+
final fakeDevToolsUri =
73+
Uri.parse('http://localhost:12345/my_devtools/');
74+
dds = await DartDevelopmentServiceLauncher.start(
75+
remoteVmServiceUri: remoteVmServiceUri,
76+
serveDevTools: true,
77+
devToolsServerAddress: fakeDevToolsUri,
78+
);
79+
80+
expect(dds.devToolsUri,
81+
fakeDevToolsUri.replace(query: 'uri=${dds.wsUri.toString()}'));
82+
},
83+
);
84+
6985
createSmokeTest(true);
7086
createSmokeTest(false);
7187
});

0 commit comments

Comments
 (0)