| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 String extension = 'precompiled.js'; | 250 String extension = 'precompiled.js'; |
| 251 String outPath = out.path; | 251 String outPath = out.path; |
| 252 if (outPath.endsWith('.js')) { | 252 if (outPath.endsWith('.js')) { |
| 253 outPath = outPath.substring(0, outPath.length - 3); | 253 outPath = outPath.substring(0, outPath.length - 3); |
| 254 return out.resolve('$outPath.$extension'); | 254 return out.resolve('$outPath.$extension'); |
| 255 } else { | 255 } else { |
| 256 return out.resolve(extension); | 256 return out.resolve(extension); |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 | 259 |
| 260 EventSink<String> call(String name, String extension) { | 260 Uri createUri(String name, String extension, OutputType type) { |
| 261 return createEventSink(name, extension); | |
| 262 } | |
| 263 | |
| 264 Uri createUri(String name, String extension) { | |
| 265 Uri uri; | 261 Uri uri; |
| 266 if (extension == "deferred_map") { | 262 // TODO(johnniwinther): Unify handle of [name] and [extension] to prepare |
| 267 uri = out.resolve(name); | 263 // for using a single, possibly relative, [uri] as input. |
| 268 } else if (name == '') { | 264 switch (type) { |
| 269 if (extension == 'js' || extension == 'dart') { | 265 case OutputType.js: |
| 270 uri = out; | 266 if (name == '') { |
| 271 } else if (extension == 'precompiled.js') { | 267 uri = out; |
| 272 uri = computePrecompiledUri(out); | 268 } else { |
| 273 onInfo("File ($uri) is compatible with header" | 269 uri = out.resolve('$name.$extension'); |
| 274 " \"Content-Security-Policy: script-src 'self'\""); | 270 } |
| 275 } else if (extension == 'js.map' || extension == 'dart.map') { | 271 break; |
| 276 uri = sourceMapOut; | 272 case OutputType.sourceMap: |
| 277 } else if (extension == 'info.json') { | 273 if (name == '') { |
| 278 String outName = out.path.substring(out.path.lastIndexOf('/') + 1); | 274 uri = sourceMapOut; |
| 279 uri = out.resolve('$outName.$extension'); | 275 } else { |
| 280 } else if (extension == 'data') { | 276 uri = out.resolve('$name.$extension'); |
| 277 } |
| 278 break; |
| 279 case OutputType.jsPart: |
| 280 uri = out.resolve('$name.$extension'); |
| 281 break; |
| 282 case OutputType.serializationData: |
| 281 if (resolutionOutput == null) { | 283 if (resolutionOutput == null) { |
| 282 onFailure('Serialization target unspecified.'); | 284 onFailure('Serialization target unspecified.'); |
| 283 } | 285 } |
| 284 uri = resolutionOutput; | 286 uri = resolutionOutput; |
| 285 } else { | 287 break; |
| 286 onFailure('Unknown extension: $extension'); | 288 case OutputType.info: |
| 287 } | 289 if (name == '') { |
| 288 } else { | 290 name = out.pathSegments.last; |
| 289 uri = out.resolve('$name.$extension'); | 291 } |
| 292 if (extension == '') { |
| 293 uri = out.resolve(name); |
| 294 } else { |
| 295 uri = out.resolve('$name.$extension'); |
| 296 } |
| 297 break; |
| 298 case OutputType.debug: |
| 299 uri = out.resolve('$name.$extension'); |
| 300 break; |
| 301 default: |
| 302 onFailure('Unknown output type: $type'); |
| 290 } | 303 } |
| 291 return uri; | 304 return uri; |
| 292 } | 305 } |
| 293 | 306 |
| 294 EventSink<String> createEventSink(String name, String extension) { | 307 OutputSink createOutputSink(String name, String extension, OutputType type) { |
| 295 // TODO (johnniwinther, sigurdm): Make a better interface for | 308 Uri uri = createUri(name, extension, type); |
| 296 // output-providers. | |
| 297 Uri uri = createUri(name, extension); | |
| 298 bool isPrimaryOutput = uri == out; | 309 bool isPrimaryOutput = uri == out; |
| 299 | 310 |
| 300 if (uri.scheme != 'file') { | 311 if (uri.scheme != 'file') { |
| 301 onFailure('Unhandled scheme ${uri.scheme} in $uri.'); | 312 onFailure('Unhandled scheme ${uri.scheme} in $uri.'); |
| 302 } | 313 } |
| 303 | 314 |
| 304 RandomAccessFile output; | 315 RandomAccessFile output; |
| 305 try { | 316 try { |
| 306 output = new File(uri.toFilePath()).openSync(mode: FileMode.WRITE); | 317 output = new File(uri.toFilePath()).openSync(mode: FileMode.WRITE); |
| 307 } on FileSystemException catch (e) { | 318 } on FileSystemException catch (e) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 325 charactersWritten += data.length; | 336 charactersWritten += data.length; |
| 326 } | 337 } |
| 327 | 338 |
| 328 onDone() { | 339 onDone() { |
| 329 output.closeSync(); | 340 output.closeSync(); |
| 330 if (isPrimaryOutput) { | 341 if (isPrimaryOutput) { |
| 331 totalCharactersWritten += charactersWritten; | 342 totalCharactersWritten += charactersWritten; |
| 332 } | 343 } |
| 333 } | 344 } |
| 334 | 345 |
| 335 return new _EventSinkWrapper(writeStringSync, onDone); | 346 return new _OutputSinkWrapper(writeStringSync, onDone); |
| 336 } | 347 } |
| 337 } | 348 } |
| 338 | 349 |
| 339 class _EventSinkWrapper extends EventSink<String> { | 350 class _OutputSinkWrapper extends OutputSink { |
| 340 var onAdd, onClose; | 351 var onAdd, onClose; |
| 341 | 352 |
| 342 _EventSinkWrapper(this.onAdd, this.onClose); | 353 _OutputSinkWrapper(this.onAdd, this.onClose); |
| 343 | 354 |
| 344 void add(String data) => onAdd(data); | 355 void add(String data) => onAdd(data); |
| 345 | 356 |
| 346 void addError(error, [StackTrace stackTrace]) => throw error; | |
| 347 | |
| 348 void close() => onClose(); | 357 void close() => onClose(); |
| 349 } | 358 } |
| 350 | 359 |
| 351 /// Adapter to integrate dart2js in bazel. | 360 /// Adapter to integrate dart2js in bazel. |
| 352 /// | 361 /// |
| 353 /// To handle bazel's special layout: | 362 /// To handle bazel's special layout: |
| 354 /// | 363 /// |
| 355 /// * We specify a .packages configuration file that expands packages to their | 364 /// * We specify a .packages configuration file that expands packages to their |
| 356 /// corresponding bazel location. This way there is no need to create a pub | 365 /// corresponding bazel location. This way there is no need to create a pub |
| 357 /// cache prior to invoking dart2js. | 366 /// cache prior to invoking dart2js. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 resolvedUri = file; | 412 resolvedUri = file; |
| 404 break; | 413 break; |
| 405 } | 414 } |
| 406 } | 415 } |
| 407 } | 416 } |
| 408 var result = await readUtf8BytesFromUri(resolvedUri); | 417 var result = await readUtf8BytesFromUri(resolvedUri); |
| 409 sourceFiles[uri] = sourceFiles[resolvedUri]; | 418 sourceFiles[uri] = sourceFiles[resolvedUri]; |
| 410 return result; | 419 return result; |
| 411 } | 420 } |
| 412 } | 421 } |
| OLD | NEW |