| 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 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:convert' show JSON; | |
| 10 import 'dart:math' as math; | 9 import 'dart:math' as math; |
| 11 import 'dart:io'; | 10 import 'dart:io'; |
| 12 | 11 |
| 13 import 'package:analyzer/src/generated/ast.dart' show CompilationUnit; | 12 import 'package:analyzer/src/generated/ast.dart' show CompilationUnit; |
| 14 import 'package:analyzer/src/generated/element.dart'; | 13 import 'package:analyzer/src/generated/element.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart' | 14 import 'package:analyzer/src/generated/engine.dart' |
| 16 show AnalysisEngine, AnalysisContext, ChangeSet, ParseDartTask; | 15 show AnalysisEngine, AnalysisContext, ChangeSet, ParseDartTask; |
| 17 import 'package:analyzer/src/generated/error.dart' | 16 import 'package:analyzer/src/generated/error.dart' |
| 18 show AnalysisError, ErrorSeverity, ErrorType; | 17 show AnalysisError, ErrorSeverity, ErrorType; |
| 19 import 'package:analyzer/src/generated/error.dart'; | 18 import 'package:analyzer/src/generated/error.dart'; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 /// Compile with the given options and return success or failure. | 62 /// Compile with the given options and return success or failure. |
| 64 bool compile(CompilerOptions options) { | 63 bool compile(CompilerOptions options) { |
| 65 assert(!options.serverMode); | 64 assert(!options.serverMode); |
| 66 | 65 |
| 67 var context = createAnalysisContextWithSources(options.sourceOptions); | 66 var context = createAnalysisContextWithSources(options.sourceOptions); |
| 68 var reporter = createErrorReporter(context, options); | 67 var reporter = createErrorReporter(context, options); |
| 69 bool status = new BatchCompiler(context, options, reporter: reporter).run(); | 68 bool status = new BatchCompiler(context, options, reporter: reporter).run(); |
| 70 | 69 |
| 71 if (reporter is HtmlReporter) { | 70 if (reporter is HtmlReporter) { |
| 72 reporter.finish(options); | 71 reporter.finish(options); |
| 73 } else if (options.dumpInfo && reporter is SummaryReporter) { | 72 } else if (reporter is SummaryReporter) { |
| 74 var result = reporter.result; | 73 var result = reporter.result; |
| 75 print(summaryToString(result)); | 74 print(summaryToString(result)); |
| 76 if (options.dumpInfoFile != null) { | |
| 77 var file = new File(options.dumpInfoFile); | |
| 78 file.writeAsStringSync(JSON.encode(result.toJsonMap())); | |
| 79 } | |
| 80 } | 75 } |
| 81 | 76 |
| 82 return status; | 77 return status; |
| 83 } | 78 } |
| 84 | 79 |
| 85 // Callback on each individual compiled library | 80 // Callback on each individual compiled library |
| 86 typedef void CompilationNotifier(String path); | 81 typedef void CompilationNotifier(String path); |
| 87 | 82 |
| 88 class BatchCompiler extends AbstractCompiler { | 83 class BatchCompiler extends AbstractCompiler { |
| 89 JSGenerator _jsGen; | 84 JSGenerator _jsGen; |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 } | 469 } |
| 475 } | 470 } |
| 476 return failure; | 471 return failure; |
| 477 } | 472 } |
| 478 } | 473 } |
| 479 | 474 |
| 480 AnalysisErrorListener createErrorReporter( | 475 AnalysisErrorListener createErrorReporter( |
| 481 AnalysisContext context, CompilerOptions options) { | 476 AnalysisContext context, CompilerOptions options) { |
| 482 return options.htmlReport | 477 return options.htmlReport |
| 483 ? new HtmlReporter(context) | 478 ? new HtmlReporter(context) |
| 484 : options.dumpInfo | 479 : options.serverMode |
| 485 ? new SummaryReporter(context, options.logLevel) | 480 ? new SummaryReporter(context, options.logLevel) |
| 486 : new LogReporter(context, useColors: options.useColors); | 481 : new LogReporter(context, useColors: options.useColors); |
| 487 } | 482 } |
| 488 | 483 |
| 489 // TODO(jmesserly): find a better home for these. | 484 // TODO(jmesserly): find a better home for these. |
| 490 /// Curated order to minimize lazy classes needed by dart:core and its | 485 /// Curated order to minimize lazy classes needed by dart:core and its |
| 491 /// transitive SDK imports. | 486 /// transitive SDK imports. |
| 492 final corelibOrder = [ | 487 final corelibOrder = [ |
| 493 'dart:core', | 488 'dart:core', |
| 494 'dart:collection', | 489 'dart:collection', |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 var files = [ | 528 var files = [ |
| 534 'harmony_feature_check.js', | 529 'harmony_feature_check.js', |
| 535 'dart_library.js', | 530 'dart_library.js', |
| 536 'dart/_runtime.js', | 531 'dart/_runtime.js', |
| 537 ]; | 532 ]; |
| 538 files.addAll(corelibOrder.map(coreToFile)); | 533 files.addAll(corelibOrder.map(coreToFile)); |
| 539 return files; | 534 return files; |
| 540 }(); | 535 }(); |
| 541 | 536 |
| 542 final _log = new Logger('dev_compiler.src.compiler'); | 537 final _log = new Logger('dev_compiler.src.compiler'); |
| OLD | NEW |