Skip to content

Commit 7da1aa2

Browse files
committed
tools/upgrade: Add first version of updating Flutter
This version leaves it to the user/developer to handle actually upgrading their Flutter install to latest; but it takes care of updating pubspec.yaml and pubspec.lock. The upgrade of the actual Flutter install will presumably look different anyway after #15 / #579, so we leave that to the future.
1 parent bb688ad commit 7da1aa2

File tree

2 files changed

+82
-6
lines changed

2 files changed

+82
-6
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,11 @@ new PR merged that we particularly want to take.
243243

244244
To update the version bounds:
245245
* Use `flutter upgrade` to upgrade your local Flutter and Dart.
246-
* Update the lower bounds at `environment` in `pubspec.yaml`
247-
to the new versions, as seen in `flutter --version`.
248-
* Run `flutter pub get`, which will update `pubspec.lock`.
246+
* Run `tools/upgrade flutter-local`, which makes a commit updating
247+
`pubspec.yaml` and `pubspec.lock` to match your local Flutter.
249248
* Make a quick check that things work: `tools/check`,
250249
and do a quick smoke-test of the app.
251-
* Commit and push the changes in `pubspec.yaml` and `pubspec.lock`.
250+
* Send the changes as a PR.
252251

253252

254253
### Upgrading dependencies

tools/upgrade

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ usage: tools/upgrade [OPTION]... [STEP]...
2020
2121
Upgrade our dependencies.
2222
23-
By default, run all upgrade steps:
23+
By default, run the following upgrade steps:
2424
${default_steps[*]}
2525
2626
Each step produces a Git commit if there were any changes.
@@ -29,6 +29,12 @@ The steps are:
2929
3030
pod Upgrade CocoaPods pods.
3131
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+
3238
pub Upgrade pub packages within the constraints expressed
3339
in pubspec.yaml, then upgrade pods to match.
3440
@@ -50,7 +56,7 @@ while (( $# )); do
5056
case "$1" in
5157
--no-pod)
5258
opt_pod=; shift;;
53-
pod|pub|pub-major)
59+
pod|flutter-local|pub|pub-major)
5460
opt_steps+=("$1"); shift;;
5561
--help) usage; exit 0;;
5662
*) usage >&2; exit 2;;
@@ -139,6 +145,76 @@ deps: Update CocoaPods pods (tools/upgrade pod)
139145
"
140146
}
141147

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=$'\nFlutter (\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+
142218
upgrade_pub() {
143219
check_have_cocoapods
144220
check_no_uncommitted_or_untracked
@@ -233,6 +309,7 @@ for step in "${opt_steps[@]}"; do
233309
echo "======== tools/upgrade ${step}"
234310
case "${step}" in
235311
pod) upgrade_pod ;;
312+
flutter-local) upgrade_flutter_local ;;
236313
pub) upgrade_pub ;;
237314
pub-major) upgrade_pub_major ;;
238315
*) echo >&2 "Internal error: unknown step ${step}" ;;

0 commit comments

Comments
 (0)