Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Unified Diff: runtime/bin/builtin.dart

Issue 10034001: Add support for importing using "package:" to the standalone VM. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to review. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/standalone/src/package/PackageTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/builtin.dart
diff --git a/runtime/bin/builtin.dart b/runtime/bin/builtin.dart
index 2841e57b7af2a56d1a012a34246e5bf15f4fffb3..f296a1dedca5687b516a862c7ea2ce46754e3b56 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,19 @@ 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) {
var path = uri.path;
Ivan Posva 2012/04/11 12:31:24 Maybe we should check that uri.domain is null in t
Bob Nystrom 2012/04/11 19:39:02 Done.
_logResolution("# Path: $path");
if (_is_windows) {
@@ -98,3 +111,9 @@ String _filePathFromUri(String userUri) {
}
return path;
}
+
+String _filePathFromPackageUri(Uri uri) {
+ var path = _entrypoint.resolve('packages/${uri.path}').path;
Ivan Posva 2012/04/11 12:31:24 ditto: assert(uri.domain == null)
Bob Nystrom 2012/04/11 19:39:02 Done.
+ _logResolution("# Package: $path");
+ return path;
+}
« no previous file with comments | « no previous file | tests/standalone/src/package/PackageTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698