| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 /** The entry point to the compiler. Used to implement `bin/dwc.dart`. */ | |
| 6 library dwc; | |
| 7 | |
| 8 import 'dart:async'; | |
| 9 import 'dart:io'; | |
| 10 import 'package:logging/logging.dart' show Level; | |
| 11 | |
| 12 import 'src/compiler.dart'; | |
| 13 import 'src/file_system/console.dart'; | |
| 14 import 'src/messages.dart'; | |
| 15 import 'src/compiler_options.dart'; | |
| 16 import 'src/utils.dart'; | |
| 17 | |
| 18 void main() { | |
| 19 run(new Options().arguments).then((result) { | |
| 20 exit(result.success ? 0 : 1); | |
| 21 }); | |
| 22 } | |
| 23 | |
| 24 /** Contains the result of a compiler run. */ | |
| 25 class AnalysisResults { | |
| 26 | |
| 27 /** False when errors were found by our polymer analyzer. */ | |
| 28 final bool success; | |
| 29 | |
| 30 /** Error and warning messages collected by the analyzer. */ | |
| 31 final List<String> messages; | |
| 32 | |
| 33 AnalysisResults(this.success, this.messages); | |
| 34 } | |
| 35 | |
| 36 /** | |
| 37 * Runs the polymer analyzer with the command-line options in [args]. | |
| 38 * See [CompilerOptions] for the definition of valid arguments. | |
| 39 */ | |
| 40 // TODO(sigmund): rename to analyze? and rename file as analyzer.dart | |
| 41 Future<AnalysisResults> run(List<String> args, {bool printTime, | |
| 42 bool shouldPrint: true}) { | |
| 43 var options = CompilerOptions.parse(args); | |
| 44 if (options == null) return new Future.value(new AnalysisResults(true, [])); | |
| 45 if (printTime == null) printTime = options.verbose; | |
| 46 | |
| 47 return asyncTime('Total time spent on ${options.inputFile}', () { | |
| 48 var messages = new Messages(options: options, shouldPrint: shouldPrint); | |
| 49 var compiler = new Compiler(new ConsoleFileSystem(), options, messages); | |
| 50 return compiler.run().then((_) { | |
| 51 var success = messages.messages.every((m) => m.level != Level.SEVERE); | |
| 52 var msgs = options.jsonFormat | |
| 53 ? messages.messages.map((m) => m.toJson()) | |
| 54 : messages.messages.map((m) => m.toString()); | |
| 55 return new AnalysisResults(success, msgs.toList()); | |
| 56 }); | |
| 57 }, printTime: printTime, useColors: options.useColors); | |
| 58 } | |
| OLD | NEW |