Skip to content

Commit f6bc147

Browse files
Revert "[flutter_tools] Remove sound null safety flag (flutter#120936)" (flutter#122909)
This reverts commit 7c3088c.
1 parent 7a859f7 commit f6bc147

File tree

67 files changed

+1126
-130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1126
-130
lines changed

dev/bots/test.dart

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,9 @@ Future<void> _runExampleProjectBuildTests(Directory exampleDirectory, [File? mai
573573
// Only verify caching with flutter gallery.
574574
final bool verifyCaching = exampleDirectory.path.contains('flutter_gallery');
575575
final String examplePath = path.relative(exampleDirectory.path, from: Directory.current.path);
576+
final bool hasNullSafety = File(path.join(examplePath, 'null_safety')).existsSync();
576577
final List<String> additionalArgs = <String>[
578+
if (hasNullSafety) '--no-sound-null-safety',
577579
if (mainFile != null) path.relative(mainFile.path, from: exampleDirectory.absolute.path),
578580
];
579581
if (Directory(path.join(examplePath, 'android')).existsSync()) {
@@ -769,14 +771,16 @@ Future<void> _runAddToAppLifeCycleTests() async {
769771
}
770772

771773
Future<void> _runFrameworkTests() async {
774+
final List<String> soundNullSafetyOptions = <String>['--null-assertions', '--sound-null-safety'];
775+
final List<String> mixedModeNullSafetyOptions = <String>['--null-assertions', '--no-sound-null-safety'];
772776
final List<String> trackWidgetCreationAlternatives = <String>['--track-widget-creation', '--no-track-widget-creation'];
773777

774778
Future<void> runWidgets() async {
775779
printProgress('${green}Running packages/flutter tests $reset for ${cyan}test/widgets/$reset');
776780
for (final String trackWidgetCreationOption in trackWidgetCreationAlternatives) {
777781
await _runFlutterTest(
778782
path.join(flutterRoot, 'packages', 'flutter'),
779-
options: <String>[trackWidgetCreationOption],
783+
options: <String>[trackWidgetCreationOption, ...soundNullSafetyOptions],
780784
tests: <String>[ path.join('test', 'widgets') + path.separator ],
781785
);
782786
}
@@ -791,13 +795,13 @@ Future<void> _runFrameworkTests() async {
791795
// Run release mode tests (see packages/flutter/test_release/README.md)
792796
await _runFlutterTest(
793797
path.join(flutterRoot, 'packages', 'flutter'),
794-
options: <String>['--dart-define=dart.vm.product=true'],
798+
options: <String>['--dart-define=dart.vm.product=true', ...soundNullSafetyOptions],
795799
tests: <String>['test_release${path.separator}'],
796800
);
797801
// Run profile mode tests (see packages/flutter/test_profile/README.md)
798802
await _runFlutterTest(
799803
path.join(flutterRoot, 'packages', 'flutter'),
800-
options: <String>['--dart-define=dart.vm.product=false', '--dart-define=dart.vm.profile=true'],
804+
options: <String>['--dart-define=dart.vm.product=false', '--dart-define=dart.vm.profile=true', ...soundNullSafetyOptions],
801805
tests: <String>['test_profile${path.separator}'],
802806
);
803807
}
@@ -813,7 +817,7 @@ Future<void> _runFrameworkTests() async {
813817
for (final String trackWidgetCreationOption in trackWidgetCreationAlternatives) {
814818
await _runFlutterTest(
815819
path.join(flutterRoot, 'packages', 'flutter'),
816-
options: <String>[trackWidgetCreationOption],
820+
options: <String>[trackWidgetCreationOption, ...soundNullSafetyOptions],
817821
tests: tests,
818822
);
819823
}
@@ -833,9 +837,9 @@ Future<void> _runFrameworkTests() async {
833837
workingDirectory: path.join(flutterRoot, 'examples', 'api'),
834838
);
835839
}
836-
await _runFlutterTest(path.join(flutterRoot, 'examples', 'api'));
837-
await _runFlutterTest(path.join(flutterRoot, 'examples', 'hello_world'));
838-
await _runFlutterTest(path.join(flutterRoot, 'examples', 'layers'));
840+
await _runFlutterTest(path.join(flutterRoot, 'examples', 'api'), options: soundNullSafetyOptions);
841+
await _runFlutterTest(path.join(flutterRoot, 'examples', 'hello_world'), options: soundNullSafetyOptions);
842+
await _runFlutterTest(path.join(flutterRoot, 'examples', 'layers'), options: soundNullSafetyOptions);
839843
}
840844

841845
Future<void> runTracingTests() async {
@@ -941,6 +945,7 @@ Future<void> _runFrameworkTests() async {
941945

942946
Future<void> runPrivateTests() async {
943947
final List<String> args = <String>[
948+
'--sound-null-safety',
944949
'run',
945950
'bin/test_private.dart',
946951
];
@@ -984,17 +989,17 @@ Future<void> _runFrameworkTests() async {
984989
await _runFlutterTest(path.join(flutterRoot, 'dev', 'tools', 'gen_defaults'));
985990
await _runFlutterTest(path.join(flutterRoot, 'dev', 'tools', 'gen_keycodes'));
986991
await _runFlutterTest(path.join(flutterRoot, 'dev', 'benchmarks', 'test_apps', 'stocks'));
987-
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_driver'), tests: <String>[path.join('test', 'src', 'real_tests')]);
992+
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_driver'), tests: <String>[path.join('test', 'src', 'real_tests')], options: soundNullSafetyOptions);
988993
await _runFlutterTest(path.join(flutterRoot, 'packages', 'integration_test'), options: <String>[
989994
'--enable-vmservice',
990995
// Web-specific tests depend on Chromium, so they run as part of the web_long_running_tests shard.
991996
'--exclude-tags=web',
992997
]);
993-
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_goldens'));
994-
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_localizations'));
995-
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_test'));
996-
await _runFlutterTest(path.join(flutterRoot, 'packages', 'fuchsia_remote_debug_protocol'));
997-
await _runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'non_nullable'));
998+
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_goldens'), options: soundNullSafetyOptions);
999+
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_localizations'), options: soundNullSafetyOptions);
1000+
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_test'), options: soundNullSafetyOptions);
1001+
await _runFlutterTest(path.join(flutterRoot, 'packages', 'fuchsia_remote_debug_protocol'), options: soundNullSafetyOptions);
1002+
await _runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'non_nullable'), options: mixedModeNullSafetyOptions);
9981003
const String httpClientWarning =
9991004
'Warning: At least one test in this suite creates an HttpClient. When\n'
10001005
'running a test suite that uses TestWidgetsFlutterBinding, all HTTP\n'
@@ -1224,7 +1229,7 @@ Future<void> _runWebLongRunningTests() async {
12241229
() => _runWebDebugTest('lib/framework_stack_trace.dart'),
12251230
() => _runWebDebugTest('lib/web_directory_loading.dart'),
12261231
() => _runWebDebugTest('test/test.dart'),
1227-
() => _runWebDebugTest('lib/null_safe_main.dart'),
1232+
() => _runWebDebugTest('lib/null_safe_main.dart', enableNullSafety: true),
12281233
() => _runWebDebugTest('lib/web_define_loading.dart',
12291234
additionalArguments: <String>[
12301235
'--dart-define=test.valueA=Example,A',
@@ -1237,8 +1242,12 @@ Future<void> _runWebLongRunningTests() async {
12371242
'--dart-define=test.valueB=Value',
12381243
]
12391244
),
1240-
() => _runWebDebugTest('lib/sound_mode.dart'),
1241-
() => _runWebReleaseTest('lib/sound_mode.dart'),
1245+
() => _runWebDebugTest('lib/sound_mode.dart', additionalArguments: <String>[
1246+
'--sound-null-safety',
1247+
]),
1248+
() => _runWebReleaseTest('lib/sound_mode.dart', additionalArguments: <String>[
1249+
'--sound-null-safety',
1250+
]),
12421251
() => _runFlutterWebTest(
12431252
'html',
12441253
path.join(flutterRoot, 'packages', 'integration_test'),
@@ -1297,6 +1306,7 @@ Future<void> _runFlutterDriverWebTest({
12971306
if (driver != null) '--driver=$driver',
12981307
'--target=$target',
12991308
'--browser-name=chrome',
1309+
'--no-sound-null-safety',
13001310
'-d',
13011311
'web-server',
13021312
'--$buildMode',
@@ -1338,6 +1348,7 @@ Future<void> _runWebTreeshakeTest() async {
13381348
'build',
13391349
'web',
13401350
'--target=$target',
1351+
'--no-sound-null-safety',
13411352
'--profile',
13421353
],
13431354
workingDirectory: testAppDirectory,
@@ -1563,6 +1574,7 @@ Future<void> _runGalleryE2eWebTest(String buildMode, { bool canvasKit = false })
15631574
'--driver=test_driver/transitions_perf_e2e_test.dart',
15641575
'--target=test_driver/transitions_perf_e2e.dart',
15651576
'--browser-name=chrome',
1577+
'--no-sound-null-safety',
15661578
'-d',
15671579
'web-server',
15681580
'--$buildMode',
@@ -1669,6 +1681,7 @@ Future<void> _runWebReleaseTest(String target, {
16691681
///
16701682
/// Instead, we use `flutter run --debug` and sniff out the standard output.
16711683
Future<void> _runWebDebugTest(String target, {
1684+
bool enableNullSafety = false,
16721685
List<String> additionalArguments = const<String>[],
16731686
}) async {
16741687
final String testAppDirectory = path.join(flutterRoot, 'dev', 'integration_tests', 'web');
@@ -1682,6 +1695,11 @@ Future<void> _runWebDebugTest(String target, {
16821695
<String>[
16831696
'run',
16841697
'--debug',
1698+
if (enableNullSafety)
1699+
...<String>[
1700+
'--no-sound-null-safety',
1701+
'--null-assertions',
1702+
],
16851703
'-d',
16861704
'chrome',
16871705
'--web-run-headless',
@@ -1724,6 +1742,7 @@ Future<void> _runFlutterWebTest(String webRenderer, String workingDirectory, Lis
17241742
'--platform=chrome',
17251743
'--web-renderer=$webRenderer',
17261744
'--dart-define=DART_HHH_BOT=$_runningInDartHHHBot',
1745+
'--sound-null-safety',
17271746
...flutterTestArgs,
17281747
...tests,
17291748
],

packages/flutter/test/foundation/isolates_test.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ Future<int> test5CallCompute(int value) {
8080
return compute(test5, value);
8181
}
8282

83-
Future<void> expectFileSuccessfullyCompletes(String filename) async {
83+
Future<void> expectFileSuccessfullyCompletes(String filename,
84+
[bool unsound = false]) async {
8485
// Run a Dart script that calls compute().
8586
// The Dart process will terminate only if the script exits cleanly with
8687
// all isolate ports closed.
@@ -92,10 +93,12 @@ Future<void> expectFileSuccessfullyCompletes(String filename) async {
9293
final String packageRoot = fs.path.dirname(fs.path.fromUri(platform.script));
9394
final String scriptPath =
9495
fs.path.join(packageRoot, 'test', 'foundation', filename);
96+
final String nullSafetyArg =
97+
unsound ? '--no-sound-null-safety' : '--sound-null-safety';
9598

9699
// Enable asserts to also catch potentially invalid assertions.
97100
final ProcessResult result = await Process.run(
98-
dartPath, <String>['run', '--enable-asserts', scriptPath]);
101+
dartPath, <String>[nullSafetyArg, 'run', '--enable-asserts', scriptPath]);
99102
expect(result.exitCode, 0);
100103
}
101104

packages/flutter/test_private/bin/test_private.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class TestCase {
225225
for (final File test in tests) {
226226
final String testPath = path.join(path.dirname(test.path), 'lib', path.basenameWithoutExtension(test.path));
227227
final ProcessRunnerResult result = await runner.runProcess(
228-
<String>[flutter, 'test', testPath],
228+
<String>[flutter, 'test', '--enable-experiment=non-nullable', '--no-sound-null-safety', '--null-assertions', testPath],
229229
failOk: true,
230230
);
231231
if (result.exitCode != 0) {

packages/flutter_tools/lib/executable.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ List<FlutterCommand> generateCommands({
171171
osUtils: globals.os,
172172
verboseHelp: verboseHelp,
173173
androidSdk: globals.androidSdk,
174+
logger: globals.logger,
174175
),
175176
ChannelCommand(verboseHelp: verboseHelp),
176177
CleanCommand(verbose: verbose),

packages/flutter_tools/lib/src/artifacts.dart

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ enum HostArtifact {
9191
webPlatformDart2JSSoundKernelDill,
9292

9393
/// The precompiled SDKs and sourcemaps for web debug builds.
94-
94+
webPrecompiledSdk,
95+
webPrecompiledSdkSourcemaps,
96+
webPrecompiledCanvaskitSdk,
97+
webPrecompiledCanvaskitSdkSourcemaps,
98+
webPrecompiledCanvaskitAndHtmlSdk,
99+
webPrecompiledCanvaskitAndHtmlSdkSourcemaps,
95100
webPrecompiledSoundSdk,
96101
webPrecompiledSoundSdkSourcemaps,
97102
webPrecompiledCanvaskitSoundSdk,
@@ -243,10 +248,16 @@ String _hostArtifactToFileName(HostArtifact artifact, Platform platform) {
243248
return 'dart2js_platform.dill';
244249
case HostArtifact.flutterWebLibrariesJson:
245250
return 'libraries.json';
251+
case HostArtifact.webPrecompiledSdk:
252+
case HostArtifact.webPrecompiledCanvaskitSdk:
253+
case HostArtifact.webPrecompiledCanvaskitAndHtmlSdk:
246254
case HostArtifact.webPrecompiledSoundSdk:
247255
case HostArtifact.webPrecompiledCanvaskitSoundSdk:
248256
case HostArtifact.webPrecompiledCanvaskitAndHtmlSoundSdk:
249257
return 'dart_sdk.js';
258+
case HostArtifact.webPrecompiledSdkSourcemaps:
259+
case HostArtifact.webPrecompiledCanvaskitSdkSourcemaps:
260+
case HostArtifact.webPrecompiledCanvaskitAndHtmlSdkSourcemaps:
250261
case HostArtifact.webPrecompiledSoundSdkSourcemaps:
251262
case HostArtifact.webPrecompiledCanvaskitSoundSdkSourcemaps:
252263
case HostArtifact.webPrecompiledCanvaskitAndHtmlSoundSdkSourcemaps:
@@ -396,6 +407,18 @@ class CachedArtifacts implements Artifacts {
396407
case HostArtifact.webPlatformDart2JSSoundKernelDill:
397408
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', _hostArtifactToFileName(artifact, _platform));
398409
return _fileSystem.file(path);
410+
case HostArtifact.webPrecompiledSdk:
411+
case HostArtifact.webPrecompiledSdkSourcemaps:
412+
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd', _hostArtifactToFileName(artifact, _platform));
413+
return _fileSystem.file(path);
414+
case HostArtifact.webPrecompiledCanvaskitSdk:
415+
case HostArtifact.webPrecompiledCanvaskitSdkSourcemaps:
416+
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit', _hostArtifactToFileName(artifact, _platform));
417+
return _fileSystem.file(path);
418+
case HostArtifact.webPrecompiledCanvaskitAndHtmlSdk:
419+
case HostArtifact.webPrecompiledCanvaskitAndHtmlSdkSourcemaps:
420+
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit-html', _hostArtifactToFileName(artifact, _platform));
421+
return _fileSystem.file(path);
399422
case HostArtifact.webPrecompiledSoundSdk:
400423
case HostArtifact.webPrecompiledSoundSdkSourcemaps:
401424
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-sound', _hostArtifactToFileName(artifact, _platform));
@@ -828,6 +851,18 @@ class CachedLocalEngineArtifacts implements Artifacts {
828851
case HostArtifact.webPlatformDart2JSSoundKernelDill:
829852
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', _hostArtifactToFileName(artifact, _platform));
830853
return _fileSystem.file(path);
854+
case HostArtifact.webPrecompiledSdk:
855+
case HostArtifact.webPrecompiledSdkSourcemaps:
856+
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd', _hostArtifactToFileName(artifact, _platform));
857+
return _fileSystem.file(path);
858+
case HostArtifact.webPrecompiledCanvaskitSdk:
859+
case HostArtifact.webPrecompiledCanvaskitSdkSourcemaps:
860+
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit', _hostArtifactToFileName(artifact, _platform));
861+
return _fileSystem.file(path);
862+
case HostArtifact.webPrecompiledCanvaskitAndHtmlSdk:
863+
case HostArtifact.webPrecompiledCanvaskitAndHtmlSdkSourcemaps:
864+
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit-html', _hostArtifactToFileName(artifact, _platform));
865+
return _fileSystem.file(path);
831866
case HostArtifact.webPrecompiledSoundSdk:
832867
case HostArtifact.webPrecompiledSoundSdkSourcemaps:
833868
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-sound', _hostArtifactToFileName(artifact, _platform));
@@ -1118,6 +1153,18 @@ class CachedLocalWebSdkArtifacts implements Artifacts {
11181153
case HostArtifact.webPlatformDart2JSSoundKernelDill:
11191154
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', _hostArtifactToFileName(artifact, _platform));
11201155
return _fileSystem.file(path);
1156+
case HostArtifact.webPrecompiledSdk:
1157+
case HostArtifact.webPrecompiledSdkSourcemaps:
1158+
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd', _hostArtifactToFileName(artifact, _platform));
1159+
return _fileSystem.file(path);
1160+
case HostArtifact.webPrecompiledCanvaskitSdk:
1161+
case HostArtifact.webPrecompiledCanvaskitSdkSourcemaps:
1162+
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit', _hostArtifactToFileName(artifact, _platform));
1163+
return _fileSystem.file(path);
1164+
case HostArtifact.webPrecompiledCanvaskitAndHtmlSdk:
1165+
case HostArtifact.webPrecompiledCanvaskitAndHtmlSdkSourcemaps:
1166+
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit-html', _hostArtifactToFileName(artifact, _platform));
1167+
return _fileSystem.file(path);
11211168
case HostArtifact.webPrecompiledSoundSdk:
11221169
case HostArtifact.webPrecompiledSoundSdkSourcemaps:
11231170
final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-sound', _hostArtifactToFileName(artifact, _platform));

packages/flutter_tools/lib/src/build_info.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class BuildInfo {
4040
this.performanceMeasurementFile,
4141
this.dartDefineConfigJsonMap,
4242
this.packagesPath = '.dart_tool/package_config.json', // TODO(zanderso): make this required and remove the default.
43+
this.nullSafetyMode = NullSafetyMode.sound,
4344
this.codeSizeDirectory,
4445
this.androidGradleDaemon = true,
4546
this.packageConfig = PackageConfig.empty,
@@ -53,6 +54,11 @@ class BuildInfo {
5354

5455
final BuildMode mode;
5556

57+
/// The null safety mode the application should be run in.
58+
///
59+
/// If not provided, defaults to [NullSafetyMode.autodetect].
60+
final NullSafetyMode nullSafetyMode;
61+
5662
/// Whether the build should subset icon fonts.
5763
final bool treeShakeIcons;
5864

packages/flutter_tools/lib/src/commands/attach.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class AttachCommand extends FlutterCommand {
9090
usesDartDefineOption();
9191
usesDeviceUserOption();
9292
addEnableExperimentation(hide: !verboseHelp);
93+
addNullSafetyModeOptions(hide: !verboseHelp);
9394
usesInitializeFromDillOption(hide: !verboseHelp);
9495
argParser
9596
..addOption(

0 commit comments

Comments
 (0)