@@ -220,7 +220,7 @@ run_test() {
220
220
}
221
221
222
222
# Check the Flutter version in pubspec.yaml is commented with a commit ID,
223
- # and the commit is from upstream main.
223
+ # which agrees with the version, and the commit is from upstream main.
224
224
run_flutter_version () {
225
225
# Omitted from this files check:
226
226
# tools/check
@@ -231,14 +231,49 @@ run_flutter_version() {
231
231
flutter_tree=$( flutter_tree)
232
232
flutter_git=( git --git-dir=" ${flutter_tree} " /.git )
233
233
234
- # Parse our Flutter version spec with its commit-ID comment.
235
- local flutter_commit
236
- flutter_commit=$(
234
+ # Parse our Flutter version spec and its commit-ID comment.
235
+ local parsed flutter_version flutter_commit
236
+ # shellcheck disable=SC2207 # output has controlled whitespace
237
+ parsed=( $(
237
238
perl < pubspec.yaml -0ne '
238
- print $1 if (/^ sdk: .*\n flutter: \S+\s*# ([0-9a-f]{40})$/m)'
239
+ print "$1 $2" if (
240
+ /^ sdk: .*\n flutter: ' \' ' >=(\S+)' \' ' \s*# ([0-9a-f]{40})$/m)'
241
+ ) ) || return
242
+ if [ -z " ${# parsed[@]} " ]; then
243
+ echo >&2 " error: Flutter version spec not recognized in pubspec.yaml"
244
+ return 1
245
+ fi
246
+ flutter_version=" ${parsed[0]} "
247
+ flutter_commit=" ${parsed[1]} "
248
+
249
+ # Check the version name matches the commit ID.
250
+ local commit_described predicted_version
251
+ commit_described=$(
252
+ " ${flutter_git[@]} " describe --tags " ${flutter_commit} "
239
253
) || return
240
- if [ -z " ${flutter_commit} " ]; then
241
- echo >&2 " error: Flutter commit spec not found in pubspec.yaml"
254
+ predicted_version=$(
255
+ echo " ${commit_described} " \
256
+ | perl -lne ' print if (s
257
+ # This transformation is ad hoc.
258
+ # If we find cases where it fails, we can study
259
+ # how the `flutter` tool actually decides the version name.
260
+ <^(\d+\.\d+\.\d+-) (\d+) (\.\d+\.pre) -(\d+) -g[0-9a-f]+$>
261
+ <$1 . ($2 + 1) . $3 . "." . $4>xe)'
262
+ ) || return
263
+ if [ -z " ${predicted_version} " ]; then
264
+ cat >&2 << EOF
265
+ error: unexpected 'git describe' result on Flutter commit in pubspec.yaml
266
+ Commit ${flutter_commit} was described as: ${commit_described}
267
+ EOF
268
+ return 1
269
+ fi
270
+ if [ " ${flutter_version} " != " ${predicted_version} " ]; then
271
+ cat >&2 << EOF
272
+ error: Flutter commit in pubspec.yaml seems to differ from version bound
273
+ Commit ${flutter_commit} was described as: ${commit_described}
274
+ We therefore expect the Flutter version name to be: ${predicted_version}
275
+ But the Flutter version bound in pubspec.yaml is: ${flutter_version}
276
+ EOF
242
277
return 1
243
278
fi
244
279
257
292
return 1
258
293
fi
259
294
260
- if_verbose echo " OK Flutter commit ${flutter_commit} "
295
+ if_verbose echo " OK Flutter ${flutter_version} aka ${flutter_commit} "
261
296
262
297
return 0
263
298
}
0 commit comments