mirror of
https://github.com/flutter/flutter
synced 2024-09-19 08:11:56 +00:00
[null-safety] pass experiments to builders (#67152)
Force opt-in flutter test platform to null safety for repo testing
This commit is contained in:
parent
b42e34690a
commit
f6cbf488e1
|
@ -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';
|
||||
|
@ -75,27 +72,6 @@ final List<core.BuilderApplication> builders = <core.BuilderApplication>[
|
|||
],
|
||||
),
|
||||
),
|
||||
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],
|
||||
|
@ -127,6 +103,7 @@ final List<core.BuilderApplication> builders = <core.BuilderApplication>[
|
|||
kernelTargetName: 'ddc',
|
||||
useIncrementalCompiler: true,
|
||||
trackUnusedInputs: true,
|
||||
experiments: <String>['non-nullable'], // ignore: deprecated_member_use
|
||||
),
|
||||
(BuilderOptions builderOptions) => DevCompilerBuilder(
|
||||
useIncrementalCompiler: true,
|
||||
|
@ -134,6 +111,7 @@ final List<core.BuilderApplication> builders = <core.BuilderApplication>[
|
|||
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')),
|
||||
),
|
||||
],
|
||||
|
@ -141,23 +119,6 @@ final List<core.BuilderApplication> builders = <core.BuilderApplication>[
|
|||
isOptional: true,
|
||||
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>[
|
||||
|
@ -208,35 +169,6 @@ class FlutterWebTestEntrypointBuilder implements Builder {
|
|||
}
|
||||
}
|
||||
|
||||
/// 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 @@ StreamChannel postMessageChannel() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -226,12 +226,6 @@ class BuildDaemonCreator {
|
|||
'--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)
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue