Skip to content

Commit af065a6

Browse files
[tool/ci] Add minimum supported SDK validation (flutter#7028)
Adds options to `pubspec.yaml` to check that the minimum supported SDK range for Flutter/Dart is at least a given version, to add CI enforcement that we're updating all of our support claims when we update our tested versions (rather than it being something we have to remember to do), and enables it in CI. As part of enabling it, fixes some violations: - path_provider_foundation had been temporarily dropped back to 2.10 as part of pushing out a regression fix. - a number of examples were missing Flutter constraints even though they used Flutter. - the non-Flutter `plugin_platform_interface` package hadn't been update since I hadn't thought about Dart-only constraints in the past.
1 parent e9406bc commit af065a6

File tree

16 files changed

+270
-12
lines changed

16 files changed

+270
-12
lines changed

.cirrus.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ task:
101101
always:
102102
format_script: ./script/tool_runner.sh format --fail-on-change
103103
license_script: $PLUGIN_TOOL_COMMAND license-check
104-
pubspec_script: ./script/tool_runner.sh pubspec-check
104+
# The major and minor versions here should match the lowest version
105+
# analyzed in legacy_version_analyze.
106+
pubspec_script: ./script/tool_runner.sh pubspec-check --min-min-flutter-version=3.0.0 --min-min-dart-version=2.17.0
105107
readme_script:
106108
- ./script/tool_runner.sh readme-check
107109
# Re-run with --require-excerpts, skipping packages that still need
@@ -171,6 +173,7 @@ task:
171173
- name: legacy_version_analyze
172174
depends_on: analyze
173175
matrix:
176+
# Change the arguments to pubspec-check when changing these values.
174177
env:
175178
CHANNEL: "3.0.5"
176179
DART_VERSION: "2.17.6"

packages/file_selector/file_selector/example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ version: 1.0.0+1
66

77
environment:
88
sdk: ">=2.12.0 <3.0.0"
9+
flutter: ">=3.0.0"
910

1011
dependencies:
1112
file_selector:

packages/file_selector/file_selector_ios/example/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version: 1.0.0
55

66
environment:
77
sdk: ">=2.14.4 <3.0.0"
8+
flutter: ">=3.0.0"
89

910
dependencies:
1011
# The following adds the Cupertino Icons font to your application.
@@ -28,4 +29,4 @@ dev_dependencies:
2829
sdk: flutter
2930

3031
flutter:
31-
uses-material-design: true
32+
uses-material-design: true

packages/file_selector/file_selector_linux/example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version: 1.0.0+1
55

66
environment:
77
sdk: ">=2.12.0 <3.0.0"
8+
flutter: ">=3.0.0"
89

910
dependencies:
1011
file_selector_linux:

packages/flutter_plugin_android_lifecycle/example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ publish_to: none
44

55
environment:
66
sdk: ">=2.12.0 <3.0.0"
7+
flutter: ">=3.0.0"
78

89
dependencies:
910
flutter:

packages/path_provider/path_provider_foundation/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## NEXT
2+
3+
* Updates minimum supported Flutter version to 3.0.
4+
15
## 2.1.1
26

37
* Fixes a regression in the path retured by `getApplicationSupportDirectory` on iOS.

packages/path_provider/path_provider_foundation/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ version: 2.1.1
66

77
environment:
88
sdk: ">=2.12.0 <3.0.0"
9-
flutter: ">=2.10.0"
9+
flutter: ">=3.0.0"
1010

1111
flutter:
1212
plugin:

packages/plugin_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## NEXT
2+
3+
* Updates minimum supported Dart version.
4+
15
## 2.1.3
26

37
* Minor fixes for new analysis options.

packages/plugin_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+
1818
version: 2.1.3
1919

2020
environment:
21-
sdk: ">=2.12.0 <3.0.0"
21+
sdk: ">=2.17.0 <3.0.0"
2222

2323
dependencies:
2424
meta: ^1.3.0

packages/webview_flutter/webview_flutter_android/example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ publish_to: none
44

55
environment:
66
sdk: ">=2.14.0 <3.0.0"
7+
flutter: ">=3.0.0"
78

89
dependencies:
910
flutter:

packages/webview_flutter/webview_flutter_web/example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ publish_to: none
44

55
environment:
66
sdk: ">=2.14.0 <3.0.0"
7+
flutter: ">=3.0.0"
78

89
dependencies:
910
flutter:

packages/webview_flutter/webview_flutter_wkwebview/example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ publish_to: none
44

55
environment:
66
sdk: ">=2.12.0 <3.0.0"
7+
flutter: ">=3.0.0"
78

89
dependencies:
910
flutter:

script/tool/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.13.4
2+
3+
* Adds the ability to validate minimum supported Dart/Flutter versions in
4+
`pubspec-check`.
5+
16
## 0.13.3
27

38
* Renames `podspecs` to `podspec-check`. The old name will continue to work.

script/tool/lib/src/pubspec_check_command.dart

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:file/file.dart';
66
import 'package:git/git.dart';
77
import 'package:platform/platform.dart';
8+
import 'package:pub_semver/pub_semver.dart';
89
import 'package:yaml/yaml.dart';
910

1011
import 'common/core.dart';
@@ -29,7 +30,23 @@ class PubspecCheckCommand extends PackageLoopingCommand {
2930
processRunner: processRunner,
3031
platform: platform,
3132
gitDir: gitDir,
32-
);
33+
) {
34+
argParser.addOption(
35+
_minMinDartVersionFlag,
36+
help:
37+
'The minimum Dart version to allow as the minimum SDK constraint.\n\n'
38+
'This is only enforced for non-Flutter packages; Flutter packages '
39+
'use --$_minMinFlutterVersionFlag',
40+
);
41+
argParser.addOption(
42+
_minMinFlutterVersionFlag,
43+
help:
44+
'The minimum Flutter version to allow as the minimum SDK constraint.',
45+
);
46+
}
47+
48+
static const String _minMinDartVersionFlag = 'min-min-dart-version';
49+
static const String _minMinFlutterVersionFlag = 'min-min-flutter-version';
3350

