[flutter_tools] deprecate flutter generate and codegen (#58328)

This commit is contained in:
Jonah Williams
2020-06-03 09:28:02 -07:00
committed by GitHub
parent 8033da2558
commit 01b9bf8ea6
62 changed files with 41 additions and 1369 deletions

View File

@@ -139,6 +139,14 @@ class CodeGeneratingResidentCompiler implements ResidentCompiler {
if (runCold) {
return residentCompiler;
}
globals.printError(<String>[
'"flutter generate" is deprecated, use "dart pub run build_runner" instead. ',
'The following dependencies must be added to dev_dependencies in pubspec.yaml:',
'build_runner: 1.10.0',
for (Object dependency in flutterProject.builders?.keys ?? const <Object>[])
'$dependency: ${flutterProject.builders[dependency]}'
].join('\n'));
final CodegenDaemon codegenDaemon = await codeGenerator.daemon(flutterProject);
codegenDaemon.startBuild();
final CodegenStatus status = await codegenDaemon.buildResults.firstWhere((CodegenStatus status) {

View File

@@ -20,10 +20,21 @@ class GenerateCommand extends FlutterCommand {
@override
String get name => 'generate';
@override
bool get hidden => true;
@override
Future<FlutterCommandResult> runCommand() async {
Cache.releaseLockEarly();
final FlutterProject flutterProject = FlutterProject.current();
globals.printError(<String>[
'"flutter generate" is deprecated, use "dart pub run build_runner" instead. ',
'The following dependencies must be added to dev_dependencies in pubspec.yaml:',
'build_runner: 1.10.0',
for (Object dependency in flutterProject.builders?.keys ?? const <Object>[])
'$dependency: ${flutterProject.builders[dependency]}'
].join('\n'));
final CodegenDaemon codegenDaemon = await codeGenerator.daemon(flutterProject);
codegenDaemon.startBuild();
await for (final CodegenStatus codegenStatus in codegenDaemon.buildResults) {

View File

@@ -44,6 +44,28 @@ void main() {
});
});
test('Outputs deprecation warning from flutter generate', () => testbed.run(() async {
final GenerateCommand command = GenerateCommand();
applyMocksToCommand(command);
globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
.createSync(recursive: true);
globals.fs.currentDirectory
.childDirectory('.dart_tool')
.childDirectory('build')
.childDirectory('abcdefg')
.createSync(recursive: true);
await createTestCommandRunner(command)
.run(const <String>['generate']);
expect(testLogger.errorText, contains(
'"flutter generate" is deprecated, use "dart pub run build_runner" instead.'
));
expect(testLogger.errorText, contains(
'build_runner: 1.10.0'
));
}));
test('Outputs error information from flutter generate', () => testbed.run(() async {
final GenerateCommand command = GenerateCommand();
applyMocksToCommand(command);