Skip to content

Commit 0a71249

Browse files
kenzieschmollCommit Queue
authored andcommitted
Add support for connecting a debug version of DevTools to the DevTools server.
Requires flutter/devtools#8621. Bug: flutter/devtools#6486 Change-Id: I57b6a6d1551831d89cc7d007376291e8cffd920e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366421 Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Ben Konyi <[email protected]> Reviewed-by: Elliott Brooks <[email protected]>
1 parent cb3447f commit 0a71249

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

pkg/dds/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
.packages
44
build/
55
pubspec.lock
6+
*.code-workspace
7+
logs/

pkg/dds/lib/devtools_server.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class DevToolsServer {
299299
);
300300

301301
handler ??= await defaultHandler(
302-
buildDir: customDevToolsPath!,
302+
buildDir: customDevToolsPath,
303303
clientManager: clientManager,
304304
dtd: dtdInfo,
305305
devtoolsExtensionsManager: ExtensionsManager(),
@@ -336,6 +336,16 @@ class DevToolsServer {
336336
server.defaultResponseHeaders.add('origin-agent-cluster', '?1');
337337
}
338338

339+
// This is only true when the DevTools server is started through the
340+
// tool/devtools_server/serve_local.dart script. This is required to allow
341+
// connecting a debug instance of DevTools app to a running DevTools server.
342+
if (Platform.script.toString().endsWith('serve_local.dart')) {
343+
server.defaultResponseHeaders.add(
344+
HttpHeaders.accessControlAllowOriginHeader,
345+
'*',
346+
);
347+
}
348+
339349
// Ensure browsers don't cache older versions of the app.
340350
server.defaultResponseHeaders.add(
341351
HttpHeaders.cacheControlHeader,

pkg/dds/lib/src/devtools/handler.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import 'utils.dart';
4242
/// client that is not the DevTools server (e.g. an IDE).
4343
FutureOr<Handler> defaultHandler({
4444
DartDevelopmentServiceImpl? dds,
45-
required String buildDir,
45+
String? buildDir,
4646
ClientManager? clientManager,
4747
Handler? notFoundHandler,
4848
DtdInfo? dtd,
@@ -55,15 +55,6 @@ FutureOr<Handler> defaultHandler({
5555
appRoot = '/${dds!.authCode}$appRoot';
5656
}
5757

58-
const defaultDocument = 'index.html';
59-
final indexFile = File(path.join(buildDir, defaultDocument));
60-
61-
// Serves the static web assets for DevTools.
62-
final devtoolsStaticAssetHandler = createStaticHandler(
63-
buildDir,
64-
defaultDocument: defaultDocument,
65-
);
66-
6758
/// A wrapper around [devtoolsStaticAssetHandler] that handles serving
6859
/// index.html up for / and non-file requests like /memory, /inspector, etc.
6960
/// with the correct base href for the DevTools root.
@@ -106,6 +97,12 @@ FutureOr<Handler> defaultHandler({
10697
}
10798
}
10899

100+
if (buildDir == null) {
101+
return Response.notFound('No build directory was specified.');
102+
}
103+
104+
const defaultDocument = 'index.html';
105+
final indexFile = File(path.join(buildDir, defaultDocument));
109106
final isValidRootPage = pathSegments.isEmpty ||
110107
(pathSegments.length == 1 && !pathSegments[0].contains('.'));
111108

@@ -118,6 +115,11 @@ FutureOr<Handler> defaultHandler({
118115
);
119116
}
120117

118+
// Serves the static web assets for DevTools.
119+
final devtoolsStaticAssetHandler = createStaticHandler(
120+
buildDir,
121+
defaultDocument: defaultDocument,
122+
);
121123
return devtoolsStaticAssetHandler(request);
122124
}
123125

pkg/dds/tool/devtools_server/serve_local.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ void main(List<String> args) {
1515
argDevToolsBuild,
1616
help: 'The location of the DevTools build to serve from DevTools server '
1717
'(e.g. --devtools-build=absolute/path/to/devtools/build).',
18-
mandatory: true,
1918
);
2019

2120
try {
2221
final ArgResults argResults = argParser.parse(args);
2322
unawaited(
2423
DevToolsServer().serveDevToolsWithArgs(
2524
_removeDevToolsBuildOption(args),
26-
customDevToolsPath: argResults[argDevToolsBuild],
25+
customDevToolsPath: argResults.wasParsed(argDevToolsBuild)
26+
? argResults[argDevToolsBuild]
27+
: null,
2728
),
2829
);
2930
} on FormatException catch (e) {

0 commit comments

Comments
 (0)