Skip to content

Commit 6eb8594

Browse files
bkonyiCommit Queue
authored andcommitted
[ VM / DDS ] Add --print-dtd-uri flag and launch DTD from the correct snapshot for AOT
This adds support for printing the DTD connection information to stdout when --print-dtd-uri is passed. This change also fixes an issue where DDS would fail to spawn an isolate with the DTD snapshot when DDS was running in AOT mode. This means the SDK must be shipped with both AppJIT and AOT DTD snapshots, at least until dartdev is moved to run from AOT. Fixes #55034 TEST=run_test.dart Change-Id: I788ef9bfe76297a8d594992a2aac440ed9e2ecac Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358541 Reviewed-by: Siva Annamalai <[email protected]> Commit-Queue: Ben Konyi <[email protected]> Reviewed-by: Kenzie Davisson <[email protected]>
1 parent 87df8c4 commit 6eb8594

File tree

23 files changed

+281
-356
lines changed

23 files changed

+281
-356
lines changed

pkg/dartdev/lib/src/commands/run.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ class RunCommand extends DartdevCommand {
264264
hide: !verbose,
265265
help: 'Enable hosting Observatory through the VM Service.',
266266
defaultsTo: true)
267+
..addFlag(
268+
'print-dtd',
269+
hide: !verbose,
270+
help: 'Prints connection details for the Dart Tooling Daemon (DTD).'
271+
'Useful for Dart DevTools extension authors working with DTD in the '
272+
'extension development environment.',
273+
)
267274
..addFlag(
268275
'debug-dds',
269276
hide: true,

pkg/dartdev/lib/src/dds_runner.dart

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,11 @@ class DDSRunner {
2424
}) async {
2525
final sdkDir = dirname(sdk.dart);
2626
final fullSdk = sdkDir.endsWith('bin');
27-
String snapshotName = fullSdk
28-
? sdk.ddsAotSnapshot
29-
: absolute(sdkDir, 'dds_aot.dart.snapshot');
30-
String execName = sdk.dartAotRuntime;
31-
// Check to see if the AOT snapshot and dartaotruntime are available.
32-
// If not, fall back to running from the AppJIT snapshot.
33-
//
34-
// This can happen if:
35-
// - The SDK is built for IA32 which doesn't support AOT compilation
36-
// - We only have artifacts available from the 'runtime' build
37-
// configuration, which the VM SDK build bots frequently run from
38-
if (!Sdk.checkArtifactExists(snapshotName, logError: false) ||
39-
!Sdk.checkArtifactExists(sdk.dartAotRuntime, logError: false)) {
40-
snapshotName =
41-
fullSdk ? sdk.ddsSnapshot : absolute(sdkDir, 'dds.dart.snapshot');
42-
if (!Sdk.checkArtifactExists(snapshotName)) {
43-
return false;
44-
}
45-
execName = sdk.dart;
27+
final execName = sdk.dart;
28+
final snapshotName =
29+
fullSdk ? sdk.ddsSnapshot : absolute(sdkDir, 'dds.dart.snapshot');
30+
if (!Sdk.checkArtifactExists(snapshotName)) {
31+
return false;
4632
}
4733

4834
final process = await Process.start(

pkg/dartdev/test/commands/devtools_test.dart

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ final dartVMServiceRegExp = RegExp(
1818
final ddsStartedRegExp = RegExp(
1919
r'Started the Dart Development Service \(DDS\) at (http://127.0.0.1:.*)',
2020
);
21+
final dtdStartedRegExp = RegExp(
22+
r'Serving the Dart Tooling Daemon at (ws://127.0.0.1:.*)',
23+
);
2124
final servingDevToolsRegExp = RegExp(
2225
r'Serving DevTools at (http://127.0.0.1:.*)',
2326
);
@@ -138,10 +141,54 @@ void devtools() {
138141
});
139142
});
140143

144+
Future<void> startDevTools({
145+
String? vmServiceUri,
146+
bool shouldStartDds = false,
147+
bool shouldPrintDtd = false,
148+
}) async {
149+
final process = await p.start([
150+
'devtools',
151+
'--no-launch-browser',
152+
if (shouldPrintDtd) '--print-dtd',
153+
if (vmServiceUri != null) vmServiceUri,
154+
]);
155+
process.stderr.transform(utf8.decoder).listen(print);
156+
157+
bool startedDds = false;
158+
bool startedDtd = false;
159+
final devToolsServedCompleter = Completer<void>();
160+
late StreamSubscription sub;
161+
sub = process.stdout
162+
.transform<String>(utf8.decoder)
163+
.transform<String>(const LineSplitter())
164+
.listen((event) async {
165+
print(event);
166+
if (event.contains(ddsStartedRegExp)) {
167+
startedDds = true;
168+
} else if (event.contains(dtdStartedRegExp)) {
169+
startedDtd = true;
170+
} else if (event.contains(servingDevToolsRegExp)) {
171+
await sub.cancel();
172+
devToolsServedCompleter.complete();
173+
}
174+
});
175+
176+
await devToolsServedCompleter.future;
177+
expect(startedDds, shouldStartDds);
178+
expect(startedDtd, shouldPrintDtd);
179+
180+
// kill the process
181+
process.kill();
182+
}
183+
184+
test('prints DTD URI', () async {
185+
p = project();
186+
await startDevTools(shouldPrintDtd: true);
187+
});
188+
141189
group('spawns DDS integration', () {
142190
late TestProject targetProject;
143191
Process? targetProjectInstance;
144-
Process? process;
145192

146193
setUp(() {
147194
// NOTE: we don't use `project()` here since it registers a tear-down
@@ -163,9 +210,7 @@ Future<void> main() async {
163210

164211
tearDown(() {
165212
targetProjectInstance?.kill();
166-
process?.kill();
167213
targetProjectInstance = null;
168-
process = null;
169214
targetProject.dispose();
170215
p.dispose();
171216
});
@@ -199,40 +244,6 @@ Future<void> main() async {
199244
return await serviceUriCompleter.future;
200245
}
201246

202-
Future<void> startDevTools({
203-
required String vmServiceUri,
204-
required bool shouldStartDds,
205-
}) async {
206-
process = await p.start([
207-
'devtools',
208-
'--no-launch-browser',
209-
vmServiceUri,
210-
]);
211-
process!.stderr.transform(utf8.decoder).listen(print);
212-
213-
bool startedDds = false;
214-
final devToolsServedCompleter = Completer<void>();
215-
late StreamSubscription sub;
216-
sub = process!.stdout
217-
.transform<String>(utf8.decoder)
218-
.transform<String>(const LineSplitter())
219-
.listen((event) async {
220-
if (event.contains(ddsStartedRegExp)) {
221-
startedDds = true;
222-
} else if (event.contains(servingDevToolsRegExp)) {
223-
await sub.cancel();
224-
devToolsServedCompleter.complete();
225-
}
226-
});
227-
228-
await devToolsServedCompleter.future;
229-
expect(startedDds, shouldStartDds);
230-
231-
// kill the process
232-
process!.kill();
233-
process = null;
234-
}
235-
236247
for (final disableAuthCodes in const [true, false]) {
237248
final authCodesEnabledStr = disableAuthCodes ? 'disabled' : 'enabled';
238249
test('with auth codes $authCodesEnabledStr', () async {

0 commit comments

Comments
 (0)