Chromium Code Reviews| 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 import 'dart:io'; | 6 import 'dart:io'; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 // import 'root_library'; happens here from C Code | 8 // import 'root_library'; happens here from C Code |
| 9 | 9 |
| 10 // The root library (aka the script) is imported into this library. The | 10 // The root library (aka the script) is imported into this library. The |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 _entryPointScript = scriptUri; | 198 _entryPointScript = scriptUri; |
| 199 } else { | 199 } else { |
| 200 // Script does not have a scheme, assume that it is a path, | 200 // Script does not have a scheme, assume that it is a path, |
| 201 // resolve it against the working directory. | 201 // resolve it against the working directory. |
| 202 _entryPointScript = _workingDirectoryUri.resolve(scriptName); | 202 _entryPointScript = _workingDirectoryUri.resolve(scriptName); |
| 203 } | 203 } |
| 204 _logResolution('# Resolved entry point to: $_entryPointScript'); | 204 _logResolution('# Resolved entry point to: $_entryPointScript'); |
| 205 return _entryPointScript.toString(); | 205 return _entryPointScript.toString(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 const _DART_EXT 'dart-ext:'; | |
|
Ivan Posva
2014/03/03 20:38:00
How does this compile?
| |
| 208 | 209 |
| 209 String _resolveUri(String base, String userString) { | 210 String _resolveUri(String base, String userString) { |
| 211 _logResolution('# Resolving: $userString from $base'); | |
| 210 var baseUri = Uri.parse(base); | 212 var baseUri = Uri.parse(base); |
| 211 _logResolution('# Resolving: $userString from $base'); | 213 if (userString.startsWith(_DART_EXT)) { |
| 212 | 214 var uri = userString.substring(_DART_EXT.length); |
| 213 var uri = Uri.parse(userString); | 215 return '$_DART_EXT${baseUri.resolve(uri)}'; |
| 214 var resolved; | |
| 215 if ('dart-ext' == uri.scheme) { | |
| 216 // Relative URIs with scheme dart-ext should be resolved as if with no | |
| 217 // scheme. | |
| 218 resolved = baseUri.resolve(uri.path); | |
| 219 if (resolved.scheme == 'package') { | |
| 220 // If we are resolving relative to a package URI we go directly to the | |
| 221 // file path and keep the dart-ext scheme. Otherwise, we will lose the | |
| 222 // package URI path part. | |
| 223 var path = _filePathFromPackageUri(resolved); | |
| 224 if (path.startsWith('http:')) { | |
| 225 throw "Native extensions not supported in " | |
| 226 "packages loaded over http: %path"; | |
| 227 } | |
| 228 resolved = new Uri.file(path); | |
| 229 } | |
| 230 resolved = new Uri(scheme: 'dart-ext', path: resolved.path); | |
| 231 } else { | 216 } else { |
| 232 resolved = baseUri.resolve(userString); | 217 return '${baseUri.resolve(userString)}'; |
| 233 } | 218 } |
| 234 _logResolution('# Resolved to: $resolved'); | |
| 235 return resolved.toString(); | |
| 236 } | 219 } |
| 237 | 220 |
| 238 | 221 |
| 239 // Returns either a file path or a URI starting with http:, as a String. | 222 // Returns either a file path or a URI starting with http:, as a String. |
| 240 String _filePathFromUri(String userUri) { | 223 String _filePathFromUri(String userUri) { |
| 224 if (userUri.startsWith(_DART_EXT)) { | |
| 225 userUri = userUri.substring(_DART_EXT.length); | |
| 226 } | |
| 241 var uri = Uri.parse(userUri); | 227 var uri = Uri.parse(userUri); |
| 242 _logResolution('# Getting file path from: $uri'); | 228 _logResolution('# Getting file path from: $uri'); |
| 243 | 229 |
| 244 var path; | 230 var path; |
| 245 switch (uri.scheme) { | 231 switch (uri.scheme) { |
| 246 case '': | 232 case '': |
| 247 case 'file': | 233 case 'file': |
| 248 return uri.toFilePath(); | 234 return uri.toFilePath(); |
| 249 break; | 235 break; |
| 250 case 'dart-ext': | |
| 251 // Relative file URIs don't start with file:///. | |
| 252 var scheme = (uri.path.startsWith('/') ? 'file' : ''); | |
| 253 return new Uri(scheme: scheme, | |
| 254 host: uri.host, | |
| 255 path: uri.path).toFilePath(); | |
| 256 break; | |
| 257 case 'package': | 236 case 'package': |
| 258 return _filePathFromPackageUri(uri); | 237 return _filePathFromPackageUri(uri); |
| 259 break; | 238 break; |
| 260 case 'http': | 239 case 'http': |
| 261 return uri.toString(); | 240 return uri.toString(); |
| 262 default: | 241 default: |
| 263 // Only handling file, dart-ext, http, and package URIs | 242 // Only handling file, http, and package URIs |
| 264 // in standalone binary. | 243 // in standalone binary. |
| 265 _logResolution('# Unknown scheme (${uri.scheme}) in $uri.'); | 244 _logResolution('# Unknown scheme (${uri.scheme}) in $uri.'); |
| 266 throw 'Not a known scheme: $uri'; | 245 throw 'Not a known scheme: $uri'; |
| 267 } | 246 } |
| 268 } | 247 } |
| 269 | 248 |
| 270 | 249 |
| 271 String _filePathFromPackageUri(Uri uri) { | 250 String _filePathFromPackageUri(Uri uri) { |
| 272 if (!uri.host.isEmpty) { | 251 if (!uri.host.isEmpty) { |
| 273 var path = (uri.path != '') ? '${uri.host}${uri.path}' : uri.host; | 252 var path = '${uri.host}${uri.path}'; |
| 274 var right = 'package:$path'; | 253 var right = 'package:$path'; |
| 275 var wrong = 'package://$path'; | 254 var wrong = 'package://$path'; |
| 276 | 255 |
| 277 throw "URIs using the 'package:' scheme should look like " | 256 throw "URIs using the 'package:' scheme should look like " |
| 278 "'$right', not '$wrong'."; | 257 "'$right', not '$wrong'."; |
| 279 } | 258 } |
| 280 | 259 |
| 281 var packageRoot = _packageRoot == null ? | 260 var packageRoot = _packageRoot == null ? |
| 282 _entryPointScript.resolve('packages/') : | 261 _entryPointScript.resolve('packages/') : |
| 283 _packageRoot; | 262 _packageRoot; |
| 284 return _filePathFromUri(packageRoot.resolve(uri.path).toString()); | 263 return _filePathFromUri(packageRoot.resolve(uri.path).toString()); |
| 285 } | 264 } |
| OLD | NEW |