Skip to content

Commit d13316c

Browse files
Add build-mode and pub-get argument to the serve and build CLI tools (#6695)
1 parent 3674ca5 commit d13316c

File tree

10 files changed

+275
-170
lines changed

10 files changed

+275
-170
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ of launch configurations for running and debugging DevTools:
8484

8585
### Workflow for making changes
8686

87-
1. Change your local Flutter SDK to the latest flutter candidate branch: `devtools_tool update-flutter-sdk --local`
87+
1. Change your local Flutter SDK to the latest flutter candidate branch: `devtools_tool update-flutter-sdk --from-path`
8888
2. Create a branch from your cloned DevTools repo: `git checkout -b myBranch`
8989
3. Ensure your branch, dependencies, and generated code are up-to-date: `devtools_tool sync`
9090
4. Implement your changes, and commit to your branch: `git commit -m “description”`
@@ -173,7 +173,7 @@ command palette (`F1`)) and add the following to your settings:
173173
"env": {
174174
"LOCAL_DART_SDK": "/path/to/dart-sdk/sdk"
175175
// Path to the version that Flutter DevTools is pinned to.
176-
"FLUTTER_ROOT": "C:\\Dev\\Google\\devtools\\tool\\flutter-sdk"
176+
"FLUTTER_ROOT": "/path/to/devtools/tool/flutter-sdk"
177177
}
178178
},
179179
```

tool/RELEASE_INSTRUCTIONS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Make sure:
1919
c. The local checkout is at `main` branch: `git rebase-update`
2020

2121
2. Your Flutter version is equal to latest candidate release branch:
22-
- Run `devtools_tool update-flutter-sdk --local`
22+
- Run `devtools_tool update-flutter-sdk --from-path`
2323
3. You have goma [configured](http://go/ma-mac-setup)
2424

2525
### Prepare the release

tool/lib/commands/build.dart

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright 2023 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:io';
6+
7+
import 'package:args/command_runner.dart';
8+
import 'package:devtools_tool/commands/shared.dart';
9+
import 'package:devtools_tool/model.dart';
10+
import 'package:io/io.dart';
11+
import 'package:path/path.dart' as path;
12+
13+
import '../utils.dart';
14+
15+
/// This command builds the DevTools Flutter web app.
16+
///
17+
/// By default, this command builds DevTools in release mode, but this can be
18+
/// overridden by passing 'debug' or 'profile' as the
19+
/// [BuildCommandArgs.buildMode] argument.
20+
///
21+
/// If the [BuildCommandArgs.useFlutterFromPath] argument is present, the
22+
/// Flutter SDK will not be updated to the latest Flutter candidate before
23+
/// building DevTools. Use this flag to save the cost of updating the Flutter
24+
/// SDK when you already have the proper SDK checked out. This is helpful when
25+
/// developing with the DevTools server.
26+
///
27+
/// If the [BuildCommandArgs.updatePerfetto] argument is present, the
28+
/// precompiled bits for Perfetto will be updated from the
29+
/// `devtools_tool update-perfetto` command as part of the DevTools build
30+
/// process.
31+
///
32+
/// If [BuildCommandArgs.pubGet] argument is negated (e.g. --no-pub-get), then
33+
/// `devtools_tool pub-get --only-main` command will not be run before building
34+
/// the DevTools web app. Use this flag to save the cost of updating pub
35+
/// packages if your pub cahce does not need to be updated. This is helpful when
36+
/// developing with the DevTools server.
37+
class BuildCommand extends Command {
38+
BuildCommand() {
39+
argParser
40+
..addUseFlutterFromPathFlag()
41+
..addUpdatePerfettoFlag()
42+
..addPubGetFlag()
43+
..addBulidModeOption();
44+
}
45+
46+
@override
47+
String get name => 'build';
48+
49+
@override
50+
String get description => 'Prepares a release build of DevTools.';
51+
52+
@override
53+
Future run() async {
54+
final repo = DevToolsRepo.getInstance();
55+
final processManager = ProcessManager();
56+
57+
final useLocalFlutter =
58+
argResults![BuildCommandArgs.useFlutterFromPath.flagName];
59+
final updatePerfetto =
60+
argResults![BuildCommandArgs.updatePerfetto.flagName];
61+
final runPubGet = argResults![BuildCommandArgs.pubGet.flagName];
62+
final buildMode = argResults![BuildCommandArgs.buildMode.flagName];
63+
64+
final webBuildDir =
65+
Directory(path.join(repo.devtoolsAppDirectoryPath, 'build', 'web'));
66+
67+
if (!useLocalFlutter) {
68+
logStatus('updating tool/flutter-sdk to the latest flutter candidate');
69+
await processManager.runProcess(CliCommand.tool('update-flutter-sdk'));
70+
}
71+
72+
if (updatePerfetto) {
73+
logStatus('updating the bundled Perfetto assets');
74+
await processManager.runProcess(CliCommand.tool('update-perfetto'));
75+
}
76+
77+
logStatus('cleaning project');
78+
if (webBuildDir.existsSync()) {
79+
webBuildDir.deleteSync(recursive: true);
80+
}
81+
await processManager.runProcess(
82+
CliCommand.flutter('clean'),
83+
workingDirectory: repo.devtoolsAppDirectoryPath,
84+
);
85+
86+
logStatus('building DevTools in release mode');
87+
await processManager.runAll(
88+
commands: [
89+
if (runPubGet) CliCommand.tool('pub-get --only-main'),
90+
CliCommand.flutter(
91+
[
92+
'build',
93+
'web',
94+
'--web-renderer',
95+
'canvaskit',
96+
'--pwa-strategy=offline-first',
97+
if (buildMode != 'debug') '--$buildMode',
98+
'--no-tree-shake-icons',
99+
].join(' '),
100+
),
101+
],
102+
workingDirectory: repo.devtoolsAppDirectoryPath,
103+
);
104+
105+
// TODO(kenz): investigate if we need to perform a windows equivalent of
106+
// `chmod` or if we even need to perform `chmod` for linux / mac anymore.
107+
if (!Platform.isWindows) {
108+
final canvaskitDir = Directory(path.join(webBuildDir.path, 'canvaskit'));
109+
for (final file in canvaskitDir.listSync()) {
110+
if (RegExp(r'canvaskit\..*').hasMatch(file.path)) {
111+
await processManager
112+
.runProcess(CliCommand('chmod 0755 ${file.path}'));
113+
}
114+
}
115+
}
116+
}
117+
}

tool/lib/commands/build_release.dart

Lines changed: 0 additions & 96 deletions
This file was deleted.

tool/lib/commands/serve.dart

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,61 @@ import 'dart:io';
66

77
import 'package:args/command_runner.dart';
88
import 'package:devtools_tool/model.dart';
9+
import 'package:devtools_tool/utils.dart';
910
import 'package:io/io.dart';
1011
import 'package:path/path.dart' as path;
1112

12-
import '../utils.dart';
13+
import 'shared.dart';
1314

14-
const _useLocalFlutterFlag = 'use-local-flutter';
15-
const _updatePerfettoFlag = 'update-perfetto';
1615
const _buildAppFlag = 'build-app';
1716
const _machineFlag = 'machine';
1817
const _allowEmbeddingFlag = 'allow-embedding';
1918

2019
/// This command builds DevTools in release mode by running the
21-
/// `devtools_tool build-release` command and then serves DevTools with a
22-
/// locally running DevTools server.
20+
/// `devtools_tool build` command and then serves DevTools with a locally
21+
/// running DevTools server.
2322
///
24-
/// If the [_buildAppFlag] is negated (e.g. --no-build-app), then the DevTools
25-
/// web app will not be rebuilt before serving.
23+
/// If the [_buildAppFlag] argument is negated (e.g. --no-build-app), then the
24+
/// DevTools web app will not be rebuilt before serving. The following arguments
25+
/// are ignored if '--no-build-app' is present in the list of arguments passed
26+
/// to this command. All of the following commands are passed along to the
27+
/// `devtools_tool build` command.
2628
///
27-
/// If [_useLocalFlutterFlag] is present, the Flutter SDK will not be updated to
28-
/// the latest Flutter candidate. Use this flag to save the cost of updating the
29-
/// Flutter SDK when you already have the proper SDK checked out.
29+
/// If the [BuildCommandArgs.useFlutterFromPath] argument is present, the
30+
/// Flutter SDK will not be updated to the latest Flutter candidate before
31+
/// building DevTools. Use this flag to save the cost of updating the Flutter
32+
/// SDK when you already have the proper SDK checked out. This is helpful when
33+
/// developing with the DevTools server.
3034
///
31-
/// If [_updatePerfettoFlag] is present, the precompiled bits for Perfetto will
32-
/// be updated from the `devtools_tool update-perfetto` command as part of the
33-
/// DevTools build process (e.g. running `devtools_tool build-release`).
35+
/// If the [BuildCommandArgs.updatePerfetto] argument is present, the
36+
/// precompiled bits for Perfetto will be updated from the
37+
/// `devtools_tool update-perfetto` command as part of the DevTools build
38+
/// process.
39+
///
40+
/// If [BuildCommandArgs.pubGet] argument is negated (e.g. --no-pub-get), then
41+
/// `devtools_tool pub-get --only-main` command will not be run before building
42+
/// the DevTools web app. Use this flag to save the cost of updating pub
43+
/// packages if your pub cahce does not need to be updated. This is helpful when
44+
/// developing with the DevTools server.
45+
///
46+
/// The [BuildCommandArgs.buildMode] argument specifies the Flutter build mode
47+
/// that the DevTools web app will be built in ('release', 'profile', 'debug').
48+
/// This defaults to 'release' if unspecified.
3449
class ServeCommand extends Command {
3550
ServeCommand() {
3651
argParser
37-
..addFlag(
38-
_useLocalFlutterFlag,
39-
negatable: false,
40-
defaultsTo: false,
41-
help:
42-
'Whether to use the Flutter SDK on PATH instead of the Flutter SDK '
43-
'contained in the "tool/flutter-sdk" directory.',
44-
)
45-
..addFlag(
46-
_updatePerfettoFlag,
47-
negatable: false,
48-
defaultsTo: false,
49-
help: 'Whether to update the Perfetto assets before building DevTools.',
50-
)
5152
..addFlag(
5253
_buildAppFlag,
5354
negatable: true,
5455
defaultsTo: true,
5556
help:
56-
'Whether to build the DevTools app in release mode before starting '
57-
'the DevTools server.',
57+
'Whether to build the DevTools web app before starting the DevTools'
58+
' server.',
5859
)
60+
..addUseFlutterFromPathFlag()
61+
..addUpdatePerfettoFlag()
62+
..addPubGetFlag()
63+
..addBulidModeOption()
5964
// Flags defined in the server in DDS.
6065
..addFlag(
6166
_machineFlag,
@@ -81,15 +86,25 @@ class ServeCommand extends Command {
8186
final repo = DevToolsRepo.getInstance();
8287
final processManager = ProcessManager();
8388

84-
final useLocalFlutter = argResults![_useLocalFlutterFlag];
85-
final updatePerfetto = argResults![_updatePerfettoFlag];
8689
final buildApp = argResults![_buildAppFlag];
90+
final useFlutterFromPath =
91+
argResults![BuildCommandArgs.useFlutterFromPath.flagName];
92+
final updatePerfetto =
93+
argResults![BuildCommandArgs.updatePerfetto.flagName];
94+
final runPubGet = argResults![BuildCommandArgs.pubGet.flagName];
95+
final devToolsAppBuildMode =
96+
argResults![BuildCommandArgs.buildMode.flagName];
8797

8898
final remainingArguments = List.of(argResults!.arguments)
89-
..remove(_useLocalFlutterFlag)
90-
..remove(_updatePerfettoFlag)
91-
..remove(_buildAppFlag)
92-
..remove('--no-$_buildAppFlag');
99+
..remove(BuildCommandArgs.useFlutterFromPath.asArg())
100+
..remove(BuildCommandArgs.updatePerfetto.asArg())
101+
..remove(valueAsArg(_buildAppFlag))
102+
..remove(valueAsArg(_buildAppFlag, negated: true))
103+
..remove(BuildCommandArgs.pubGet.asArg())
104+
..remove(BuildCommandArgs.pubGet.asArg(negated: true))
105+
..removeWhere(
106+
(element) => element.startsWith(BuildCommandArgs.buildMode.asArg()),
107+
);
93108

94109
final localDartSdkLocation = Platform.environment['LOCAL_DART_SDK'];
95110
if (localDartSdkLocation == null) {
@@ -114,14 +129,16 @@ class ServeCommand extends Command {
114129
if (buildApp) {
115130
final process = await processManager.runProcess(
116131
CliCommand.tool(
117-
'build-release'
118-
' ${useLocalFlutter ? '--$_useLocalFlutterFlag' : ''}'
119-
' ${updatePerfetto ? '--$_updatePerfettoFlag' : ''}',
132+
'build'
133+
'${useFlutterFromPath ? ' ${BuildCommandArgs.useFlutterFromPath.asArg()}' : ''}'
134+
'${updatePerfetto ? ' ${BuildCommandArgs.updatePerfetto.asArg()}' : ''}'
135+
' ${BuildCommandArgs.buildMode.asArg()}=$devToolsAppBuildMode'
136+
' ${BuildCommandArgs.pubGet.asArg(negated: !runPubGet)}',
120137
),
121138
);
122139
if (process.exitCode == 1) {
123140
throw Exception(
124-
'Something went wrong while running `devtools_tool build-release`',
141+
'Something went wrong while running `devtools_tool build`',
125142
);
126143
}
127144
logStatus('completed building DevTools: $devToolsBuildLocation');

0 commit comments

Comments
 (0)