| 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:math' as math; | 10 import 'dart:math' as math; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 import 'package:dev_compiler/strong_mode.dart' show StrongModeOptions; | 28 import 'package:dev_compiler/strong_mode.dart' show StrongModeOptions; |
| 29 | 29 |
| 30 import 'analysis_context.dart'; | 30 import 'analysis_context.dart'; |
| 31 import 'checker/checker.dart'; | 31 import 'checker/checker.dart'; |
| 32 import 'checker/rules.dart'; | 32 import 'checker/rules.dart'; |
| 33 import 'codegen/html_codegen.dart' as html_codegen; | 33 import 'codegen/html_codegen.dart' as html_codegen; |
| 34 import 'codegen/js_codegen.dart'; | 34 import 'codegen/js_codegen.dart'; |
| 35 import 'info.dart' | 35 import 'info.dart' |
| 36 show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit; | 36 show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit; |
| 37 import 'server/server.dart' show DevServer; | |
| 38 import 'options.dart'; | 37 import 'options.dart'; |
| 39 import 'report.dart'; | 38 import 'report.dart'; |
| 40 | 39 |
| 41 /// Sets up the type checker logger to print a span that highlights error | 40 /// Sets up the type checker logger to print a span that highlights error |
| 42 /// messages. | 41 /// messages. |
| 43 StreamSubscription setupLogger(Level level, printFn) { | 42 StreamSubscription setupLogger(Level level, printFn) { |
| 44 Logger.root.level = level; | 43 Logger.root.level = level; |
| 45 return Logger.root.onRecord.listen((LogRecord rec) { | 44 return Logger.root.onRecord.listen((LogRecord rec) { |
| 46 printFn('${rec.level.name.toLowerCase()}: ${rec.message}'); | 45 printFn('${rec.level.name.toLowerCase()}: ${rec.message}'); |
| 47 }); | 46 }); |
| 48 } | 47 } |
| 49 | 48 |
| 50 CompilerOptions validateOptions(List<String> args, {bool forceOutDir: false}) { | 49 CompilerOptions validateOptions(List<String> args, {bool forceOutDir: false}) { |
| 51 var options = parseOptions(args, forceOutDir: forceOutDir); | 50 var options = parseOptions(args, forceOutDir: forceOutDir); |
| 52 if (!options.help) { | 51 if (!options.help) { |
| 53 var srcOpts = options.sourceOptions; | 52 var srcOpts = options.sourceOptions; |
| 54 if (!srcOpts.useMockSdk && srcOpts.dartSdkPath == null) { | 53 if (!srcOpts.useMockSdk && srcOpts.dartSdkPath == null) { |
| 55 print('Could not automatically find dart sdk path.'); | 54 print('Could not automatically find dart sdk path.'); |
| 56 print('Please pass in explicitly: --dart-sdk <path>'); | 55 print('Please pass in explicitly: --dart-sdk <path>'); |
| 57 exit(1); | 56 exit(1); |
| 58 } | 57 } |
| 59 if (options.inputs.length == 0) { | 58 if (options.inputs.length == 0) { |
| 60 print('Expected filename.'); | 59 print('Expected filename.'); |
| 61 return null; | 60 return null; |
| 62 } | 61 } |
| 63 } | 62 } |
| 64 return options; | 63 return options; |
| 65 } | 64 } |
| 66 | 65 |
| 67 Future<bool> compile(CompilerOptions options) async { | 66 bool compile(CompilerOptions options) { |
| 68 setupLogger(options.logLevel, print); | 67 assert(!options.serverMode); |
| 69 | 68 var context = createAnalysisContextWithSources( |
| 70 if (options.serverMode) { | 69 options.strongOptions, options.sourceOptions); |
| 71 return new DevServer(options).start(); | 70 var reporter = createErrorReporter(context, options); |
| 72 } else { | 71 return new BatchCompiler(context, options, reporter: reporter).run(); |
| 73 var context = createAnalysisContextWithSources( | |
| 74 options.strongOptions, options.sourceOptions); | |
| 75 var reporter = createErrorReporter(context, options); | |
| 76 // Note: run returns a bool, turned into a future since this function is asy
nc. | |
| 77 return new BatchCompiler(context, options, reporter: reporter).run(); | |
| 78 } | |
| 79 } | 72 } |
| 80 | 73 |
| 81 class BatchCompiler extends AbstractCompiler { | 74 class BatchCompiler extends AbstractCompiler { |
| 82 JSGenerator _jsGen; | 75 JSGenerator _jsGen; |
| 83 LibraryElement _dartCore; | 76 LibraryElement _dartCore; |
| 84 String _runtimeOutputDir; | 77 String _runtimeOutputDir; |
| 85 | 78 |
| 86 /// Already compiled sources, so we don't compile them again. | 79 /// Already compiled sources, so we don't compile them again. |
| 87 final _compiled = new HashSet<LibraryElement>(); | 80 final _compiled = new HashSet<LibraryElement>(); |
| 88 | 81 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 '_rtti.js', | 439 '_rtti.js', |
| 447 '_classes.js', | 440 '_classes.js', |
| 448 '_operations.js', | 441 '_operations.js', |
| 449 'dart_runtime.js', | 442 'dart_runtime.js', |
| 450 ]; | 443 ]; |
| 451 files.addAll(corelibOrder.map((l) => l.replaceAll('.', '/') + '.js')); | 444 files.addAll(corelibOrder.map((l) => l.replaceAll('.', '/') + '.js')); |
| 452 return files; | 445 return files; |
| 453 }(); | 446 }(); |
| 454 | 447 |
| 455 final _log = new Logger('dev_compiler.src.compiler'); | 448 final _log = new Logger('dev_compiler.src.compiler'); |
| OLD | NEW |