Skip to content

Commit 4e3a2e9

Browse files
authored
Remove legacy gen_defaults analyze checks (flutter#191629)
Related to flutter#184950 This PR is to remove the legacy `gen-defaults-names` and `gen-defaults-up-to-date` analyze checks from Flutter CI. These checks validate `dev/tools/gen_defaults`, which has become legacy and only targets the frozen SDK Material library under `packages/flutter/lib/src/material`. Material development has moved to the standalone `material_ui` packages in `flutter/packages`, and we introduced new `gen_defaults` script in flutter/packages, so these check for old script is not useful at all. This PR also removes the now-unused helper methods and their test coverage. TODO: the old `gen_defaults` tool should eventually be deprecated and removed. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
1 parent 2130ecf commit 4e3a2e9

8 files changed

Lines changed: 0 additions & 604 deletions

File tree

‎dev/bots/analyze.dart‎

Lines changed: 0 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'dart:core' hide print;
77
import 'dart:io' hide exit;
88
import 'dart:typed_data';
99

10-
import 'package:collection/equality.dart';
1110
import 'package:crypto/crypto.dart';
1211
import 'package:meta/meta.dart';
1312
import 'package:path/path.dart' as path;
@@ -302,16 +301,6 @@ List<Validation> _getValidations({
302301
'Dart analysis (mega gallery)...',
303302
() => _verifyMegaGallery(flutterRoot, dart, passthroughArguments),
304303
),
305-
Validation(
306-
'gen-defaults-names',
307-
'Correct file names in gen_defaults.dart...',
308-
() => verifyTokenTemplatesUpdateCorrectFiles(flutterRoot),
309-
),
310-
Validation(
311-
'gen-defaults-up-to-date',
312-
'Material library files are up-to-date with token template files...',
313-
() => verifyMaterialFilesAreUpToDateWithTemplateFiles(flutterRoot, dart),
314-
),
315304
Validation(
316305
'integration-templates',
317306
'Up to date integration test template files...',
@@ -433,138 +422,6 @@ Future<void> verifyTargetPlatform(String workingDirectory) async {
433422
}
434423
}
435424

436-
/// Verify Token Templates are mapped to correct file names while generating
437-
/// M3 defaults in /dev/tools/gen_defaults/bin/gen_defaults.dart.
438-
Future<void> verifyTokenTemplatesUpdateCorrectFiles(String workingDirectory) async {
439-
final errors = <String>[];
440-
441-
String getMaterialDirPath(List<String> lines) {
442-
final String line = lines.firstWhere((String line) => line.contains('String materialLib'));
443-
final String relativePath = line.substring(line.indexOf("'") + 1, line.lastIndexOf("'"));
444-
return path.join(workingDirectory, relativePath);
445-
}
446-
447-
String getFileName(String line) {
448-
const materialLibString = r"'$materialLib/";
449-
final String leftClamp = line.substring(
450-
line.indexOf(materialLibString) + materialLibString.length,
451-
);
452-
return leftClamp.substring(0, leftClamp.indexOf("'"));
453-
}
454-
455-
final genDefaultsBinDir = '$workingDirectory/dev/tools/gen_defaults/bin';
456-
final file = File(path.join(genDefaultsBinDir, 'gen_defaults.dart'));
457-
final List<String> lines = file.readAsLinesSync();
458-
final String materialDirPath = getMaterialDirPath(lines);
459-
var atLeastOneTargetLineExists = false;
460-
461-
for (final line in lines) {
462-
if (line.contains('updateFile();')) {
463-
atLeastOneTargetLineExists = true;
464-
final String fileName = getFileName(line);
465-
final String filePath = path.join(materialDirPath, fileName);
466-
final file = File(filePath);
467-
468-
if (!file.existsSync()) {
469-
errors.add('file $filePath does not exist.');
470-
}
471-
}
472-
}
473-
474-
assert(
475-
atLeastOneTargetLineExists,
476-
'No lines exist that this test expects to '
477-
'verify. Check if the target file is correct or remove this test',
478-
);
479-
480-
// Fail if any errors
481-
if (errors.isNotEmpty) {
482-
final s = errors.length > 1 ? 's' : '';
483-
final itThem = errors.length > 1 ? 'them' : 'it';
484-
foundError(<String>[
485-
...errors,
486-
'${bold}Please correct the file name$s or remove $itThem from /dev/tools/gen_defaults/bin/gen_defaults.dart$reset',
487-
]);
488-
}
489-
}
490-
491-
/// Verify Material library files are up-to-date with the token template files
492-
/// when running /dev/tools/gen_defaults/bin/gen_defaults.dart.
493-
Future<void> verifyMaterialFilesAreUpToDateWithTemplateFiles(
494-
String workingDirectory,
495-
String dartExecutable,
496-
) async {
497-
final errors = <String>[];
498-
const beginGeneratedComment = '// BEGIN GENERATED TOKEN PROPERTIES';
499-
500-
String getMaterialDirPath(List<String> lines) {
501-
final String line = lines.firstWhere((String line) => line.contains('String materialLib'));
502-
final String relativePath = line.substring(line.indexOf("'") + 1, line.lastIndexOf("'"));
503-
return path.join(workingDirectory, relativePath);
504-
}
505-
506-
String getFileName(String line) {
507-
const materialLibString = r"'$materialLib/";
508-
final String leftClamp = line.substring(
509-
line.indexOf(materialLibString) + materialLibString.length,
510-
);
511-
return leftClamp.substring(0, leftClamp.indexOf("'"));
512-
}
513-
514-
// Get the template generated code from the file.
515-
List<String> getGeneratedCode(List<String> lines) {
516-
return lines.skipWhile((String line) => !line.contains(beginGeneratedComment)).toList();
517-
}
518-
519-
final genDefaultsBinDir = '$workingDirectory/dev/tools/gen_defaults/bin';
520-
final file = File(path.join(genDefaultsBinDir, 'gen_defaults.dart'));
521-
final List<String> lines = file.readAsLinesSync();
522-
final String materialDirPath = getMaterialDirPath(lines);
523-
final beforeGeneratedCode = <String, List<String>>{};
524-
final afterGeneratedCode = <String, List<String>>{};
525-
526-
for (final line in lines) {
527-
if (line.contains('updateFile();')) {
528-
final String fileName = getFileName(line);
529-
final String filePath = path.join(materialDirPath, fileName);
530-
final file = File(filePath);
531-
beforeGeneratedCode[fileName] = getGeneratedCode(file.readAsLinesSync());
532-
}
533-
}
534-
535-
// Run gen_defaults.dart to generate the token template files.
536-
await runCommand(dartExecutable, <String>[
537-
'--enable-asserts',
538-
path.join('dev', 'tools', 'gen_defaults', 'bin', 'gen_defaults.dart'),
539-
], workingDirectory: workingDirectory);
540-
541-
for (final line in lines) {
542-
if (line.contains('updateFile();')) {
543-
final String fileName = getFileName(line);
544-
final String filePath = path.join(materialDirPath, fileName);
545-
final file = File(filePath);
546-
afterGeneratedCode[fileName] = getGeneratedCode(file.readAsLinesSync());
547-
}
548-
}
549-
550-
// Compare the generated code before and after running gen_defaults.dart.
551-
for (final String fileName in beforeGeneratedCode.keys) {
552-
final List<String> before = beforeGeneratedCode[fileName]!;
553-
final List<String> after = afterGeneratedCode[fileName]!;
554-
if (!const IterableEquality<String>().equals(before, after)) {
555-
errors.add('$fileName is not up-to-date with the token template file.');
556-
}
557-
}
558-
559-
// Fail if any errors.
560-
if (errors.isNotEmpty) {
561-
foundError(<String>[
562-
...errors,
563-
'${bold}See: https://github.com/flutter/flutter/blob/main/dev/tools/gen_defaults to update the token template files.$reset',
564-
]);
565-
}
566-
}
567-
568425
/// Verify tool test files end in `_test.dart`.
569426
///
570427
/// The test runner will only recognize files ending in `_test.dart` as tests to

‎dev/bots/test/analyze-gen-defaults/dev/tools/gen_defaults/bin/chip_template.dart‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎dev/bots/test/analyze-gen-defaults/dev/tools/gen_defaults/bin/gen_defaults.dart‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)