OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library source_file_provider; | 5 library source_file_provider; |
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 import 'dart:math' as math; | 10 import 'dart:math' as math; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 void call(Uri uri, int begin, int end, String message, api.Diagnostic kind) { | 234 void call(Uri uri, int begin, int end, String message, api.Diagnostic kind) { |
235 return report(null, uri, begin, end, message, kind); | 235 return report(null, uri, begin, end, message, kind); |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 typedef void MessageCallback(String message); | 239 typedef void MessageCallback(String message); |
240 | 240 |
241 class RandomAccessFileOutputProvider implements CompilerOutput { | 241 class RandomAccessFileOutputProvider implements CompilerOutput { |
242 final Uri out; | 242 final Uri out; |
243 final Uri sourceMapOut; | 243 final Uri sourceMapOut; |
| 244 final Uri resolutionOutput; |
244 final MessageCallback onInfo; | 245 final MessageCallback onInfo; |
245 final MessageCallback onFailure; | 246 final MessageCallback onFailure; |
246 | 247 |
247 int totalCharactersWritten = 0; | 248 int totalCharactersWritten = 0; |
248 List<String> allOutputFiles = new List<String>(); | 249 List<String> allOutputFiles = new List<String>(); |
249 | 250 |
250 RandomAccessFileOutputProvider(this.out, this.sourceMapOut, | 251 RandomAccessFileOutputProvider(this.out, this.sourceMapOut, |
251 {this.onInfo, this.onFailure}); | 252 {this.onInfo, this.onFailure, this.resolutionOutput}); |
252 | 253 |
253 static Uri computePrecompiledUri(Uri out) { | 254 static Uri computePrecompiledUri(Uri out) { |
254 String extension = 'precompiled.js'; | 255 String extension = 'precompiled.js'; |
255 String outPath = out.path; | 256 String outPath = out.path; |
256 if (outPath.endsWith('.js')) { | 257 if (outPath.endsWith('.js')) { |
257 outPath = outPath.substring(0, outPath.length - 3); | 258 outPath = outPath.substring(0, outPath.length - 3); |
258 return out.resolve('$outPath.$extension'); | 259 return out.resolve('$outPath.$extension'); |
259 } else { | 260 } else { |
260 return out.resolve(extension); | 261 return out.resolve(extension); |
261 } | 262 } |
262 } | 263 } |
263 | 264 |
264 EventSink<String> call(String name, String extension) { | 265 EventSink<String> call(String name, String extension) { |
265 return createEventSink(name, extension); | 266 return createEventSink(name, extension); |
266 } | 267 } |
267 | 268 |
268 EventSink<String> createEventSink(String name, String extension) { | 269 EventSink<String> createEventSink(String name, String extension) { |
269 Uri uri; | 270 Uri uri; |
270 bool isPrimaryOutput = false; | 271 bool isPrimaryOutput = false; |
271 // TODO (johnniwinther, sigurdm): Make a better interface for | 272 // TODO (johnniwinther, sigurdm): Make a better interface for |
272 // output-providers. | 273 // output-providers. |
273 if (extension == "deferred_map") { | 274 if (extension == "deferred_map") { |
274 uri = out.resolve(name); | 275 uri = out.resolve(name); |
275 } else if (name == '') { | 276 } else if (name == '') { |
276 if (extension == 'js' || extension == 'dart') { | 277 if (extension == 'js' || extension == 'dart') { |
277 isPrimaryOutput = true; | 278 isPrimaryOutput = true; |
278 uri = out; | 279 uri = out; |
279 } else if (extension == 'precompiled.js') { | 280 } else if (extension == 'precompiled.js') { |
280 uri = computePrecompiledUri(out); | 281 uri = computePrecompiledUri(out); |
281 onInfo("File ($uri) is compatible with header" | 282 onInfo("File ($uri) is compatible with header" |
282 " \"Content-Security-Policy: script-src 'self'\""); | 283 " \"Content-Security-Policy: script-src 'self'\""); |
283 } else if (extension == 'js.map' || extension == 'dart.map') { | 284 } else if (extension == 'js.map' || extension == 'dart.map') { |
284 uri = sourceMapOut; | 285 uri = sourceMapOut; |
285 } else if (extension == "info.json") { | 286 } else if (extension == 'info.json') { |
286 String outName = out.path.substring(out.path.lastIndexOf('/') + 1); | 287 String outName = out.path.substring(out.path.lastIndexOf('/') + 1); |
287 uri = out.resolve('$outName.$extension'); | 288 uri = out.resolve('$outName.$extension'); |
| 289 } else if (extension == 'data') { |
| 290 if (resolutionOutput == null) { |
| 291 onFailure('Serialization target unspecified.'); |
| 292 } |
| 293 uri = resolutionOutput; |
288 } else { | 294 } else { |
289 onFailure('Unknown extension: $extension'); | 295 onFailure('Unknown extension: $extension'); |
290 } | 296 } |
291 } else { | 297 } else { |
292 uri = out.resolve('$name.$extension'); | 298 uri = out.resolve('$name.$extension'); |
293 } | 299 } |
294 | 300 |
295 if (uri.scheme != 'file') { | 301 if (uri.scheme != 'file') { |
296 onFailure('Unhandled scheme ${uri.scheme} in $uri.'); | 302 onFailure('Unhandled scheme ${uri.scheme} in $uri.'); |
297 } | 303 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 var onAdd, onClose; | 341 var onAdd, onClose; |
336 | 342 |
337 EventSinkWrapper(this.onAdd, this.onClose); | 343 EventSinkWrapper(this.onAdd, this.onClose); |
338 | 344 |
339 void add(String data) => onAdd(data); | 345 void add(String data) => onAdd(data); |
340 | 346 |
341 void addError(error, [StackTrace stackTrace]) => throw error; | 347 void addError(error, [StackTrace stackTrace]) => throw error; |
342 | 348 |
343 void close() => onClose(); | 349 void close() => onClose(); |
344 } | 350 } |
OLD | NEW |