| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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("builtin"); | 5 #library("builtin"); |
| 6 | 6 |
| 7 void print(arg) { | 7 void print(arg) { |
| 8 _Logger._printString(arg.toString()); | 8 _Logger._printString(arg.toString()); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 var base = new Uri(scheme: "file", path: cwd.endsWith("/") ? cwd : "$cwd/"); | 60 var base = new Uri(scheme: "file", path: cwd.endsWith("/") ? cwd : "$cwd/"); |
| 61 _entrypoint = base.resolve(scriptName); | 61 _entrypoint = base.resolve(scriptName); |
| 62 _logResolution("# Resolved script to: $_entrypoint"); | 62 _logResolution("# Resolved script to: $_entrypoint"); |
| 63 | 63 |
| 64 return _entrypoint.toString(); | 64 return _entrypoint.toString(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 String _resolveUri(String base, String userString) { | 67 String _resolveUri(String base, String userString) { |
| 68 var baseUri = new Uri.fromString(base); | 68 var baseUri = new Uri.fromString(base); |
| 69 _logResolution("# Resolving: $userString from $base"); | 69 _logResolution("# Resolving: $userString from $base"); |
| 70 var resolved = baseUri.resolve(userString); | 70 |
| 71 // Relative URIs with scheme dart-ext should be resolved as if with no scheme. |
| 72 var uri = new Uri.fromString(userString); |
| 73 var resolved; |
| 74 if ('dart-ext' == uri.scheme) { |
| 75 resolved = baseUri.resolve(uri.path); |
| 76 resolved = new Uri(scheme: "dart-ext", path: resolved.path); |
| 77 } else { |
| 78 resolved = baseUri.resolve(userString); |
| 79 } |
| 71 _logResolution("# Resolved to: $resolved"); | 80 _logResolution("# Resolved to: $resolved"); |
| 72 return resolved.toString(); | 81 return resolved.toString(); |
| 73 } | 82 } |
| 74 | 83 |
| 75 String _resolveExtensionUri(String base, String userString) { | |
| 76 var uri = new Uri.fromString(userString); | |
| 77 if ("dart-ext" != uri.scheme) { | |
| 78 throw "Not a Dart extension uri: $uri"; | |
| 79 } | |
| 80 var schemelessUri = new Uri(path: uri.path); | |
| 81 var baseUri = new Uri.fromString(base); | |
| 82 _logResolution("# Resolving: $userString from $base"); | |
| 83 var resolved = baseUri.resolveUri(schemelessUri); | |
| 84 resolved = new Uri(scheme: 'dart-ext', path: resolved.path); | |
| 85 _logResolution("# Resolved to: $resolved"); | |
| 86 return resolved.toString(); | |
| 87 } | |
| 88 | 84 |
| 89 String _filePathFromUri(String userUri) { | 85 String _filePathFromUri(String userUri) { |
| 90 var uri = new Uri.fromString(userUri); | 86 var uri = new Uri.fromString(userUri); |
| 91 _logResolution("# Getting file path from: $uri"); | 87 _logResolution("# Getting file path from: $uri"); |
| 92 | 88 |
| 93 var path; | 89 var path; |
| 94 switch (uri.scheme) { | 90 switch (uri.scheme) { |
| 95 case 'file': path = _filePathFromFileUri(uri); break; | 91 case 'file': path = _filePathFromFileUri(uri); break; |
| 92 case 'dart-ext': path = _filePathFromOtherUri(uri); break; |
| 96 case 'package': path = _filePathFromPackageUri(uri); break; | 93 case 'package': path = _filePathFromPackageUri(uri); break; |
| 97 | 94 |
| 98 default: | 95 default: |
| 99 // Only handling file and package URIs in standalone binary. | 96 // Only handling file, dart-ext and package URIs in standalone binary. |
| 100 _logResolution("# Not a file or package URI."); | 97 _logResolution("# Not a file, dart-ext, or package URI."); |
| 101 throw "Not a known scheme: $uri"; | 98 throw "Not a known scheme: $uri"; |
| 102 } | 99 } |
| 103 | 100 |
| 104 if (_is_windows) { | 101 if (_is_windows) { |
| 105 // Drop the leading / before the drive letter. | 102 // Drop the leading / before the drive letter. |
| 106 path = path.substring(1); | 103 path = path.substring(1); |
| 107 _logResolution("# path: $path"); | 104 _logResolution("# path: $path"); |
| 108 } | 105 } |
| 109 | 106 |
| 110 return path; | 107 return path; |
| 111 } | 108 } |
| 112 | 109 |
| 113 String _filePathFromFileUri(Uri uri) { | 110 String _filePathFromFileUri(Uri uri) { |
| 114 if (uri.domain != '') { | 111 if (uri.domain != '') { |
| 115 throw "URIs using the 'file:' scheme may not contain a domain."; | 112 throw "URIs using the 'file:' scheme may not contain a domain."; |
| 116 } | 113 } |
| 117 | 114 |
| 118 _logResolution("# Path: ${uri.path}"); | 115 _logResolution("# Path: ${uri.path}"); |
| 119 return uri.path; | 116 return uri.path; |
| 120 } | 117 } |
| 121 | 118 |
| 119 String _filePathFromOtherUri(Uri uri) { |
| 120 if (uri.domain != '') { |
| 121 throw "URIs whose paths are used as file paths may not contain a domain."; |
| 122 } |
| 123 |
| 124 _logResolution("# Path: ${uri.path}"); |
| 125 return uri.path; |
| 126 } |
| 127 |
| 122 String _filePathFromPackageUri(Uri uri) { | 128 String _filePathFromPackageUri(Uri uri) { |
| 123 if (uri.domain != '') { | 129 if (uri.domain != '') { |
| 124 var path = (uri.path != '') ? '${uri.domain}${uri.path}' : uri.domain; | 130 var path = (uri.path != '') ? '${uri.domain}${uri.path}' : uri.domain; |
| 125 var right = 'package:$path'; | 131 var right = 'package:$path'; |
| 126 var wrong = 'package://$path'; | 132 var wrong = 'package://$path'; |
| 127 | 133 |
| 128 throw "URIs using the 'package:' scheme should look like " + | 134 throw "URIs using the 'package:' scheme should look like " + |
| 129 "'$right', not '$wrong'."; | 135 "'$right', not '$wrong'."; |
| 130 } | 136 } |
| 131 | 137 |
| 132 var path = _entrypoint.resolve('packages/${uri.path}').path; | 138 var path = _entrypoint.resolve('packages/${uri.path}').path; |
| 133 _logResolution("# Package: $path"); | 139 _logResolution("# Package: $path"); |
| 134 return path; | 140 return path; |
| 135 } | 141 } |
| OLD | NEW |