Skip to content

Commit c30dd25

Browse files
stereotype441Commit Queue
authored andcommitted
Use package_root.dart for all analyzer_utilities-based codegen.
All code generation logic that uses the analyzer_utilities package's `GeneratedContent` class hierarchy is modified to use `package:analyzer_testing/package_root.dart` to locate the `pkg` directory in the root of the SDK repo. This paves the way for some follow-up work in which I intend to modify the `GeneratedContent` class hierarchy so that it tracks the locations of all code generation targets relative to the `pkg` directory rather than the individual package directories. That in turn should make it easier for code generation logic to be shared between error messages belonging to `pkg/analyzer`, `pkg/front_end`, and `pkg/_fe_analyzer_shared`. Change-Id: Iee59e977e844261f46fb62ed4e222db79db45a25 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438061 Auto-Submit: Paul Berry <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent 51fee27 commit c30dd25

File tree

12 files changed

+38
-94
lines changed

12 files changed

+38
-94
lines changed

pkg/analysis_server/integration_test/coverage_test.dart

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,21 @@
55
import 'dart:io';
66

77
import 'package:analyzer_plugin/src/utilities/string_utilities.dart';
8+
import 'package:analyzer_testing/package_root.dart' as pkg_root;
89
import 'package:path/path.dart' as path;
910
import 'package:test/test.dart';
1011

11-
import '../tool/spec/api.dart';
1212
import '../tool/spec/from_html.dart';
1313

