| 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.devc; | 6 library dev_compiler.devc; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 final CompilerOptions _options; | 44 final CompilerOptions _options; |
| 45 final TypeResolver _resolver; | 45 final TypeResolver _resolver; |
| 46 final CheckerReporter _reporter; | 46 final CheckerReporter _reporter; |
| 47 final TypeRules _rules; | 47 final TypeRules _rules; |
| 48 final CodeChecker _checker; | 48 final CodeChecker _checker; |
| 49 final SourceGraph _graph; | 49 final SourceGraph _graph; |
| 50 final SourceNode _entryNode; | 50 final SourceNode _entryNode; |
| 51 List<LibraryInfo> _libraries = <LibraryInfo>[]; | 51 List<LibraryInfo> _libraries = <LibraryInfo>[]; |
| 52 final List<CodeGenerator> _generators; | 52 final List<CodeGenerator> _generators; |
| 53 bool _failure = false; | 53 bool _failure = false; |
| 54 bool _devCompilerRuntimeCopied = false; | |
| 55 | 54 |
| 56 factory Compiler(CompilerOptions options, | 55 factory Compiler(CompilerOptions options, |
| 57 [TypeResolver resolver, CheckerReporter reporter]) { | 56 [TypeResolver resolver, CheckerReporter reporter]) { |
| 58 if (resolver == null) { | 57 if (resolver == null) { |
| 59 resolver = options.useMockSdk | 58 resolver = options.useMockSdk |
| 60 ? new TypeResolver.fromMock(mockSdkSources, options) | 59 ? new TypeResolver.fromMock(mockSdkSources, options) |
| 61 : new TypeResolver.fromDir(options.dartSdkPath, options); | 60 : new TypeResolver.fromDir(options.dartSdkPath, options); |
| 62 } | 61 } |
| 63 | 62 |
| 64 if (reporter == null) { | 63 if (reporter == null) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 92 } | 91 } |
| 93 | 92 |
| 94 Compiler._(this._options, this._resolver, this._reporter, this._rules, | 93 Compiler._(this._options, this._resolver, this._reporter, this._rules, |
| 95 this._checker, this._graph, this._entryNode, this._generators); | 94 this._checker, this._graph, this._entryNode, this._generators); |
| 96 | 95 |
| 97 bool _buildSource(SourceNode node) { | 96 bool _buildSource(SourceNode node) { |
| 98 if (node is HtmlSourceNode) { | 97 if (node is HtmlSourceNode) { |
| 99 _buildHtmlFile(node); | 98 _buildHtmlFile(node); |
| 100 } else if (node is DartSourceNode) { | 99 } else if (node is DartSourceNode) { |
| 101 _buildDartLibrary(node); | 100 _buildDartLibrary(node); |
| 101 } else if (node is JavaScriptSourceNode) { |
| 102 _buildJavaScriptFile(node); |
| 102 } else { | 103 } else { |
| 103 assert(false); // should not get a build request on PartSourceNode | 104 assert(false); // should not get a build request on PartSourceNode |
| 104 } | 105 } |
| 105 | 106 |
| 106 // TODO(sigmund): don't always return true. Use summarization to better | 107 // TODO(sigmund): don't always return true. Use summarization to better |
| 107 // determine when rebuilding is needed. | 108 // determine when rebuilding is needed. |
| 108 return true; | 109 return true; |
| 109 } | 110 } |
| 110 | 111 |
| 111 void _buildHtmlFile(HtmlSourceNode node) { | 112 void _buildHtmlFile(HtmlSourceNode node) { |
| 112 if (_options.outputDir == null) return; | 113 if (_options.outputDir == null) return; |
| 113 var output = generateEntryHtml(node, _options); | 114 var output = generateEntryHtml(node, _options); |
| 114 if (output == null) { | 115 if (output == null) { |
| 115 _failure = true; | 116 _failure = true; |
| 116 return; | 117 return; |
| 117 } | 118 } |
| 118 var filename = path.basename(node.uri.path); | 119 var filename = path.basename(node.uri.path); |
| 119 String outputFile = path.join(_options.outputDir, filename); | 120 String outputFile = path.join(_options.outputDir, filename); |
| 120 new File(outputFile).writeAsStringSync(output); | 121 new File(outputFile).writeAsStringSync(output); |
| 121 | 122 |
| 122 if (_options.outputDart || _devCompilerRuntimeCopied) return; | 123 if (_options.outputDart) return; |
| 123 // Copy the dev_compiler runtime (implicit dependency for js codegen) | 124 } |
| 124 // TODO(sigmund): split this out as a separate node in our dependency graph | 125 |
| 125 // (https://github.com/dart-lang/dev_compiler/issues/85). | 126 void _buildJavaScriptFile(JavaScriptSourceNode node) { |
| 126 var runtimeDir = path.join( | 127 // JavaScriptSourceNodes are runtime .js files that just need to be copied |
| 127 path.dirname(path.dirname(Platform.script.path)), 'lib/runtime/'); | 128 // over to the output location. These can be external dependencies or pieces |
| 128 var runtimeOutput = path.join(_options.outputDir, 'dev_compiler/runtime/'); | 129 // of the dev_compiler runtime. |
| 129 new Directory(runtimeOutput).createSync(recursive: true); | 130 if (_options.outputDir == null || _options.outputDart) return; |
| 130 new File(path.join(runtimeDir, 'harmony_feature_check.js')) | 131 assert(node.uri.scheme == 'package'); |
| 131 .copy(path.join(runtimeOutput, 'harmony_feature_check.js')); | 132 var filepath = path.join(_options.outputDir, node.uri.path); |
| 132 new File(path.join(runtimeDir, 'dart_runtime.js')) | 133 var dir = path.dirname(filepath); |
| 133 .copy(path.join(runtimeOutput, 'dart_runtime.js')); | 134 new Directory(dir).createSync(recursive: true); |
| 134 _devCompilerRuntimeCopied = true; | 135 new File(filepath).writeAsStringSync(node.source.contents.data); |
| 135 } | 136 } |
| 136 | 137 |
| 137 bool _isEntry(DartSourceNode node) { | 138 bool _isEntry(DartSourceNode node) { |
| 138 if (_entryNode is DartSourceNode) return _entryNode == node; | 139 if (_entryNode is DartSourceNode) return _entryNode == node; |
| 139 return (_entryNode as HtmlSourceNode).scripts.contains(node); | 140 return (_entryNode as HtmlSourceNode).scripts.contains(node); |
| 140 } | 141 } |
| 141 | 142 |
| 142 void _buildDartLibrary(DartSourceNode node) { | 143 void _buildDartLibrary(DartSourceNode node) { |
| 143 var source = node.source; | 144 var source = node.source; |
| 144 // TODO(sigmund): find out from analyzer team if there is a better way | 145 // TODO(sigmund): find out from analyzer team if there is a better way |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 264 } |
| 264 | 265 |
| 265 rebuildIfNeeded(shelf.Request request) { | 266 rebuildIfNeeded(shelf.Request request) { |
| 266 var filepath = request.url.path; | 267 var filepath = request.url.path; |
| 267 if (filepath == '/$_entryPath' || filepath == '/') compiler._runAgain(); | 268 if (filepath == '/$_entryPath' || filepath == '/') compiler._runAgain(); |
| 268 } | 269 } |
| 269 } | 270 } |
| 270 | 271 |
| 271 final _log = new Logger('dev_compiler'); | 272 final _log = new Logger('dev_compiler'); |
| 272 final _earlyErrorResult = new CheckerResults(const [], null, true); | 273 final _earlyErrorResult = new CheckerResults(const [], null, true); |
| OLD | NEW |