Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: pkg/analyzer_cli/lib/src/driver.dart

Issue 2793813002: Fix an issue with duplicate reported analysis errors. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer_cli.src.driver; 5 library analyzer_cli.src.driver;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io' as io; 9 import 'dart:io' as io;
10 10
(...skipping 20 matching lines...) Expand all
31 import 'package:analyzer/src/generated/source_io.dart'; 31 import 'package:analyzer/src/generated/source_io.dart';
32 import 'package:analyzer/src/generated/utilities_general.dart' 32 import 'package:analyzer/src/generated/utilities_general.dart'
33 show PerformanceTag; 33 show PerformanceTag;
34 import 'package:analyzer/src/source/source_resource.dart'; 34 import 'package:analyzer/src/source/source_resource.dart';
35 import 'package:analyzer/src/summary/idl.dart'; 35 import 'package:analyzer/src/summary/idl.dart';
36 import 'package:analyzer/src/summary/package_bundle_reader.dart'; 36 import 'package:analyzer/src/summary/package_bundle_reader.dart';
37 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; 37 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk;
38 import 'package:analyzer_cli/src/analyzer_impl.dart'; 38 import 'package:analyzer_cli/src/analyzer_impl.dart';
39 import 'package:analyzer_cli/src/build_mode.dart'; 39 import 'package:analyzer_cli/src/build_mode.dart';
40 import 'package:analyzer_cli/src/error_formatter.dart'; 40 import 'package:analyzer_cli/src/error_formatter.dart';
41 import 'package:analyzer_cli/src/error_severity.dart';
41 import 'package:analyzer_cli/src/options.dart'; 42 import 'package:analyzer_cli/src/options.dart';
42 import 'package:analyzer_cli/src/perf_report.dart'; 43 import 'package:analyzer_cli/src/perf_report.dart';
43 import 'package:analyzer_cli/starter.dart' show CommandLineStarter; 44 import 'package:analyzer_cli/starter.dart' show CommandLineStarter;
44 import 'package:linter/src/rules.dart' as linter; 45 import 'package:linter/src/rules.dart' as linter;
45 import 'package:package_config/discovery.dart' as pkg_discovery; 46 import 'package:package_config/discovery.dart' as pkg_discovery;
46 import 'package:package_config/packages.dart' show Packages; 47 import 'package:package_config/packages.dart' show Packages;
47 import 'package:package_config/packages_file.dart' as pkgfile show parse; 48 import 'package:package_config/packages_file.dart' as pkgfile show parse;
48 import 'package:package_config/src/packages_impl.dart' show MapPackages; 49 import 'package:package_config/src/packages_impl.dart' show MapPackages;
49 import 'package:path/path.dart' as path; 50 import 'package:path/path.dart' as path;
50 import 'package:plugin/manager.dart'; 51 import 'package:plugin/manager.dart';
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 if (analysisDriver == null) { 226 if (analysisDriver == null) {
226 context.applyChanges(changeSet); 227 context.applyChanges(changeSet);
227 } 228 }
228 } 229 }
229 230
230 // Analyze the libraries. 231 // Analyze the libraries.
231 ErrorSeverity allResult = ErrorSeverity.NONE; 232 ErrorSeverity allResult = ErrorSeverity.NONE;
232 List<Uri> libUris = <Uri>[]; 233 List<Uri> libUris = <Uri>[];
233 Set<Source> partSources = new Set<Source>(); 234 Set<Source> partSources = new Set<Source>();
234 235
236 SeverityProcessor defaultSeverityProcessor = (AnalysisError error) {
237 return determineProcessedSeverity(
238 error, options, _context.analysisOptions);
239 };
240
241 // We currently print out to stderr to ensure that when in batch mode we
242 // print to stderr, this is because the prints from batch are made to
243 // stderr. The reason that options.shouldBatch isn't used is because when
244 // the argument flags are constructed in BatchRunner and passed in from
245 // batch mode which removes the batch flag to prevent the "cannot have the
246 // batch flag and source file" error message.
247 ErrorFormatter formatter;
248 if (options.machineFormat) {
249 formatter = new MachineErrorFormatter(errorSink, options, stats,
250 severityProcessor: defaultSeverityProcessor);
251 } else {
252 formatter = new HumanErrorFormatter(outSink, options, stats,
253 severityProcessor: defaultSeverityProcessor);
254 }
255
235 for (Source source in sourcesToAnalyze) { 256 for (Source source in sourcesToAnalyze) {
236 SourceKind sourceKind = analysisDriver != null 257 SourceKind sourceKind = analysisDriver != null
237 ? await analysisDriver.getSourceKind(source.fullName) 258 ? await analysisDriver.getSourceKind(source.fullName)
238 : context.computeKindOf(source); 259 : context.computeKindOf(source);
239 if (sourceKind == SourceKind.PART) { 260 if (sourceKind == SourceKind.PART) {
240 partSources.add(source); 261 partSources.add(source);
241 continue; 262 continue;
242 } 263 }
243 // TODO(devoncarew): Analyzing each source individually causes errors to 264 ErrorSeverity status = await _runAnalyzer(source, options, formatter);
244 // be reported multiple times (#25697).
245 ErrorSeverity status = await _runAnalyzer(source, options);
246 allResult = allResult.max(status); 265 allResult = allResult.max(status);
247 libUris.add(source.uri); 266 libUris.add(source.uri);
248 } 267 }
249 268
269 formatter.flush();
270
250 // Check that each part has a corresponding source in the input list. 271 // Check that each part has a corresponding source in the input list.
251 for (Source partSource in partSources) { 272 for (Source partSource in partSources) {
252 bool found = false; 273 bool found = false;
253 if (analysisDriver != null) { 274 if (analysisDriver != null) {
254 var partFile = 275 var partFile =
255 analysisDriver.fsState.getFileForPath(partSource.fullName); 276 analysisDriver.fsState.getFileForPath(partSource.fullName);
256 if (libUris.contains(partFile.library?.uri)) { 277 if (libUris.contains(partFile.library?.uri)) {
257 found = true; 278 found = true;
258 } 279 }
259 } else { 280 } else {
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 plugins.addAll(AnalysisEngine.instance.requiredPlugins); 705 plugins.addAll(AnalysisEngine.instance.requiredPlugins);
685 plugins.addAll(_userDefinedPlugins); 706 plugins.addAll(_userDefinedPlugins);
686 707
687 ExtensionManager manager = new ExtensionManager(); 708 ExtensionManager manager = new ExtensionManager();
688 manager.processPlugins(plugins); 709 manager.processPlugins(plugins);
689 710
690 linter.registerLintRules(); 711 linter.registerLintRules();
691 } 712 }
692 713
693 /// Analyze a single source. 714 /// Analyze a single source.
694 Future<ErrorSeverity> _runAnalyzer( 715 Future<ErrorSeverity> _runAnalyzer(Source source, CommandLineOptions options,
695 Source source, CommandLineOptions options) async { 716 ErrorFormatter formatter) async {
696 int startTime = currentTimeMillis; 717 int startTime = currentTimeMillis;
697 AnalyzerImpl analyzer = new AnalyzerImpl(_context.analysisOptions, _context, 718 AnalyzerImpl analyzer = new AnalyzerImpl(_context.analysisOptions, _context,
698 analysisDriver, source, options, stats, startTime); 719 analysisDriver, source, options, stats, startTime);
699 ErrorSeverity errorSeverity = await analyzer.analyze(); 720 ErrorSeverity errorSeverity = await analyzer.analyze(formatter);
700 if (errorSeverity == ErrorSeverity.ERROR) { 721 if (errorSeverity == ErrorSeverity.ERROR) {
701 io.exitCode = errorSeverity.ordinal; 722 io.exitCode = errorSeverity.ordinal;
702 } 723 }
703 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) { 724 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) {
704 io.exitCode = errorSeverity.ordinal; 725 io.exitCode = errorSeverity.ordinal;
705 } 726 }
706 return errorSeverity; 727 return errorSeverity;
707 } 728 }
708 729
709 void _setupSdk(CommandLineOptions options, bool useSummaries, 730 void _setupSdk(CommandLineOptions options, bool useSummaries,
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 for (var package in packages) { 933 for (var package in packages) {
913 var packageName = path.basename(package.path); 934 var packageName = path.basename(package.path);
914 var realPath = package.resolveSymbolicLinksSync(); 935 var realPath = package.resolveSymbolicLinksSync();
915 result[packageName] = [ 936 result[packageName] = [
916 PhysicalResourceProvider.INSTANCE.getFolder(realPath) 937 PhysicalResourceProvider.INSTANCE.getFolder(realPath)
917 ]; 938 ];
918 } 939 }
919 return result; 940 return result;
920 } 941 }
921 } 942 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698