1414
/// Define tests to fail if there's no mention in the coverage file.
1515
void main() {
16-
Api api;
17-
File coverageFile;
18-
String pathPrefix;
19-
2016
// parse the API file
21-
if (FileSystemEntity.isFileSync(
22-
path.join('tool', 'spec', 'spec_input.html'),
23-
)) {
24-
api = readApi('.');
25-
pathPrefix = '.';
26-
} else {
27-
api = readApi(path.join('pkg', 'analysis_server'));
28-
pathPrefix = path.join('pkg', 'analysis_server');
29-
}
17+
var pathPrefix = path.join(pkg_root.packageRoot, 'analysis_server');
18+
var api = readApi(pathPrefix);
3019

31-
coverageFile = File(path.join(pathPrefix, 'integration_test', 'coverage.md'));
20+
var coverageFile = File(
21+
path.join(pathPrefix, 'integration_test', 'coverage.md'),
22+
);
3223
var lines = coverageFile.readAsLinesSync();
3324

3425
// ## server domain

pkg/analysis_server/tool/spec/check_all_test.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:io';
6-
5+
import 'package:analyzer_testing/package_root.dart' as pkg_root;
76
import 'package:analyzer_utilities/tools.dart';
87
import 'package:path/path.dart';
98

@@ -12,10 +11,7 @@ import 'generate_all.dart';
1211
/// Check that all targets have been code generated. If they haven't tell the
1312
/// user to run generate_all.dart.
1413
Future<void> main() async {
15-
var script = Platform.script.toFilePath(windows: Platform.isWindows);
16-
var components = split(script);
17-
var index = components.indexOf('analysis_server');
18-
var pkgPath = joinAll(components.sublist(0, index + 1));
14+
var pkgPath = normalize(join(pkg_root.packageRoot, 'analysis_server'));
1915
await GeneratedContent.checkAll(
2016
pkgPath,
2117
join(pkgPath, 'tool', 'spec', 'generate_all.dart'),

pkg/analysis_server/tool/spec/generate_all.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:io';
6-
5+
import 'package:analyzer_testing/package_root.dart' as pkg_root;
76
import 'package:analyzer_utilities/tools.dart';
87
import 'package:path/path.dart';
98

@@ -19,8 +18,7 @@ import 'to_html.dart' as to_html;
1918

2019
/// Generate all targets.
2120
Future<void> main() async {
22-
var script = Platform.script.toFilePath(windows: Platform.isWindows);
23-
var pkgPath = normalize(join(dirname(script), '..', '..'));
21+
var pkgPath = normalize(join(pkg_root.packageRoot, 'analysis_server'));
2422
await GeneratedContent.generateAll(pkgPath, allTargets);
2523
}
2624

pkg/analyzer/tool/experiments/experiments_test.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import "dart:io" show Platform;
6-
5+
import 'package:analyzer_testing/package_root.dart' as pkg_root;
76
import 'package:analyzer_utilities/tools.dart';
87
import 'package:path/path.dart';
98

@@ -12,10 +11,7 @@ import 'generate.dart';
1211
/// Check that all targets have been code generated. If they haven't tell the
1312
/// user to run `generate.dart`.
1413
void main() async {
15-
String script = Platform.script.toFilePath(windows: Platform.isWindows);
16-
List<String> components = split(script);
17-
int index = components.indexOf('analyzer');
18-
String pkgPath = joinAll(components.sublist(0, index + 1));
14+
String pkgPath = normalize(join(pkg_root.packageRoot, 'analyzer'));
1915
await GeneratedContent.checkAll(
2016
pkgPath,
2117
join(pkgPath, 'tool', 'experiments', 'generate.dart'),

pkg/analyzer/tool/generate_files

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ VM_OPTIONS+=("--enable-asserts")
4343

4444
cd "${SCRIPT_DIR}"
4545
"${DART}" "${VM_OPTIONS[@]}" "messages/generate.dart"
46-
"${DART}" "${VM_OPTIONS[@]}" "summary/generate.dart" "${ROOT_DIR}/pkg/analyzer/lib/src/summary/idl.dart"
46+
"${DART}" "${VM_OPTIONS[@]}" "summary/generate.dart"

pkg/analyzer/tool/summary/check_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ void main() async {
1919
idlFolderPath,
2020
'pkg/analyzer/tool/summary/generate.dart',
2121
getAllTargets(idlPath),
22-
args: [idlPath],
2322
);
2423
}

pkg/analyzer/tool/summary/generate.dart

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,19 @@ import 'dart:convert';
2323
import 'dart:io';
2424

2525
import 'package:_fe_analyzer_shared/src/scanner/scanner.dart';
26+
import 'package:analyzer_testing/package_root.dart' as pkg_root;
2627
import 'package:analyzer_utilities/tools.dart';
28+
import 'package:path/path.dart';
2729

2830
import 'idl_model.dart' as idl_model;
2931
import 'mini_ast.dart';
3032

31-
void main(List<String> args) async {
32-
if (args.length != 1) {
33-
print('Error: IDL path is required');
34-
print('usage: dart generate.dart path/to/idl.dart');
35-
return;
36-
}
37-
String idlPath = args[0];
38-
await GeneratedContent.generateAll(
39-
File(idlPath).parent.path,
40-
getAllTargets(idlPath),
33+
void main() async {
34+
var idlFolderPath = normalize(
35+
join(pkg_root.packageRoot, 'analyzer', 'lib', 'src', 'summary'),
4136
);
37+
var idlPath = normalize(join(idlFolderPath, 'idl.dart'));
38+
await GeneratedContent.generateAll(idlFolderPath, getAllTargets(idlPath));
4239
}
4340

4441
List<GeneratedContent> getAllTargets(String idlPath) {

pkg/analyzer_plugin/tool/spec/check_all_test.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:io';
6-
5+
import 'package:analyzer_testing/package_root.dart' as pkg_root;
76
import 'package:analyzer_utilities/tools.dart';
87
import 'package:path/path.dart';
98

@@ -12,10 +11,7 @@ import 'generate_all.dart';
1211
/// Check that all targets have been code generated. If they haven't tell the
1312
/// user to run generate_all.dart.
1413
Future<void> main() async {
15-
var script = Platform.script.toFilePath(windows: Platform.isWindows);
16-
var components = split(script);
17-
var index = components.indexOf('analyzer_plugin');
18-
var pkgPath = joinAll(components.sublist(0, index + 1));
14+
var pkgPath = normalize(join(pkg_root.packageRoot, 'analyzer_plugin'));
1915
await GeneratedContent.checkAll(
2016
pkgPath, join(pkgPath, 'tool', 'spec', 'generate_all.dart'), allTargets);
2117
}

pkg/analyzer_plugin/tool/spec/generate_all.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:io';
6-
5+
import 'package:analyzer_testing/package_root.dart' as pkg_root;
76
import 'package:analyzer_utilities/tools.dart';
87
import 'package:path/path.dart';
98

@@ -16,8 +15,7 @@ import 'to_html.dart' as to_html;
1615

1716
/// Generate all targets.
1817
Future<void> main() async {
19-
var script = Platform.script.toFilePath(windows: Platform.isWindows);
20-
var pkgPath = normalize(join(dirname(script), '..', '..'));
18+
var pkgPath = normalize(join(pkg_root.packageRoot, 'analyzer_plugin'));
2119
await GeneratedContent.generateAll(pkgPath, allTargets);
2220
}
2321

pkg/analyzer_utilities/lib/tools.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,8 @@ abstract class GeneratedContent {
307307
static Future<void> checkAll(
308308
String pkgPath,
309309
String generatorPath,
310-
Iterable<GeneratedContent> targets, {
311-
List<String> args = const [],
312-
}) async {
310+
Iterable<GeneratedContent> targets,
311+
) async {
313312
var generateNeeded = false;
314313
for (var target in targets) {
315314
var ok = await target.check(pkgPath);
@@ -325,7 +324,7 @@ abstract class GeneratedContent {
325324
print('Please regenerate using:');
326325
var executable = Platform.executable;
327326
var generateScript = normalize(joinAll(posix.split(generatorPath)));
328-
print(' $executable $generateScript ${args.join(" ")}');
327+
print(' $executable $generateScript');
329328
fail('Generated content needs to be regenerated');
330329
}
331330
}

0 commit comments

Comments
 (0)