From 19a212b5aca72588d8f2c37984b45168ad254aa7 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Tue, 14 Jan 2025 12:47:08 -0800 Subject: [PATCH] Check that localization files of stocks app are up-to-date (#161608) Fixes https://github.com/flutter/flutter/issues/160473 --- .ci.yaml | 1 - dev/benchmarks/test_apps/stocks/l10n.yaml | 2 + dev/bots/analyze.dart | 46 +++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/.ci.yaml b/.ci.yaml index 2b55e08bcc..69b6387ff8 100644 --- a/.ci.yaml +++ b/.ci.yaml @@ -389,7 +389,6 @@ targets: - name: Linux packages_autoroller presubmit: false recipe: pub_autoroller/pub_autoroller - bringup: true # https://github.com/flutter/flutter/issues/160473 # This takes a while because we need to fetch network dependencies and run # Gradle for every android app in the repo timeout: 45 diff --git a/dev/benchmarks/test_apps/stocks/l10n.yaml b/dev/benchmarks/test_apps/stocks/l10n.yaml index c459c79878..414eb5f7f6 100644 --- a/dev/benchmarks/test_apps/stocks/l10n.yaml +++ b/dev/benchmarks/test_apps/stocks/l10n.yaml @@ -20,3 +20,5 @@ template-arb-file: stocks_en.arb ## StockStrings getter. This removes the need for adding null checks ## in the Flutter application itself. nullable-getter: false +## Run the formatter on the generated localization files. +format: true diff --git a/dev/bots/analyze.dart b/dev/bots/analyze.dart index 66198a54ff..6700bc7da9 100644 --- a/dev/bots/analyze.dart +++ b/dev/bots/analyze.dart @@ -152,6 +152,9 @@ Future run(List arguments) async { printProgress('Internationalization...'); await verifyInternationalizations(flutterRoot, dart); + printProgress('Localization files of stocks app...'); + await verifyStockAppLocalizations(flutterRoot); + printProgress('Integration test timeouts...'); await verifyIntegrationTestTimeouts(flutterRoot); @@ -1312,6 +1315,49 @@ Future verifyInternationalizations(String workingDirectory, String dartExe } } +Future verifyStockAppLocalizations(String workingDirectory) async { + final Directory appRoot = Directory( + path.join(workingDirectory, 'dev', 'benchmarks', 'test_apps', 'stocks'), + ); + if (!appRoot.existsSync()) { + foundError(['Stocks app does not exist at expected location: ${appRoot.path}']); + } + + // Regenerate the localizations. + final String flutterExecutable = path.join( + workingDirectory, + 'bin', + 'flutter${Platform.isWindows ? '.bat' : ''}', + ); + await _evalCommand(flutterExecutable, const ['gen-l10n'], workingDirectory: appRoot.path); + final Directory i10nDirectory = Directory(path.join(appRoot.path, 'lib', 'i18n')); + if (!i10nDirectory.existsSync()) { + foundError([ + 'Localization files for stocks app not found at expected location: ${i10nDirectory.path}', + ]); + } + + // Check that regeneration did not dirty the tree. + final EvalResult result = await _evalCommand('git', [ + 'diff', + '--name-only', + '--exit-code', + i10nDirectory.path, + ], workingDirectory: workingDirectory); + if (result.exitCode == 1) { + foundError([ + 'The following localization files for the stocks app appear to be out of date:', + ...(const LineSplitter().convert(result.stdout).map((String line) => ' * $line')), + 'Run "flutter gen-l10n" in "${path.relative(appRoot.path, from: workingDirectory)}" to regenerate.', + ]); + } else if (result.exitCode != 0) { + foundError([ + 'Failed to run "git diff" on localization files of stocks app:', + result.stderr, + ]); + } +} + /// Verifies that all instances of "checked mode" have been migrated to "debug mode". Future verifyNoCheckedMode(String workingDirectory) async { final String flutterPackages = path.join(workingDirectory, 'packages');