diff --git a/script/tool/CHANGELOG.md b/script/tool/CHANGELOG.md index 07cafee7f8b6..9606eed20b27 100644 --- a/script/tool/CHANGELOG.md +++ b/script/tool/CHANGELOG.md @@ -1,9 +1,12 @@ -## NEXT +## 0.8.7 - Supports empty custom analysis allow list files. - `drive-examples` now validates files to ensure that they don't accidentally use `test(...)`. - Adds a new `dependabot-check` command to ensure complete Dependabot coverage. +- Adds `skip-if-not-supporting-dart-version` to allow for the same use cases + as `skip-if-not-supporting-flutter-version` but for packages without Flutter + constraints. ## 0.8.6 diff --git a/script/tool/lib/src/common/package_looping_command.dart b/script/tool/lib/src/common/package_looping_command.dart index a295215f3628..1a194bd45b9e 100644 --- a/script/tool/lib/src/common/package_looping_command.dart +++ b/script/tool/lib/src/common/package_looping_command.dart @@ -96,10 +96,17 @@ abstract class PackageLoopingCommand extends PluginCommand { help: 'Skip any packages that require a Flutter version newer than ' 'the provided version.', ); + argParser.addOption( + _skipByDartVersionArg, + help: 'Skip any packages that require a Dart version newer than ' + 'the provided version.', + ); } static const String _skipByFlutterVersionArg = 'skip-if-not-supporting-flutter-version'; + static const String _skipByDartVersionArg = + 'skip-if-not-supporting-dart-version'; /// Packages that had at least one [logWarning] call. final Set _packagesWithWarnings = @@ -264,6 +271,9 @@ abstract class PackageLoopingCommand extends PluginCommand { final Version? minFlutterVersion = minFlutterVersionArg.isEmpty ? null : Version.parse(minFlutterVersionArg); + final String minDartVersionArg = getStringArg(_skipByDartVersionArg); + final Version? minDartVersion = + minDartVersionArg.isEmpty ? null : Version.parse(minDartVersionArg); final DateTime runStart = DateTime.now(); @@ -289,7 +299,8 @@ abstract class PackageLoopingCommand extends PluginCommand { PackageResult result; try { result = await _runForPackageIfSupported(entry.package, - minFlutterVersion: minFlutterVersion); + minFlutterVersion: minFlutterVersion, + minDartVersion: minDartVersion); } catch (e, stack) { printError(e.toString()); printError(stack.toString()); @@ -337,6 +348,7 @@ abstract class PackageLoopingCommand extends PluginCommand { Future _runForPackageIfSupported( RepositoryPackage package, { Version? minFlutterVersion, + Version? minDartVersion, }) async { if (minFlutterVersion != null) { final Pubspec pubspec = package.parsePubspec(); @@ -349,6 +361,15 @@ abstract class PackageLoopingCommand extends PluginCommand { } } + if (minDartVersion != null) { + final Pubspec pubspec = package.parsePubspec(); + final VersionConstraint? dartConstraint = pubspec.environment?['sdk']; + if (dartConstraint != null && !dartConstraint.allows(minDartVersion)) { + return PackageResult.skip( + 'Does not support Dart ${minDartVersion.toString()}'); + } + } + return await runForPackage(package); } diff --git a/script/tool/pubspec.yaml b/script/tool/pubspec.yaml index 138c1183fa1c..1e631b1c0a17 100644 --- a/script/tool/pubspec.yaml +++ b/script/tool/pubspec.yaml @@ -1,7 +1,7 @@ name: flutter_plugin_tools description: Productivity utils for flutter/plugins and flutter/packages repository: https://github.com/flutter/plugins/tree/main/script/tool -version: 0.8.6 +version: 0.8.7 dependencies: args: ^2.1.0 diff --git a/script/tool/test/common/package_looping_command_test.dart b/script/tool/test/common/package_looping_command_test.dart index a7e7dfdf6ebb..ec2b9b9be232 100644 --- a/script/tool/test/common/package_looping_command_test.dart +++ b/script/tool/test/common/package_looping_command_test.dart @@ -340,7 +340,7 @@ void main() { } }); - test('skips unsupported versions when requested', () async { + test('skips unsupported Flutter versions when requested', () async { final RepositoryPackage excluded = createFakePlugin( 'a_plugin', packagesDir, flutterConstraint: '>=2.10.0'); @@ -370,6 +370,37 @@ void main() { '$_startSkipColor SKIPPING: Does not support Flutter 2.5.0$_endColor', ])); }); + + test('skips unsupported Dart versions when requested', () async { + final RepositoryPackage excluded = createFakePackage( + 'excluded_package', packagesDir, + isFlutter: false, dartConstraint: '>=2.17.0 <3.0.0'); + final RepositoryPackage included = createFakePackage( + 'a_package', packagesDir, + isFlutter: false, dartConstraint: '>=2.14.0 <3.0.0'); + + final TestPackageLoopingCommand command = createTestCommand( + packageLoopingType: PackageLoopingType.includeAllSubpackages, + hasLongOutput: false); + final List output = await runCommand(command, + arguments: ['--skip-if-not-supporting-dart-version=2.14.0']); + + expect( + command.checkedPackages, + unorderedEquals([ + included.path, + getExampleDir(included).path, + ])); + expect(command.checkedPackages, isNot(contains(excluded.path))); + + expect( + output, + containsAllInOrder([ + '${_startHeadingColor}Running for a_package...$_endColor', + '${_startHeadingColor}Running for excluded_package...$_endColor', + '$_startSkipColor SKIPPING: Does not support Dart 2.14.0$_endColor', + ])); + }); }); group('output', () { diff --git a/script/tool/test/util.dart b/script/tool/test/util.dart index 4c99873e937d..041d93367f9f 100644 --- a/script/tool/test/util.dart +++ b/script/tool/test/util.dart @@ -23,6 +23,9 @@ import 'mocks.dart'; export 'package:flutter_plugin_tools/src/common/repository_package.dart'; +const String _defaultDartConstraint = '>=2.14.0 <3.0.0'; +const String _defaultFlutterConstraint = '>=2.5.0'; + /// Returns the exe name that command will use when running Flutter on /// [platform]. String getFlutterCommand(Platform platform) => @@ -97,14 +100,19 @@ RepositoryPackage createFakePlugin( Map platformSupport = const {}, String? version = '0.0.1', - String flutterConstraint = '>=2.5.0', + String flutterConstraint = _defaultFlutterConstraint, + String dartConstraint = _defaultDartConstraint, }) { - final RepositoryPackage package = createFakePackage(name, parentDirectory, - isFlutter: true, - examples: examples, - extraFiles: extraFiles, - version: version, - flutterConstraint: flutterConstraint); + final RepositoryPackage package = createFakePackage( + name, + parentDirectory, + isFlutter: true, + examples: examples, + extraFiles: extraFiles, + version: version, + flutterConstraint: flutterConstraint, + dartConstraint: dartConstraint, + ); createFakePubspec( package, @@ -114,6 +122,7 @@ RepositoryPackage createFakePlugin( platformSupport: platformSupport, version: version, flutterConstraint: flutterConstraint, + dartConstraint: dartConstraint, ); return package; @@ -136,7 +145,8 @@ RepositoryPackage createFakePackage( List extraFiles = const [], bool isFlutter = false, String? version = '0.0.1', - String flutterConstraint = '>=2.5.0', + String flutterConstraint = _defaultFlutterConstraint, + String dartConstraint = _defaultDartConstraint, bool includeCommonFiles = true, String? directoryName, String? publishTo, @@ -150,7 +160,8 @@ RepositoryPackage createFakePackage( name: name, isFlutter: isFlutter, version: version, - flutterConstraint: flutterConstraint); + flutterConstraint: flutterConstraint, + dartConstraint: dartConstraint); if (includeCommonFiles) { package.changelogFile.writeAsStringSync(''' ## $version @@ -167,7 +178,8 @@ RepositoryPackage createFakePackage( includeCommonFiles: false, isFlutter: isFlutter, publishTo: 'none', - flutterConstraint: flutterConstraint); + flutterConstraint: flutterConstraint, + dartConstraint: dartConstraint); } else if (examples.isNotEmpty) { final Directory examplesDirectory = getExampleDir(package)..createSync(); for (final String exampleName in examples) { @@ -176,7 +188,8 @@ RepositoryPackage createFakePackage( includeCommonFiles: false, isFlutter: isFlutter, publishTo: 'none', - flutterConstraint: flutterConstraint); + flutterConstraint: flutterConstraint, + dartConstraint: dartConstraint); } } @@ -189,7 +202,7 @@ RepositoryPackage createFakePackage( return package; } -/// Creates a `pubspec.yaml` file with a flutter dependency. +/// Creates a `pubspec.yaml` file for [package]. /// /// [platformSupport] is a map of platform string to the support details for /// that platform. If empty, no `plugin` entry will be created unless `isPlugin` @@ -203,8 +216,8 @@ void createFakePubspec( const {}, String? publishTo, String? version, - String dartConstraint = '>=2.0.0 <3.0.0', - String flutterConstraint = '>=2.5.0', + String dartConstraint = _defaultDartConstraint, + String flutterConstraint = _defaultFlutterConstraint, }) { isPlugin |= platformSupport.isNotEmpty;