From e31f9fc55fdf1fbe60369742683961bac48e2c22 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 26 Sep 2018 17:42:32 +0000 Subject: [PATCH] Track front end errors. In a later CL I will add code to print out the errors in the case where the front end detects errors but the analyzer does not. Change-Id: I675a9ffcce7cfe7afa32406b3310e7b1d42d2afc Reviewed-on: https://dart-review.googlesource.com/76720 Reviewed-by: Brian Wilkerson Reviewed-by: Konstantin Shcheglov Commit-Queue: Paul Berry --- .../lib/src/kernel.dart | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/pkg/analyzer_fe_comparison/lib/src/kernel.dart b/pkg/analyzer_fe_comparison/lib/src/kernel.dart index 561f5e6023cc5..24170d3d1465e 100644 --- a/pkg/analyzer_fe_comparison/lib/src/kernel.dart +++ b/pkg/analyzer_fe_comparison/lib/src/kernel.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'package:analyzer_fe_comparison/src/comparison_node.dart'; +import 'package:front_end/src/api_prototype/compilation_message.dart'; import 'package:front_end/src/api_prototype/compiler_options.dart'; import 'package:front_end/src/api_prototype/kernel_generator.dart'; import 'package:front_end/src/api_prototype/standard_file_system.dart'; @@ -15,14 +16,12 @@ import 'package:kernel/target/targets.dart'; /// [ComparisonNode] representing them. Future analyzePackage( List inputs, Uri packagesFileUri, Uri platformUri) async { - bool errorOccurred = false; + var errors = []; var component = await kernelForComponent( - inputs, - _makeCompilerOptions(packagesFileUri, platformUri, (_) { - errorOccurred = true; - })); - if (errorOccurred) { - return ComparisonNode('Error occurred'); + inputs, _makeCompilerOptions(packagesFileUri, platformUri, errors.add)); + if (errors.isNotEmpty) { + return ComparisonNode( + 'Error occurred', errors.map(_compilationMessageToNode).toList()); } var libraryNodes = []; var visitor = _KernelVisitor(libraryNodes); @@ -40,14 +39,12 @@ Future analyzePackage( /// Only libraries whose URI passes the [uriFilter] are included in the results. Future analyzeProgram(Uri input, Uri packagesFileUri, Uri platformUri, bool uriFilter(Uri uri)) async { - var errorOccurred = false; + var errors = []; var component = await kernelForProgram( - input, - _makeCompilerOptions(packagesFileUri, platformUri, (_) { - errorOccurred = true; - })); - if (errorOccurred) { - return ComparisonNode('Error occurred'); + input, _makeCompilerOptions(packagesFileUri, platformUri, errors.add)); + if (errors.isNotEmpty) { + return ComparisonNode( + 'Error occurred', errors.map(_compilationMessageToNode).toList()); } var libraryNodes = []; var visitor = _KernelVisitor(libraryNodes); @@ -59,6 +56,10 @@ Future analyzeProgram(Uri input, Uri packagesFileUri, return ComparisonNode.sorted('Component', libraryNodes); } +ComparisonNode _compilationMessageToNode(CompilationMessage message) { + return ComparisonNode(message.toString()); +} + CompilerOptions _makeCompilerOptions( Uri packagesFileUri, Uri platformUri, ErrorHandler onError) { var targetFlags = TargetFlags(strongMode: true, syncAsync: true);