Unverified Commit 374f09e1 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] No more implicit --no-sound-null-safety (#118491)

* remove implicit no-sound-null-safety

* add test

* bump sdk constraint in test file
parent 8a58ec5c
...@@ -83,10 +83,8 @@ class FlutterDevice { ...@@ -83,10 +83,8 @@ class FlutterDevice {
required Platform platform, required Platform platform,
TargetModel targetModel = TargetModel.flutter, TargetModel targetModel = TargetModel.flutter,
List<String>? experimentalFlags, List<String>? experimentalFlags,
ResidentCompiler? generator,
String? userIdentifier, String? userIdentifier,
}) async { }) async {
ResidentCompiler generator;
final TargetPlatform targetPlatform = await device.targetPlatform; final TargetPlatform targetPlatform = await device.targetPlatform;
if (device.platformType == PlatformType.fuchsia) { if (device.platformType == PlatformType.fuchsia) {
targetModel = TargetModel.flutterRunner; targetModel = TargetModel.flutterRunner;
...@@ -111,6 +109,8 @@ class FlutterDevice { ...@@ -111,6 +109,8 @@ class FlutterDevice {
fileSystem: globals.fs, fileSystem: globals.fs,
); );
final ResidentCompiler generator;
// For both web and non-web platforms we initialize dill to/from // For both web and non-web platforms we initialize dill to/from
// a shared location for faster bootstrapping. If the compiler fails // a shared location for faster bootstrapping. If the compiler fails
// due to a kernel target or version mismatch, no error is reported // due to a kernel target or version mismatch, no error is reported
...@@ -119,7 +119,7 @@ class FlutterDevice { ...@@ -119,7 +119,7 @@ class FlutterDevice {
// used to file a bug, but the compiler will still start up correctly. // used to file a bug, but the compiler will still start up correctly.
if (targetPlatform == TargetPlatform.web_javascript) { if (targetPlatform == TargetPlatform.web_javascript) {
// TODO(zanderso): consistently provide these flags across platforms. // TODO(zanderso): consistently provide these flags across platforms.
late String platformDillName; final String platformDillName;
final List<String> extraFrontEndOptions = List<String>.of(buildInfo.extraFrontEndOptions); final List<String> extraFrontEndOptions = List<String>.of(buildInfo.extraFrontEndOptions);
if (buildInfo.nullSafetyMode == NullSafetyMode.unsound) { if (buildInfo.nullSafetyMode == NullSafetyMode.unsound) {
platformDillName = 'ddc_outline.dill'; platformDillName = 'ddc_outline.dill';
...@@ -132,12 +132,12 @@ class FlutterDevice { ...@@ -132,12 +132,12 @@ class FlutterDevice {
extraFrontEndOptions.add('--sound-null-safety'); extraFrontEndOptions.add('--sound-null-safety');
} }
} else { } 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( final String platformDillPath = globals.fs.path.join(
getWebPlatformBinariesDirectory(globals.artifacts!, buildInfo.webRenderer).path, getWebPlatformBinariesDirectory(globals.artifacts!, buildInfo.webRenderer).path,
platformDillName platformDillName,
); );
generator = ResidentCompiler( generator = ResidentCompiler(
......
...@@ -1093,7 +1093,11 @@ abstract class FlutterCommand extends Command<void> { ...@@ -1093,7 +1093,11 @@ abstract class FlutterCommand extends Command<void> {
(languageVersion.major == nullSafeVersion.major && languageVersion.minor >= nullSafeVersion.minor)) { (languageVersion.major == nullSafeVersion.major && languageVersion.minor >= nullSafeVersion.minor)) {
nullSafetyMode = NullSafetyMode.sound; nullSafetyMode = NullSafetyMode.sound;
} else { } 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) { } else if (!wasNullSafetyFlagParsed) {
// This mode is only used for commands which do not build a single target like // This mode is only used for commands which do not build a single target like
......
...@@ -554,6 +554,27 @@ void main() { ...@@ -554,6 +554,27 @@ void main() {
ProcessManager: () => processManager, 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 { testUsingContext('use packagesPath to generate BuildInfo', () async {
final DummyFlutterCommand flutterCommand = DummyFlutterCommand(packagesPath: 'foo'); final DummyFlutterCommand flutterCommand = DummyFlutterCommand(packagesPath: 'foo');
final BuildInfo buildInfo = await flutterCommand.getBuildInfo(forcedBuildMode: BuildMode.debug); final BuildInfo buildInfo = await flutterCommand.getBuildInfo(forcedBuildMode: BuildMode.debug);
......
...@@ -65,7 +65,7 @@ class WebSteppingProject extends Project { ...@@ -65,7 +65,7 @@ class WebSteppingProject extends Project {
final String pubspec = ''' final String pubspec = '''
name: test name: test
environment: environment:
sdk: '>=2.10.0 <4.0.0' sdk: '>=2.12.0 <4.0.0'
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment