Skip to content
Merged
23 changes: 18 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,20 @@ dependency_overrides:
path: relative/path/to/devtools/packages/devtools_shared
```

Then you can run DevTools with the server by running the following from the top-level `devtools` directory:
```
dt serve
```
Then you can run DevTools with the server by running the following from anywhere under the `devtools/` directory:
1. To run DevTools in release mode, served with the DevTools server (this emulates the production environment):
```
dt serve
```
2. To run DevTools in debug mode with full debugging support and a connection to a live DevTools server:
```sh
dt run
```

Option 2 is useful for a quicker development cycle. The DevTools build time will be faster, and you will be
able to connect the DevTools web app to an IDE or DevTools for debugging purposes.

To see the full list of arguments available for either command, please pass the `-h` flag.

### DevTools + VS Code integration (IDE-embedded DevTools experience)

Expand All @@ -191,7 +201,10 @@ command palette (`F1`)) and add the following to your settings:
"LOCAL_DART_SDK": "/path/to/sdk"
// Path to the version that Flutter DevTools is pinned to.
"FLUTTER_ROOT": "/path/to/devtools/tool/flutter-sdk"
}
},
"args": [
// Arguments that will be passed along to the `dt serve` command.
],
},
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ class PreferencesController extends DisposableController
return;
}

// Whether DevTools was run using the `dt serve --run-app` command, which
// runs DevTools in debug mode using `flutter run` and connects it to an
// instance of the DevTools server.
// Whether DevTools was run using the `dt run` command, which runs DevTools
// using `flutter run` and connects it to a locally running instance of the
// DevTools server.
final usingDebugDevToolsServer =
(const String.fromEnvironment('debug_devtools_server')).isNotEmpty &&
!kReleaseMode;
Expand Down
5 changes: 2 additions & 3 deletions packages/devtools_app/lib/src/shared/server/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ String get devToolsServerUriAsString {
_debugDevToolsServerFlag,
);
// Ensure we only use the debug DevTools server URI in non-release
// builds. By running `dt serve --run-app`, an instance of DevTools ran
// with `flutter run` can be connected to the DevTools server on a
// different port.
// builds. By running `dt run`, an instance of DevTools run with `flutter run`
// can be connected to the DevTools server on a different port.
return debugDevToolsServerUriAsString.isNotEmpty && !kReleaseMode
? debugDevToolsServerUriAsString
: Uri.base.toString();
Expand Down
24 changes: 12 additions & 12 deletions tool/lib/commands/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ import '../utils.dart';
///
/// By default, this command builds DevTools in release mode, but this can be
/// overridden by passing 'debug' or 'profile' as the
/// [BuildCommandArgs.buildMode] argument. For testing embedded content in
/// [SharedCommandArgs.buildMode] argument. For testing embedded content in
/// VS Code, 'profile' or the default 'release' mode must be used because
/// the '--dart2js-optimization=O1' flag that is passed for 'debug' builds
/// will cause issues with the VS Code embedding.
///
/// If the [BuildCommandArgs.useFlutterFromPath] argument is present, the
/// If the [SharedCommandArgs.useFlutterFromPath] argument is present, the
/// Flutter SDK will not be updated to the latest Flutter candidate before
/// building DevTools. Use this flag to save the cost of updating the Flutter
/// SDK when you already have the proper SDK checked out. This is helpful when
/// developing with the DevTools server.
///
/// If the [BuildCommandArgs.updatePerfetto] argument is present, the
/// If the [SharedCommandArgs.updatePerfetto] argument is present, the
/// precompiled bits for Perfetto will be updated from the
/// `dt update-perfetto` command as part of the DevTools build
/// process.
///
/// If [BuildCommandArgs.pubGet] argument is negated (e.g. --no-pub-get), then
/// If [SharedCommandArgs.pubGet] argument is negated (e.g. --no-pub-get), then
/// `dt pub-get --only-main` command will not be run before building
/// the DevTools web app. Use this flag to save the cost of updating pub
/// packages if your pub cahce does not need to be updated. This is helpful when
Expand Down Expand Up @@ -60,13 +60,13 @@ class BuildCommand extends Command {
final processManager = ProcessManager();
final results = argResults!;
final updateFlutter =
results[BuildCommandArgs.updateFlutter.flagName] as bool;
results[SharedCommandArgs.updateFlutter.flagName] as bool;
final updatePerfetto =
results[BuildCommandArgs.updatePerfetto.flagName] as bool;
final runPubGet = results[BuildCommandArgs.pubGet.flagName] as bool;
final buildMode = results[BuildCommandArgs.buildMode.flagName] as String;
final useWasm = results[BuildCommandArgs.wasm.flagName] as bool;
final noStripWasm = results[BuildCommandArgs.noStripWasm.flagName] as bool;
results[SharedCommandArgs.updatePerfetto.flagName] as bool;
final runPubGet = results[SharedCommandArgs.pubGet.flagName] as bool;
final buildMode = results[SharedCommandArgs.buildMode.flagName] as String;
final useWasm = results[SharedCommandArgs.wasm.flagName] as bool;
final noStripWasm = results[SharedCommandArgs.noStripWasm.flagName] as bool;

final webBuildDir = Directory(
path.join(repo.devtoolsAppDirectoryPath, 'build', 'web'),
Expand Down Expand Up @@ -103,8 +103,8 @@ class BuildCommand extends Command {
'web',
'--source-maps',
if (useWasm) ...[
BuildCommandArgs.wasm.asArg(),
if (noStripWasm) BuildCommandArgs.noStripWasm.asArg(),
SharedCommandArgs.wasm.asArg(),
if (noStripWasm) SharedCommandArgs.noStripWasm.asArg(),
] else ...[
'--web-renderer',
'canvaskit',
Expand Down
43 changes: 43 additions & 0 deletions tool/lib/commands/run.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2024 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:args/command_runner.dart';
import 'package:devtools_tool/commands/shared.dart';
import 'package:io/io.dart';

import '../utils.dart';

/// Runs the DevTools web app in debug mode with `flutter run` and connects it
/// to a locally running instance of the DevTools server.
///
/// To open a debug connection to the DevTools server, pass the `--debug-server`
/// flag to this command.
class RunCommand extends Command {
RunCommand() {
argParser.addDebugServerFlag();
}

@override
String get name => 'run';

@override
String get description =>
'Runs the DevTools web app in debug mode using "flutter run" and connects'
' it to a locally running instance of the DevTools server.';

@override
Future run() async {
final processManager = ProcessManager();
final process = await processManager.runProcess(
CliCommand.tool([
'serve',
SharedCommandArgs.runApp.asArg(),
...argResults!.arguments,
]),
);
if (process.exitCode == 1) {
throw Exception('Something went wrong while running `dt run`.');
}
}
}
Loading
Loading