Skip to content

Commit 955e351

Browse files
munificentCommit Queue
authored andcommitted
Batch files when running CFE to update static error tests.
The static error test updater needs to ask analyzer, CFE, and dart2js for the errors for each updated test file. Previously, it would invoke each of those as a separate process, one at a time, for each test file. This was comically slow. I recently updated it to invoke analyzer as a library and analyze all the files at once, which made that part >100x faster. This CL does essentially the same thing for CFE. It's still invoking CFE as a process, but it does so with a batch of files. It's not as fast as analyzer is, but it's much better. It's still calling dart2js once per file but, strangely, that isn't too slow. Also, web static error tests aren't very common, so this isn't as important. Change-Id: I6756901bb761579dc90f8af4d9774014b04bb009 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399885 Auto-Submit: Bob Nystrom <[email protected]> Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Bob Nystrom <[email protected]>
1 parent 4e5144a commit 955e351

File tree

2 files changed

+277
-194
lines changed

2 files changed

+277
-194
lines changed

pkg/test_runner/tool/convert_multitest.dart

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@ import 'dart:io';
1313

1414
import 'package:args/args.dart';
1515
import 'package:path/path.dart';
16+
import 'package:path/path.dart' as p;
17+
import 'package:test_runner/src/command_output.dart';
1618
import 'package:test_runner/src/multitest.dart';
1719
import 'package:test_runner/src/path.dart';
1820
import 'package:test_runner/src/static_error.dart';
1921
import 'package:test_runner/src/test_file.dart';
2022
import 'package:test_runner/src/update_errors.dart';
2123

22-
import 'update_static_error_tests.dart' show runAnalyzerCli, runCfe;
24+
import 'update_static_error_tests.dart' show dartPath;
25+
26+
final _analyzerPath = p.join('pkg', 'analyzer_cli', 'bin', 'analyzer.dart');
2327

2428
Future<List<StaticError>> getErrors(
2529
List<String> options, String filePath) async {
26-
var analyzerErrors = await runAnalyzerCli(File(filePath), options);
27-
var cfeErrors = await runCfe(File(filePath), options);
30+
var analyzerErrors = await _runAnalyzer(File(filePath), options);
31+
var cfeErrors = await _runCfe(File(filePath), options);
2832
return [...analyzerErrors, ...cfeErrors];
2933
}
3034

@@ -264,3 +268,61 @@ Future<void> main(List<String> arguments) async {
264268
(results["enable-experiment"] as List).cast<String>());
265269
}
266270
}
271+
272+
/// Invoke analyzer on [file] and gather all static errors it reports.
273+
Future<List<StaticError>> _runAnalyzer(File file, List<String> options) async {
274+
var result = await Process.run(dartPath, [
275+
_analyzerPath,
276+
...options,
277+
"--format=json",
278+
file.absolute.path,
279+
]);
280+
281+
// Analyzer returns 3 when it detects errors, 2 when it detects
282+
// warnings and --fatal-warnings is enabled, 1 when it detects
283+
// hints and --fatal-hints or --fatal-infos are enabled.
284+
if (result.exitCode < 0 || result.exitCode > 3) {
285+
print("Analyzer run failed: ${result.stdout}\n${result.stderr}");
286+
print("Error: failed to update ${file.path}");
287+
return const [];
288+
}
289+
290+
var errors = <StaticError>[];
291+
var warnings = <StaticError>[];
292+
AnalysisCommandOutput.parseErrors(result.stdout as String, errors, warnings);
293+
294+
return [...errors, ...warnings];
295+
}
296+
297+
/// Invoke CFE on [file] and gather all static errors it reports.
298+
Future<List<StaticError>> _runCfe(File file, List<String> options) async {
299+
var absolutePath = file.absolute.path;
300+
// TODO(rnystrom): Running the CFE command line each time is slow and wastes
301+
// time generating code, which we don't care about. Import it as a library or
302+
// at least run it in batch mode.
303+
var result = await Process.run(dartPath, [
304+
"pkg/front_end/tool/compile.dart",
305+
...options,
306+
"--verify",
307+
"-o",
308+
"dev:null", // Output is only created for file URIs.
309+
absolutePath,
310+
]);
311+
312+
// Running the above command may generate a dill file next to the test, which
313+
// we don't want, so delete it if present.
314+
var dill = File("$absolutePath.dill");
315+
if (await dill.exists()) {
316+
await dill.delete();
317+
}
318+
319+
if (result.exitCode != 0) {
320+
print("CFE run failed: ${result.stdout}\n${result.stderr}");
321+
print("Error: failed to update ${file.path}");
322+
return const [];
323+
}
324+
var errors = <StaticError>[];
325+
var warnings = <StaticError>[];
326+
FastaCommandOutput.parseErrors(result.stdout as String, errors, warnings);
327+
return [...errors, ...warnings];
328+
}

0 commit comments

Comments
 (0)