@@ -158,6 +158,10 @@ class RunCommand extends DartdevCommand {
158158 hide: ! verbose,
159159 negatable: false ,
160160 help: 'Enables tracing of library and script loading.' ,
161+ )
162+ ..addFlag (
163+ 'debug-dds' ,
164+ hide: true ,
161165 );
162166 addExperimentalFlags (argParser, verbose);
163167 }
@@ -179,13 +183,18 @@ class RunCommand extends DartdevCommand {
179183 String launchDdsArg = argResults['launch-dds' ];
180184 String ddsHost = '' ;
181185 String ddsPort = '' ;
186+
187+ // TODO(bkonyi): allow for users to choose not to launch DevTools
188+ // See https://github.com/dart-lang/sdk/issues/45867.
189+ const bool launchDevTools = true ;
182190 bool launchDds = false ;
183191 if (launchDdsArg != null ) {
184192 launchDds = true ;
185- final ddsUrl = launchDdsArg.split (':' );
193+ final ddsUrl = launchDdsArg.split ('\\ :' );
186194 ddsHost = ddsUrl[0 ];
187195 ddsPort = ddsUrl[1 ];
188196 }
197+ final bool debugDds = argResults['debug-dds' ];
189198
190199 bool disableServiceAuthCodes = argResults['disable-service-auth-codes' ];
191200
@@ -198,7 +207,12 @@ class RunCommand extends DartdevCommand {
198207 if (launchDds) {
199208 debugSession = _DebuggingSession ();
200209 if (! await debugSession.start (
201- ddsHost, ddsPort, disableServiceAuthCodes)) {
210+ ddsHost,
211+ ddsPort,
212+ disableServiceAuthCodes,
213+ launchDevTools,
214+ debugDds,
215+ )) {
202216 return errorExitCode;
203217 }
204218 }
@@ -242,10 +256,19 @@ String maybeUriToFilename(String maybeUri) {
242256
243257class _DebuggingSession {
244258 Future <bool > start (
245- String host, String port, bool disableServiceAuthCodes) async {
246- final ddsSnapshot = (dirname (sdk.dart).endsWith ('bin' ))
259+ String host,
260+ String port,
261+ bool disableServiceAuthCodes,
262+ bool enableDevTools,
263+ bool debugDds,
264+ ) async {
265+ final sdkDir = dirname (sdk.dart);
266+ final fullSdk = sdkDir.endsWith ('bin' );
267+ final ddsSnapshot = fullSdk
247268 ? sdk.ddsSnapshot
248- : absolute (dirname (sdk.dart), 'gen' , 'dds.dart.snapshot' );
269+ : absolute (sdkDir, 'gen' , 'dds.dart.snapshot' );
270+ final devToolsBinaries =
271+ fullSdk ? sdk.devToolsBinaries : absolute (sdkDir, 'devtools' );
249272 if (! Sdk .checkArtifactExists (ddsSnapshot)) {
250273 return false ;
251274 }
@@ -256,30 +279,51 @@ class _DebuggingSession {
256279 serviceInfo = await Service .getInfo ();
257280 }
258281 final process = await Process .start (
259- sdk.dart,
260- [
261- if (dirname (sdk.dart).endsWith ('bin' ))
262- sdk.ddsSnapshot
263- else
264- absolute (dirname (sdk.dart), 'gen' , 'dds.dart.snapshot' ),
265- serviceInfo.serverUri.toString (),
266- host,
267- port,
268- disableServiceAuthCodes.toString (),
269- ],
270- mode: ProcessStartMode .detachedWithStdio);
282+ sdk.dart,
283+ [
284+ if (debugDds) '--enable-vm-service=0' ,
285+ ddsSnapshot,
286+ serviceInfo.serverUri.toString (),
287+ host,
288+ port,
289+ disableServiceAuthCodes.toString (),
290+ enableDevTools.toString (),
291+ devToolsBinaries,
292+ debugDds.toString (),
293+ ],
294+ mode: ProcessStartMode .detachedWithStdio,
295+ );
271296 final completer = Completer <void >();
272- StreamSubscription sub;
273- sub = process.stderr.transform (utf8.decoder).listen ((event) {
274- if (event == 'DDS started' ) {
275- sub.cancel ();
297+ const devToolsMessagePrefix =
298+ 'The Dart DevTools debugger and profiler is available at:' ;
299+ if (debugDds) {
300+ StreamSubscription stdoutSub;
301+ stdoutSub = process.stdout.transform (utf8.decoder).listen ((event) {
302+ if (event.startsWith (devToolsMessagePrefix)) {
303+ final ddsDebuggingUri = event.split (' ' ).last;
304+ print (
305+ 'A DevTools debugger for DDS is available at: $ddsDebuggingUri ' ,
306+ );
307+ stdoutSub.cancel ();
308+ }
309+ });
310+ }
311+ StreamSubscription stderrSub;
312+ stderrSub = process.stderr.transform (utf8.decoder).listen ((event) {
313+ final result = json.decode (event) as Map <String , dynamic >;
314+ final state = result['state' ];
315+ if (state == 'started' ) {
316+ if (result.containsKey ('devToolsUri' )) {
317+ final devToolsUri = result['devToolsUri' ];
318+ print ('$devToolsMessagePrefix $devToolsUri ' );
319+ }
320+ stderrSub.cancel ();
276321 completer.complete ();
277- } else if (event.contains ('Failed to start DDS' )) {
278- sub.cancel ();
279- completer.completeError (event.replaceAll (
280- 'Failed to start DDS' ,
322+ } else {
323+ stderrSub.cancel ();
324+ completer.completeError (
281325 'Could not start Observatory HTTP server' ,
282- )) ;
326+ );
283327 }
284328 });
285329 try {
0 commit comments