Skip to content

Commit 9304826

Browse files
bkonyiCommit Queue
authored and
Commit Queue
committed
[ DDS ] Refactor DDS entrypoint to allow for overriding behavior in google3
This moves the CLI logic into lib/src/dds_cli_entrypoint.dart so it can be invoked by a custom google3 entrypoint (bin/dds.dart can't be imported using a package: URI). Since google3 will be able to perform some custom configuration of DDS, google3 related logic (e.g., `BazelUriConverter`) is also removed. This is technically a breaking change, but should be safe as this functionality isn't currently being used. Change-Id: I54d8a9927ff2df70e013ca5c8bc1d510b0b95f02 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371520 Reviewed-by: Derek Xu <[email protected]> Commit-Queue: Derek Xu <[email protected]> Auto-Submit: Ben Konyi <[email protected]>
1 parent 02faed0 commit 9304826

File tree

5 files changed

+154
-439
lines changed

5 files changed

+154
-439
lines changed

pkg/dds/bin/dds.dart

Lines changed: 5 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -2,147 +2,11 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:convert';
6-
import 'dart:io';
7-
8-
import 'package:dds/dds.dart';
9-
import 'package:dds/src/arg_parser.dart';
10-
import 'package:dds/src/bazel_uri_converter.dart';
11-
12-
import 'package:path/path.dart' as path;
13-
14-
Uri _getDevToolsAssetPath() {
15-
final dartDir = File(Platform.resolvedExecutable).parent.path;
16-
final fullSdk = dartDir.endsWith('bin');
17-
return Uri.file(
18-
fullSdk
19-
? path.absolute(
20-
dartDir,
21-
'resources',
22-
'devtools',
23-
)
24-
: path.absolute(
25-
dartDir,
26-
'devtools',
27-
),
28-
);
29-
}
5+
import 'package:dds/src/dds_cli_entrypoint.dart';
306

317
Future<void> main(List<String> args) async {
32-
final argParser = DartDevelopmentServiceOptions.createArgParser(
33-
includeHelp: true,
34-
);
35-
final argResults = argParser.parse(args);
36-
if (args.isEmpty || argResults.wasParsed('help')) {
37-
print('''
38-
Starts a Dart Development Service (DDS) instance.
39-
40-
Usage:
41-
${argParser.usage}
42-
''');
43-
return;
44-
}
45-
46-
// This URI is provided by the VM service directly so don't bother doing a
47-
// lookup.
48-
final remoteVmServiceUri = Uri.parse(
49-
argResults[DartDevelopmentServiceOptions.vmServiceUriOption],
50-
);
51-
52-
// Resolve the address which is potentially provided by the user.
53-
late InternetAddress address;
54-
final bindAddress =
55-
argResults[DartDevelopmentServiceOptions.bindAddressOption];
56-
try {
57-
final addresses = await InternetAddress.lookup(bindAddress);
58-
// Prefer IPv4 addresses.
59-
for (int i = 0; i < addresses.length; i++) {
60-
address = addresses[i];
61-
if (address.type == InternetAddressType.IPv4) break;
62-
}
63-
} on SocketException catch (e, st) {
64-
writeErrorResponse('Invalid bind address: $bindAddress', st);
65-
return;
66-
}
67-
68-
final portString = argResults[DartDevelopmentServiceOptions.bindPortOption];
69-
int port;
70-
try {
71-
port = int.parse(portString);
72-
} on FormatException catch (e, st) {
73-
writeErrorResponse('Invalid port: $portString', st);
74-
return;
75-
}
76-
final serviceUri = Uri(
77-
scheme: 'http',
78-
host: address.address,
79-
port: port,
80-
);
81-
final disableServiceAuthCodes =
82-
argResults[DartDevelopmentServiceOptions.disableServiceAuthCodesFlag];
83-
84-
final serveDevTools =
85-
argResults[DartDevelopmentServiceOptions.serveDevToolsFlag];
86-
final devToolsServerAddressStr =
87-
argResults[DartDevelopmentServiceOptions.devToolsServerAddressOption];
88-
Uri? devToolsBuildDirectory;
89-
final devToolsServerAddress = devToolsServerAddressStr == null
90-
? null
91-
: Uri.parse(devToolsServerAddressStr);
92-
if (serveDevTools) {
93-
devToolsBuildDirectory = _getDevToolsAssetPath();
94-
}
95-
final enableServicePortFallback =
96-
argResults[DartDevelopmentServiceOptions.enableServicePortFallbackFlag];
97-
final cachedUserTags =
98-
argResults[DartDevelopmentServiceOptions.cachedUserTagsOption];
99-
final google3WorkspaceRoot =
100-
argResults[DartDevelopmentServiceOptions.google3WorkspaceRootOption];
101-
102-
try {
103-
final dds = await DartDevelopmentService.startDartDevelopmentService(
104-
remoteVmServiceUri,
105-
serviceUri: serviceUri,
106-
enableAuthCodes: !disableServiceAuthCodes,
107-
ipv6: address.type == InternetAddressType.IPv6,
108-
devToolsConfiguration: serveDevTools && devToolsBuildDirectory != null
109-
? DevToolsConfiguration(
110-
enable: serveDevTools,
111-
customBuildDirectoryPath: devToolsBuildDirectory,
112-
devToolsServerAddress: devToolsServerAddress,
113-
)
114-
: null,
115-
enableServicePortFallback: enableServicePortFallback,
116-
cachedUserTags: cachedUserTags,
117-
uriConverter: google3WorkspaceRoot != null
118-
? BazelUriConverter(google3WorkspaceRoot).uriToPath
119-
: null,
120-
);
121-
final dtdInfo = dds.hostedDartToolingDaemon;
122-
stderr.write(json.encode({
123-
'state': 'started',
124-
'ddsUri': dds.uri.toString(),
125-
if (dds.devToolsUri != null) 'devToolsUri': dds.devToolsUri.toString(),
126-
if (dtdInfo != null)
127-
'dtd': {
128-
'uri': dtdInfo.uri,
129-
},
130-
}));
131-
stderr.close();
132-
} catch (e, st) {
133-
writeErrorResponse(e, st);
134-
} finally {
135-
// Always close stderr to notify tooling that DDS has finished writing
136-
// launch details.
137-
await stderr.close();
138-
}
139-
}
140-
141-
void writeErrorResponse(Object e, StackTrace st) {
142-
stderr.write(json.encode({
143-
'state': 'error',
144-
'error': '$e',
145-
'stacktrace': '$st',
146-
if (e is DartDevelopmentServiceException) 'ddsExceptionDetails': e.toJson(),
147-
}));
8+
// This level of indirection is only here so DDS can be configured for
9+
// google3 specific functionality as it's not possible to import files under
10+
// a package's bin directory to wrap the entrypoint.
11+
await runDartDevelopmentServiceFromCLI(args);
14812
}

pkg/dds/lib/src/arg_parser.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ abstract class DartDevelopmentServiceOptions {
1616
static const enableServicePortFallbackFlag = 'enable-service-port-fallback';
1717
static const cachedUserTagsOption = 'cached-user-tags';
1818
static const devToolsServerAddressOption = 'devtools-server-address';
19-
static const google3WorkspaceRootOption = 'google3-workspace-root';
2019

2120
static ArgParser createArgParser({
2221
int? usageLineLength,
@@ -78,12 +77,6 @@ abstract class DartDevelopmentServiceOptions {
7877
help: 'A set of UserTag names used to determine which CPU samples are '
7978
'cached by DDS.',
8079
defaultsTo: <String>[],
81-
)
82-
..addOption(
83-
google3WorkspaceRootOption,
84-
help: 'Sets the Google3 workspace root used for google3:// URI '
85-
'resolution.',
86-
hide: !verbose,
8780
);
8881
if (includeHelp) {
8982
argParser.addFlag('help', negatable: false);

0 commit comments

Comments
 (0)