| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 /** | |
| 6 * An code reader that abstracts away the distinction between internal and user | |
| 7 * libraries. | |
| 8 */ | |
| 9 class LibraryReader { | |
| 10 Map _specialLibs; | |
| 11 LibraryReader() { | |
| 12 if (options.config == 'dev') { | |
| 13 _specialLibs = { | |
| 14 'dart:core': joinPaths(options.libDir, 'corelib.dart'), | |
| 15 'dart:coreimpl': joinPaths(options.libDir, 'corelib_impl.dart'), | |
| 16 'dart:html': joinPaths(options.libDir, | |
| 17 '../../lib/html/frog/html_frog.dart'), | |
| 18 'dart:dom_deprecated': joinPaths(options.libDir, | |
| 19 '../../lib/dom/frog/dom_frog.dart'), | |
| 20 'dart:crypto': joinPaths(options.libDir, | |
| 21 '../../lib/crypto/crypto.dart'), | |
| 22 'dart:json': joinPaths(options.libDir, '../../lib/json/json_frog.dart'), | |
| 23 'dart:io': joinPaths(options.libDir, | |
| 24 '../../lib/compiler/implementation/lib/io.dart'), | |
| 25 'dart:isolate': joinPaths(options.libDir, | |
| 26 '../../lib/isolate/isolate_frog.dart'), | |
| 27 'dart:uri': joinPaths(options.libDir, '../../lib/uri/uri.dart'), | |
| 28 'dart:utf': joinPaths(options.libDir, '../../lib/utf/utf.dart'), | |
| 29 }; | |
| 30 } else if (options.config == 'sdk') { | |
| 31 _specialLibs = { | |
| 32 'dart:core': joinPaths(options.libDir, 'core/core_frog.dart'), | |
| 33 'dart:coreimpl': joinPaths(options.libDir, | |
| 34 'coreimpl/coreimpl_frog.dart'), | |
| 35 'dart:html': joinPaths(options.libDir, 'html/html_frog.dart'), | |
| 36 'dart:dom_deprecated': joinPaths(options.libDir, 'dom/dom_frog.dart'), | |
| 37 // TODO(rnystrom): How should we handle dart:io here? | |
| 38 'dart:isolate': joinPaths(options.libDir, 'isolate/isolate_frog.dart'), | |
| 39 'dart:crypto': joinPaths(options.libDir, 'crypto/crypto.dart'), | |
| 40 'dart:json': joinPaths(options.libDir, 'json/json_frog.dart'), | |
| 41 'dart:uri': joinPaths(options.libDir, 'uri/uri.dart'), | |
| 42 'dart:utf': joinPaths(options.libDir, 'utf/utf.dart'), | |
| 43 }; | |
| 44 } else { | |
| 45 world.error('Invalid configuration ${options.config}'); | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 SourceFile readFile(String fullName) { | |
| 50 String filename; | |
| 51 | |
| 52 | |
| 53 if (fullName.startsWith('package:')) { | |
| 54 String name = fullName.substring('package:'.length); | |
| 55 if (options.packageRoot !== null) { | |
| 56 filename = joinPaths(options.packageRoot, name); | |
| 57 } else { | |
| 58 filename = joinPaths(dirname(options.dartScript), | |
| 59 joinPaths('packages', name)); | |
| 60 } | |
| 61 } else { | |
| 62 filename = _specialLibs[fullName]; | |
| 63 } | |
| 64 | |
| 65 if (filename == null) { | |
| 66 filename = fullName; | |
| 67 } | |
| 68 | |
| 69 if (world.files.fileExists(filename)) { | |
| 70 // TODO(jimhug): Should we cache these based on time stamps here? | |
| 71 return new SourceFile(filename, world.files.readAll(filename)); | |
| 72 } else { | |
| 73 world.error('File not found: $filename', null); | |
| 74 return new SourceFile(filename, ''); | |
| 75 } | |
| 76 } | |
| 77 } | |
| OLD | NEW |