mirror of
https://github.com/flutter/packages.git
synced 2025-06-21 23:52:15 +08:00
[tools] Allow skipping packages by Dart version (#6038)
This commit is contained in:
@ -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
|
||||
|
||||
|
@ -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 =
|
||||
@ -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<PackageResult> _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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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<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', () {
|
||||
|
@ -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<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,
|
||||
final RepositoryPackage package = createFakePackage(
|
||||
name,
|
||||
parentDirectory,
|
||||
isFlutter: true,
|
||||
examples: examples,
|
||||
extraFiles: extraFiles,
|
||||
version: version,
|
||||
flutterConstraint: flutterConstraint);
|
||||
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<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,
|
||||
@ -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, 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;
|
||||
|
||||
|
Reference in New Issue
Block a user