OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:io'; | 5 import 'dart:io'; |
6 import 'package:analyzer/src/generated/source.dart' show Source; | 6 import 'package:analyzer/src/generated/source.dart' show Source; |
7 import 'package:analyzer/src/summary/package_bundle_reader.dart' | 7 import 'package:analyzer/src/summary/package_bundle_reader.dart' |
8 show InSummarySource; | 8 show InSummarySource; |
9 import 'package:args/args.dart' show ArgParser, ArgResults; | 9 import 'package:args/args.dart' show ArgParser, ArgResults; |
10 import 'package:args/command_runner.dart' show UsageException; | 10 import 'package:args/command_runner.dart' show UsageException; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 var unit = new BuildUnit(modulePath, libraryRoot, argResults.rest, | 147 var unit = new BuildUnit(modulePath, libraryRoot, argResults.rest, |
148 (source) => _moduleForLibrary(moduleRoot, source, compilerOpts)); | 148 (source) => _moduleForLibrary(moduleRoot, source, compilerOpts)); |
149 | 149 |
150 var module = compiler.compile(unit, compilerOpts); | 150 var module = compiler.compile(unit, compilerOpts); |
151 module.errors.forEach(printFn); | 151 module.errors.forEach(printFn); |
152 | 152 |
153 if (!module.isValid) throw new CompileErrorException(); | 153 if (!module.isValid) throw new CompileErrorException(); |
154 | 154 |
155 // Write JS file, as well as source map and summary (if requested). | 155 // Write JS file, as well as source map and summary (if requested). |
156 for (var i = 0; i < outPaths.length; i++) { | 156 for (var i = 0; i < outPaths.length; i++) { |
157 var outPath = outPaths[i]; | 157 module.writeCodeSync(moduleFormats[i], outPaths[i], |
158 module.writeCodeSync(moduleFormats[i], singleOutFile, outPath); | 158 singleOutFile: singleOutFile); |
159 if (module.summaryBytes != null) { | 159 } |
160 var summaryPath = | 160 if (module.summaryBytes != null) { |
161 path.withoutExtension(outPath) + '.${compilerOpts.summaryExtension}'; | 161 var summaryPaths = compilerOpts.summaryOutPath != null |
| 162 ? [compilerOpts.summaryOutPath] |
| 163 : outPaths.map((p) => |
| 164 '${path.withoutExtension(p)}.${compilerOpts.summaryExtension}'); |
| 165 |
| 166 // place next to every compiled module |
| 167 for (var summaryPath in summaryPaths) { |
162 // Only overwrite if summary changed. This plays better with timestamp | 168 // Only overwrite if summary changed. This plays better with timestamp |
163 // based build systems. | 169 // based build systems. |
164 var file = new File(summaryPath); | 170 var file = new File(summaryPath); |
165 if (!file.existsSync() || | 171 if (!file.existsSync() || |
166 _changed(file.readAsBytesSync(), module.summaryBytes)) { | 172 _changed(file.readAsBytesSync(), module.summaryBytes)) { |
167 file.writeAsBytesSync(module.summaryBytes); | 173 file.writeAsBytesSync(module.summaryBytes); |
168 } | 174 } |
169 } | 175 } |
170 } | 176 } |
171 } | 177 } |
(...skipping 25 matching lines...) Expand all Loading... |
197 '\n\n${_argParser.usage}'; | 203 '\n\n${_argParser.usage}'; |
198 | 204 |
199 void _usageException(String message) { | 205 void _usageException(String message) { |
200 throw new UsageException(message, _usageMessage); | 206 throw new UsageException(message, _usageMessage); |
201 } | 207 } |
202 | 208 |
203 /// Thrown when the input source code has errors. | 209 /// Thrown when the input source code has errors. |
204 class CompileErrorException implements Exception { | 210 class CompileErrorException implements Exception { |
205 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; | 211 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; |
206 } | 212 } |
OLD | NEW |