Skip to content

Commit 2f5a53c

Browse files
bkonyiCommit Queue
authored andcommitted
[ DDS ] Add --devtools-server-address to support external DevTools servers
This allows for DDS to redirect requests for DevTools assets directly to external DevTools instances served by IDEs. Change-Id: I6a4730267144ef5e924b69800a53392a97e574f2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362401 Commit-Queue: Ben Konyi <[email protected]> Reviewed-by: Derek Xu <[email protected]>
1 parent 3b07865 commit 2f5a53c

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

pkg/dds/bin/dds.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ ${argParser.usage}
8383

8484
final serveDevTools =
8585
argResults[DartDevelopmentServiceOptions.serveDevToolsFlag];
86+
final devToolsServerAddressStr =
87+
argResults[DartDevelopmentServiceOptions.devToolsServerAddressOption];
8688
Uri? devToolsBuildDirectory;
89+
final devToolsServerAddress = devToolsServerAddressStr == null
90+
? null
91+
: Uri.parse(devToolsServerAddressStr);
8792
if (serveDevTools) {
8893
devToolsBuildDirectory = _getDevToolsAssetPath();
8994
}
@@ -104,6 +109,7 @@ ${argParser.usage}
104109
? DevToolsConfiguration(
105110
enable: serveDevTools,
106111
customBuildDirectoryPath: devToolsBuildDirectory,
112+
devToolsServerAddress: devToolsServerAddress,
107113
)
108114
: null,
109115
enableServicePortFallback: enableServicePortFallback,

pkg/dds/lib/dds.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,11 @@ class ExistingDartDevelopmentServiceException
242242
class DevToolsConfiguration {
243243
const DevToolsConfiguration({
244244
required this.customBuildDirectoryPath,
245+
this.devToolsServerAddress,
245246
this.enable = false,
246247
});
247248

248249
final bool enable;
250+
final Uri? devToolsServerAddress;
249251
final Uri customBuildDirectoryPath;
250252
}

pkg/dds/lib/src/arg_parser.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ abstract class DartDevelopmentServiceOptions {
1515
static const serveDevToolsFlag = 'serve-devtools';
1616
static const enableServicePortFallbackFlag = 'enable-service-port-fallback';
1717
static const cachedUserTagsOption = 'cached-user-tags';
18+
static const devToolsServerAddressOption = 'devtools-server-address';
1819
static const google3WorkspaceRootOption = 'google3-workspace-root';
1920

2021
static ArgParser createArgParser({
@@ -59,7 +60,13 @@ abstract class DartDevelopmentServiceOptions {
5960
)
6061
..addFlag(
6162
serveDevToolsFlag,
62-
help: 'If provided, DDS will serve DevTools.',
63+
help: 'If provided, DDS will serve DevTools. If not specified, '
64+
'"--$devToolsServerAddressOption" is ignored.',
65+
)
66+
..addOption(
67+
devToolsServerAddressOption,
68+
help: 'Redirect to an existing DevTools server. Ignored if '
69+
'"--$serveDevToolsFlag" is not specified.',
6370
)
6471
..addFlag(
6572
enableServicePortFallbackFlag,

pkg/dds/lib/src/dds_impl.dart

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -361,21 +361,28 @@ class DartDevelopmentServiceImpl implements DartDevelopmentService {
361361
Handler _httpHandler() {
362362
final notFoundHandler = proxyHandler(remoteVmServiceUri);
363363

364-
// If DDS is serving DevTools, install the DevTools handlers and forward
365-
// any unhandled HTTP requests to the VM service.
366364
if (_devToolsConfiguration?.enable ?? false) {
367-
final String buildDir =
368-
_devToolsConfiguration!.customBuildDirectoryPath.toFilePath();
369-
return defaultHandler(
370-
dds: this,
371-
buildDir: buildDir,
372-
notFoundHandler: notFoundHandler,
373-
dtd: (
374-
uri: _hostedDartToolingDaemon?.uri,
375-
secret: _hostedDartToolingDaemon?.secret
376-
),
377-
devtoolsExtensionsManager: ExtensionsManager(),
378-
) as FutureOr<Response> Function(Request);
365+
final existingDevToolsAddress =
366+
_devToolsConfiguration!.devToolsServerAddress;
367+
if (existingDevToolsAddress == null) {
368+
// If DDS is serving DevTools, install the DevTools handlers and
369+
// forward any unhandled HTTP requests to the VM service.
370+
final String buildDir =
371+
_devToolsConfiguration!.customBuildDirectoryPath.toFilePath();
372+
return defaultHandler(
373+
dds: this,
374+
buildDir: buildDir,
375+
notFoundHandler: notFoundHandler,
376+
dtd: (
377+
uri: _hostedDartToolingDaemon?.uri,
378+
secret: _hostedDartToolingDaemon?.secret
379+
),
380+
devtoolsExtensionsManager: ExtensionsManager(),
381+
) as FutureOr<Response> Function(Request);
382+
}
383+
// Otherwise, set the DevTools URI to point to the externally hosted
384+
// DevTools instance.
385+
_devToolsUri = existingDevToolsAddress;
379386
}
380387

381388
// Otherwise, DevTools may be served externally, or not at all.
@@ -488,7 +495,8 @@ class DartDevelopmentServiceImpl implements DartDevelopmentService {
488495

489496
@override
490497
void setExternalDevToolsUri(Uri uri) {
491-
if (_devToolsConfiguration?.enable ?? false) {
498+
if ((_devToolsConfiguration?.enable ?? false) &&
499+
_devToolsConfiguration?.devToolsServerAddress != null) {
492500
throw StateError('A hosted DevTools instance is already being served.');
493501
}
494502
_devToolsUri = uri;

0 commit comments

Comments
 (0)