| OLD | NEW |
| 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 /// Command line tool to run the checker on a Dart program. | 5 /// Command line tool to run the checker on a Dart program. |
| 6 library dev_compiler.src.compiler; | 6 library dev_compiler.src.compiler; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 import 'dart:convert' show JSON; | 10 import 'dart:convert' show JSON; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 import 'package:logging/logging.dart' show Level, Logger, LogRecord; | 25 import 'package:logging/logging.dart' show Level, Logger, LogRecord; |
| 26 import 'package:path/path.dart' as path; | 26 import 'package:path/path.dart' as path; |
| 27 | 27 |
| 28 import 'analysis_context.dart'; | 28 import 'analysis_context.dart'; |
| 29 import 'codegen/html_codegen.dart' as html_codegen; | 29 import 'codegen/html_codegen.dart' as html_codegen; |
| 30 import 'codegen/js_codegen.dart'; | 30 import 'codegen/js_codegen.dart'; |
| 31 import 'info.dart' | 31 import 'info.dart' |
| 32 show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit; | 32 show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit; |
| 33 import 'options.dart'; | 33 import 'options.dart'; |
| 34 import 'report.dart'; | 34 import 'report.dart'; |
| 35 import 'report/html_reporter.dart'; |
| 35 | 36 |
| 36 /// Sets up the type checker logger to print a span that highlights error | 37 /// Sets up the type checker logger to print a span that highlights error |
| 37 /// messages. | 38 /// messages. |
| 38 StreamSubscription setupLogger(Level level, printFn) { | 39 StreamSubscription setupLogger(Level level, printFn) { |
| 39 Logger.root.level = level; | 40 Logger.root.level = level; |
| 40 return Logger.root.onRecord.listen((LogRecord rec) { | 41 return Logger.root.onRecord.listen((LogRecord rec) { |
| 41 printFn('${rec.level.name.toLowerCase()}: ${rec.message}'); | 42 printFn('${rec.level.name.toLowerCase()}: ${rec.message}'); |
| 42 }); | 43 }); |
| 43 } | 44 } |
| 44 | 45 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 60 } | 61 } |
| 61 | 62 |
| 62 /// Compile with the given options and return success or failure. | 63 /// Compile with the given options and return success or failure. |
| 63 bool compile(CompilerOptions options) { | 64 bool compile(CompilerOptions options) { |
| 64 assert(!options.serverMode); | 65 assert(!options.serverMode); |
| 65 | 66 |
| 66 var context = createAnalysisContextWithSources(options.sourceOptions); | 67 var context = createAnalysisContextWithSources(options.sourceOptions); |
| 67 var reporter = createErrorReporter(context, options); | 68 var reporter = createErrorReporter(context, options); |
| 68 bool status = new BatchCompiler(context, options, reporter: reporter).run(); | 69 bool status = new BatchCompiler(context, options, reporter: reporter).run(); |
| 69 | 70 |
| 70 if (options.dumpInfo && reporter is SummaryReporter) { | 71 if (reporter is HtmlReporter) { |
| 71 var result = (reporter as SummaryReporter).result; | 72 reporter.finish(options); |
| 73 } else if (options.dumpInfo && reporter is SummaryReporter) { |
| 74 var result = reporter.result; |
| 72 print(summaryToString(result)); | 75 print(summaryToString(result)); |
| 73 if (options.dumpInfoFile != null) { | 76 if (options.dumpInfoFile != null) { |
| 74 var file = new File(options.dumpInfoFile); | 77 var file = new File(options.dumpInfoFile); |
| 75 file.writeAsStringSync(JSON.encode(result.toJsonMap())); | 78 file.writeAsStringSync(JSON.encode(result.toJsonMap())); |
| 76 } | 79 } |
| 77 } | 80 } |
| 78 | 81 |
| 79 return status; | 82 return status; |
| 80 } | 83 } |
| 81 | 84 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 } else { | 472 } else { |
| 470 // Skip hints for now. | 473 // Skip hints for now. |
| 471 } | 474 } |
| 472 } | 475 } |
| 473 return failure; | 476 return failure; |
| 474 } | 477 } |
| 475 } | 478 } |
| 476 | 479 |
| 477 AnalysisErrorListener createErrorReporter( | 480 AnalysisErrorListener createErrorReporter( |
| 478 AnalysisContext context, CompilerOptions options) { | 481 AnalysisContext context, CompilerOptions options) { |
| 479 return options.dumpInfo | 482 return options.htmlReport ? new HtmlReporter(context) : options.dumpInfo |
| 480 ? new SummaryReporter(context, options.logLevel) | 483 ? new SummaryReporter(context, options.logLevel) |
| 481 : new LogReporter(context, useColors: options.useColors); | 484 : new LogReporter(context, useColors: options.useColors); |
| 482 } | 485 } |
| 483 | 486 |
| 484 // TODO(jmesserly): find a better home for these. | 487 // TODO(jmesserly): find a better home for these. |
| 485 /// Curated order to minimize lazy classes needed by dart:core and its | 488 /// Curated order to minimize lazy classes needed by dart:core and its |
| 486 /// transitive SDK imports. | 489 /// transitive SDK imports. |
| 487 const corelibOrder = const [ | 490 const corelibOrder = const [ |
| 488 'dart.core', | 491 'dart.core', |
| 489 'dart.collection', | 492 'dart.collection', |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 '_rtti.js', | 526 '_rtti.js', |
| 524 '_classes.js', | 527 '_classes.js', |
| 525 '_operations.js', | 528 '_operations.js', |
| 526 'dart_runtime.js', | 529 'dart_runtime.js', |
| 527 ]; | 530 ]; |
| 528 files.addAll(corelibOrder.map((l) => l.replaceAll('.', '/') + '.js')); | 531 files.addAll(corelibOrder.map((l) => l.replaceAll('.', '/') + '.js')); |
| 529 return files; | 532 return files; |
| 530 }(); | 533 }(); |
| 531 | 534 |
| 532 final _log = new Logger('dev_compiler.src.compiler'); | 535 final _log = new Logger('dev_compiler.src.compiler'); |
| OLD | NEW |