Skip to content

Commit b4c6fa5

Browse files
Allow the --update-on-path flag to be passed to the dt sync command (#9212)
1 parent 00da6cf commit b4c6fa5

4 files changed

Lines changed: 62 additions & 84 deletions

File tree

CONTRIBUTING.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ of launch configurations for running and debugging DevTools:
100100

101101
### Workflow for making changes
102102

103-
1. Change your local Flutter SDK to the latest flutter candidate branch:
103+
1. Ensure your local Flutter SDK, DevTools dependencies, and generated code are up-to-date:
104104
```sh
105-
dt update-flutter-sdk --update-on-path
105+
dt sync --update-on-path
106106
```
107107
> Warning: this will delete any local changes in your Flutter SDK you checked out from git.
108108

@@ -111,23 +111,18 @@ of launch configurations for running and debugging DevTools:
111111
git checkout -b myBranch
112112
```
113113

114-
3. Ensure your branch, dependencies, and generated code are up-to-date:
115-
```sh
116-
dt sync
117-
```
118-
119-
4. Implement your changes, and commit to your branch:
114+
3. Implement your changes, and commit to your branch:
120115
```sh
121116
git commit -m “description”
122117
```
123118
If your improvement is user-facing, [document it](packages/devtools_app/release_notes/README.md) in the same PR.
124119

125-
5. Push to your branch to GitHub:
120+
4. Push to your branch to GitHub:
126121
```sh
127122
git push origin myBranch
128123
```
129124

130-
6. Navigate to the [Pull Requests](https://github.com/flutter/devtools/pulls) tab in the main
125+
5. Navigate to the [Pull Requests](https://github.com/flutter/devtools/pulls) tab in the main
131126
[DevTools repo](https://github.com/flutter/devtools). You should see a popup to create a pull
132127
request from the branch in your cloned repo to the DevTools `master` branch. Create a pull request.
133128

@@ -137,9 +132,18 @@ request from the branch in your cloned repo to the DevTools `master` branch. Cre
137132
```
138133
dt sync
139134
```
140-
This will pull the latest code from the upstream DevTools, upgrade dependencies, and perform code generation.
141-
142-
- If you want to upgrade dependencies and re-generate code (like mocks), but do not want to merge `upstream/master`, instead run
135+
This command will:
136+
- pull the latest code from the upstream DevTools master branch
137+
- update `tool/flutter-sdk` to the Flutter version DevTools is built and tested
138+
with on the CI
139+
- upgrade dependencies
140+
- perform code generation
141+
142+
Optionally, pass the `--update-on-path` flag to also update your local Flutter SDK
143+
git checkout along with the `tool/flutter-sdk`.
144+
145+
- If you want to upgrade dependencies and re-generate code (like mocks), but do
146+
not want to merge `upstream/master` or update your Flutter SDK version, instead run
143147
```
144148
dt generate-code --upgrade
145149
```

tool/lib/commands/shared.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ extension BuildCommandArgsExtension on ArgParser {
5252
);
5353
}
5454

55+
void addUpdateOnPathFlag() {
56+
addFlag(
57+
SharedCommandArgs.updateOnPath.flagName,
58+
negatable: false,
59+
help:
60+
'Update the Flutter SDK that is on PATH (your local '
61+
'flutter/flutter git checkout). This flag is to be used in '
62+
'combination with the ${SharedCommandArgs.updateFlutter.asArg()} '
63+
'flag.',
64+
);
65+
}
66+
5567
void addWasmFlag() {
5668
addFlag(
5769
SharedCommandArgs.wasm.flagName,
@@ -100,6 +112,7 @@ enum SharedCommandArgs {
100112
runApp('run-app'),
101113
serveWithDartSdk('serve-with-dart-sdk'),
102114
updateFlutter('update-flutter'),
115+
updateOnPath('update-on-path'),
103116
updatePerfetto('update-perfetto');
104117

105118
const SharedCommandArgs(this.flagName);

tool/lib/commands/sync.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ import 'package:args/command_runner.dart';
66
import 'package:io/io.dart';
77

88
import '../utils.dart';
9+
import 'shared.dart';
910

1011
class SyncCommand extends Command {
12+
SyncCommand() {
13+
argParser.addUpdateOnPathFlag();
14+
}
15+
1116
@override
1217
String get name => 'sync';
1318

@@ -21,7 +26,14 @@ class SyncCommand extends Command {
2126
await processManager.runProcess(
2227
CliCommand.git(['pull', 'upstream', 'master']),
2328
);
24-
await processManager.runProcess(CliCommand.tool(['update-flutter-sdk']));
29+
final updateOnPath =
30+
argResults![SharedCommandArgs.updateOnPath.flagName] as bool;
31+
await processManager.runProcess(
32+
CliCommand.tool([
33+
'update-flutter-sdk',
34+
if (updateOnPath) SharedCommandArgs.updateOnPath.asArg(),
35+
]),
36+
);
2537
await processManager.runProcess(
2638
CliCommand.tool(['generate-code', '--upgrade']),
2739
);

tool/lib/commands/update_flutter_sdk.dart

Lines changed: 19 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,24 @@ import 'package:devtools_tool/model.dart';
1010
import 'package:io/io.dart';
1111

1212
import '../utils.dart';
13-
14-
const _updateOnPath = 'update-on-path';
15-
const _useCacheFlag = 'use-cache';
13+
import 'shared.dart';
1614

1715
final _flutterPreReleaseTagRegExp = RegExp(r'[0-9]+.[0-9]+.0-[0-9]+.0.pre');
1816

1917
/// This command updates the the Flutter SDK contained in the 'tool/' directory
20-
/// to the latest Flutter candidate branch.
21-
///
22-
/// When the '--from-path' flag is passed, the Flutter SDK that is on PATH (your
23-
/// local flutter/flutter git checkout) will be updated as well.
18+
/// to the latest Flutter candidate branch, as specified by the commit hash in
19+
/// the flutter-candidate.txt file in the repository root.
2420
///
25-
/// This command will use the Flutter version from the 'flutter-candidate.txt'
26-
/// file in the repository root, unless the '--no-use-cache' flag is passed,
27-
/// in which case it will run the 'tool/latest_flutter_candidate.sh' script to
28-
/// fetch the latest version from upstream.
29-
///
30-
/// The version from 'flutter-candidate.txt' should be identical most of the
31-
/// time since the GitHub workflow that updates this file runs twice per day.
21+
/// When the '--update-on-path' flag is passed, the Flutter SDK that is on PATH
22+
/// (your local flutter/flutter git checkout) will be updated as well.
3223
///
3324
/// To run this script:
34-
/// `dt update-flutter-sdk [--from-path] [--no-use-cache]`
25+
/// `dt update-flutter-sdk [--update-on-path]`
3526
class UpdateFlutterSdkCommand extends Command {
3627
UpdateFlutterSdkCommand() {
37-
argParser
38-
..addFlag(
39-
_updateOnPath,
40-
negatable: false,
41-
help:
42-
'Also update the Flutter SDK that is on PATH (your local '
43-
'flutter/flutter git checkout)',
44-
)
45-
..addFlag(
46-
_useCacheFlag,
47-
negatable: true,
48-
defaultsTo: true,
49-
help:
50-
'Update the Flutter SDK(s) to the cached Flutter version stored '
51-
'in "flutter-candidate.txt" instead of the latest version at '
52-
'"https://flutter.googlesource.com/mirrors/flutter/"',
53-
);
28+
argParser.addUpdateOnPathFlag();
5429
}
30+
5531
@override
5632
String get name => 'update-flutter-sdk';
5733

@@ -63,49 +39,22 @@ class UpdateFlutterSdkCommand extends Command {
6339

6440
@override
6541
Future run() async {
66-
final updateOnPath = argResults![_updateOnPath] as bool;
67-
final useCachedVersion = argResults![_useCacheFlag] as bool;
42+
final updateOnPath =
43+
argResults![SharedCommandArgs.updateOnPath.flagName] as bool;
6844
final log = Logger.standard();
69-
70-
// TODO(kenz): we can remove this if we can rewrite the
71-
// 'latest_flutter_candidate.sh' script as a Dart script, or if we instead
72-
// duplicate it as a Windows script (we may need this to be a non-Dart
73-
// script for execution on the bots before we have a Dart SDK available).
74-
if (Platform.isWindows && !useCachedVersion) {
75-
log.stderr(
76-
'On windows, you can only use the cached Flutter version from '
77-
'"flutter-candidate.txt". Please remove the "--no-use-cache" flag and '
78-
'try again.',
79-
);
80-
return 1;
81-
}
82-
8345
final repo = DevToolsRepo.getInstance();
8446
final processManager = ProcessManager();
8547

8648
final String? flutterVersion;
87-
88-
if (useCachedVersion) {
89-
final versionStr =
90-
repo.readFile(Uri.parse('flutter-candidate.txt')).trim();
91-
// If the version string doesn't match the expected pattern for a
92-
// pre-release tag, then assume it's a commit hash:
93-
flutterVersion =
94-
_flutterPreReleaseTagRegExp.hasMatch(versionStr)
95-
? 'tags/$versionStr'
96-
: versionStr;
97-
} else {
98-
flutterVersion =
99-
(await processManager.runProcess(
100-
CliCommand('sh', ['latest_flutter_candidate.sh']),
101-
workingDirectory: repo.toolDirectoryPath,
102-
)).stdout.replaceFirst('refs/', '').trim();
103-
}
104-
105-
log.stdout(
106-
'Updating to Flutter version '
107-
'${useCachedVersion ? 'from cache' : 'from upstream'}: $flutterVersion',
108-
);
49+
final versionStr = repo.readFile(Uri.parse('flutter-candidate.txt')).trim();
50+
// If the version string doesn't match the expected pattern for a
51+
// pre-release tag, then assume it's a commit hash:
52+
flutterVersion =
53+
_flutterPreReleaseTagRegExp.hasMatch(versionStr)
54+
? 'tags/$versionStr'
55+
: versionStr;
56+
57+
log.stdout('Updating to Flutter version from cache: $flutterVersion');
10958

11059
final flutterSdkDirName = repo.sdkDirectoryName;
11160
final toolSdkPath = repo.toolFlutterSdkPath;

0 commit comments

Comments
 (0)