Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[tools] Allow skipping packages by Dart version #6038

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion script/tool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
23 changes: 22 additions & 1 deletion script/tool/lib/src/common/package_looping_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<PackageEnumerationEntry> _packagesWithWarnings =
Expand Down Expand Up @@ -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();

Expand All @@ -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());
Expand Down Expand Up @@ -337,6 +348,7 @@ abstract class PackageLoopingCommand extends PluginCommand {
Future<PackageResult> _runForPackageIfSupported(
RepositoryPackage package, {
Version? minFlutterVersion,
Version? minDartVersion,
}) async {
if (minFlutterVersion != null) {
final Pubspec pubspec = package.parsePubspec();
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion script/tool/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
33 changes: 32 additions & 1 deletion script/tool/test/common/package_looping_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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<String> output = await runCommand(command,
arguments: <String>['--skip-if-not-supporting-dart-version=2.14.0']);

expect(
command.checkedPackages,
unorderedEquals(<String>[
included.path,
getExampleDir(included).path,
]));
expect(command.checkedPackages, isNot(contains(excluded.path)));

expect(
output,
containsAllInOrder(<String>[
'${_startHeadingColor}Running for a_package...$_endColor',
'${_startHeadingColor}Running for excluded_package...$_endColor',
'$_startSkipColor SKIPPING: Does not support Dart 2.14.0$_endColor',
]));
});
});

group('output', () {
Expand Down
41 changes: 27 additions & 14 deletions script/tool/test/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -97,14 +100,19 @@ RepositoryPackage createFakePlugin(
Map<String, PlatformDetails> platformSupport =
const <String, PlatformDetails>{},
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,
Expand All @@ -114,6 +122,7 @@ RepositoryPackage createFakePlugin(
platformSupport: platformSupport,
version: version,
flutterConstraint: flutterConstraint,
dartConstraint: dartConstraint,
);

return package;
Expand All @@ -136,7 +145,8 @@ RepositoryPackage createFakePackage(
List<String> extraFiles = const <String>[],
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,
Expand All @@ -150,7 +160,8 @@ RepositoryPackage createFakePackage(
name: name,
isFlutter: isFlutter,
version: version,
flutterConstraint: flutterConstraint);
flutterConstraint: flutterConstraint,
dartConstraint: dartConstraint);
if (includeCommonFiles) {
package.changelogFile.writeAsStringSync('''
## $version
Expand All @@ -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) {
Expand All @@ -176,7 +188,8 @@ RepositoryPackage createFakePackage(
includeCommonFiles: false,
isFlutter: isFlutter,
publishTo: 'none',
flutterConstraint: flutterConstraint);
flutterConstraint: flutterConstraint,
dartConstraint: dartConstraint);
}
}

Expand All @@ -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`
Expand All @@ -203,8 +216,8 @@ void createFakePubspec(
const <String, PlatformDetails>{},
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;

Expand Down