Starts using the --source flag to compile the dart registrant. (#98046)
* Starts using the `--source` flag to compile the dart registrant. * updated general.shard tests * Fixed the resident compiler flow * added integration test * made the integration test self contained * renamed generated_main to dart_plugin_registrant * cleaned up for review * added task runner for ci * added bringup and TESTOWNERS * updated failure message
This commit is contained in:
@@ -12,7 +12,7 @@ import '../../flutter_plugins.dart';
|
||||
import '../../project.dart';
|
||||
import '../build_system.dart';
|
||||
|
||||
/// Generates a new `./dart_tool/flutter_build/generated_main.dart`
|
||||
/// Generates a new `./dart_tool/flutter_build/dart_plugin_registrant.dart`
|
||||
/// based on the current dependency map in `pubspec.lock`.
|
||||
class DartPluginRegistrantTarget extends Target {
|
||||
/// Construct a [DartPluginRegistrantTarget].
|
||||
@@ -86,7 +86,7 @@ class DartPluginRegistrantTarget extends Target {
|
||||
@override
|
||||
List<Source> get outputs => <Source>[
|
||||
const Source.pattern(
|
||||
'{PROJECT_DIR}/.dart_tool/flutter_build/generated_main.dart',
|
||||
'{PROJECT_DIR}/.dart_tool/flutter_build/dart_plugin_registrant.dart',
|
||||
optional: true,
|
||||
),
|
||||
];
|
||||
|
||||
@@ -261,14 +261,12 @@ class KernelCompiler {
|
||||
if (outputFilePath != null && !_fileSystem.isFileSync(outputFilePath)) {
|
||||
_fileSystem.file(outputFilePath).createSync(recursive: true);
|
||||
}
|
||||
if (buildDir != null && checkDartPluginRegistry) {
|
||||
// Check if there's a Dart plugin registrant.
|
||||
// This is contained in the file `generated_main.dart` under `.dart_tools/flutter_build/`.
|
||||
final File newMainDart = buildDir.parent.childFile('generated_main.dart');
|
||||
if (newMainDart.existsSync()) {
|
||||
mainUri = newMainDart.path;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if there's a Dart plugin registrant.
|
||||
// This is contained in the file `dart_plugin_registrant.dart` under `.dart_tools/flutter_build/`.
|
||||
final File? dartPluginRegistrant = checkDartPluginRegistry
|
||||
? buildDir?.parent.childFile('dart_plugin_registrant.dart')
|
||||
: null;
|
||||
|
||||
final List<String> command = <String>[
|
||||
engineDartPath,
|
||||
@@ -316,6 +314,10 @@ class KernelCompiler {
|
||||
'--platform',
|
||||
platformDill,
|
||||
],
|
||||
if (dartPluginRegistrant != null && dartPluginRegistrant.existsSync()) ...<String>[
|
||||
'--source',
|
||||
dartPluginRegistrant.path,
|
||||
],
|
||||
...?extraFrontEndOptions,
|
||||
mainUri,
|
||||
];
|
||||
@@ -359,6 +361,7 @@ class _RecompileRequest extends _CompilationRequest {
|
||||
this.outputPath,
|
||||
this.packageConfig,
|
||||
this.suppressErrors,
|
||||
{this.additionalSource}
|
||||
) : super(completer);
|
||||
|
||||
Uri mainUri;
|
||||
@@ -366,6 +369,7 @@ class _RecompileRequest extends _CompilationRequest {
|
||||
String outputPath;
|
||||
PackageConfig packageConfig;
|
||||
bool suppressErrors;
|
||||
final String? additionalSource;
|
||||
|
||||
@override
|
||||
Future<CompilerOutput?> _run(DefaultResidentCompiler compiler) async =>
|
||||
@@ -628,24 +632,31 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
if (!_controller.hasListener) {
|
||||
_controller.stream.listen(_handleCompilationRequest);
|
||||
}
|
||||
// `generated_main.dart` contains the Dart plugin registry.
|
||||
String? additionalSource;
|
||||
// `dart_plugin_registrant.dart` contains the Dart plugin registry.
|
||||
if (checkDartPluginRegistry && projectRootPath != null && fs != null) {
|
||||
final File generatedMainDart = fs.file(
|
||||
final File dartPluginRegistrantDart = fs.file(
|
||||
fs.path.join(
|
||||
projectRootPath,
|
||||
'.dart_tool',
|
||||
'flutter_build',
|
||||
'generated_main.dart',
|
||||
'dart_plugin_registrant.dart',
|
||||
),
|
||||
);
|
||||
if (generatedMainDart != null && generatedMainDart.existsSync()) {
|
||||
mainUri = generatedMainDart.uri;
|
||||
if (dartPluginRegistrantDart != null && dartPluginRegistrantDart.existsSync()) {
|
||||
additionalSource = dartPluginRegistrantDart.path;
|
||||
}
|
||||
}
|
||||
final Completer<CompilerOutput?> completer = Completer<CompilerOutput?>();
|
||||
_controller.add(
|
||||
_RecompileRequest(completer, mainUri, invalidatedFiles, outputPath, packageConfig, suppressErrors)
|
||||
);
|
||||
_controller.add(_RecompileRequest(
|
||||
completer,
|
||||
mainUri,
|
||||
invalidatedFiles,
|
||||
outputPath,
|
||||
packageConfig,
|
||||
suppressErrors,
|
||||
additionalSource: additionalSource,
|
||||
));
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
@@ -659,7 +670,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
|
||||
final Process? server = _server;
|
||||
if (server == null) {
|
||||
return _compile(mainUri, request.outputPath);
|
||||
return _compile(mainUri, request.outputPath, additionalSource: request.additionalSource);
|
||||
}
|
||||
final String inputKey = Uuid().generateV4();
|
||||
|
||||
@@ -705,6 +716,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
Future<CompilerOutput?> _compile(
|
||||
String scriptUri,
|
||||
String? outputPath,
|
||||
{String? additionalSource}
|
||||
) async {
|
||||
final String frontendServer = _artifacts.getArtifactPath(
|
||||
Artifact.frontendServerSnapshotForEngineDartSdk
|
||||
@@ -756,6 +768,10 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
'--initialize-from-dill',
|
||||
initializeFromDill!,
|
||||
],
|
||||
if (additionalSource != null) ...<String>[
|
||||
'--source',
|
||||
additionalSource,
|
||||
],
|
||||
if (platformDill != null) ...<String>[
|
||||
'--platform',
|
||||
platformDill!,
|
||||
|
||||
@@ -706,10 +706,6 @@ const String _dartPluginRegistryForNonWebTemplate = '''
|
||||
|
||||
// @dart = {{dartLanguageVersion}}
|
||||
|
||||
// When `{{mainEntrypoint}}` defines `main`, that definition is shadowed by the definition below.
|
||||
export '{{mainEntrypoint}}';
|
||||
|
||||
import '{{mainEntrypoint}}' as entrypoint;
|
||||
import 'dart:io'; // flutter_ignore: dart_io_import.
|
||||
{{#android}}
|
||||
import 'package:{{pluginName}}/{{pluginName}}.dart';
|
||||
@@ -754,18 +750,6 @@ $_dartPluginRegisterWith
|
||||
{{/windows}}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
typedef _UnaryFunction = dynamic Function(List<String> args);
|
||||
typedef _NullaryFunction = dynamic Function();
|
||||
|
||||
void main(List<String> args) {
|
||||
if (entrypoint.main is _UnaryFunction) {
|
||||
(entrypoint.main as _UnaryFunction)(args);
|
||||
} else {
|
||||
(entrypoint.main as _NullaryFunction)();
|
||||
}
|
||||
}
|
||||
''';
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ class FlutterProject {
|
||||
/// The generated Dart plugin registrant for non-web platforms.
|
||||
File get dartPluginRegistrant => dartTool
|
||||
.childDirectory('flutter_build')
|
||||
.childFile('generated_main.dart');
|
||||
.childFile('dart_plugin_registrant.dart');
|
||||
|
||||
/// The example sub-project of this project.
|
||||
FlutterProject get example => FlutterProject(
|
||||
|
||||
Reference in New Issue
Block a user