diff --git a/packages/flutter_tools/lib/src/commands/packages.dart b/packages/flutter_tools/lib/src/commands/packages.dart index 096bd72cd4..824077cd8c 100644 --- a/packages/flutter_tools/lib/src/commands/packages.dart +++ b/packages/flutter_tools/lib/src/commands/packages.dart @@ -6,8 +6,10 @@ import 'package:args/args.dart'; import '../base/common.dart'; import '../base/os.dart'; +import '../base/utils.dart'; import '../build_info.dart'; import '../build_system/build_system.dart'; +import '../build_system/targets/localizations.dart'; import '../cache.dart'; import '../dart/generate_synthetic_packages.dart'; import '../dart/pub.dart'; @@ -304,6 +306,32 @@ class PackagesGetCommand extends FlutterCommand { environment: environment, buildSystem: globals.buildSystem, ); + } else if (rootProject.directory.childFile('l10n.yaml').existsSync()) { + final Environment environment = Environment( + artifacts: globals.artifacts!, + logger: globals.logger, + cacheDir: globals.cache.getRoot(), + engineVersion: globals.flutterVersion.engineRevision, + fileSystem: globals.fs, + flutterRootDir: globals.fs.directory(Cache.flutterRoot), + outputDir: globals.fs.directory(getBuildDirectory()), + processManager: globals.processManager, + platform: globals.platform, + usage: globals.flutterUsage, + projectDir: rootProject.directory, + generateDartPluginRegistry: true, + ); + final BuildResult result = await globals.buildSystem.build( + const GenerateLocalizationsTarget(), + environment, + ); + if (result.hasException) { + throwToolExit( + 'Generating synthetic localizations package failed with ${result.exceptions.length} ${pluralize('error', result.exceptions.length)}:' + '\n\n' + '${result.exceptions.values.map((ExceptionMeasurement e) => e.exception).join('\n\n')}', + ); + } } } final String? relativeTarget = target == null ? null : globals.fs.path.relative(target); diff --git a/packages/flutter_tools/test/commands.shard/permeable/packages_test.dart b/packages/flutter_tools/test/commands.shard/permeable/packages_test.dart index 0a9be004be..df14535004 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/packages_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/packages_test.dart @@ -255,6 +255,81 @@ void main() { ), }); + testUsingContext('get generates synthetic package when l10n.yaml has synthetic-package: true', () async { + final String projectPath = await createProject(tempDir, + arguments: ['--no-pub', '--template=module']); + final Directory projectDir = globals.fs.directory(projectPath); + projectDir + .childDirectory('lib') + .childDirectory('l10n') + .childFile('app_en.arb') + ..createSync(recursive: true) + ..writeAsStringSync('{ "hello": "Hello world!" }'); + String pubspecFileContent = projectDir.childFile('pubspec.yaml').readAsStringSync(); + pubspecFileContent = pubspecFileContent.replaceFirst(RegExp(r'\nflutter\:'), ''' +flutter: + generate: true +'''); + projectDir + .childFile('pubspec.yaml') + .writeAsStringSync(pubspecFileContent); + projectDir + .childFile('l10n.yaml') + .writeAsStringSync('synthetic-package: true'); + await runCommandIn(projectPath, 'get'); + expect( + projectDir + .childDirectory('.dart_tool') + .childDirectory('flutter_gen') + .childDirectory('gen_l10n') + .childFile('app_localizations.dart') + .existsSync(), + true + ); + }, overrides: { + Pub: () => Pub( + fileSystem: globals.fs, + logger: globals.logger, + processManager: globals.processManager, + usage: globals.flutterUsage, + botDetector: globals.botDetector, + platform: globals.platform, + ), + }); + + testUsingContext('get generates normal files when l10n.yaml has synthetic-package: false', () async { + final String projectPath = await createProject(tempDir, + arguments: ['--no-pub', '--template=module']); + final Directory projectDir = globals.fs.directory(projectPath); + projectDir + .childDirectory('lib') + .childDirectory('l10n') + .childFile('app_en.arb') + ..createSync(recursive: true) + ..writeAsStringSync('{ "hello": "Hello world!" }'); + projectDir + .childFile('l10n.yaml') + .writeAsStringSync('synthetic-package: false'); + await runCommandIn(projectPath, 'get'); + expect( + projectDir + .childDirectory('lib') + .childDirectory('l10n') + .childFile('app_localizations.dart') + .existsSync(), + true + ); + }, overrides: { + Pub: () => Pub( + fileSystem: globals.fs, + logger: globals.logger, + processManager: globals.processManager, + usage: globals.flutterUsage, + botDetector: globals.botDetector, + platform: globals.platform, + ), + }); + testUsingContext('set no plugins as usage value', () async { final String projectPath = await createProject(tempDir, arguments: ['--no-pub', '--template=module']);