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

Unified Diff: pkg/analyzer_cli/lib/src/driver.dart

Issue 2704103002: Some improvements to the command-line analyzer's output. (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer_cli/lib/src/driver.dart
diff --git a/pkg/analyzer_cli/lib/src/driver.dart b/pkg/analyzer_cli/lib/src/driver.dart
index e6e3ad7197df7846220bbfdb77f1013a3f0f4b0c..cfd3b49d5bf0807103b8beccf3e09d99937afc54 100644
--- a/pkg/analyzer_cli/lib/src/driver.dart
+++ b/pkg/analyzer_cli/lib/src/driver.dart
@@ -38,12 +38,6 @@ import 'package:analyzer/src/summary/idl.dart';
import 'package:analyzer/src/summary/package_bundle_reader.dart';
import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk;
import 'package:analyzer/src/task/options.dart';
-import 'package:analyzer_cli/src/analyzer_impl.dart';
-import 'package:analyzer_cli/src/build_mode.dart';
-import 'package:analyzer_cli/src/error_formatter.dart';
-import 'package:analyzer_cli/src/options.dart';
-import 'package:analyzer_cli/src/perf_report.dart';
-import 'package:analyzer_cli/starter.dart';
import 'package:linter/src/rules.dart' as linter;
import 'package:package_config/discovery.dart' as pkg_discovery;
import 'package:package_config/packages.dart' show Packages;
@@ -54,6 +48,13 @@ import 'package:plugin/manager.dart';
import 'package:plugin/plugin.dart';
import 'package:yaml/yaml.dart';
+import '../starter.dart' show CommandLineStarter;
+import 'analyzer_impl.dart';
+import 'build_mode.dart';
+import 'error_formatter.dart';
+import 'options.dart';
+import 'perf_report.dart';
+
/// Shared IO sink for standard error reporting.
///
/// *Visible for testing.*
@@ -159,7 +160,7 @@ class Driver implements CommandLineStarter {
if (options.perfReport != null) {
String json = makePerfReport(
- startTime, currentTimeMillis(), options, _analyzedFileCount, stats);
+ startTime, currentTimeMillis, options, _analyzedFileCount, stats);
new io.File(options.perfReport).writeAsStringSync(json);
}
}
@@ -176,7 +177,17 @@ class Driver implements CommandLineStarter {
/// Perform analysis according to the given [options].
Future<ErrorSeverity> _analyzeAllImpl(CommandLineOptions options) async {
if (!options.machineFormat) {
- outSink.writeln("Analyzing ${options.sourceFiles}...");
+ List<String> fileNames = options.sourceFiles.map((String file) {
+ file = path.normalize(file);
+ if (file == '.') {
+ file = path.basename(path.current);
+ } else if (file == '..') {
+ file = path.basename(path.normalize(path.absolute(file)));
+ }
+ return file;
+ }).toList();
+
+ outSink.writeln("Analyzing ${fileNames.join(', ')}...");
}
// Create a context, or re-use the previous one.
@@ -187,11 +198,11 @@ class Driver implements CommandLineStarter {
return ErrorSeverity.ERROR;
}
- // Add all the files to be analyzed en masse to the context. Skip any
+ // Add all the files to be analyzed en masse to the context. Skip any
// files that were added earlier (whether explicitly or implicitly) to
// avoid causing those files to be unnecessarily re-read.
Set<Source> knownSources = context.sources.toSet();
- List<Source> sourcesToAnalyze = <Source>[];
+ Set<Source> sourcesToAnalyze = new Set<Source>();
ChangeSet changeSet = new ChangeSet();
for (String sourcePath in options.sourceFiles) {
sourcePath = sourcePath.trim();
@@ -215,49 +226,50 @@ class Driver implements CommandLineStarter {
sourcesToAnalyze.add(source);
}
- if (analysisDriver != null) {
- files.forEach((file) {
- analysisDriver.addFile(file.path);
- });
- } else {
- context.applyChanges(changeSet);
- }
+ files.forEach((file) {
Brian Wilkerson 2017/02/19 22:52:17 It looks like this CL is also removing the non-dri
devoncarew 2017/02/21 04:30:47 No - it's unintentional. I had a fair amount of ch
+ analysisDriver.addFile(file.path);
+ });
}
// Analyze the libraries.
ErrorSeverity allResult = ErrorSeverity.NONE;
- var libUris = <Uri>[];
- var parts = <Source>[];
+ List<Uri> libUris = <Uri>[];
+ Set<Source> partSources = new Set<Source>();
+
for (Source source in sourcesToAnalyze) {
SourceKind sourceKind = analysisDriver != null
? await analysisDriver.getSourceKind(source.fullName)
: context.computeKindOf(source);
if (sourceKind == SourceKind.PART) {
- parts.add(source);
+ partSources.add(source);
continue;
}
+ // TODO(devoncarew): Analyzing each source individually causes errors to
+ // be reported multiple times (#25697).
ErrorSeverity status = await _runAnalyzer(source, options);
allResult = allResult.max(status);
libUris.add(source.uri);
}
// Check that each part has a corresponding source in the input list.
- for (Source part in parts) {
+ for (Source partSource in partSources) {
bool found = false;
if (analysisDriver != null) {
- var partFile = analysisDriver.fsState.getFileForPath(part.fullName);
+ var partFile =
+ analysisDriver.fsState.getFileForPath(partSource.fullName);
if (libUris.contains(partFile.library?.uri)) {
found = true;
}
} else {
- for (var lib in context.getLibrariesContaining(part)) {
+ for (var lib in context.getLibrariesContaining(partSource)) {
if (libUris.contains(lib.uri)) {
found = true;
}
}
}
if (!found) {
- errorSink.writeln("${part.fullName} is a part and cannot be analyzed.");
+ errorSink.writeln(
+ "${partSource.fullName} is a part and cannot be analyzed.");
errorSink.writeln("Please pass in a library that contains this part.");
io.exitCode = ErrorSeverity.ERROR.ordinal;
allResult = allResult.max(ErrorSeverity.ERROR);
@@ -468,6 +480,8 @@ class Driver implements CommandLineStarter {
return new SourceFactory(resolvers, packageInfo.packages);
}
+ // TODO(devoncarew): This needs to respect analysis_options excludes.
+
/// Collect all analyzable files at [filePath], recursively if it's a
/// directory, ignoring links.
Iterable<io.File> _collectFiles(String filePath) {
@@ -688,7 +702,7 @@ class Driver implements CommandLineStarter {
/// Analyze a single source.
Future<ErrorSeverity> _runAnalyzer(
Source source, CommandLineOptions options) async {
- int startTime = currentTimeMillis();
+ int startTime = currentTimeMillis;
AnalyzerImpl analyzer = new AnalyzerImpl(_context.analysisOptions, _context,
analysisDriver, source, options, stats, startTime);
ErrorSeverity errorSeverity = await analyzer.analyze();

Powered by Google App Engine
This is Rietveld 408576698