Skip to content

Commit 6610e5c

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Break dependency between analyzer message codegen and analyzer.
This fixes a bootstrapping problem: previously we could get into a situation where the generated files for analyzer diagnostic messages were out of date, but the code generator for those messages couldn't be run, because it imported the analyzer itself, which contained compiled errors due to the generated files being out of date. There were two problematic dependencies: - The `GeneratedContent.check` and `GeneratedContent.checkAll` methods relied on invoking the Dart formatter as a library (rather than invoking `dart format` as a subprocess); the Dart formatter library imports the analyzer. Fortunately, this functionality is not needed by the code generators themselves. It's only needed by the _tests_ that verify that code generation has run. So I was able to break the dependency by moving this functionality into a new file, `package:analyzer_utilities/generated_content_check.dart`, which is imported only by the code generation tests. The new API is slightly different: `GeneratedContent.checkAll` has been replaced by an extension method `check` on `Iterable<GeneratedContent>`. - The diagnostic message code generator used to have a post-processing step that made use of the scanner to find error messages used by the parser that needed to be translated, and issued a warning if it found any. This check was useful a long time ago, when we were unifying the analyzer and CFE parsers, and is no longer useful, so I've removed it. Change-Id: I509b741faca3b9ae21c23936001105ded731b490 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442241 Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent c42bdd1 commit 6610e5c

File tree

14 files changed

+161
-216
lines changed

14 files changed

+161
-216
lines changed

pkg/analysis_server/tool/spec/check_all_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer_testing/package_root.dart' as pkg_root;
6-
import 'package:analyzer_utilities/tools.dart';
6+
import 'package:analyzer_utilities/generated_content_check.dart';
77
import 'package:path/path.dart';
88

