Read dart_plugin_registrant path from FlutterProject to support non-standard path. (#107617)

This commit is contained in:
Lau Ching Jun
2022-07-15 12:33:07 -07:00
committed by GitHub
parent cdf4a6a2f5
commit 8f834cf150
11 changed files with 376 additions and 212 deletions

View File

@@ -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(

View File

@@ -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>[]));
}

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -1120,6 +1120,7 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
FileSystem fs,
bool suppressErrors = false,
bool checkDartPluginRegistry = false,
File dartPluginRegistrant,
}) async {
return output;
}