Skip to content

Commit 65ceb66

Browse files
authored
Serve command still works with --machine flag (#8638)
1 parent 5ecc043 commit 65ceb66

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

tool/lib/commands/serve.dart

+38-16
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,17 @@ class ServeCommand extends Command {
157157
final devToolsAppBuildMode =
158158
results[SharedCommandArgs.buildMode.flagName] as String;
159159
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+
}
160171

161172
// Any flag that we aren't removing here is intended to be passed through.
162173
final remainingArguments =
@@ -271,23 +282,34 @@ class ServeCommand extends Command {
271282
}
272283

273284
// 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+
274311
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,
291313
workingDirectory: localDartSdkLocation,
292314
waitForOutput: _devToolsServerAddressLine,
293315
onOutput: processServeLocalOutput,

0 commit comments

Comments
 (0)