@@ -20,7 +20,7 @@ usage: tools/upgrade [OPTION]... [STEP]...
20
20
21
21
Upgrade our dependencies.
22
22
23
- By default, run all upgrade steps:
23
+ By default, run the following upgrade steps:
24
24
${default_steps[*]}
25
25
26
26
Each step produces a Git commit if there were any changes.
@@ -29,6 +29,12 @@ The steps are:
29
29
30
30
pod Upgrade CocoaPods pods.
31
31
32
+ flutter-local
33
+ Upgrade Flutter and its supporting libraries.
34
+ EXPERIMENTAL and not in the default list,
35
+ because it takes your current locally-installed version
36
+ rather than finding the latest.
37
+
32
38
pub Upgrade pub packages within the constraints expressed
33
39
in pubspec.yaml, then upgrade pods to match.
34
40
@@ -50,7 +56,7 @@ while (( $# )); do
50
56
case " $1 " in
51
57
--no-pod)
52
58
opt_pod=; shift ;;
53
- pod|pub|pub-major)
59
+ pod|flutter-local| pub|pub-major)
54
60
opt_steps+=(" $1 " ); shift ;;
55
61
--help) usage; exit 0;;
56
62
* ) usage >&2 ; exit 2;;
@@ -139,6 +145,76 @@ deps: Update CocoaPods pods (tools/upgrade pod)
139
145
"
140
146
}
141
147
148
+ upgrade_flutter_local () {
149
+ local pattern flutter_version_output flutter_version dart_sdk_version
150
+
151
+ check_no_uncommitted_or_untracked
152
+
153
+ # No check_pub_get_clean. This operates on a `flutter` you've
154
+ # already locally upgraded, so if that happens to update any
155
+ # supporting libraries then it's expected that those will show up
156
+ # on `flutter pub get`.
157
+ # check_pub_get_clean
158
+
159
+ # TODO upgrade Flutter to latest, rather than what's lying around
160
+
161
+ # Sometimes the `flutter --version` output begins with lines like
162
+ # "Resolving dependencies..."; so the pattern accommodates those.
163
+ # The pattern requires Dart 3.x, because we'll emit "<4.0.0" below.
164
+ pattern=$' \n Flutter (\S+) .*\sDart \S+ \(build (3\.\S+)\)'
165
+
166
+ flutter_version_output=$( run_visibly flutter --version)
167
+ if ! [[ $' \n ' " ${flutter_version_output} " =~ $pattern ]]; then
168
+ echo >&2 " error: 'flutter --version' output not recognized"
169
+ printf >&2 " output was:\n-----\n%s\n-----" " ${flutter_version_output} "
170
+ return 1
171
+ fi
172
+ flutter_version=" ${BASH_REMATCH[1]} "
173
+ dart_sdk_version=" ${BASH_REMATCH[2]} "
174
+
175
+ yaml_fragment=" \
176
+ sdk: '>=${dart_sdk_version} <4.0.0'
177
+ flutter: '>=${flutter_version} '
178
+ " \
179
+ perl -i -0pe ' s/^ sdk: .*\n flutter: .*\n/$ENV{yaml_fragment}/m' \
180
+ pubspec.yaml
181
+
182
+ if no_uncommitted_changes; then
183
+ echo >&2 " flutter: No changes."
184
+ return
185
+ fi
186
+
187
+ run_visibly flutter pub get
188
+
189
+ local libraries_updated=
190
+ if git diff pubspec.lock | perl -0ne '
191
+ s/.*?\n(@@)/$1/s; # cut `git diff` header
192
+ if (/^[-+](?! (dart|flutter):)/m) { exit 0; } else { exit 1; }
193
+ ' ; then
194
+ libraries_updated=y
195
+ fi
196
+
197
+ local more="
198
+
199
+ And update Flutter's supporting libraries to match."
200
+ git commit -a -m " \
201
+ deps: Upgrade Flutter to ${flutter_version}${libraries_updated: +" ${more} " }
202
+ "
203
+
204
+ cat << EOF
205
+
206
+ There was a Flutter upgrade${libraries_updated: +, and libraries were updated} .
207
+
208
+ The \` tools/upgrade\` script created a draft commit, but
209
+ it requires manual checking:
210
+
211
+ * The update was to the Flutter version you currently
212
+ have installed at the \` flutter\` command.
213
+ Check that is is the latest Flutter from main,
214
+ or otherwise the version you intend to upgrade to.
215
+ EOF
216
+ }
217
+
142
218
upgrade_pub () {
143
219
check_have_cocoapods
144
220
check_no_uncommitted_or_untracked
@@ -233,6 +309,7 @@ for step in "${opt_steps[@]}"; do
233
309
echo " ======== tools/upgrade ${step} "
234
310
case " ${step} " in
235
311
pod) upgrade_pod ;;
312
+ flutter-local) upgrade_flutter_local ;;
236
313
pub) upgrade_pub ;;
237
314
pub-major) upgrade_pub_major ;;
238
315
* ) echo >&2 " Internal error: unknown step ${step} " ;;
0 commit comments