Skip to content

Commit fb2d117

Browse files
stereotype441Commit Queue
authored andcommitted
Reference all genearted file paths to pkg directory.
Modifies `GeneratedDirectory.outputDirPath` and `GeneratedFile.outputPath` to be relative to the SDK's `pkg` directory rather than relative to the containing package. Accordingly, modifies the `GeneratedContent` methods `check`, `checkAll`, `generate`, `generateAll`, `output`, as well as the `DirectoryContentsComputer` and `FileContentsComputer` callbacks, so that their first parameter is the path to the `pkg` directory rather than the path to the containing package. Also modifies the `readApi` functions in `pkg/analysis_server` and `pkg/analyzer_plugin` to accept a path to the `pkg` directory rather than a path to the containing package, since these functions are called by code generation callbacks. These changes should make code generation logic easier to reason about. They also will make it easier to move the outputs of code generation from one package to another, which will pave the way for some follow-up work in which I intend to start sharing error message representations belonging to `pkg/analyzer`, `pkg/front_end`, and `pkg/_fe_analyzer_shared`. Change-Id: Ia9b369b16f2df931c8a472f91400f2c5a0b8be9d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438480 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent f895110 commit fb2d117

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+206
-199
lines changed

pkg/analysis_server/integration_test/coverage_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import '../tool/spec/from_html.dart';
1515
void main() {
1616
// parse the API file
1717
var pathPrefix = path.join(pkg_root.packageRoot, 'analysis_server');
18-
var api = readApi(pathPrefix);
18+
var api = readApi(pkg_root.packageRoot);
1919

2020
var coverageFile = File(
2121
path.join(pathPrefix, 'integration_test', 'coverage.md'),

pkg/analysis_server/tool/generate_analyzer_version.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ import 'package:path/path.dart';
1010
import 'package:yaml/yaml.dart';
1111

1212
void main() async {
13-
await GeneratedContent.generateAll(
14-
normalize(join(packageRoot, 'analysis_server')),
15-
allTargets,
16-
);
13+
await GeneratedContent.generateAll(packageRoot, allTargets);
1714
}
1815

1916
List<GeneratedContent> get allTargets {
2017
return [
21-
GeneratedFile('lib/src/plugin2/analyzer_version.g.dart', (_) async {
18+
GeneratedFile('analysis_server/lib/src/plugin2/analyzer_version.g.dart', (
19+
_,
20+
) async {
2221
var buffer = StringBuffer('''
2322
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2423
// for details. All rights reserved. Use of this source code is governed by a

pkg/analysis_server/tool/spec/check_all_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'generate_all.dart';
1313
Future<void> main() async {
1414
var pkgPath = normalize(join(pkg_root.packageRoot, 'analysis_server'));
1515
await GeneratedContent.checkAll(
16-
pkgPath,
16+
pkg_root.packageRoot,
1717
join(pkgPath, 'tool', 'spec', 'generate_all.dart'),
1818
allTargets,
1919
);

pkg/analysis_server/tool/spec/codegen_analysis_server.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'api.dart';
1111
import 'codegen_java.dart';
1212

1313
final GeneratedFile target = javaGeneratedFile(
14-
'tool/spec/generated/java/AnalysisServer.java',
14+
'analysis_server/tool/spec/generated/java/AnalysisServer.java',
1515
(Api api) => CodegenAnalysisServer(api),
1616
);
1717

pkg/analysis_server/tool/spec/codegen_dart_notification_handler.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import 'from_html.dart';
1313

1414
GeneratedFile clientTarget() {
1515
return GeneratedFile(
16-
'../analysis_server_client/lib/handler/notification_handler.dart',
17-
(String pkgPath) async {
18-
var visitor = CodegenNotificationHandlerVisitor(readApi(pkgPath));
16+
'analysis_server_client/lib/handler/notification_handler.dart',
17+
(pkgRoot) async {
18+
var visitor = CodegenNotificationHandlerVisitor(readApi(pkgRoot));
1919
return visitor.collectCode(visitor.visitApi);
2020
},
2121
);

pkg/analysis_server/tool/spec/codegen_dart_protocol.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:convert';
66

77
import 'package:analyzer_utilities/html_dom.dart' as dom;
88
import 'package:analyzer_utilities/tools.dart';
9-
import 'package:path/path.dart' as path;
109

1110
import 'api.dart';
1211
import 'codegen_dart.dart';
@@ -30,14 +29,14 @@ GeneratedFile clientTarget(
3029
CodegenUriConverterKind clientUriConverterKind,
3130
) {
3231
return GeneratedFile(
33-
'../analysis_server_client/lib/src/protocol/protocol_generated.dart',
34-
(String pkgPath) async {
32+
'analysis_server_client/lib/src/protocol/protocol_generated.dart',
33+
(pkgRoot) async {
3534
var visitor = CodegenProtocolVisitor(
3635
'analysis_server_client',
3736
responseRequiresRequestTime,
3837
clientUriConverterKind,
3938
false,
40-
readApi(pkgPath),
39+
readApi(pkgRoot),
4140
);
4241
return visitor.collectCode(visitor.visitApi);
4342
},
@@ -48,15 +47,15 @@ GeneratedFile serverTarget(
4847
bool responseRequiresRequestTime,
4948
CodegenUriConverterKind clientUriConverterKind,
5049
) {
51-
return GeneratedFile('lib/protocol/protocol_generated.dart', (
52-
String pkgPath,
50+
return GeneratedFile('analysis_server/lib/protocol/protocol_generated.dart', (
51+
pkgRoot,
5352
) async {
5453
var visitor = CodegenProtocolVisitor(
55-
path.basename(pkgPath),
54+
'analysis_server',
5655
responseRequiresRequestTime,
5756
clientUriConverterKind,
5857
true,
59-
readApi(pkgPath),
58+
readApi(pkgRoot),
6059
);
6160
return visitor.collectCode(visitor.visitApi);
6261
});

pkg/analysis_server/tool/spec/codegen_inttest_methods.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@
66
library;
77

88
import 'package:analyzer_utilities/tools.dart';
9-
import 'package:path/path.dart' as path;
109

1110
import 'api.dart';
1211
import 'codegen_dart.dart';
1312
import 'from_html.dart';
1413
import 'to_html.dart';
1514

1615
final GeneratedFile target = GeneratedFile(
17-
'integration_test/support/integration_test_methods.dart',
18-
(String pkgPath) async {
16+
'analysis_server/integration_test/support/integration_test_methods.dart',
17+
(pkgRoot) async {
1918
var visitor = CodegenInttestMethodsVisitor(
20-
path.basename(pkgPath),
21-
readApi(pkgPath),
19+
'analysis_server',
20+
readApi(pkgRoot),
2221
);
2322
return visitor.collectCode(visitor.visitApi);
2423
},

pkg/analysis_server/tool/spec/codegen_java.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ GeneratedFile javaGeneratedFile(
1818
String path,
1919
CodegenJavaVisitor Function(Api api) createVisitor,
2020
) {
21-
return GeneratedFile(path, (String pkgPath) async {
22-
var visitor = createVisitor(readApi(pkgPath));
21+
return GeneratedFile(path, (pkgRoot) async {
22+
var visitor = createVisitor(readApi(pkgRoot));
2323
return visitor.collectCode(visitor.visitApi);
2424
});
2525
}

pkg/analysis_server/tool/spec/codegen_java_types.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ const Map<String, String> _extraMethodsOnElement = {
4343
/// Type references in the spec that are named something else in Java.
4444
const Map<String, String> _typeRenames = {'Override': 'OverrideMember'};
4545

46-
final String pathToGenTypes = 'tool/spec/generated/java/types';
46+
final String pathToGenTypes = 'analysis_server/tool/spec/generated/java/types';
4747

4848
final GeneratedDirectory targetDir = GeneratedDirectory(pathToGenTypes, (
49-
String pkgPath,
49+
pkgRoot,
5050
) {
51-
var api = readApi(pkgPath);
51+
var api = readApi(pkgRoot);
5252
var impliedTypes = computeImpliedTypes(api);
5353
var map = <String, FileContentsComputer>{};
5454
for (var impliedType in impliedTypes.values) {
@@ -67,7 +67,7 @@ final GeneratedDirectory targetDir = GeneratedDirectory(pathToGenTypes, (
6767
if (renamedTo != null) {
6868
typeNameInJava = renamedTo;
6969
}
70-
map['$typeNameInJava.java'] = (String pkgPath) async {
70+
map['$typeNameInJava.java'] = (pkgRoot) async {
7171
String? superclassName;
7272
if (isRefactoringFeedback) {
7373
superclassName = 'RefactoringFeedback';

pkg/analysis_server/tool/spec/codegen_matchers.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import 'implied_types.dart';
1313
import 'to_html.dart';
1414

1515
final GeneratedFile target = GeneratedFile(
16-
'integration_test/support/protocol_matchers.dart',
17-
(String pkgPath) async {
18-
var visitor = CodegenMatchersVisitor(readApi(pkgPath));
16+
'analysis_server/integration_test/support/protocol_matchers.dart',
17+
(pkgRoot) async {
18+
var visitor = CodegenMatchersVisitor(readApi(pkgRoot));
1919
return visitor.collectCode(visitor.visitApi);
2020
},
2121
);

0 commit comments

Comments
 (0)