OLD | NEW |
1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
2 | 2 |
3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
4 // for details. All rights reserved. Use of this source code is governed by a | 4 // for details. All rights reserved. Use of this source code is governed by a |
5 // BSD-style license that can be found in the LICENSE file. | 5 // BSD-style license that can be found in the LICENSE file. |
6 | 6 |
7 /** The entry point for the analyzer. */ | 7 /** The entry point for the analyzer. */ |
8 library analyzer; | 8 library analyzer; |
9 | 9 |
10 import 'dart:async'; | 10 import 'dart:async'; |
(...skipping 20 matching lines...) Expand all Loading... |
31 var options = CommandLineOptions.parse(args); | 31 var options = CommandLineOptions.parse(args); |
32 return _runAnalyzer(options); | 32 return _runAnalyzer(options); |
33 }); | 33 }); |
34 } else { | 34 } else { |
35 ErrorSeverity result = _runAnalyzer(options); | 35 ErrorSeverity result = _runAnalyzer(options); |
36 exit(result.ordinal); | 36 exit(result.ordinal); |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 ErrorSeverity _runAnalyzer(CommandLineOptions options) { | 40 ErrorSeverity _runAnalyzer(CommandLineOptions options) { |
| 41 if (!options.machineFormat) { |
| 42 stdout.writeln("Analyzing ${options.sourceFiles}..."); |
| 43 } |
| 44 ErrorSeverity allResult = ErrorSeverity.NONE; |
41 for (String sourcePath in options.sourceFiles) { | 45 for (String sourcePath in options.sourceFiles) { |
42 sourcePath = sourcePath.trim(); | 46 sourcePath = sourcePath.trim(); |
43 // check that file exists | 47 // check that file exists |
44 if (!new File(sourcePath).existsSync()) { | 48 if (!new File(sourcePath).existsSync()) { |
45 print('File not found: $sourcePath'); | 49 print('File not found: $sourcePath'); |
46 return ErrorSeverity.ERROR; | 50 return ErrorSeverity.ERROR; |
47 } | 51 } |
48 // check that file is Dart file | 52 // check that file is Dart file |
49 if (!AnalysisEngine.isDartFileName(sourcePath)) { | 53 if (!AnalysisEngine.isDartFileName(sourcePath)) { |
50 print('$sourcePath is not a Dart file'); | 54 print('$sourcePath is not a Dart file'); |
51 return ErrorSeverity.ERROR; | 55 return ErrorSeverity.ERROR; |
52 } | 56 } |
53 // start analysis | 57 // do analyze |
54 ErrorFormatter formatter = new ErrorFormatter(options.machineFormat ? stderr
: stdout, options); | 58 ErrorFormatter formatter = new ErrorFormatter(options.machineFormat ? stderr
: stdout, options); |
55 formatter.startAnalysis(); | |
56 // do analyze | |
57 AnalyzerImpl analyzer = new AnalyzerImpl(options); | 59 AnalyzerImpl analyzer = new AnalyzerImpl(options); |
58 analyzer.analyze(sourcePath); | 60 analyzer.analyze(sourcePath); |
59 // pring errors | 61 // pring errors |
60 formatter.formatErrors(analyzer.errorInfos); | 62 formatter.formatErrors(analyzer.errorInfos); |
61 // prepare status | 63 // prepare status |
62 ErrorSeverity status = analyzer.maxErrorSeverity; | 64 ErrorSeverity status = analyzer.maxErrorSeverity; |
63 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { | 65 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { |
64 status = ErrorSeverity.ERROR; | 66 status = ErrorSeverity.ERROR; |
65 } | 67 } |
66 return status; | 68 allResult = allResult.max(status); |
67 } | 69 } |
| 70 return allResult; |
68 } | 71 } |
69 | 72 |
70 typedef ErrorSeverity BatchRunnerHandler(List<String> args); | 73 typedef ErrorSeverity BatchRunnerHandler(List<String> args); |
71 | 74 |
72 /// Provides a framework to read command line options from stdin and feed them t
o a callback. | 75 /// Provides a framework to read command line options from stdin and feed them t
o a callback. |
73 class BatchRunner { | 76 class BatchRunner { |
74 /** | 77 /** |
75 * Run the tool in 'batch' mode, receiving command lines through stdin and ret
urning pass/fail | 78 * Run the tool in 'batch' mode, receiving command lines through stdin and ret
urning pass/fail |
76 * status through stdout. This feature is intended for use in unit testing. | 79 * status through stdout. This feature is intended for use in unit testing. |
77 */ | 80 */ |
(...skipping 16 matching lines...) Expand all Loading... |
94 } | 97 } |
95 // prepare aruments | 98 // prepare aruments |
96 var args; | 99 var args; |
97 { | 100 { |
98 var lineArgs = line.split(new RegExp('\\s+')); | 101 var lineArgs = line.split(new RegExp('\\s+')); |
99 args = new List<String>(); | 102 args = new List<String>(); |
100 args.addAll(sharedArgs); | 103 args.addAll(sharedArgs); |
101 args.addAll(lineArgs); | 104 args.addAll(lineArgs); |
102 args.remove('-b'); | 105 args.remove('-b'); |
103 args.remove('--batch'); | 106 args.remove('--batch'); |
| 107 // TODO(scheglov) https://code.google.com/p/dart/issues/detail?id=11061 |
| 108 args.remove('-batch'); |
104 } | 109 } |
105 // analyze single set of arguments | 110 // analyze single set of arguments |
106 try { | 111 try { |
107 totalTests++; | 112 totalTests++; |
108 ErrorSeverity result = handler(args); | 113 ErrorSeverity result = handler(args); |
109 bool resultPass = result != ErrorSeverity.ERROR; | 114 bool resultPass = result != ErrorSeverity.ERROR; |
110 if (!resultPass) { | 115 if (!resultPass) { |
111 testsFailed++; | 116 testsFailed++; |
112 } | 117 } |
113 batchResult = batchResult.max(result); | 118 batchResult = batchResult.max(result); |
114 // Write stderr end token and flush. | 119 // Write stderr end token and flush. |
115 stderr.writeln('>>> EOF STDERR'); | 120 stderr.writeln('>>> EOF STDERR'); |
116 String resultPassString = resultPass ? 'PASS' : 'FAIL'; | 121 String resultPassString = resultPass ? 'PASS' : 'FAIL'; |
117 stdout.writeln('>>> TEST $resultPassString ${stopwatch.elapsedMillisecon
ds}ms'); | 122 stdout.writeln('>>> TEST $resultPassString ${stopwatch.elapsedMillisecon
ds}ms'); |
118 } catch (e, stackTrace) { | 123 } catch (e, stackTrace) { |
119 stderr.writeln(e); | 124 stderr.writeln(e); |
120 stderr.writeln(stackTrace); | 125 stderr.writeln(stackTrace); |
121 stderr.writeln('>>> EOF STDERR'); | 126 stderr.writeln('>>> EOF STDERR'); |
122 stdout.writeln('>>> TEST CRASH'); | 127 stdout.writeln('>>> TEST CRASH'); |
123 } | 128 } |
124 }); | 129 }); |
125 } | 130 } |
126 } | 131 } |
OLD | NEW |