Skip to content

Commit

Permalink
Serve command still works with --machine flag (#8638)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliette authored Dec 17, 2024
1 parent 5ecc043 commit 65ceb66
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions tool/lib/commands/serve.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ class ServeCommand extends Command {
final devToolsAppBuildMode =
results[SharedCommandArgs.buildMode.flagName] as String;
final serveWithDartSdk = results[_serveWithDartSdkFlag] as String?;
final forMachine = results[_machineFlag] as bool;

// TODO(https://github.com/flutter/devtools/issues/8643): Support running in
// machine mode with a debuggable DevTools app.
if (runApp && forMachine) {
throw Exception(
'Machine mode is not supported with `flutter run` DevTools.\n'
'Please use either --machine or --run-app, not both.\n'
'See https://github.com/flutter/devtools/issues/8643 for details.',
);
}

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

// This call will not exit until explicitly terminated by the user.
final cliCommand = CliCommand.dart([
if (debugServer) ...['run', '--observe=0'],
ddsServeLocalScriptPath,
if (runApp)
// When running DevTools via `flutter run`, the [flutterRunProcess]
// below will launch DevTools in the browser.
'--no-launch-browser'
else
// Only pass a build location if the server is serving the web assets
// (i.e. not when DevTools app is ran via `flutter run`).
'--devtools-build=$devToolsBuildLocation',
// Pass any args that were provided to our script along. This allows IDEs
// to pass `--machine` (etc.) so that this script can behave the same as
// the "dart devtools" command for testing local DevTools/server changes.
...remainingArguments,
], sdkOverride: serveWithDartSdk);
if (forMachine) {
// If --machine flag is true, then the output is a tool-readable JSON.
// Therefore, skip reading the process output and instead just run the
// process.
return processManager.runProcess(
cliCommand,
workingDirectory: localDartSdkLocation,
);
}

final serveLocalProcess = await startIndependentProcess(
CliCommand.dart([
if (debugServer) ...['run', '--observe=0'],
ddsServeLocalScriptPath,
if (runApp)
// When running DevTools via `flutter run`, the [flutterRunProcess]
// below will launch DevTools in the browser.
'--no-launch-browser'
else
// Only pass a build location if the server is serving the web assets
// (i.e. not when DevTools app is ran via `flutter run`).
'--devtools-build=$devToolsBuildLocation',
// Pass any args that were provided to our script along. This allows IDEs
// to pass `--machine` (etc.) so that this script can behave the same as
// the "dart devtools" command for testing local DevTools/server changes.
...remainingArguments,
], sdkOverride: serveWithDartSdk),
cliCommand,
workingDirectory: localDartSdkLocation,
waitForOutput: _devToolsServerAddressLine,
onOutput: processServeLocalOutput,
Expand Down

0 comments on commit 65ceb66

Please sign in to comment.