Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 analyze_helper; | 5 library analyze_helper; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'package:compiler/compiler.dart' as api; | 9 import 'package:compiler/compiler.dart' as api; |
| 10 import 'package:compiler/compiler_new.dart' as new_api; | 10 import 'package:compiler/compiler_new.dart' as new_api; |
| 11 import 'package:compiler/src/apiimpl.dart'; | 11 import 'package:compiler/src/apiimpl.dart'; |
| 12 import 'package:compiler/src/commandline_options.dart'; | 12 import 'package:compiler/src/commandline_options.dart'; |
| 13 import 'package:compiler/src/diagnostics/messages.dart' show | 13 import 'package:compiler/src/diagnostics/messages.dart' show |
| 14 Message, | 14 Message, |
| 15 MessageKind; | 15 MessageKind; |
| 16 import 'package:compiler/src/filenames.dart'; | 16 import 'package:compiler/src/filenames.dart'; |
| 17 import 'package:compiler/src/source_file_provider.dart'; | 17 import 'package:compiler/src/source_file_provider.dart'; |
| 18 import 'package:compiler/src/util/uri_extras.dart'; | 18 import 'package:compiler/src/util/uri_extras.dart'; |
| 19 | 19 |
| 20 /// Option for hiding whitelisted messages. | |
| 21 const String HIDE_WHITELISTED = '--hide-whitelisted'; | |
| 22 | |
| 20 /** | 23 /** |
| 21 * Map of whitelisted warnings and errors. | 24 * Map of whitelisted warnings and errors. |
| 22 * | 25 * |
| 23 * Only add a whitelisting together with a bug report to dartbug.com and add | 26 * Only add a whitelisting together with a bug report to dartbug.com and add |
| 24 * the bug issue number as a comment on the whitelisting. | 27 * the bug issue number as a comment on the whitelisting. |
| 25 * | 28 * |
| 26 * Use an identifiable suffix of the file uri as key. Use a fixed substring of | 29 * Use an identifiable suffix of the file uri as key. Use a fixed substring of |
| 27 * the error/warning message in the list of whitelistings for each file. | 30 * the error/warning message in the list of whitelistings for each file. |
| 28 */ | 31 */ |
| 29 // TODO(johnniwinther): Support canonical URIs as keys and message kinds as | 32 // TODO(johnniwinther): Support canonical URIs as keys and message kinds as |
| 30 // values. | 33 // values. |
| 31 | 34 |
| 32 class CollectingDiagnosticHandler extends FormattingDiagnosticHandler { | 35 class CollectingDiagnosticHandler extends FormattingDiagnosticHandler { |
| 33 bool hasWarnings = false; | 36 bool hasWarnings = false; |
| 34 bool hasHint = false; | 37 bool hasHint = false; |
| 35 bool hasErrors = false; | 38 bool hasErrors = false; |
| 36 bool lastWasWhitelisted = false; | 39 bool lastWasWhitelisted = false; |
| 40 bool showWhitelisted = true; | |
| 37 | 41 |
| 38 Map<String, Map<dynamic/*String|MessageKind*/, int>> whiteListMap | 42 Map<String, Map<dynamic/*String|MessageKind*/, int>> whiteListMap |
| 39 = new Map<String, Map<dynamic/*String|MessageKind*/, int>>(); | 43 = new Map<String, Map<dynamic/*String|MessageKind*/, int>>(); |
| 40 | 44 |
| 41 CollectingDiagnosticHandler( | 45 CollectingDiagnosticHandler( |
| 42 Map<String, List/*<String|MessageKind>*/> whiteList, | 46 Map<String, List/*<String|MessageKind>*/> whiteList, |
| 43 SourceFileProvider provider) | 47 SourceFileProvider provider) |
| 44 : super(provider) { | 48 : super(provider) { |
| 45 whiteList.forEach((String file, List/*<String|MessageKind>*/ messageParts) { | 49 whiteList.forEach((String file, List/*<String|MessageKind>*/ messageParts) { |
| 46 var useMap = new Map<dynamic/*String|MessageKind*/, int>(); | 50 var useMap = new Map<dynamic/*String|MessageKind*/, int>(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 return false; | 110 return false; |
| 107 } | 111 } |
| 108 | 112 |
| 109 @override | 113 @override |
| 110 void report(Message message, Uri uri, int begin, int end, String text, | 114 void report(Message message, Uri uri, int begin, int end, String text, |
| 111 api.Diagnostic kind) { | 115 api.Diagnostic kind) { |
| 112 if (kind == api.Diagnostic.WARNING) { | 116 if (kind == api.Diagnostic.WARNING) { |
| 113 if (checkWhiteList(uri, message, text)) { | 117 if (checkWhiteList(uri, message, text)) { |
| 114 // Suppress whitelisted warnings. | 118 // Suppress whitelisted warnings. |
| 115 lastWasWhitelisted = true; | 119 lastWasWhitelisted = true; |
| 116 if (verbose) { | 120 if (showWhitelisted || verbose) { |
| 117 super.report(message, uri, begin, end, text, kind); | 121 super.report(message, uri, begin, end, text, kind); |
| 118 } | 122 } |
| 119 return; | 123 return; |
| 120 } | 124 } |
| 121 hasWarnings = true; | 125 hasWarnings = true; |
| 122 } | 126 } |
| 123 if (kind == api.Diagnostic.HINT) { | 127 if (kind == api.Diagnostic.HINT) { |
| 124 if (checkWhiteList(uri, message, text)) { | 128 if (checkWhiteList(uri, message, text)) { |
| 125 // Suppress whitelisted hints. | 129 // Suppress whitelisted hints. |
| 126 lastWasWhitelisted = true; | 130 lastWasWhitelisted = true; |
| 127 if (verbose) { | 131 if (showWhitelisted || verbose) { |
| 128 super.report(message, uri, begin, end, text, kind); | 132 super.report(message, uri, begin, end, text, kind); |
| 129 } | 133 } |
| 130 return; | 134 return; |
| 131 } | 135 } |
| 132 hasHint = true; | 136 hasHint = true; |
| 133 } | 137 } |
| 134 if (kind == api.Diagnostic.ERROR) { | 138 if (kind == api.Diagnostic.ERROR) { |
| 135 if (checkWhiteList(uri, message, text)) { | 139 if (checkWhiteList(uri, message, text)) { |
| 136 // Suppress whitelisted errors. | 140 // Suppress whitelisted errors. |
| 137 lastWasWhitelisted = true; | 141 lastWasWhitelisted = true; |
| 138 if (verbose) { | 142 if (showWhitelisted || verbose) { |
| 139 super.report(message, uri, begin, end, text, kind); | 143 super.report(message, uri, begin, end, text, kind); |
| 140 } | 144 } |
| 141 return; | 145 return; |
| 142 } | 146 } |
| 143 hasErrors = true; | 147 hasErrors = true; |
| 144 } | 148 } |
| 145 if (kind == api.Diagnostic.INFO && lastWasWhitelisted) { | 149 if (kind == api.Diagnostic.INFO && lastWasWhitelisted) { |
| 146 return; | 150 return; |
| 147 } | 151 } |
| 148 lastWasWhitelisted = false; | 152 lastWasWhitelisted = false; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 break; | 201 break; |
| 198 case AnalysisMode.ALL: | 202 case AnalysisMode.ALL: |
| 199 options.add(Flags.analyzeAll); | 203 options.add(Flags.analyzeAll); |
| 200 break; | 204 break; |
| 201 case AnalysisMode.TREE_SHAKING: | 205 case AnalysisMode.TREE_SHAKING: |
| 202 break; | 206 break; |
| 203 } | 207 } |
| 204 if (options.contains(Flags.verbose)) { | 208 if (options.contains(Flags.verbose)) { |
| 205 handler.verbose = true; | 209 handler.verbose = true; |
| 206 } | 210 } |
| 211 if (options.contains(HIDE_WHITELISTED)) { | |
| 212 handler.showWhitelisted = false; | |
| 213 } | |
|
Bill Hesse
2016/03/29 11:56:26
Are verbose and showWhitelisted only used together
Johnni Winther
2016/03/30 07:02:30
Verbose include (some very noisy) info messages wh
| |
| 207 var compiler = new CompilerImpl( | 214 var compiler = new CompilerImpl( |
| 208 provider, | 215 provider, |
| 209 null, | 216 null, |
| 210 handler, | 217 handler, |
| 211 new new_api.CompilerOptions.parse( | 218 new new_api.CompilerOptions.parse( |
| 212 libraryRoot: libraryRoot, | 219 libraryRoot: libraryRoot, |
| 213 packageRoot: packageRoot, | 220 packageRoot: packageRoot, |
| 214 options: options, | 221 options: options, |
| 215 environment: {})); | 222 environment: {})); |
| 216 String MESSAGE = """ | 223 String MESSAGE = """ |
| 217 | 224 |
| 218 | 225 |
| 219 === | 226 === |
| 220 === ERROR: Unexpected result of analysis. | 227 === ERROR: Unexpected result of analysis. |
| 221 === | 228 === |
| 222 === Please update [WHITE_LIST] in $testFileName | 229 === Please update [WHITE_LIST] in $testFileName |
| 223 === | 230 === |
| 224 """; | 231 """; |
| 225 | 232 |
| 226 if (mode == AnalysisMode.URI) { | 233 if (mode == AnalysisMode.URI) { |
| 227 for (Uri uri in uriList) { | 234 for (Uri uri in uriList) { |
| 235 print('Analyzing uri: $uri'); | |
| 228 await compiler.analyzeUri(uri); | 236 await compiler.analyzeUri(uri); |
| 229 } | 237 } |
| 230 } else if (mode != AnalysisMode.TREE_SHAKING) { | 238 } else if (mode != AnalysisMode.TREE_SHAKING) { |
| 239 print('Analyzing libraries: $uriList'); | |
| 231 compiler.librariesToAnalyzeWhenRun = uriList; | 240 compiler.librariesToAnalyzeWhenRun = uriList; |
| 232 await compiler.run(null); | 241 await compiler.run(null); |
| 233 } else { | 242 } else { |
| 243 print('Analyzing entry point: ${uriList.single}'); | |
| 234 await compiler.run(uriList.single); | 244 await compiler.run(uriList.single); |
| 235 } | 245 } |
| 236 | 246 |
| 237 bool result; | 247 bool result; |
| 238 if (checkResults != null) { | 248 if (checkResults != null) { |
| 239 result = checkResults(compiler, handler); | 249 result = checkResults(compiler, handler); |
| 240 } else { | 250 } else { |
| 241 result = handler.checkResults(); | 251 result = handler.checkResults(); |
| 242 } | 252 } |
| 243 if (!result) { | 253 if (!result) { |
| 244 print(MESSAGE); | 254 print(MESSAGE); |
| 245 exit(1); | 255 exit(1); |
| 246 } | 256 } |
| 247 } | 257 } |
| OLD | NEW |