mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] No more implicit --no-sound-null-safety (#118491)
* remove implicit no-sound-null-safety * add test * bump sdk constraint in test file
This commit is contained in:
parent
8a58ec5c32
commit
374f09e1a6
@ -83,10 +83,8 @@ class FlutterDevice {
|
||||
required Platform platform,
|
||||
TargetModel targetModel = TargetModel.flutter,
|
||||
List<String>? experimentalFlags,
|
||||
ResidentCompiler? generator,
|
||||
String? userIdentifier,
|
||||
}) async {
|
||||
ResidentCompiler generator;
|
||||
final TargetPlatform targetPlatform = await device.targetPlatform;
|
||||
if (device.platformType == PlatformType.fuchsia) {
|
||||
targetModel = TargetModel.flutterRunner;
|
||||
@ -111,6 +109,8 @@ class FlutterDevice {
|
||||
fileSystem: globals.fs,
|
||||
);
|
||||
|
||||
final ResidentCompiler generator;
|
||||
|
||||
// For both web and non-web platforms we initialize dill to/from
|
||||
// a shared location for faster bootstrapping. If the compiler fails
|
||||
// due to a kernel target or version mismatch, no error is reported
|
||||
@ -119,7 +119,7 @@ class FlutterDevice {
|
||||
// used to file a bug, but the compiler will still start up correctly.
|
||||
if (targetPlatform == TargetPlatform.web_javascript) {
|
||||
// TODO(zanderso): consistently provide these flags across platforms.
|
||||
late String platformDillName;
|
||||
final String platformDillName;
|
||||
final List<String> extraFrontEndOptions = List<String>.of(buildInfo.extraFrontEndOptions);
|
||||
if (buildInfo.nullSafetyMode == NullSafetyMode.unsound) {
|
||||
platformDillName = 'ddc_outline.dill';
|
||||
@ -132,12 +132,12 @@ class FlutterDevice {
|
||||
extraFrontEndOptions.add('--sound-null-safety');
|
||||
}
|
||||
} else {
|
||||
assert(false);
|
||||
throw StateError('Expected buildInfo.nullSafetyMode to be one of unsound or sound, got ${buildInfo.nullSafetyMode}');
|
||||
}
|
||||
|
||||
final String platformDillPath = globals.fs.path.join(
|
||||
getWebPlatformBinariesDirectory(globals.artifacts!, buildInfo.webRenderer).path,
|
||||
platformDillName
|
||||
platformDillName,
|
||||
);
|
||||
|
||||
generator = ResidentCompiler(
|
||||
|
@ -1093,7 +1093,11 @@ abstract class FlutterCommand extends Command<void> {
|
||||
(languageVersion.major == nullSafeVersion.major && languageVersion.minor >= nullSafeVersion.minor)) {
|
||||
nullSafetyMode = NullSafetyMode.sound;
|
||||
} else {
|
||||
nullSafetyMode = NullSafetyMode.unsound;
|
||||
throwToolExit(
|
||||
'This application does not support sound null-safety (its language version is $languageVersion).\n'
|
||||
'To build this application, you must provide the CLI flag --no-sound-null-safety. Dart 3 will only '
|
||||
'support sound null safety, see https://dart.dev/null-safety.',
|
||||
);
|
||||
}
|
||||
} else if (!wasNullSafetyFlagParsed) {
|
||||
// This mode is only used for commands which do not build a single target like
|
||||
|
@ -554,6 +554,27 @@ void main() {
|
||||
ProcessManager: () => processManager,
|
||||
});
|
||||
|
||||
testUsingContext('tool exits on non-sound-null-safe code when explicit flag not passed', () async {
|
||||
final DummyFlutterCommand flutterCommand = DummyFlutterCommand(packagesPath: 'foo');
|
||||
flutterCommand.argParser
|
||||
..addFlag(FlutterOptions.kNullSafety, defaultsTo: true)
|
||||
..addOption('target');
|
||||
final File targetFile = fileSystem.file('targetFile.dart')
|
||||
..writeAsStringSync('// @dart = 2.11');
|
||||
expect(
|
||||
() async => flutterCommand.getBuildInfo(
|
||||
forcedBuildMode: BuildMode.debug,
|
||||
forcedTargetFile: targetFile,
|
||||
),
|
||||
throwsToolExit(
|
||||
message: 'This application does not support sound null-safety (its language version is 2.11)',
|
||||
),
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
});
|
||||
|
||||
testUsingContext('use packagesPath to generate BuildInfo', () async {
|
||||
final DummyFlutterCommand flutterCommand = DummyFlutterCommand(packagesPath: 'foo');
|
||||
final BuildInfo buildInfo = await flutterCommand.getBuildInfo(forcedBuildMode: BuildMode.debug);
|
||||
|
@ -65,7 +65,7 @@ class WebSteppingProject extends Project {
|
||||
final String pubspec = '''
|
||||
name: test
|
||||
environment:
|
||||
sdk: '>=2.10.0 <4.0.0'
|
||||
sdk: '>=2.12.0 <4.0.0'
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
Loading…
Reference in New Issue
Block a user