Fix Dart plugin registrant interaction with 'flutter test' (#90288)
Building an application for a desktop platform that transitively included any Dart-based plugins (such as path_provider) broke `flutter test`, because its compilation was overriding the provided main (in this case, the test main) with `generated_main.dart` if it was present. This PR: - Changes the `flutter test` compilation path to update `generated_main.dart`, so that the tests will work, and will include any registered Dart plugins. - Makes using `generated_main.dart` during recompile opt-in, to try to reduce the chance of a similar bug happening with other codepaths in the future. Fixes https://github.com/flutter/flutter/issues/88794
This commit is contained in:
parent
dc59bc5444
commit
97fb8c0560
@ -33,27 +33,23 @@ class DartPluginRegistrantTarget extends Target {
|
|||||||
@override
|
@override
|
||||||
Future<void> build(Environment environment) async {
|
Future<void> build(Environment environment) async {
|
||||||
assert(environment.generateDartPluginRegistry);
|
assert(environment.generateDartPluginRegistry);
|
||||||
final File packagesFile = environment.projectDir
|
final FlutterProject project = _project
|
||||||
.childDirectory('.dart_tool')
|
?? FlutterProject.fromDirectory(environment.projectDir);
|
||||||
.childFile('package_config.json');
|
|
||||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||||
packagesFile,
|
project.packageConfigFile,
|
||||||
logger: environment.logger,
|
logger: environment.logger,
|
||||||
);
|
);
|
||||||
final String targetFile = environment.defines[kTargetFile] ??
|
final String targetFilePath = environment.defines[kTargetFile] ??
|
||||||
environment.fileSystem.path.join('lib', 'main.dart');
|
environment.fileSystem.path.join('lib', 'main.dart');
|
||||||
final File mainFile = environment.fileSystem.file(targetFile);
|
final File mainFile = environment.fileSystem.file(targetFilePath);
|
||||||
final Uri mainFileUri = mainFile.absolute.uri;
|
final Uri mainFileUri = mainFile.absolute.uri;
|
||||||
final String mainUri = packageConfig.toPackageUri(mainFileUri)?.toString() ?? mainFileUri.toString();
|
final String mainFileUriString = packageConfig.toPackageUri(mainFileUri)?.toString()
|
||||||
final File newMainDart = environment.projectDir
|
?? mainFileUri.toString();
|
||||||
.childDirectory('.dart_tool')
|
|
||||||
.childDirectory('flutter_build')
|
|
||||||
.childFile('generated_main.dart');
|
|
||||||
await generateMainDartWithPluginRegistrant(
|
await generateMainDartWithPluginRegistrant(
|
||||||
_project ?? FlutterProject.fromDirectory(environment.projectDir),
|
project,
|
||||||
packageConfig,
|
packageConfig,
|
||||||
mainUri,
|
mainFileUriString,
|
||||||
newMainDart,
|
|
||||||
mainFile,
|
mainFile,
|
||||||
throwOnPluginPubspecError: false,
|
throwOnPluginPubspecError: false,
|
||||||
);
|
);
|
||||||
|
@ -462,6 +462,10 @@ abstract class ResidentCompiler {
|
|||||||
/// point that is used for recompilation.
|
/// point that is used for recompilation.
|
||||||
/// Binary file name is returned if compilation was successful, otherwise
|
/// Binary file name is returned if compilation was successful, otherwise
|
||||||
/// null is returned.
|
/// null is returned.
|
||||||
|
///
|
||||||
|
/// If [checkDartPluginRegistry] is true, it is the caller's responsibility
|
||||||
|
/// to ensure that the generated registrant file has been updated such that
|
||||||
|
/// it is wrapping [mainUri].
|
||||||
Future<CompilerOutput?> recompile(
|
Future<CompilerOutput?> recompile(
|
||||||
Uri mainUri,
|
Uri mainUri,
|
||||||
List<Uri>? invalidatedFiles, {
|
List<Uri>? invalidatedFiles, {
|
||||||
@ -470,6 +474,7 @@ abstract class ResidentCompiler {
|
|||||||
required String projectRootPath,
|
required String projectRootPath,
|
||||||
required FileSystem fs,
|
required FileSystem fs,
|
||||||
bool suppressErrors = false,
|
bool suppressErrors = false,
|
||||||
|
bool checkDartPluginRegistry = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<CompilerOutput?> compileExpression(
|
Future<CompilerOutput?> compileExpression(
|
||||||
@ -610,6 +615,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
|||||||
required String outputPath,
|
required String outputPath,
|
||||||
required PackageConfig packageConfig,
|
required PackageConfig packageConfig,
|
||||||
bool suppressErrors = false,
|
bool suppressErrors = false,
|
||||||
|
bool checkDartPluginRegistry = false,
|
||||||
String? projectRootPath,
|
String? projectRootPath,
|
||||||
FileSystem? fs,
|
FileSystem? fs,
|
||||||
}) async {
|
}) async {
|
||||||
@ -618,7 +624,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
|||||||
_controller.stream.listen(_handleCompilationRequest);
|
_controller.stream.listen(_handleCompilationRequest);
|
||||||
}
|
}
|
||||||
// `generated_main.dart` contains the Dart plugin registry.
|
// `generated_main.dart` contains the Dart plugin registry.
|
||||||
if (projectRootPath != null && fs != null) {
|
if (checkDartPluginRegistry && projectRootPath != null && fs != null) {
|
||||||
final File generatedMainDart = fs.file(
|
final File generatedMainDart = fs.file(
|
||||||
fs.path.join(
|
fs.path.join(
|
||||||
projectRootPath,
|
projectRootPath,
|
||||||
|
@ -613,6 +613,7 @@ class DevFS {
|
|||||||
fs: _fileSystem,
|
fs: _fileSystem,
|
||||||
projectRootPath: projectRootPath,
|
projectRootPath: projectRootPath,
|
||||||
packageConfig: packageConfig,
|
packageConfig: packageConfig,
|
||||||
|
checkDartPluginRegistry: true, // The entry point is assumed not to have changed.
|
||||||
).then((CompilerOutput result) {
|
).then((CompilerOutput result) {
|
||||||
compileTimer.stop();
|
compileTimer.stop();
|
||||||
return result;
|
return result;
|
||||||
|
@ -1233,7 +1233,6 @@ Future<void> generateMainDartWithPluginRegistrant(
|
|||||||
FlutterProject rootProject,
|
FlutterProject rootProject,
|
||||||
PackageConfig packageConfig,
|
PackageConfig packageConfig,
|
||||||
String currentMainUri,
|
String currentMainUri,
|
||||||
File newMainDart,
|
|
||||||
File mainFile, {
|
File mainFile, {
|
||||||
bool throwOnPluginPubspecError = false,
|
bool throwOnPluginPubspecError = false,
|
||||||
}) async {
|
}) async {
|
||||||
@ -1254,6 +1253,7 @@ Future<void> generateMainDartWithPluginRegistrant(
|
|||||||
MacOSPlugin.kConfigKey: <Object?>[],
|
MacOSPlugin.kConfigKey: <Object?>[],
|
||||||
WindowsPlugin.kConfigKey: <Object?>[],
|
WindowsPlugin.kConfigKey: <Object?>[],
|
||||||
};
|
};
|
||||||
|
final File newMainDart = rootProject.dartPluginRegistrant;
|
||||||
if (resolutions.isEmpty) {
|
if (resolutions.isEmpty) {
|
||||||
try {
|
try {
|
||||||
if (newMainDart.existsSync()) {
|
if (newMainDart.existsSync()) {
|
||||||
|
@ -219,6 +219,11 @@ class FlutterProject {
|
|||||||
.childDirectory('generated')
|
.childDirectory('generated')
|
||||||
.childDirectory(manifest.appName);
|
.childDirectory(manifest.appName);
|
||||||
|
|
||||||
|
/// The generated Dart plugin registrant for non-web platforms.
|
||||||
|
File get dartPluginRegistrant => dartTool
|
||||||
|
.childDirectory('flutter_build')
|
||||||
|
.childFile('generated_main.dart');
|
||||||
|
|
||||||
/// The example sub-project of this project.
|
/// The example sub-project of this project.
|
||||||
FlutterProject get example => FlutterProject(
|
FlutterProject get example => FlutterProject(
|
||||||
_exampleDirectory(directory),
|
_exampleDirectory(directory),
|
||||||
|
@ -381,6 +381,7 @@ class HotRunner extends ResidentRunner {
|
|||||||
// the native build step. If there is a Dart compilation error, it
|
// the native build step. If there is a Dart compilation error, it
|
||||||
// should only be displayed once.
|
// should only be displayed once.
|
||||||
suppressErrors: applicationBinary == null,
|
suppressErrors: applicationBinary == null,
|
||||||
|
checkDartPluginRegistry: true,
|
||||||
outputPath: dillOutputPath ??
|
outputPath: dillOutputPath ??
|
||||||
getDefaultApplicationKernelPath(
|
getDefaultApplicationKernelPath(
|
||||||
trackWidgetCreation: debuggingOptions.buildInfo.trackWidgetCreation,
|
trackWidgetCreation: debuggingOptions.buildInfo.trackWidgetCreation,
|
||||||
|
@ -13,6 +13,7 @@ import '../base/file_system.dart';
|
|||||||
import '../build_info.dart';
|
import '../build_info.dart';
|
||||||
import '../bundle.dart';
|
import '../bundle.dart';
|
||||||
import '../compile.dart';
|
import '../compile.dart';
|
||||||
|
import '../flutter_plugins.dart';
|
||||||
import '../globals_null_migrated.dart' as globals;
|
import '../globals_null_migrated.dart' as globals;
|
||||||
import '../project.dart';
|
import '../project.dart';
|
||||||
|
|
||||||
@ -143,12 +144,29 @@ class TestCompiler {
|
|||||||
compiler = await createCompiler();
|
compiler = await createCompiler();
|
||||||
firstCompile = true;
|
firstCompile = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final List<Uri> invalidatedRegistrantFiles = <Uri>[];
|
||||||
|
if (flutterProject != null) {
|
||||||
|
// Update the generated registrant to use the test target's main.
|
||||||
|
final String mainUriString = buildInfo.packageConfig.toPackageUri(request.mainUri)?.toString()
|
||||||
|
?? request.mainUri.toString();
|
||||||
|
await generateMainDartWithPluginRegistrant(
|
||||||
|
flutterProject,
|
||||||
|
buildInfo.packageConfig,
|
||||||
|
mainUriString,
|
||||||
|
globals.fs.file(request.mainUri),
|
||||||
|
throwOnPluginPubspecError: false,
|
||||||
|
);
|
||||||
|
invalidatedRegistrantFiles.add(flutterProject.dartPluginRegistrant.absolute.uri);
|
||||||
|
}
|
||||||
|
|
||||||
final CompilerOutput compilerOutput = await compiler.recompile(
|
final CompilerOutput compilerOutput = await compiler.recompile(
|
||||||
request.mainUri,
|
request.mainUri,
|
||||||
<Uri>[request.mainUri],
|
<Uri>[request.mainUri, ...invalidatedRegistrantFiles],
|
||||||
outputPath: outputDill.path,
|
outputPath: outputDill.path,
|
||||||
packageConfig: buildInfo.packageConfig,
|
packageConfig: buildInfo.packageConfig,
|
||||||
projectRootPath: flutterProject?.directory?.absolute?.path,
|
projectRootPath: flutterProject?.directory?.absolute?.path,
|
||||||
|
checkDartPluginRegistry: true,
|
||||||
fs: globals.fs,
|
fs: globals.fs,
|
||||||
);
|
);
|
||||||
final String outputPath = compilerOutput?.outputFilename;
|
final String outputPath = compilerOutput?.outputFilename;
|
||||||
|
@ -33,7 +33,8 @@ void main() {
|
|||||||
..manifest = flutterManifest
|
..manifest = flutterManifest
|
||||||
..directory = directory
|
..directory = directory
|
||||||
..flutterPluginsFile = directory.childFile('.flutter-plugins')
|
..flutterPluginsFile = directory.childFile('.flutter-plugins')
|
||||||
..flutterPluginsDependenciesFile = directory.childFile('.flutter-plugins-dependencies');
|
..flutterPluginsDependenciesFile = directory.childFile('.flutter-plugins-dependencies')
|
||||||
|
..dartPluginRegistrant = directory.childFile('generated_main.dart');
|
||||||
flutterProject.directory.childFile('.packages').createSync(recursive: true);
|
flutterProject.directory.childFile('.packages').createSync(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -610,7 +611,6 @@ void main() {
|
|||||||
void main() {
|
void main() {
|
||||||
}
|
}
|
||||||
''');
|
''');
|
||||||
final File generatedMainFile = flutterProject.directory.childFile('generated_main.dart');
|
|
||||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||||
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json'),
|
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json'),
|
||||||
logger: globals.logger,
|
logger: globals.logger,
|
||||||
@ -620,11 +620,10 @@ void main() {
|
|||||||
flutterProject,
|
flutterProject,
|
||||||
packageConfig,
|
packageConfig,
|
||||||
'package:app/main.dart',
|
'package:app/main.dart',
|
||||||
generatedMainFile,
|
|
||||||
mainFile,
|
mainFile,
|
||||||
throwOnPluginPubspecError: true,
|
throwOnPluginPubspecError: true,
|
||||||
);
|
);
|
||||||
expect(generatedMainFile.readAsStringSync(),
|
expect(flutterProject.dartPluginRegistrant.readAsStringSync(),
|
||||||
'//\n'
|
'//\n'
|
||||||
'// Generated file. Do not edit.\n'
|
'// Generated file. Do not edit.\n'
|
||||||
'// This file is generated from template in file `flutter_tools/lib/src/flutter_plugins.dart`.\n'
|
'// This file is generated from template in file `flutter_tools/lib/src/flutter_plugins.dart`.\n'
|
||||||
@ -730,7 +729,6 @@ void main() {
|
|||||||
libDir.createSync(recursive: true);
|
libDir.createSync(recursive: true);
|
||||||
|
|
||||||
final File mainFile = libDir.childFile('main.dart')..writeAsStringSync('');
|
final File mainFile = libDir.childFile('main.dart')..writeAsStringSync('');
|
||||||
final File generatedMainFile = flutterProject.directory.childFile('generated_main.dart');
|
|
||||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||||
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json'),
|
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json'),
|
||||||
logger: globals.logger,
|
logger: globals.logger,
|
||||||
@ -741,7 +739,6 @@ void main() {
|
|||||||
flutterProject,
|
flutterProject,
|
||||||
packageConfig,
|
packageConfig,
|
||||||
'package:app/main.dart',
|
'package:app/main.dart',
|
||||||
generatedMainFile,
|
|
||||||
mainFile,
|
mainFile,
|
||||||
throwOnPluginPubspecError: true,
|
throwOnPluginPubspecError: true,
|
||||||
), throwsToolExit(message:
|
), throwsToolExit(message:
|
||||||
@ -773,7 +770,6 @@ void main() {
|
|||||||
libDir.createSync(recursive: true);
|
libDir.createSync(recursive: true);
|
||||||
|
|
||||||
final File mainFile = libDir.childFile('main.dart')..writeAsStringSync('');
|
final File mainFile = libDir.childFile('main.dart')..writeAsStringSync('');
|
||||||
final File generatedMainFile = flutterProject.directory.childFile('generated_main.dart');
|
|
||||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||||
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json'),
|
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json'),
|
||||||
logger: globals.logger,
|
logger: globals.logger,
|
||||||
@ -784,7 +780,6 @@ void main() {
|
|||||||
flutterProject,
|
flutterProject,
|
||||||
packageConfig,
|
packageConfig,
|
||||||
'package:app/main.dart',
|
'package:app/main.dart',
|
||||||
generatedMainFile,
|
|
||||||
mainFile,
|
mainFile,
|
||||||
throwOnPluginPubspecError: true,
|
throwOnPluginPubspecError: true,
|
||||||
), throwsToolExit(message:
|
), throwsToolExit(message:
|
||||||
@ -834,7 +829,6 @@ void main() {
|
|||||||
libDir.createSync(recursive: true);
|
libDir.createSync(recursive: true);
|
||||||
|
|
||||||
final File mainFile = libDir.childFile('main.dart')..writeAsStringSync('');
|
final File mainFile = libDir.childFile('main.dart')..writeAsStringSync('');
|
||||||
final File generatedMainFile = flutterProject.directory.childFile('generated_main.dart');
|
|
||||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||||
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json'),
|
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json'),
|
||||||
logger: globals.logger,
|
logger: globals.logger,
|
||||||
@ -844,11 +838,10 @@ void main() {
|
|||||||
flutterProject,
|
flutterProject,
|
||||||
packageConfig,
|
packageConfig,
|
||||||
'package:app/main.dart',
|
'package:app/main.dart',
|
||||||
generatedMainFile,
|
|
||||||
mainFile,
|
mainFile,
|
||||||
throwOnPluginPubspecError: true,
|
throwOnPluginPubspecError: true,
|
||||||
);
|
);
|
||||||
expect(generatedMainFile.existsSync(), isFalse);
|
expect(flutterProject.dartPluginRegistrant.existsSync(), isFalse);
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: <Type, Generator>{
|
||||||
FileSystem: () => fs,
|
FileSystem: () => fs,
|
||||||
ProcessManager: () => FakeProcessManager.any(),
|
ProcessManager: () => FakeProcessManager.any(),
|
||||||
@ -876,7 +869,6 @@ void main() {
|
|||||||
libDir.createSync(recursive: true);
|
libDir.createSync(recursive: true);
|
||||||
|
|
||||||
final File mainFile = libDir.childFile('main.dart')..writeAsStringSync('');
|
final File mainFile = libDir.childFile('main.dart')..writeAsStringSync('');
|
||||||
final File generatedMainFile = flutterProject.directory.childFile('generated_main.dart');
|
|
||||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||||
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json'),
|
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json'),
|
||||||
logger: globals.logger,
|
logger: globals.logger,
|
||||||
@ -886,11 +878,10 @@ void main() {
|
|||||||
flutterProject,
|
flutterProject,
|
||||||
packageConfig,
|
packageConfig,
|
||||||
'package:app/main.dart',
|
'package:app/main.dart',
|
||||||
generatedMainFile,
|
|
||||||
mainFile,
|
mainFile,
|
||||||
throwOnPluginPubspecError: true,
|
throwOnPluginPubspecError: true,
|
||||||
);
|
);
|
||||||
expect(generatedMainFile.existsSync(), isTrue);
|
expect(flutterProject.dartPluginRegistrant.existsSync(), isTrue);
|
||||||
|
|
||||||
// No plugins.
|
// No plugins.
|
||||||
createFakeDartPlugins(
|
createFakeDartPlugins(
|
||||||
@ -903,11 +894,10 @@ void main() {
|
|||||||
flutterProject,
|
flutterProject,
|
||||||
packageConfig,
|
packageConfig,
|
||||||
'package:app/main.dart',
|
'package:app/main.dart',
|
||||||
generatedMainFile,
|
|
||||||
mainFile,
|
mainFile,
|
||||||
throwOnPluginPubspecError: true,
|
throwOnPluginPubspecError: true,
|
||||||
);
|
);
|
||||||
expect(generatedMainFile.existsSync(), isFalse);
|
expect(flutterProject.dartPluginRegistrant.existsSync(), isFalse);
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: <Type, Generator>{
|
||||||
FileSystem: () => fs,
|
FileSystem: () => fs,
|
||||||
ProcessManager: () => FakeProcessManager.any(),
|
ProcessManager: () => FakeProcessManager.any(),
|
||||||
@ -962,6 +952,9 @@ class FakeFlutterProject extends Fake implements FlutterProject {
|
|||||||
@override
|
@override
|
||||||
File flutterPluginsDependenciesFile;
|
File flutterPluginsDependenciesFile;
|
||||||
|
|
||||||
|
@override
|
||||||
|
File dartPluginRegistrant;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
IosProject ios;
|
IosProject ios;
|
||||||
|
|
||||||
|
@ -476,7 +476,7 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
|
|||||||
Future<CompilerOutput> Function(Uri mainUri, List<Uri> invalidatedFiles) onRecompile;
|
Future<CompilerOutput> Function(Uri mainUri, List<Uri> invalidatedFiles) onRecompile;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<CompilerOutput> recompile(Uri mainUri, List<Uri> invalidatedFiles, {String outputPath, PackageConfig packageConfig, String projectRootPath, FileSystem fs, bool suppressErrors = false}) {
|
Future<CompilerOutput> recompile(Uri mainUri, List<Uri> invalidatedFiles, {String outputPath, PackageConfig packageConfig, String projectRootPath, FileSystem fs, bool suppressErrors = false, bool checkDartPluginRegistry = false}) {
|
||||||
return onRecompile?.call(mainUri, invalidatedFiles)
|
return onRecompile?.call(mainUri, invalidatedFiles)
|
||||||
?? Future<CompilerOutput>.value(const CompilerOutput('', 1, <Uri>[]));
|
?? Future<CompilerOutput>.value(const CompilerOutput('', 1, <Uri>[]));
|
||||||
}
|
}
|
||||||
|
@ -2191,6 +2191,7 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
|
|||||||
@required String projectRootPath,
|
@required String projectRootPath,
|
||||||
@required FileSystem fs,
|
@required FileSystem fs,
|
||||||
bool suppressErrors = false,
|
bool suppressErrors = false,
|
||||||
|
bool checkDartPluginRegistry = false,
|
||||||
}) async {
|
}) async {
|
||||||
didSuppressErrors = suppressErrors;
|
didSuppressErrors = suppressErrors;
|
||||||
return nextOutput ?? const CompilerOutput('foo.dill', 0, <Uri>[]);
|
return nextOutput ?? const CompilerOutput('foo.dill', 0, <Uri>[]);
|
||||||
|
@ -1115,6 +1115,7 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
|
|||||||
@required String projectRootPath,
|
@required String projectRootPath,
|
||||||
@required FileSystem fs,
|
@required FileSystem fs,
|
||||||
bool suppressErrors = false,
|
bool suppressErrors = false,
|
||||||
|
bool checkDartPluginRegistry = false,
|
||||||
}) async {
|
}) async {
|
||||||
return const CompilerOutput('foo.dill', 0, <Uri>[]);
|
return const CompilerOutput('foo.dill', 0, <Uri>[]);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
// @dart = 2.8
|
// @dart = 2.8
|
||||||
|
|
||||||
import 'package:file/memory.dart';
|
import 'package:file/memory.dart';
|
||||||
|
import 'package:file_testing/file_testing.dart';
|
||||||
import 'package:flutter_tools/src/base/file_system.dart';
|
import 'package:flutter_tools/src/base/file_system.dart';
|
||||||
import 'package:flutter_tools/src/base/logger.dart';
|
import 'package:flutter_tools/src/base/logger.dart';
|
||||||
import 'package:flutter_tools/src/base/platform.dart';
|
import 'package:flutter_tools/src/base/platform.dart';
|
||||||
@ -40,6 +41,7 @@ void main() {
|
|||||||
fileSystem = MemoryFileSystem.test();
|
fileSystem = MemoryFileSystem.test();
|
||||||
fileSystem.file('pubspec.yaml').createSync();
|
fileSystem.file('pubspec.yaml').createSync();
|
||||||
fileSystem.file('test/foo.dart').createSync(recursive: true);
|
fileSystem.file('test/foo.dart').createSync(recursive: true);
|
||||||
|
fileSystem.file('.packages').createSync();
|
||||||
residentCompiler = FakeResidentCompiler(fileSystem);
|
residentCompiler = FakeResidentCompiler(fileSystem);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -113,6 +115,57 @@ void main() {
|
|||||||
ProcessManager: () => FakeProcessManager.any(),
|
ProcessManager: () => FakeProcessManager.any(),
|
||||||
Logger: () => BufferLogger.test(),
|
Logger: () => BufferLogger.test(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testUsingContext('TestCompiler updates generated_main.dart', () async {
|
||||||
|
final Directory fakeDartPlugin = fileSystem.directory('a_plugin');
|
||||||
|
fileSystem.file('pubspec.yaml').writeAsStringSync('''
|
||||||
|
name: foo
|
||||||
|
dependencies:
|
||||||
|
flutter:
|
||||||
|
sdk: flutter
|
||||||
|
a_plugin: 1.0.0
|
||||||
|
''');
|
||||||
|
fileSystem.file('.packages').writeAsStringSync('a_plugin:/a_plugin/lib/');
|
||||||
|
fakeDartPlugin.childFile('pubspec.yaml')
|
||||||
|
..createSync(recursive: true)
|
||||||
|
..writeAsStringSync('''
|
||||||
|
name: a_plugin
|
||||||
|
flutter:
|
||||||
|
plugin:
|
||||||
|
implements: a
|
||||||
|
platforms:
|
||||||
|
linux:
|
||||||
|
dartPluginClass: APlugin
|
||||||
|
environment:
|
||||||
|
sdk: ">=2.14.0 <3.0.0"
|
||||||
|
flutter: ">=2.5.0"
|
||||||
|
''');
|
||||||
|
|
||||||
|
residentCompiler.compilerOutput = const CompilerOutput('abc.dill', 0, <Uri>[]);
|
||||||
|
final FakeTestCompiler testCompiler = FakeTestCompiler(
|
||||||
|
debugBuild,
|
||||||
|
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
|
||||||
|
residentCompiler,
|
||||||
|
);
|
||||||
|
|
||||||
|
await testCompiler.compile(Uri.parse('test/foo.dart'));
|
||||||
|
|
||||||
|
final File generatedMain = fileSystem
|
||||||
|
.directory('.dart_tool')
|
||||||
|
.childDirectory('flutter_build')
|
||||||
|
.childFile('generated_main.dart');
|
||||||
|
|
||||||
|
expect(generatedMain, exists);
|
||||||
|
expect(
|
||||||
|
generatedMain.readAsLinesSync(),
|
||||||
|
contains("import 'test/foo.dart' as entrypoint;")
|
||||||
|
);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
FileSystem: () => fileSystem,
|
||||||
|
Platform: () => linuxPlatform,
|
||||||
|
ProcessManager: () => FakeProcessManager.any(),
|
||||||
|
Logger: () => BufferLogger.test(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Override the creation of the Resident Compiler to simplify testing.
|
/// Override the creation of the Resident Compiler to simplify testing.
|
||||||
@ -150,6 +203,7 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
|
|||||||
String projectRootPath,
|
String projectRootPath,
|
||||||
FileSystem fs,
|
FileSystem fs,
|
||||||
bool suppressErrors = false,
|
bool suppressErrors = false,
|
||||||
|
bool checkDartPluginRegistry = false,
|
||||||
}) async {
|
}) async {
|
||||||
if (compilerOutput != null) {
|
if (compilerOutput != null) {
|
||||||
fileSystem.file(compilerOutput.outputFilename).createSync(recursive: true);
|
fileSystem.file(compilerOutput.outputFilename).createSync(recursive: true);
|
||||||
|
@ -1077,6 +1077,7 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
|
|||||||
String projectRootPath,
|
String projectRootPath,
|
||||||
FileSystem fs,
|
FileSystem fs,
|
||||||
bool suppressErrors = false,
|
bool suppressErrors = false,
|
||||||
|
bool checkDartPluginRegistry = false,
|
||||||
}) async {
|
}) async {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user