@@ -10,48 +10,24 @@ import 'package:devtools_tool/model.dart';
1010import 'package:io/io.dart' ;
1111
1212import '../utils.dart' ;
13-
14- const _updateOnPath = 'update-on-path' ;
15- const _useCacheFlag = 'use-cache' ;
13+ import 'shared.dart' ;
1614
1715final _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 ]`
3526class 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