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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 return new BatchCompiler(context, options, reporter: reporter).run(); | 71 return new BatchCompiler(context, options, reporter: reporter).run(); |
72 } | 72 } |
73 | 73 |
74 class BatchCompiler extends AbstractCompiler { | 74 class BatchCompiler extends AbstractCompiler { |
75 JSGenerator _jsGen; | 75 JSGenerator _jsGen; |
76 LibraryElement _dartCore; | 76 LibraryElement _dartCore; |
77 String _runtimeOutputDir; | 77 String _runtimeOutputDir; |
78 | 78 |
79 /// Already compiled sources, so we don't compile them again. | 79 /// Already compiled sources, so we don't compile them again. |
80 final _compiled = new HashSet<LibraryElement>(); | 80 final _compiled = new HashSet<LibraryElement>(); |
| 81 bool _sdkCopied = false; |
81 | 82 |
82 bool _failure = false; | 83 bool _failure = false; |
83 bool get failure => _failure; | 84 bool get failure => _failure; |
84 | 85 |
85 BatchCompiler(AnalysisContext context, CompilerOptions options, | 86 BatchCompiler(AnalysisContext context, CompilerOptions options, |
86 {AnalysisErrorListener reporter}) | 87 {AnalysisErrorListener reporter}) |
87 : super( | 88 : super( |
88 context, | 89 context, |
89 options, | 90 options, |
90 new ErrorCollector( | 91 new ErrorCollector( |
91 reporter ?? AnalysisErrorListener.NULL_LISTENER)) { | 92 reporter ?? AnalysisErrorListener.NULL_LISTENER)) { |
92 _inputBaseDir = options.inputBaseDir; | 93 _inputBaseDir = options.inputBaseDir; |
93 if (outputDir != null) { | 94 if (outputDir != null) { |
94 _jsGen = new JSGenerator(this); | 95 _jsGen = new JSGenerator(this); |
95 _runtimeOutputDir = path.join(outputDir, 'dev_compiler', 'runtime'); | 96 _runtimeOutputDir = path.join(outputDir, 'dev_compiler', 'runtime'); |
96 } | 97 } |
97 _dartCore = context.typeProvider.objectType.element.library; | 98 _dartCore = context.typeProvider.objectType.element.library; |
98 } | 99 } |
99 | 100 |
100 ErrorCollector get reporter => checker.reporter; | 101 ErrorCollector get reporter => checker.reporter; |
101 | 102 |
102 void reset() { | 103 void reset() { |
103 _compiled.clear(); | 104 _compiled.clear(); |
| 105 _sdkCopied = false; |
104 } | 106 } |
105 | 107 |
106 /// Compiles every file in [options.inputs]. | 108 /// Compiles every file in [options.inputs]. |
107 /// Returns true on successful compile. | 109 /// Returns true on successful compile. |
108 bool run() { | 110 bool run() { |
109 var clock = new Stopwatch()..start(); | 111 var clock = new Stopwatch()..start(); |
110 options.inputs.forEach(compileFromUriString); | 112 options.inputs.forEach(compileFromUriString); |
111 clock.stop(); | 113 clock.stop(); |
112 var time = (clock.elapsedMilliseconds / 1000).toStringAsFixed(2); | 114 var time = (clock.elapsedMilliseconds / 1000).toStringAsFixed(2); |
113 _log.fine('Compiled ${_compiled.length} libraries in ${time} s\n'); | 115 _log.fine('Compiled ${_compiled.length} libraries in ${time} s\n'); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 173 } |
172 | 174 |
173 if (_jsGen != null) { | 175 if (_jsGen != null) { |
174 var unit = units.first; | 176 var unit = units.first; |
175 var parts = units.skip(1).toList(); | 177 var parts = units.skip(1).toList(); |
176 _jsGen.generateLibrary(new LibraryUnit(unit, parts)); | 178 _jsGen.generateLibrary(new LibraryUnit(unit, parts)); |
177 } | 179 } |
178 } | 180 } |
179 | 181 |
180 void _copyDartRuntime() { | 182 void _copyDartRuntime() { |
| 183 if (_sdkCopied) return; |
| 184 _sdkCopied = true; |
181 for (var file in defaultRuntimeFiles) { | 185 for (var file in defaultRuntimeFiles) { |
182 var input = path.join(options.runtimeDir, file); | 186 var input = new File(path.join(options.runtimeDir, file)); |
183 var output = path.join(_runtimeOutputDir, file); | 187 var output = new File(path.join(_runtimeOutputDir, file)); |
184 new Directory(path.dirname(output)).createSync(recursive: true); | 188 if (output.existsSync() && |
185 new File(input).copySync(output); | 189 output.lastModifiedSync() == input.lastModifiedSync()) { |
| 190 continue; |
| 191 } |
| 192 new Directory(path.dirname(output.path)).createSync(recursive: true); |
| 193 input.copySync(output.path); |
186 } | 194 } |
187 } | 195 } |
188 | 196 |
189 void _compileHtml(Source source) { | 197 void _compileHtml(Source source) { |
190 // TODO(jmesserly): reuse DartScriptsTask instead of copy/paste. | 198 // TODO(jmesserly): reuse DartScriptsTask instead of copy/paste. |
191 var contents = context.getContents(source); | 199 var contents = context.getContents(source); |
192 var document = html.parse(contents.data, generateSpans: true); | 200 var document = html.parse(contents.data, generateSpans: true); |
193 var scripts = document.querySelectorAll('script[type="application/dart"]'); | 201 var scripts = document.querySelectorAll('script[type="application/dart"]'); |
194 | 202 |
195 var loadedLibs = new LinkedHashSet<Uri>(); | 203 var loadedLibs = new LinkedHashSet<Uri>(); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 '_rtti.js', | 454 '_rtti.js', |
447 '_classes.js', | 455 '_classes.js', |
448 '_operations.js', | 456 '_operations.js', |
449 'dart_runtime.js', | 457 'dart_runtime.js', |
450 ]; | 458 ]; |
451 files.addAll(corelibOrder.map((l) => l.replaceAll('.', '/') + '.js')); | 459 files.addAll(corelibOrder.map((l) => l.replaceAll('.', '/') + '.js')); |
452 return files; | 460 return files; |
453 }(); | 461 }(); |
454 | 462 |
455 final _log = new Logger('dev_compiler.src.compiler'); | 463 final _log = new Logger('dev_compiler.src.compiler'); |
OLD | NEW |