@@ -157,6 +157,17 @@ class ServeCommand extends Command {
157
157
final devToolsAppBuildMode =
158
158
results[SharedCommandArgs .buildMode.flagName] as String ;
159
159
final serveWithDartSdk = results[_serveWithDartSdkFlag] as String ? ;
160
+ final forMachine = results[_machineFlag] as bool ;
161
+
162
+ // TODO(https://github.com/flutter/devtools/issues/8643): Support running in
163
+ // machine mode with a debuggable DevTools app.
164
+ if (runApp && forMachine) {
165
+ throw Exception (
166
+ 'Machine mode is not supported with `flutter run` DevTools.\n '
167
+ 'Please use either --machine or --run-app, not both.\n '
168
+ 'See https://github.com/flutter/devtools/issues/8643 for details.' ,
169
+ );
170
+ }
160
171
161
172
// Any flag that we aren't removing here is intended to be passed through.
162
173
final remainingArguments =
@@ -271,23 +282,34 @@ class ServeCommand extends Command {
271
282
}
272
283
273
284
// This call will not exit until explicitly terminated by the user.
285
+ final cliCommand = CliCommand .dart ([
286
+ if (debugServer) ...['run' , '--observe=0' ],
287
+ ddsServeLocalScriptPath,
288
+ if (runApp)
289
+ // When running DevTools via `flutter run`, the [flutterRunProcess]
290
+ // below will launch DevTools in the browser.
291
+ '--no-launch-browser'
292
+ else
293
+ // Only pass a build location if the server is serving the web assets
294
+ // (i.e. not when DevTools app is ran via `flutter run`).
295
+ '--devtools-build=$devToolsBuildLocation ' ,
296
+ // Pass any args that were provided to our script along. This allows IDEs
297
+ // to pass `--machine` (etc.) so that this script can behave the same as
298
+ // the "dart devtools" command for testing local DevTools/server changes.
299
+ ...remainingArguments,
300
+ ], sdkOverride: serveWithDartSdk);
301
+ if (forMachine) {
302
+ // If --machine flag is true, then the output is a tool-readable JSON.
303
+ // Therefore, skip reading the process output and instead just run the
304
+ // process.
305
+ return processManager.runProcess (
306
+ cliCommand,
307
+ workingDirectory: localDartSdkLocation,
308
+ );
309
+ }
310
+
274
311
final serveLocalProcess = await startIndependentProcess (
275
- CliCommand .dart ([
276
- if (debugServer) ...['run' , '--observe=0' ],
277
- ddsServeLocalScriptPath,
278
- if (runApp)
279
- // When running DevTools via `flutter run`, the [flutterRunProcess]
280
- // below will launch DevTools in the browser.
281
- '--no-launch-browser'
282
- else
283
- // Only pass a build location if the server is serving the web assets
284
- // (i.e. not when DevTools app is ran via `flutter run`).
285
- '--devtools-build=$devToolsBuildLocation ' ,
286
- // Pass any args that were provided to our script along. This allows IDEs
287
- // to pass `--machine` (etc.) so that this script can behave the same as
288
- // the "dart devtools" command for testing local DevTools/server changes.
289
- ...remainingArguments,
290
- ], sdkOverride: serveWithDartSdk),
312
+ cliCommand,
291
313
workingDirectory: localDartSdkLocation,
292
314
waitForOutput: _devToolsServerAddressLine,
293
315
onOutput: processServeLocalOutput,
0 commit comments