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

Side by Side Diff: pkg/analyzer/bin/analyzer.dart

Issue 1102613002: Analyzer CLI removal. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env dart
2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file.
5
6 /** The entry point for the analyzer. */
7 library analyzer;
8
9 import 'dart:async';
10 import 'dart:convert';
11 import 'dart:io';
12
13 import 'package:analyzer/options.dart';
14 import 'package:analyzer/src/analyzer_impl.dart';
15 import 'package:analyzer/src/generated/engine.dart';
16 import 'package:analyzer/src/generated/error.dart';
17 import 'package:analyzer/src/generated/interner.dart';
18 import 'package:analyzer/src/generated/java_core.dart' show JavaSystem;
19 import 'package:analyzer/src/generated/java_engine.dart';
20 import 'package:analyzer/src/generated/utilities_general.dart';
21
22 void main(List<String> args) {
23 StringUtilities.INTERNER = new MappedInterner();
24 CommandLineOptions options = CommandLineOptions.parse(args);
25 if (options.shouldBatch) {
26 BatchRunner.runAsBatch(args, (List<String> args) {
27 CommandLineOptions options = CommandLineOptions.parse(args);
28 return _analyzeAll(options, true);
29 });
30 } else {
31 _analyzeAll(options, false);
32 }
33 }
34
35 _analyzeAll(CommandLineOptions options, bool isBatch) {
36 if (!options.machineFormat) {
37 stdout.writeln("Analyzing ${options.sourceFiles}...");
38 }
39 ErrorSeverity allResult = ErrorSeverity.NONE;
40 for (String sourcePath in options.sourceFiles) {
41 sourcePath = sourcePath.trim();
42 // check that file exists
43 if (!new File(sourcePath).existsSync()) {
44 print('File not found: $sourcePath');
45 exitCode = ErrorSeverity.ERROR.ordinal;
46 // fail fast; don't analyze more files
47 return ErrorSeverity.ERROR;
48 }
49 // check that file is Dart file
50 if (!AnalysisEngine.isDartFileName(sourcePath)) {
51 print('$sourcePath is not a Dart file');
52 exitCode = ErrorSeverity.ERROR.ordinal;
53 // fail fast; don't analyze more files
54 return ErrorSeverity.ERROR;
55 }
56 ErrorSeverity status = _runAnalyzer(options, sourcePath, isBatch);
57 allResult = allResult.max(status);
58 }
59 return allResult;
60 }
61
62 _runAnalyzer(CommandLineOptions options, String sourcePath, bool isBatch) {
63 if (options.warmPerf) {
64 int startTime = JavaSystem.currentTimeMillis();
65 AnalyzerImpl analyzer =
66 new AnalyzerImpl(sourcePath, options, startTime, isBatch);
67 analyzer.analyzeSync(printMode: 2);
68
69 for (int i = 0; i < 8; i++) {
70 startTime = JavaSystem.currentTimeMillis();
71 analyzer = new AnalyzerImpl(sourcePath, options, startTime, isBatch);
72 analyzer.analyzeSync(printMode: 0);
73 }
74
75 PerformanceTag.reset();
76 startTime = JavaSystem.currentTimeMillis();
77 analyzer = new AnalyzerImpl(sourcePath, options, startTime, isBatch);
78 return analyzer.analyzeSync();
79 }
80 int startTime = JavaSystem.currentTimeMillis();
81 AnalyzerImpl analyzer =
82 new AnalyzerImpl(sourcePath, options, startTime, isBatch);
83 var errorSeverity = analyzer.analyzeSync();
84 if (errorSeverity == ErrorSeverity.ERROR) {
85 exitCode = errorSeverity.ordinal;
86 }
87 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) {
88 exitCode = errorSeverity.ordinal;
89 }
90 return errorSeverity;
91 }
92
93 typedef ErrorSeverity BatchRunnerHandler(List<String> args);
94
95 /// Provides a framework to read command line options from stdin and feed them t o a callback.
96 class BatchRunner {
97 /**
98 * Run the tool in 'batch' mode, receiving command lines through stdin and ret urning pass/fail
99 * status through stdout. This feature is intended for use in unit testing.
100 */
101 static void runAsBatch(List<String> sharedArgs, BatchRunnerHandler handler) {
102 stdout.writeln('>>> BATCH START');
103 Stopwatch stopwatch = new Stopwatch();
104 stopwatch.start();
105 int testsFailed = 0;
106 int totalTests = 0;
107 ErrorSeverity batchResult = ErrorSeverity.NONE;
108 // read line from stdin
109 Stream cmdLine =
110 stdin.transform(UTF8.decoder).transform(new LineSplitter());
111 cmdLine.listen((String line) {
112 // may be finish
113 if (line.isEmpty) {
114 var time = stopwatch.elapsedMilliseconds;
115 stdout.writeln(
116 '>>> BATCH END (${totalTests - testsFailed}/$totalTests) ${time}ms') ;
117 exitCode = batchResult.ordinal;
118 }
119 // prepare aruments
120 var args;
121 {
122 var lineArgs = line.split(new RegExp('\\s+'));
123 args = new List<String>();
124 args.addAll(sharedArgs);
125 args.addAll(lineArgs);
126 args.remove('-b');
127 args.remove('--batch');
128 }
129 // analyze single set of arguments
130 try {
131 totalTests++;
132 ErrorSeverity result = handler(args);
133 bool resultPass = result != ErrorSeverity.ERROR;
134 if (!resultPass) {
135 testsFailed++;
136 }
137 batchResult = batchResult.max(result);
138 // Write stderr end token and flush.
139 stderr.writeln('>>> EOF STDERR');
140 String resultPassString = resultPass ? 'PASS' : 'FAIL';
141 stdout.writeln(
142 '>>> TEST $resultPassString ${stopwatch.elapsedMilliseconds}ms');
143 } catch (e, stackTrace) {
144 stderr.writeln(e);
145 stderr.writeln(stackTrace);
146 stderr.writeln('>>> EOF STDERR');
147 stdout.writeln('>>> TEST CRASH');
148 }
149 });
150 }
151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698