Chromium Code Reviews| Index: runtime/bin/builtin.dart |
| diff --git a/runtime/bin/builtin.dart b/runtime/bin/builtin.dart |
| index 2841e57b7af2a56d1a012a34246e5bf15f4fffb3..b5f9a3d7028f95da2a83df1d7e88b59fd57f8fcf 100644 |
| --- a/runtime/bin/builtin.dart |
| +++ b/runtime/bin/builtin.dart |
| @@ -27,6 +27,10 @@ class _Logger { |
| // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx |
| var _is_windows; |
| +// The URI that the entrypoint script was loaded from. Remembered so that |
| +// package imports can be resolved relative to it. |
| +Uri _entrypoint; |
| + |
| void _logResolution(String msg) { |
| final enabled = false; |
| if (enabled) { |
| @@ -54,9 +58,10 @@ String _resolveScriptUri(String cwd, String scriptName, bool windows) { |
| _logResolution("## scriptName: $scriptName"); |
| } |
| var base = new Uri(scheme: "file", path: cwd.endsWith("/") ? cwd : "$cwd/"); |
| - var resolved = base.resolve(scriptName); |
| - _logResolution("# Resolved to: $resolved"); |
| - return resolved.toString(); |
| + _entrypoint = base.resolve(scriptName); |
| + _logResolution("# Resolved script to: $_entrypoint"); |
| + |
| + return _entrypoint.toString(); |
| } |
| String _resolveUri(String base, String userString) { |
| @@ -84,11 +89,23 @@ String _resolveExtensionUri(String base, String userString) { |
| String _filePathFromUri(String userUri) { |
| var uri = new Uri.fromString(userUri); |
| _logResolution("# Getting file path from: $uri"); |
| - if ("file" != uri.scheme) { |
| - // Only handling file URIs in standalone binary. |
| - _logResolution("# Not a file URI."); |
| - throw "Not a file uri: $uri"; |
| + |
| + switch (uri.scheme) { |
| + case 'file': return _filePathFromFileUri(uri); |
| + case 'package': return _filePathFromPackageUri(uri); |
| + |
| + default: |
| + // Only handling file and package URIs in standalone binary. |
| + _logResolution("# Not a file or package URI."); |
| + throw "Not a known scheme: $uri"; |
| + } |
| +} |
| + |
| +String _filePathFromFileUri(Uri uri) { |
| + if (uri.domain != '') { |
| + throw "URIs using the 'file:' scheme may not contain a domain."; |
| } |
| + |
| var path = uri.path; |
| _logResolution("# Path: $path"); |
| if (_is_windows) { |
| @@ -98,3 +115,18 @@ String _filePathFromUri(String userUri) { |
| } |
| return path; |
| } |
| + |
| +String _filePathFromPackageUri(Uri uri) { |
| + if (uri.domain != '') { |
| + var path = (uri.path != '') ? '${uri.domain}${uri.path}' : uri.domain; |
| + var right = 'package:$path'; |
| + var wrong = 'package://$path'; |
| + |
| + throw "URIs using the 'package:' scheme should look like " + |
| + "'$right', not '$wrong'."; |
| + } |
| + |
| + var path = _entrypoint.resolve('packages/${uri.path}').path; |
|
srdjan
2012/04/11 19:48:13
This probably does not work on windows....
Bob Nystrom
2012/04/11 20:28:04
I think that's OK, but I'm not sure. I don't see a
Ivan Posva
2012/04/11 20:47:58
As far as I can tell URIs contain forward slashes
|
| + _logResolution("# Package: $path"); |
| + return path; |
| +} |