[null-safety] pass experiments to builders (#67152)
Force opt-in flutter test platform to null safety for repo testing
diff --git a/packages/_flutter_web_build_script/lib/build_script.dart b/packages/_flutter_web_build_script/lib/build_script.dart
index d0c4f5d..3635df9 100644
--- a/packages/_flutter_web_build_script/lib/build_script.dart
+++ b/packages/_flutter_web_build_script/lib/build_script.dart
@@ -5,9 +5,6 @@
// ignore_for_file: implementation_imports
import 'dart:isolate';
-import 'package:analyzer/dart/analysis/results.dart';
-import 'package:analyzer/dart/analysis/utilities.dart';
-import 'package:analyzer/dart/ast/ast.dart';
import 'package:build/build.dart';
import 'package:build_config/build_config.dart';
import 'package:build_modules/build_modules.dart';
@@ -76,27 +73,6 @@
),
),
core.apply(
- 'flutter_tools:shell',
- <BuilderFactory>[
- (BuilderOptions options) {
- final bool hasPlugins = options.config['hasPlugins'] == true;
- final bool initializePlatform = options.config['initializePlatform'] == true;
- return FlutterWebShellBuilder(
- hasPlugins: hasPlugins,
- initializePlatform: initializePlatform,
- );
- },
- ],
- core.toRoot(),
- hideOutput: true,
- defaultGenerateFor: const InputSet(
- include: <String>[
- 'lib/**',
- 'web/**',
- ],
- ),
- ),
- core.apply(
'flutter_tools:module_library',
<Builder Function(BuilderOptions)>[moduleLibraryBuilder],
core.toAllPackages(),
@@ -127,6 +103,7 @@
kernelTargetName: 'ddc',
useIncrementalCompiler: true,
trackUnusedInputs: true,
+ experiments: <String>['non-nullable'], // ignore: deprecated_member_use
),
(BuilderOptions builderOptions) => DevCompilerBuilder(
useIncrementalCompiler: true,
@@ -134,6 +111,7 @@
platform: flutterWebPlatform,
platformSdk: builderOptions.config['flutterWebSdk'] as String,
sdkKernelPath: path.url.join('kernel', 'flutter_ddc_sdk.dill'),
+ experiments: <String>['non-nullable'],
librariesPath: path.absolute(path.join(builderOptions.config['flutterWebSdk'] as String, 'libraries.json')),
),
],
@@ -142,23 +120,6 @@
hideOutput: true,
appliesBuilders: <String>['flutter_tools:ddc_modules']),
core.apply(
- 'flutter_tools:entrypoint',
- <BuilderFactory>[
- (BuilderOptions options) => FlutterWebEntrypointBuilder(
- options.config[kReleaseFlag] as bool ?? false,
- options.config[kProfileFlag] as bool ?? false,
- options.config['flutterWebSdk'] as String,
- ),
- ],
- core.toRoot(),
- hideOutput: true,
- defaultGenerateFor: const InputSet(
- include: <String>[
- 'lib/**_web_entrypoint.dart',
- ],
- ),
- ),
- core.apply(
'flutter_tools:test_entrypoint',
<BuilderFactory>[
(BuilderOptions options) => const FlutterWebTestEntrypointBuilder(),
@@ -208,35 +169,6 @@
}
}
-/// A ddc-only entry point builder that respects the Flutter target flag.
-class FlutterWebEntrypointBuilder implements Builder {
- const FlutterWebEntrypointBuilder(this.release, this.profile, this.flutterWebSdk);
-
- final bool release;
- final bool profile;
- final String flutterWebSdk;
-
- @override
- Map<String, List<String>> get buildExtensions => const <String, List<String>>{
- '.dart': <String>[
- ddcBootstrapExtension,
- jsEntrypointExtension,
- jsEntrypointSourceMapExtension,
- jsEntrypointArchiveExtension,
- digestsEntrypointExtension,
- ],
- };
-
- @override
- Future<void> build(BuildStep buildStep) async {
- await bootstrapDdc(
- buildStep,
- platform: flutterWebPlatform,
- skipPlatformCheck: true,
- );
- }
-}
-
/// Bootstraps the test entry point.
class FlutterWebTestBootstrapBuilder implements Builder {
const FlutterWebTestBootstrapBuilder();
@@ -334,86 +266,3 @@
}
}
}
-
-/// A shell builder which generates the web specific entry point.
-class FlutterWebShellBuilder implements Builder {
- const FlutterWebShellBuilder({this.hasPlugins = false, this.initializePlatform = true});
-
- final bool hasPlugins;
-
- /// Whether to call webOnlyInitializePlatform.
- final bool initializePlatform;
-
- @override
- Future<void> build(BuildStep buildStep) async {
- final AssetId dartEntrypointId = buildStep.inputId;
- final bool isAppEntrypoint = await _isAppEntryPoint(dartEntrypointId, buildStep);
- if (!isAppEntrypoint) {
- return;
- }
- final AssetId outputId = buildStep.inputId.changeExtension('_web_entrypoint.dart');
- final String pluginRegistrantPath = _getPluginRegistrantPath(dartEntrypointId.path);
- if (hasPlugins) {
- await buildStep.writeAsString(outputId, '''
-import 'dart:ui' as ui;
-
-import 'package:flutter_web_plugins/flutter_web_plugins.dart';
-
-import '$pluginRegistrantPath';
-import "${path.url.basename(buildStep.inputId.path)}" as entrypoint;
-
-Future<void> main() async {
- registerPlugins(webPluginRegistry);
- if ($initializePlatform) {
- await ui.webOnlyInitializePlatform();
- }
- entrypoint.main();
-}
-''');
- } else {
- await buildStep.writeAsString(outputId, '''
-import 'dart:ui' as ui;
-
-import "${path.url.basename(buildStep.inputId.path)}" as entrypoint;
-
-Future<void> main() async {
- if ($initializePlatform) {
- await ui.webOnlyInitializePlatform();
- }
- entrypoint.main();
-}
-''');
- }
- }
-
- /// Gets the relative path to the generated plugin registrant from the app
- /// app entrypoint.
- String _getPluginRegistrantPath(String entrypoint) {
- return path.url.relative('lib/generated_plugin_registrant.dart',
- from: path.url.dirname(entrypoint));
- }
-
- @override
- Map<String, List<String>> get buildExtensions => const <String, List<String>>{
- '.dart': <String>['_web_entrypoint.dart'],
- };
-}
-
-/// Returns whether or not [dartId] is an app entry point (basically, whether
-/// or not it has a `main` function).
-Future<bool> _isAppEntryPoint(AssetId dartId, AssetReader reader) async {
- assert(dartId.extension == '.dart');
- // Skip reporting errors here, dartdevc will report them later with nicer
- // formatting.
- final ParseStringResult result = parseString(
- content: await reader.readAsString(dartId),
- throwIfDiagnostics: false,
- );
- // Allow two or fewer arguments so that entrypoints intended for use with
- // [spawnUri] get counted.
- return result.unit.declarations.any((CompilationUnitMember node) {
- return node is FunctionDeclaration &&
- node.name.name == 'main' &&
- node.functionExpression.parameters.parameters.length <= 2;
- });
-}
diff --git a/packages/flutter/test/foundation/print_test.dart b/packages/flutter/test/foundation/print_test.dart
index efbcb45..e20e8ed 100644
--- a/packages/flutter/test/foundation/print_test.dart
+++ b/packages/flutter/test/foundation/print_test.dart
@@ -2,14 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// @dart = 2.8
-
+// @dart = 2.10
import 'package:flutter/foundation.dart';
import 'package:fake_async/fake_async.dart';
import '../flutter_test_alternative.dart';
import 'capture_output.dart';
+String? foo;
+
void main() {
test('debugPrint', () {
expect(
diff --git a/packages/flutter_driver/test/common.dart b/packages/flutter_driver/test/common.dart
index e5987b0..8e78458 100644
--- a/packages/flutter_driver/test/common.dart
+++ b/packages/flutter_driver/test/common.dart
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// @dart = 2.8
+
import 'dart:io';
import 'package:flutter_driver/src/common/error.dart';
diff --git a/packages/flutter_driver/test/flutter_driver_test.dart b/packages/flutter_driver/test/flutter_driver_test.dart
index 95bfba7..339e562 100644
--- a/packages/flutter_driver/test/flutter_driver_test.dart
+++ b/packages/flutter_driver/test/flutter_driver_test.dart
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// @dart = 2.8
+
import 'dart:async';
import 'dart:convert';
diff --git a/packages/flutter_driver/test/src/web_tests/web_extension_test.dart b/packages/flutter_driver/test/src/web_tests/web_extension_test.dart
index 4da772e..6cdb0c8 100644
--- a/packages/flutter_driver/test/src/web_tests/web_extension_test.dart
+++ b/packages/flutter_driver/test/src/web_tests/web_extension_test.dart
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// @dart = 2.8
import 'dart:js' as js;
import 'package:flutter_driver/src/extension/_extension_web.dart';
diff --git a/packages/flutter_driver/test_driver/failure.dart b/packages/flutter_driver/test_driver/failure.dart
index c2d4131..a0c717e 100644
--- a/packages/flutter_driver/test_driver/failure.dart
+++ b/packages/flutter_driver/test_driver/failure.dart
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// @dart = 2.8
+
void main() {
// Dummy. Only needed because driver needs an entry point.
}
diff --git a/packages/flutter_driver/test_driver/failure_test.dart b/packages/flutter_driver/test_driver/failure_test.dart
index 0701284..919bbb3 100644
--- a/packages/flutter_driver/test_driver/failure_test.dart
+++ b/packages/flutter_driver/test_driver/failure_test.dart
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// @dart = 2.8
+
void main() {
// Intentionally fail the test. We want to see driver return a non-zero exit
// code when this happens.
diff --git a/packages/flutter_tools/lib/src/isolated/web_compilation_delegate.dart b/packages/flutter_tools/lib/src/isolated/web_compilation_delegate.dart
index fe5b734..5e226fa 100644
--- a/packages/flutter_tools/lib/src/isolated/web_compilation_delegate.dart
+++ b/packages/flutter_tools/lib/src/isolated/web_compilation_delegate.dart
@@ -226,12 +226,6 @@
'--enable-experiment=non-nullable',
'--skip-build-script-check',
'--define', 'flutter_tools:ddc=flutterWebSdk=$flutterWebSdk',
- '--define', 'flutter_tools:entrypoint=flutterWebSdk=$flutterWebSdk',
- '--define', 'flutter_tools:entrypoint=release=$release',
- '--define', 'flutter_tools:entrypoint=profile=$profile',
- '--define', 'flutter_tools:shell=flutterWebSdk=$flutterWebSdk',
- '--define', 'flutter_tools:shell=hasPlugins=$hasPlugins',
- '--define', 'flutter_tools:shell=initializePlatform=$initializePlatform',
// The following will cause build runner to only build tests that were requested.
if (testTargets != null && testTargets.hasBuildFilters)
for (final String buildFilter in testTargets.buildFilters)
diff --git a/packages/flutter_web_plugins/lib/flutter_web_plugins.dart b/packages/flutter_web_plugins/lib/flutter_web_plugins.dart
index f6bad0d..9459dfc 100644
--- a/packages/flutter_web_plugins/lib/flutter_web_plugins.dart
+++ b/packages/flutter_web_plugins/lib/flutter_web_plugins.dart
@@ -2,5 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// @dart = 2.8
+
export 'src/plugin_event_channel.dart';
export 'src/plugin_registry.dart';
diff --git a/packages/flutter_web_plugins/lib/src/plugin_event_channel.dart b/packages/flutter_web_plugins/lib/src/plugin_event_channel.dart
index 86497fe..d52d249 100644
--- a/packages/flutter_web_plugins/lib/src/plugin_event_channel.dart
+++ b/packages/flutter_web_plugins/lib/src/plugin_event_channel.dart
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// @dart = 2.8
+
import 'dart:async';
import 'package:flutter/services.dart';
diff --git a/packages/flutter_web_plugins/lib/src/plugin_registry.dart b/packages/flutter_web_plugins/lib/src/plugin_registry.dart
index 88bac5e..00eaf85 100644
--- a/packages/flutter_web_plugins/lib/src/plugin_registry.dart
+++ b/packages/flutter_web_plugins/lib/src/plugin_registry.dart
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// @dart = 2.8
+
import 'dart:async';
import 'dart:ui' as ui;
diff --git a/packages/flutter_web_plugins/test/plugin_event_channel_test.dart b/packages/flutter_web_plugins/test/plugin_event_channel_test.dart
index 35eeb3e..6d62b12 100644
--- a/packages/flutter_web_plugins/test/plugin_event_channel_test.dart
+++ b/packages/flutter_web_plugins/test/plugin_event_channel_test.dart
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// @dart = 2.8
+
@TestOn('chrome') // Uses web-only Flutter SDK
import 'dart:async';
diff --git a/packages/flutter_web_plugins/test/plugin_registry_test.dart b/packages/flutter_web_plugins/test/plugin_registry_test.dart
index ac6016f..1088e28 100644
--- a/packages/flutter_web_plugins/test/plugin_registry_test.dart
+++ b/packages/flutter_web_plugins/test/plugin_registry_test.dart
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// @dart = 2.8
+
@TestOn('chrome') // Uses web-only Flutter SDK
import 'dart:ui' as ui;