99
import 'generate_all.dart';
@@ -12,9 +12,8 @@ import 'generate_all.dart';
1212
/// user to run generate_all.dart.
1313
Future<void> main() async {
1414
var pkgPath = normalize(join(pkg_root.packageRoot, 'analysis_server'));
15-
await GeneratedContent.checkAll(
15+
await allTargets.check(
1616
pkg_root.packageRoot,
1717
join(pkgPath, 'tool', 'spec', 'generate_all.dart'),
18-
allTargets,
1918
);
2019
}

pkg/analysis_server_plugin/tool/api/generate_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
// date.
77

88
import 'package:analyzer_testing/package_root.dart' as pkg_root;
9-
import 'package:analyzer_utilities/tools.dart';
9+
import 'package:analyzer_utilities/generated_content_check.dart';
1010
import 'package:path/path.dart';
1111

1212
import 'generate.dart';
1313

1414
Future<void> main() async {
15-
await GeneratedContent.checkAll(
15+
await allTargets.check(
1616
pkg_root.packageRoot,
1717
join(pkg_root.packageRoot, 'analysis_server_plugin', 'tool', 'api',
1818
'generate.dart'),
19-
allTargets,
2019
);
2120
}

pkg/analyzer/tool/api/generate_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
// date.
77

88
import 'package:analyzer_testing/package_root.dart' as pkg_root;
9-
import 'package:analyzer_utilities/tools.dart';
9+
import 'package:analyzer_utilities/generated_content_check.dart';
1010
import 'package:path/path.dart';
1111

1212
import 'generate.dart';
1313

1414
Future<void> main() async {
15-
await GeneratedContent.checkAll(
15+
await allTargets.check(
1616
pkg_root.packageRoot,
1717
join(pkg_root.packageRoot, 'analyzer', 'tool', 'api', 'generate.dart'),
18-
allTargets,
1918
);
2019
}

pkg/analyzer/tool/experiments/experiments_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer_testing/package_root.dart' as pkg_root;
6-
import 'package:analyzer_utilities/tools.dart';
6+
import 'package:analyzer_utilities/generated_content_check.dart';
77
import 'package:path/path.dart';
88

99
import 'generate.dart';
@@ -12,9 +12,8 @@ import 'generate.dart';
1212
/// user to run `generate.dart`.
1313
void main() async {
1414
String pkgPath = normalize(join(pkg_root.packageRoot, 'analyzer'));
15-
await GeneratedContent.checkAll(
15+
await allTargets.check(
1616
pkg_root.packageRoot,
1717
join(pkgPath, 'tool', 'experiments', 'generate.dart'),
18-
allTargets,
1918
);
2019
}

pkg/analyzer/tool/messages/generate.dart

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ library;
1919
import 'dart:convert';
2020
import 'dart:io';
2121

22-
import 'package:_fe_analyzer_shared/src/scanner/scanner.dart';
2322
import 'package:analyzer_testing/package_root.dart' as pkg_root;
2423
import 'package:analyzer_utilities/tools.dart';
2524
import 'package:collection/collection.dart';
@@ -384,52 +383,6 @@ class _SyntacticErrorGenerator {
384383
print(' ${analyzerToFasta.length} total');
385384
}
386385
}
387-
388-
// List error codes in the parser that have not been translated.
389-
var untranslatedFastaErrorCodes = <String>{};
390-
Token token = scanString(parserSource).tokens;
391-
while (!token.isEof) {
392-
if (token.isIdentifier) {
393-
String? fastaErrorCode;
394-
String lexeme = token.lexeme;
395-
if (lexeme.length > 7) {
396-
if (lexeme.startsWith('message')) {
397-
fastaErrorCode = lexeme.substring(7);
398-
} else if (lexeme.length > 8) {
399-
if (lexeme.startsWith('template')) {
400-
fastaErrorCode = lexeme.substring(8);
401-
}
402-
}
403-
}
404-
if (fastaErrorCode != null &&
405-
cfeToAnalyzerErrorCodeTables.frontEndCodeToInfo[fastaErrorCode] ==
406-
null) {
407-
untranslatedFastaErrorCodes.add(fastaErrorCode);
408-
}
409-
}
410-
token = token.next!;
411-
}
412-
if (untranslatedFastaErrorCodes.isNotEmpty) {
413-
print('');
414-
print('The following error codes in the parser are not auto generated:');
415-
var sorted = untranslatedFastaErrorCodes.toList()..sort();
416-
for (String fastaErrorCode in sorted) {
417-
String analyzerCode = '';
418-
String problemMessage = '';
419-
var entry = frontEndMessages[fastaErrorCode];
420-
if (entry != null) {
421-
// TODO(paulberry): handle multiple analyzer codes
422-
if (entry.index == null && entry.analyzerCode.length == 1) {
423-
analyzerCode = entry.analyzerCode.single;
424-
problemMessage = entry.problemMessage;
425-
}
426-
}
427-
print(
428-
' ${fastaErrorCode.padRight(30)} --> $analyzerCode'
429-
'\n $problemMessage',
430-
);
431-
}
432-
}
433386
}
434387
}
435388

pkg/analyzer/tool/messages/generate_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
// date.
77

88
import 'package:analyzer_testing/package_root.dart' as pkg_root;
9-
import 'package:analyzer_utilities/tools.dart';
9+
import 'package:analyzer_utilities/generated_content_check.dart';
1010
import 'package:path/path.dart';
1111

1212
import 'error_code_info.dart';
1313
import 'generate.dart';
1414

1515
Future<void> main() async {
16-
await GeneratedContent.checkAll(
16+
await allTargets.check(
1717
pkg_root.packageRoot,
1818
join(analyzerPkgPath, 'tool', 'messages', 'generate.dart'),
19-
allTargets,
2019
);
2120
}

pkg/analyzer/tool/summary/check_test.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer_testing/package_root.dart' as package_root;
6-
import 'package:analyzer_utilities/tools.dart';
6+
import 'package:analyzer_utilities/generated_content_check.dart';
77
import 'package:path/path.dart';
88

99
import 'generate.dart';
@@ -15,9 +15,7 @@ void main() async {
1515
join(package_root.packageRoot, 'analyzer', 'lib', 'src', 'summary'),
1616
);
1717
var idlPath = normalize(join(idlFolderPath, 'idl.dart'));
18-
await GeneratedContent.checkAll(
19-
package_root.packageRoot,
20-
'pkg/analyzer/tool/summary/generate.dart',
21-
getAllTargets(idlPath),
22-
);
18+
await getAllTargets(
19+
idlPath,
20+
).check(package_root.packageRoot, 'pkg/analyzer/tool/summary/generate.dart');
2321
}

pkg/analyzer/tool/wolf/generate_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
// date.
77

88
import 'package:analyzer_testing/package_root.dart' as pkg_root;
9-
import 'package:analyzer_utilities/tools.dart';
9+
import 'package:analyzer_utilities/generated_content_check.dart';
1010
import 'package:path/path.dart';
1111

1212
import 'generate.dart';
1313

1414
Future<void> main() async {
15-
await GeneratedContent.checkAll(
15+
await allTargets.check(
1616
pkg_root.packageRoot,
1717
join(analyzerPkgPath, 'tool', 'wolf', 'generate.dart'),
18-
allTargets,
1918
);
2019
}

pkg/analyzer_plugin/tool/api/generate_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
// date.
77

88
import 'package:analyzer_testing/package_root.dart' as pkg_root;
9-
import 'package:analyzer_utilities/tools.dart';
9+
import 'package:analyzer_utilities/generated_content_check.dart';
1010
import 'package:path/path.dart';
1111

1212
import 'generate.dart';
1313

1414
Future<void> main() async {
15-
await GeneratedContent.checkAll(
15+
await allTargets.check(
1616
pkg_root.packageRoot,
1717
join(pkg_root.packageRoot, 'analyzer_plugin', 'tool', 'api',
1818
'generate.dart'),
19-
allTargets,
2019
);
2120
}

pkg/analyzer_plugin/tool/spec/check_all_test.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer_testing/package_root.dart' as pkg_root;
6-
import 'package:analyzer_utilities/tools.dart';
6+
import 'package:analyzer_utilities/generated_content_check.dart';
77
import 'package:path/path.dart';
88

99
import 'generate_all.dart';
@@ -12,6 +12,8 @@ import 'generate_all.dart';
1212
/// user to run generate_all.dart.
1313
Future<void> main() async {
1414
var pkgPath = normalize(join(pkg_root.packageRoot, 'analyzer_plugin'));
15-
await GeneratedContent.checkAll(pkg_root.packageRoot,
16-
join(pkgPath, 'tool', 'spec', 'generate_all.dart'), allTargets);
15+
await allTargets.check(
16+
pkg_root.packageRoot,
17+
join(pkgPath, 'tool', 'spec', 'generate_all.dart'),
18+
);
1719
}

0 commit comments

Comments
 (0)