3451
// Section order for plugins. Because the 'flutter' section is critical
3552
// information for plugins, and usually small, it goes near the top unlike in
@@ -100,6 +117,24 @@ class PubspecCheckCommand extends PackageLoopingCommand {
100117
printError('$listIndentation${sectionOrder.join('\n$listIndentation')}');
101118
}
102119

120+
final String minMinDartVersionString = getStringArg(_minMinDartVersionFlag);
121+
final String minMinFlutterVersionString =
122+
getStringArg(_minMinFlutterVersionFlag);
123+
final String? minVersionError = _checkForMinimumVersionError(
124+
pubspec,
125+
package,
126+
minMinDartVersion: minMinDartVersionString.isEmpty
127+
? null
128+
: Version.parse(minMinDartVersionString),
129+
minMinFlutterVersion: minMinFlutterVersionString.isEmpty
130+
? null
131+
: Version.parse(minMinFlutterVersionString),
132+
);
133+
if (minVersionError != null) {
134+
printError('$indentation$minVersionError');
135+
passing = false;
136+
}
137+
103138
if (isPlugin) {
104139
final String? implementsError =
105140
_checkForImplementsError(pubspec, package: package);
@@ -320,4 +355,43 @@ class PubspecCheckCommand extends PackageLoopingCommand {
320355
final String suffix = packageName.substring(parentName.length);
321356
return !nonImplementationSuffixes.contains(suffix);
322357
}
358+
359+
/// Validates that a Flutter package has a minimum SDK version constraint of
360+
/// at least [minMinFlutterVersion] (if provided), or that a non-Flutter
361+
/// package has a minimum SDK version constraint of [minMinDartVersion]
362+
/// (if provided).
363+
///
364+
/// Returns an error string if validation fails.
365+
String? _checkForMinimumVersionError(
366+
Pubspec pubspec,
367+
RepositoryPackage package, {
368+
Version? minMinDartVersion,
369+
Version? minMinFlutterVersion,
370+
}) {
371+
final VersionConstraint? dartConstraint = pubspec.environment?['sdk'];
372+
final VersionConstraint? flutterConstraint =
373+
pubspec.environment?['flutter'];
374+
375+
if (flutterConstraint != null) {
376+
// Validate Flutter packages against the Flutter requirement.
377+
if (minMinFlutterVersion != null) {
378+
final Version? constraintMin =
379+
flutterConstraint is VersionRange ? flutterConstraint.min : null;
380+
if ((constraintMin ?? Version(0, 0, 0)) < minMinFlutterVersion) {
381+
return 'Minimum allowed Flutter version $constraintMin is less than $minMinFlutterVersion';
382+
}
383+
}
384+
} else {
385+
// Validate non-Flutter packages against the Dart requirement.
386+
if (minMinDartVersion != null) {
387+
final Version? constraintMin =
388+
dartConstraint is VersionRange ? dartConstraint.min : null;
389+
if ((constraintMin ?? Version(0, 0, 0)) < minMinDartVersion) {
390+
return 'Minimum allowed Dart version $constraintMin is less than $minMinDartVersion';
391+
}
392+
}
393+
}
394+
395+
return null;
396+
}
323397
}

script/tool/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: flutter_plugin_tools
22
description: Productivity utils for flutter/plugins and flutter/packages
33
repository: https://github.com/flutter/plugins/tree/main/script/tool
4-
version: 0.13.3
4+
version: 0.13.4
55

66
dependencies:
77
args: ^2.1.0

0 commit comments

Comments
 (0)