| 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 /// Development server that compiles Dart to JS on the fly. | 5 /// Development server that compiles Dart to JS on the fly. |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 CheckerResults run() { | 80 CheckerResults run() { |
| 81 var clock = new Stopwatch()..start(); | 81 var clock = new Stopwatch()..start(); |
| 82 | 82 |
| 83 // TODO(sigmund): we are missing a couple failures here. The | 83 // TODO(sigmund): we are missing a couple failures here. The |
| 84 // dependency_graph now detects broken imports or unsupported features | 84 // dependency_graph now detects broken imports or unsupported features |
| 85 // like more than one script tag (see .severe messages in | 85 // like more than one script tag (see .severe messages in |
| 86 // dependency_graph.dart). Such failures should be reported back | 86 // dependency_graph.dart). Such failures should be reported back |
| 87 // here so we can mark failure=true in the CheckerResults. | 87 // here so we can mark failure=true in the CheckerResults. |
| 88 rebuild(_entryNode, _buildSource); | 88 rebuild(_entryNode, _buildSource); |
| 89 _dumpInfoIfRequested(); | |
| 90 clock.stop(); | 89 clock.stop(); |
| 91 var time = (clock.elapsedMilliseconds / 1000).toStringAsFixed(2); | 90 var time = (clock.elapsedMilliseconds / 1000).toStringAsFixed(2); |
| 92 _log.fine('Compiled ${_libraries.length} libraries in ${time} s\n'); | 91 _log.fine('Compiled ${_libraries.length} libraries in ${time} s\n'); |
| 93 return new CheckerResults( | 92 return new CheckerResults( |
| 94 _libraries, _failure || options.codegenOptions.forceCompile); | 93 _libraries, _failure || options.codegenOptions.forceCompile); |
| 95 } | 94 } |
| 96 | 95 |
| 97 bool _buildSource(SourceNode node) { | 96 bool _buildSource(SourceNode node) { |
| 98 node.clearSummary(); | 97 node.clearSummary(); |
| 99 if (node is HtmlSourceNode) { | 98 if (node is HtmlSourceNode) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 changed++; | 188 changed++; |
| 190 return _buildSource(n); | 189 return _buildSource(n); |
| 191 }); | 190 }); |
| 192 clock.stop(); | 191 clock.stop(); |
| 193 if (changed > 0) _dumpInfoIfRequested(); | 192 if (changed > 0) _dumpInfoIfRequested(); |
| 194 var time = (clock.elapsedMilliseconds / 1000).toStringAsFixed(2); | 193 var time = (clock.elapsedMilliseconds / 1000).toStringAsFixed(2); |
| 195 _log.fine("Compiled ${changed} libraries in ${time} s\n"); | 194 _log.fine("Compiled ${changed} libraries in ${time} s\n"); |
| 196 } | 195 } |
| 197 | 196 |
| 198 _dumpInfoIfRequested() { | 197 _dumpInfoIfRequested() { |
| 198 var reporter = this.reporter; |
| 199 if (reporter is HtmlReporter) { | 199 if (reporter is HtmlReporter) { |
| 200 (reporter as HtmlReporter).finish(options); | 200 reporter.finish(options); |
| 201 } else { | 201 } else if (reporter is SummaryReporter) { |
| 202 if (!options.dumpInfo || reporter is! SummaryReporter) return; | 202 var result = reporter.result; |
| 203 var result = (reporter as SummaryReporter).result; | 203 if (outputDir != null) { |
| 204 if (!options.serverMode) print(summaryToString(result)); | 204 var filepath = path.join(outputDir, 'messages.json'); |
| 205 var filepath = options.serverMode | 205 new File(filepath).writeAsStringSync(JSON.encode(result.toJsonMap())); |
| 206 ? path.join(outputDir, 'messages.json') | 206 } else { |
| 207 : options.dumpInfoFile; | 207 print(summaryToString(result)); |
| 208 if (filepath == null) return; | 208 } |
| 209 new File(filepath).writeAsStringSync(JSON.encode(result.toJsonMap())); | |
| 210 } | 209 } |
| 211 } | 210 } |
| 212 } | 211 } |
| 213 | 212 |
| 214 class DevServer { | 213 class DevServer { |
| 215 final ServerCompiler compiler; | 214 final ServerCompiler compiler; |
| 216 final String outDir; | 215 final String outDir; |
| 217 final String host; | 216 final String host; |
| 218 final int port; | 217 final int port; |
| 219 final String _entryPath; | 218 final String _entryPath; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 330 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 332 var src = resolver.resolveAbsolute(uri, actualUri); | 331 var src = resolver.resolveAbsolute(uri, actualUri); |
| 333 return src.exists() ? src : null; | 332 return src.exists() ? src : null; |
| 334 } | 333 } |
| 335 | 334 |
| 336 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source); | 335 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source); |
| 337 } | 336 } |
| 338 | 337 |
| 339 final _log = new Logger('dev_compiler.src.server'); | 338 final _log = new Logger('dev_compiler.src.server'); |
| 340 final _earlyErrorResult = new CheckerResults(const [], true); | 339 final _earlyErrorResult = new CheckerResults(const [], true); |
| OLD | NEW |