mirror of
https://github.com/flutter/packages.git
synced 2025-08-06 08:53:11 +08:00
[various] Align Flutter and Dart SDK constraints (#3349)
As described in https://github.com/flutter/flutter/issues/121684, we currently have inconsistencies between Flutter SDK constraints and Dart SDK constraints; we have often updated only the former. This PR: 1. Adds CI enforcement via the repo tooling that the minimum versions are consistent. 2. Adds a new repo tooling command to update SDK constraints, to help mass-fix all the violations of the new enforcement in step 1 (and for future mass changes, such as when we update our test matrix and mass-drop support for versions that are no longe tested). - In all cases, the looser constraint was updated to match the more restrictive constraint, such that there's no actual change in what Flutter version any package actually supports. 3. Runs `dart fix --apply` over all changed packages to automatically fix all of the analysis failures caused by step 2 suddenly making all of our packages able to use `super` parameters. Fixes https://github.com/flutter/flutter/issues/121684 Fixes https://github.com/flutter/flutter/issues/121685
This commit is contained in:
@ -58,8 +58,8 @@ ${publishable ? '' : "publish_to: 'none'"}
|
||||
}
|
||||
|
||||
String _environmentSection({
|
||||
String dartConstraint = '>=2.12.0 <3.0.0',
|
||||
String? flutterConstraint = '>=2.0.0',
|
||||
String dartConstraint = '>=2.17.0 <3.0.0',
|
||||
String? flutterConstraint = '>=3.0.0',
|
||||
}) {
|
||||
return <String>[
|
||||
'environment:',
|
||||
@ -995,12 +995,12 @@ ${_dependenciesSection()}
|
||||
|
||||
package.pubspecFile.writeAsStringSync('''
|
||||
${_headerSection('a_package')}
|
||||
${_environmentSection(flutterConstraint: '>=3.0.0')}
|
||||
${_environmentSection(flutterConstraint: '>=3.3.0', dartConstraint: '>=2.18.0 <3.0.0')}
|
||||
${_dependenciesSection()}
|
||||
''');
|
||||
|
||||
final List<String> output = await runCapturingPrint(runner,
|
||||
<String>['pubspec-check', '--min-min-flutter-version', '3.0.0']);
|
||||
<String>['pubspec-check', '--min-min-flutter-version', '3.3.0']);
|
||||
|
||||
expect(
|
||||
output,
|
||||
@ -1020,12 +1020,12 @@ ${_dependenciesSection()}
|
||||
|
||||
package.pubspecFile.writeAsStringSync('''
|
||||
${_headerSection('a_package')}
|
||||
${_environmentSection(flutterConstraint: '>=3.3.0')}
|
||||
${_environmentSection(flutterConstraint: '>=3.7.0', dartConstraint: '>=2.19.0 <3.0.0')}
|
||||
${_dependenciesSection()}
|
||||
''');
|
||||
|
||||
final List<String> output = await runCapturingPrint(runner,
|
||||
<String>['pubspec-check', '--min-min-flutter-version', '3.0.0']);
|
||||
<String>['pubspec-check', '--min-min-flutter-version', '3.3.0']);
|
||||
|
||||
expect(
|
||||
output,
|
||||
@ -1048,9 +1048,11 @@ ${_dependenciesSection()}
|
||||
''');
|
||||
|
||||
Error? commandError;
|
||||
final List<String> output = await runCapturingPrint(
|
||||
runner, <String>['pubspec-check', '--min-min-dart-version', '2.17.0'],
|
||||
errorHandler: (Error e) {
|
||||
final List<String> output = await runCapturingPrint(runner, <String>[
|
||||
'pubspec-check',
|
||||
'--min-min-flutter-version',
|
||||
'3.0.0'
|
||||
], errorHandler: (Error e) {
|
||||
commandError = e;
|
||||
});
|
||||
|
||||
@ -1072,12 +1074,12 @@ ${_dependenciesSection()}
|
||||
|
||||
package.pubspecFile.writeAsStringSync('''
|
||||
${_headerSection('a_package')}
|
||||
${_environmentSection(dartConstraint: '>=2.17.0 <3.0.0', flutterConstraint: null)}
|
||||
${_environmentSection(dartConstraint: '>=2.18.0 <3.0.0', flutterConstraint: null)}
|
||||
${_dependenciesSection()}
|
||||
''');
|
||||
|
||||
final List<String> output = await runCapturingPrint(runner,
|
||||
<String>['pubspec-check', '--min-min-dart-version', '2.17.0']);
|
||||
<String>['pubspec-check', '--min-min-flutter-version', '3.3.0']);
|
||||
|
||||
expect(
|
||||
output,
|
||||
@ -1102,7 +1104,7 @@ ${_dependenciesSection()}
|
||||
''');
|
||||
|
||||
final List<String> output = await runCapturingPrint(runner,
|
||||
<String>['pubspec-check', '--min-min-dart-version', '2.17.0']);
|
||||
<String>['pubspec-check', '--min-min-flutter-version', '3.0.0']);
|
||||
|
||||
expect(
|
||||
output,
|
||||
@ -1112,6 +1114,66 @@ ${_dependenciesSection()}
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test('fails when a Flutter->Dart SDK version mapping is missing', () async {
|
||||
final RepositoryPackage package =
|
||||
createFakePackage('a_package', packagesDir, examples: <String>[]);
|
||||
|
||||
package.pubspecFile.writeAsStringSync('''
|
||||
${_headerSection('a_package')}
|
||||
${_environmentSection()}
|
||||
${_dependenciesSection()}
|
||||
''');
|
||||
|
||||
Error? commandError;
|
||||
final List<String> output = await runCapturingPrint(runner, <String>[
|
||||
'pubspec-check',
|
||||
'--min-min-flutter-version',
|
||||
'2.0.0'
|
||||
], errorHandler: (Error e) {
|
||||
commandError = e;
|
||||
});
|
||||
|
||||
expect(commandError, isA<ToolExit>());
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('Dart SDK version for Fluter SDK version 2.0.0 is unknown'),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'fails when a Flutter package has a too-low minimum Dart version for '
|
||||
'the corresponding minimum Flutter version', () async {
|
||||
final RepositoryPackage package = createFakePackage(
|
||||
'a_package', packagesDir,
|
||||
isFlutter: true, examples: <String>[]);
|
||||
|
||||
package.pubspecFile.writeAsStringSync('''
|
||||
${_headerSection('a_package')}
|
||||
${_environmentSection(flutterConstraint: '>=3.3.0', dartConstraint: '>=2.16.0 <3.0.0')}
|
||||
${_dependenciesSection()}
|
||||
''');
|
||||
|
||||
Error? commandError;
|
||||
final List<String> output = await runCapturingPrint(runner, <String>[
|
||||
'pubspec-check',
|
||||
], errorHandler: (Error e) {
|
||||
commandError = e;
|
||||
});
|
||||
|
||||
expect(commandError, isA<ToolExit>());
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('The minimum Dart version is 2.16.0, but the '
|
||||
'minimum Flutter version of 3.3.0 shipped with '
|
||||
'Dart 2.18.0. Please use consistent lower SDK '
|
||||
'bounds'),
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('test pubspec_check_command on Windows', () {
|
||||
|
@ -5,7 +5,7 @@
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_plugin_tools/src/remove_dev_dependencies.dart';
|
||||
import 'package:flutter_plugin_tools/src/remove_dev_dependencies_command.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'util.dart';
|
114
script/tool/test/update_min_sdk_command_test.dart
Normal file
114
script/tool/test/update_min_sdk_command_test.dart
Normal file
@ -0,0 +1,114 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_plugin_tools/src/update_min_sdk_command.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'util.dart';
|
||||
|
||||
void main() {
|
||||
late FileSystem fileSystem;
|
||||
late Directory packagesDir;
|
||||
late CommandRunner<void> runner;
|
||||
|
||||
setUp(() {
|
||||
fileSystem = MemoryFileSystem();
|
||||
packagesDir = createPackagesDirectory(fileSystem: fileSystem);
|
||||
|
||||
final UpdateMinSdkCommand command = UpdateMinSdkCommand(
|
||||
packagesDir,
|
||||
);
|
||||
runner = CommandRunner<void>(
|
||||
'update_min_sdk_command', 'Test for update_min_sdk_command');
|
||||
runner.addCommand(command);
|
||||
});
|
||||
|
||||
test('fails if --flutter-min is missing', () async {
|
||||
Exception? commandError;
|
||||
await runCapturingPrint(runner, <String>[
|
||||
'update-min-sdk',
|
||||
], exceptionHandler: (Exception e) {
|
||||
commandError = e;
|
||||
});
|
||||
|
||||
expect(commandError, isA<UsageException>());
|
||||
});
|
||||
|
||||
test('updates Dart when only Dart is present', () async {
|
||||
final RepositoryPackage package = createFakePackage(
|
||||
'a_package', packagesDir,
|
||||
dartConstraint: '>=2.12.0 <3.0.0');
|
||||
|
||||
await runCapturingPrint(runner, <String>[
|
||||
'update-min-sdk',
|
||||
'--flutter-min',
|
||||
'3.3.0', // Corresponds to Dart 2.18.0
|
||||
]);
|
||||
|
||||
final String dartVersion =
|
||||
package.parsePubspec().environment?['sdk'].toString() ?? '';
|
||||
expect(dartVersion, '>=2.18.0 <3.0.0');
|
||||
});
|
||||
|
||||
test('does not update Dart if it is already higher', () async {
|
||||
final RepositoryPackage package = createFakePackage(
|
||||
'a_package', packagesDir,
|
||||
dartConstraint: '>=2.19.0 <3.0.0');
|
||||
|
||||
await runCapturingPrint(runner, <String>[
|
||||
'update-min-sdk',
|
||||
'--flutter-min',
|
||||
'3.3.0', // Corresponds to Dart 2.18.0
|
||||
]);
|
||||
|
||||
final String dartVersion =
|
||||
package.parsePubspec().environment?['sdk'].toString() ?? '';
|
||||
expect(dartVersion, '>=2.19.0 <3.0.0');
|
||||
});
|
||||
|
||||
test('updates both Dart and Flutter when both are present', () async {
|
||||
final RepositoryPackage package = createFakePackage(
|
||||
'a_package', packagesDir,
|
||||
isFlutter: true,
|
||||
dartConstraint: '>=2.12.0 <3.0.0',
|
||||
flutterConstraint: '>=2.10.0');
|
||||
|
||||
await runCapturingPrint(runner, <String>[
|
||||
'update-min-sdk',
|
||||
'--flutter-min',
|
||||
'3.3.0', // Corresponds to Dart 2.18.0
|
||||
]);
|
||||
|
||||
final String dartVersion =
|
||||
package.parsePubspec().environment?['sdk'].toString() ?? '';
|
||||
final String flutterVersion =
|
||||
package.parsePubspec().environment?['flutter'].toString() ?? '';
|
||||
expect(dartVersion, '>=2.18.0 <3.0.0');
|
||||
expect(flutterVersion, '>=3.3.0');
|
||||
});
|
||||
|
||||
test('does not update Flutter if it is already higher', () async {
|
||||
final RepositoryPackage package = createFakePackage(
|
||||
'a_package', packagesDir,
|
||||
isFlutter: true,
|
||||
dartConstraint: '>=2.19.0 <3.0.0',
|
||||
flutterConstraint: '>=3.7.0');
|
||||
|
||||
await runCapturingPrint(runner, <String>[
|
||||
'update-min-sdk',
|
||||
'--flutter-min',
|
||||
'3.3.0', // Corresponds to Dart 2.18.0
|
||||
]);
|
||||
|
||||
final String dartVersion =
|
||||
package.parsePubspec().environment?['sdk'].toString() ?? '';
|
||||
final String flutterVersion =
|
||||
package.parsePubspec().environment?['flutter'].toString() ?? '';
|
||||
expect(dartVersion, '>=2.19.0 <3.0.0');
|
||||
expect(flutterVersion, '>=3.7.0');
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user