Dart registrant location (#107967)
This commit is contained in:
parent
6ea83ed594
commit
922eea8763
@ -276,6 +276,13 @@ class KernelCompiler {
|
||||
? buildDir?.parent.childFile('dart_plugin_registrant.dart')
|
||||
: null;
|
||||
|
||||
String? dartPluginRegistrantUri;
|
||||
if (dartPluginRegistrant != null && dartPluginRegistrant.existsSync()) {
|
||||
final Uri dartPluginRegistrantFileUri = dartPluginRegistrant.uri;
|
||||
dartPluginRegistrantUri = packageConfig.toPackageUri(dartPluginRegistrantFileUri)?.toString() ??
|
||||
toMultiRootPath(dartPluginRegistrantFileUri, _fileSystemScheme, _fileSystemRoots, _fileSystem.path.separator == r'\');
|
||||
}
|
||||
|
||||
final List<String> command = <String>[
|
||||
engineDartPath,
|
||||
'--disable-dart-dev',
|
||||
@ -323,12 +330,12 @@ class KernelCompiler {
|
||||
'--platform',
|
||||
platformDill,
|
||||
],
|
||||
if (dartPluginRegistrant != null && dartPluginRegistrant.existsSync()) ...<String>[
|
||||
if (dartPluginRegistrantUri != null) ...<String>[
|
||||
'--source',
|
||||
dartPluginRegistrant.path,
|
||||
dartPluginRegistrantUri,
|
||||
'--source',
|
||||
'package:flutter/src/dart_plugin_registrant.dart',
|
||||
'-Dflutter.dart_plugin_registrant=${dartPluginRegistrant.uri}',
|
||||
'-Dflutter.dart_plugin_registrant=$dartPluginRegistrantUri',
|
||||
],
|
||||
// See: https://github.com/flutter/flutter/issues/103994
|
||||
'--verbosity=error',
|
||||
@ -375,7 +382,7 @@ class _RecompileRequest extends _CompilationRequest {
|
||||
this.outputPath,
|
||||
this.packageConfig,
|
||||
this.suppressErrors,
|
||||
{this.additionalSource}
|
||||
{this.additionalSourceUri}
|
||||
);
|
||||
|
||||
Uri mainUri;
|
||||
@ -383,7 +390,7 @@ class _RecompileRequest extends _CompilationRequest {
|
||||
String outputPath;
|
||||
PackageConfig packageConfig;
|
||||
bool suppressErrors;
|
||||
final String? additionalSource;
|
||||
final Uri? additionalSourceUri;
|
||||
|
||||
@override
|
||||
Future<CompilerOutput?> _run(DefaultResidentCompiler compiler) async =>
|
||||
@ -499,6 +506,7 @@ abstract class ResidentCompiler {
|
||||
String? projectRootPath,
|
||||
bool suppressErrors = false,
|
||||
bool checkDartPluginRegistry = false,
|
||||
File? dartPluginRegistrant,
|
||||
});
|
||||
|
||||
Future<CompilerOutput?> compileExpression(
|
||||
@ -642,6 +650,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
required PackageConfig packageConfig,
|
||||
bool suppressErrors = false,
|
||||
bool checkDartPluginRegistry = false,
|
||||
File? dartPluginRegistrant,
|
||||
String? projectRootPath,
|
||||
FileSystem? fs,
|
||||
}) async {
|
||||
@ -649,20 +658,10 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
if (!_controller.hasListener) {
|
||||
_controller.stream.listen(_handleCompilationRequest);
|
||||
}
|
||||
String? additionalSource;
|
||||
Uri? additionalSourceUri;
|
||||
// `dart_plugin_registrant.dart` contains the Dart plugin registry.
|
||||
if (checkDartPluginRegistry && projectRootPath != null && fs != null) {
|
||||
final File dartPluginRegistrantDart = fs.file(
|
||||
fs.path.join(
|
||||
projectRootPath,
|
||||
'.dart_tool',
|
||||
'flutter_build',
|
||||
'dart_plugin_registrant.dart',
|
||||
),
|
||||
);
|
||||
if (dartPluginRegistrantDart != null && dartPluginRegistrantDart.existsSync()) {
|
||||
additionalSource = dartPluginRegistrantDart.path;
|
||||
}
|
||||
if (checkDartPluginRegistry && dartPluginRegistrant != null && dartPluginRegistrant.existsSync()) {
|
||||
additionalSourceUri = dartPluginRegistrant.uri;
|
||||
}
|
||||
final Completer<CompilerOutput?> completer = Completer<CompilerOutput?>();
|
||||
_controller.add(_RecompileRequest(
|
||||
@ -672,7 +671,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
outputPath,
|
||||
packageConfig,
|
||||
suppressErrors,
|
||||
additionalSource: additionalSource,
|
||||
additionalSourceUri: additionalSourceUri,
|
||||
));
|
||||
return completer.future;
|
||||
}
|
||||
@ -685,9 +684,15 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
final String mainUri = request.packageConfig.toPackageUri(request.mainUri)?.toString() ??
|
||||
toMultiRootPath(request.mainUri, fileSystemScheme, fileSystemRoots, _platform.isWindows);
|
||||
|
||||
String? additionalSourceUri;
|
||||
if (request.additionalSourceUri != null) {
|
||||
additionalSourceUri = request.packageConfig.toPackageUri(request.additionalSourceUri!)?.toString() ??
|
||||
toMultiRootPath(request.additionalSourceUri!, fileSystemScheme, fileSystemRoots, _platform.isWindows);
|
||||
}
|
||||
|
||||
final Process? server = _server;
|
||||
if (server == null) {
|
||||
return _compile(mainUri, request.outputPath, additionalSource: request.additionalSource);
|
||||
return _compile(mainUri, request.outputPath, additionalSourceUri: additionalSourceUri);
|
||||
}
|
||||
final String inputKey = Uuid().generateV4();
|
||||
|
||||
@ -733,7 +738,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
Future<CompilerOutput?> _compile(
|
||||
String scriptUri,
|
||||
String? outputPath,
|
||||
{String? additionalSource}
|
||||
{String? additionalSourceUri}
|
||||
) async {
|
||||
final String frontendServer = _artifacts.getArtifactPath(
|
||||
Artifact.frontendServerSnapshotForEngineDartSdk
|
||||
@ -786,12 +791,12 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
initializeFromDill!,
|
||||
],
|
||||
if (assumeInitializeFromDillUpToDate) '--assume-initialize-from-dill-up-to-date',
|
||||
if (additionalSource != null) ...<String>[
|
||||
if (additionalSourceUri != null) ...<String>[
|
||||
'--source',
|
||||
additionalSource,
|
||||
additionalSourceUri,
|
||||
'--source',
|
||||
'package:flutter/src/dart_plugin_registrant.dart',
|
||||
'-Dflutter.dart_plugin_registrant=${Uri.file(additionalSource)}',
|
||||
'-Dflutter.dart_plugin_registrant=$additionalSourceUri',
|
||||
],
|
||||
if (platformDill != null) ...<String>[
|
||||
'--platform',
|
||||
|
@ -581,6 +581,7 @@ class DevFS {
|
||||
bool bundleFirstUpload = false,
|
||||
bool fullRestart = false,
|
||||
String? projectRootPath,
|
||||
File? dartPluginRegistrant,
|
||||
}) async {
|
||||
assert(trackWidgetCreation != null);
|
||||
assert(generator != null);
|
||||
@ -610,6 +611,7 @@ class DevFS {
|
||||
projectRootPath: projectRootPath,
|
||||
packageConfig: packageConfig,
|
||||
checkDartPluginRegistry: true, // The entry point is assumed not to have changed.
|
||||
dartPluginRegistrant: dartPluginRegistrant,
|
||||
).then((CompilerOutput? result) {
|
||||
compileTimer.stop();
|
||||
return result;
|
||||
|
@ -799,6 +799,7 @@ class WebDevFS implements DevFS {
|
||||
bool bundleFirstUpload = false,
|
||||
bool fullRestart = false,
|
||||
String? projectRootPath,
|
||||
File? dartPluginRegistrant,
|
||||
}) async {
|
||||
assert(trackWidgetCreation != null);
|
||||
assert(generator != null);
|
||||
@ -866,6 +867,7 @@ class WebDevFS implements DevFS {
|
||||
packageConfig: packageConfig,
|
||||
projectRootPath: projectRootPath,
|
||||
fs: globals.fs,
|
||||
dartPluginRegistrant: dartPluginRegistrant,
|
||||
);
|
||||
if (compilerOutput == null || compilerOutput.errorCount > 0) {
|
||||
return UpdateFSReport();
|
||||
|
@ -563,6 +563,7 @@ class FlutterDevice {
|
||||
invalidatedFiles: invalidatedFiles,
|
||||
packageConfig: packageConfig,
|
||||
devFSWriter: devFSWriter,
|
||||
dartPluginRegistrant: FlutterProject.current().dartPluginRegistrant,
|
||||
);
|
||||
} on DevFSException {
|
||||
devFSStatus.cancel();
|
||||
|
@ -373,6 +373,7 @@ class HotRunner extends ResidentRunner {
|
||||
// should only be displayed once.
|
||||
suppressErrors: applicationBinary == null,
|
||||
checkDartPluginRegistry: true,
|
||||
dartPluginRegistrant: FlutterProject.current().dartPluginRegistrant,
|
||||
outputPath: dillOutputPath,
|
||||
packageConfig: debuggingOptions.buildInfo.packageConfig,
|
||||
projectRootPath: FlutterProject.current().directory.absolute.path,
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/artifacts.dart';
|
||||
import 'package:flutter_tools/src/base/async_guard.dart';
|
||||
@ -394,6 +395,43 @@ void main() {
|
||||
'line2\nline3\n'
|
||||
));
|
||||
});
|
||||
|
||||
testWithoutContext('incremental compile with dartPluginRegistrant', () async {
|
||||
fakeProcessManager.addCommand(FakeCommand(
|
||||
command: const <String>[
|
||||
...frontendServerCommand,
|
||||
'--filesystem-root',
|
||||
'/foo/bar/fizz',
|
||||
'--filesystem-scheme',
|
||||
'scheme',
|
||||
'--source',
|
||||
'some/dir/plugin_registrant.dart',
|
||||
'--source',
|
||||
'package:flutter/src/dart_plugin_registrant.dart',
|
||||
'-Dflutter.dart_plugin_registrant=some/dir/plugin_registrant.dart',
|
||||
'--verbosity=error',
|
||||
],
|
||||
stdout: 'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0',
|
||||
stdin: frontendServerStdIn,
|
||||
));
|
||||
|
||||
final MemoryFileSystem fs = MemoryFileSystem();
|
||||
final File dartPluginRegistrant = fs.file('some/dir/plugin_registrant.dart')..createSync(recursive: true);
|
||||
final CompilerOutput? output = await generatorWithScheme.recompile(
|
||||
Uri.parse('file:///foo/bar/fizz/main.dart'),
|
||||
null /* invalidatedFiles */,
|
||||
outputPath: '/build/',
|
||||
packageConfig: PackageConfig.empty,
|
||||
fs: fs,
|
||||
projectRootPath: '',
|
||||
checkDartPluginRegistry: true,
|
||||
dartPluginRegistrant: dartPluginRegistrant,
|
||||
);
|
||||
expect(frontendServerStdIn.getAndClear(), 'compile scheme:///main.dart\n');
|
||||
expect(testLogger.errorText, equals('line1\nline2\n'));
|
||||
expect(output?.outputFilename, equals('/path/to/main.dart.dill'));
|
||||
expect(fakeProcessManager, hasNoRemainingExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _recompile(
|
||||
|
@ -581,7 +581,7 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
|
||||
Future<CompilerOutput> Function(Uri mainUri, List<Uri>? invalidatedFiles)? onRecompile;
|
||||
|
||||
@override
|
||||
Future<CompilerOutput> recompile(Uri mainUri, List<Uri>? invalidatedFiles, {String? outputPath, PackageConfig? packageConfig, String? projectRootPath, FileSystem? fs, bool suppressErrors = false, bool checkDartPluginRegistry = false}) {
|
||||
Future<CompilerOutput> recompile(Uri mainUri, List<Uri>? invalidatedFiles, {String? outputPath, PackageConfig? packageConfig, String? projectRootPath, FileSystem? fs, bool suppressErrors = false, bool checkDartPluginRegistry = false, File? dartPluginRegistrant}) {
|
||||
return onRecompile?.call(mainUri, invalidatedFiles)
|
||||
?? Future<CompilerOutput>.value(const CompilerOutput('', 1, <Uri>[]));
|
||||
}
|
||||
|
@ -2464,6 +2464,7 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
|
||||
@required FileSystem fs,
|
||||
bool suppressErrors = false,
|
||||
bool checkDartPluginRegistry = false,
|
||||
File dartPluginRegistrant,
|
||||
}) async {
|
||||
didSuppressErrors = suppressErrors;
|
||||
return nextOutput ?? const CompilerOutput('foo.dill', 0, <Uri>[]);
|
||||
@ -2623,6 +2624,7 @@ class FakeDevFS extends Fake implements DevFS {
|
||||
bool bundleFirstUpload = false,
|
||||
bool fullRestart = false,
|
||||
String projectRootPath,
|
||||
File dartPluginRegistrant,
|
||||
}) async {
|
||||
return nextUpdateReport;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -200,6 +200,7 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
|
||||
FileSystem? fs,
|
||||
bool suppressErrors = false,
|
||||
bool checkDartPluginRegistry = false,
|
||||
File? dartPluginRegistrant,
|
||||
}) async {
|
||||
if (compilerOutput != null) {
|
||||
fileSystem!.file(compilerOutput!.outputFilename).createSync(recursive: true);
|
||||
|
@ -1120,6 +1120,7 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
|
||||
FileSystem fs,
|
||||
bool suppressErrors = false,
|
||||
bool checkDartPluginRegistry = false,
|
||||
File dartPluginRegistrant,
|
||||
}) async {
|
||||
return output;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user