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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
11 void exit(int status) { 11 void exit(int status) {
12 if (status is !int) { 12 if (status is !int) {
13 throw new IllegalArgumentException("int status expected"); 13 throw new IllegalArgumentException("int status expected");
14 } 14 }
15 _exit(status); 15 _exit(status);
16 } 16 }
17 17
18 _exit(int status) native "Exit"; 18 _exit(int status) native "Exit";
19 19
20 class _Logger { 20 class _Logger {
21 static void _printString(String s) native "Logger_PrintString"; 21 static void _printString(String s) native "Logger_PrintString";
22 } 22 }
23 23
24 24
25 // Code to deal with URI resolution for the standalone binary. 25 // Code to deal with URI resolution for the standalone binary.
26 // For Windows we need to massage the paths a bit according to 26 // For Windows we need to massage the paths a bit according to
27 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx 27 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx
28 var _is_windows; 28 var _is_windows;
29 29
30 // The URI that the entrypoint script was loaded from. Remembered so that
31 // package imports can be resolved relative to it.
32 Uri _entrypoint;
33
30 void _logResolution(String msg) { 34 void _logResolution(String msg) {
31 final enabled = false; 35 final enabled = false;
32 if (enabled) { 36 if (enabled) {
33 _Logger._printString(msg); 37 _Logger._printString(msg);
34 } 38 }
35 } 39 }
36 40
37 String _resolveScriptUri(String cwd, String scriptName, bool windows) { 41 String _resolveScriptUri(String cwd, String scriptName, bool windows) {
38 _is_windows = windows; 42 _is_windows = windows;
39 _logResolution("# Current working directory: $cwd"); 43 _logResolution("# Current working directory: $cwd");
40 _logResolution("# ScriptName: $scriptName"); 44 _logResolution("# ScriptName: $scriptName");
41 if (windows) { 45 if (windows) {
42 // Convert 46 // Convert
43 // C:\one\two\three 47 // C:\one\two\three
44 // to 48 // to
45 // /C:/one/two/three 49 // /C:/one/two/three
46 cwd = "/${cwd.replaceAll('\\', '/')}"; 50 cwd = "/${cwd.replaceAll('\\', '/')}";
47 _logResolution("## cwd: $cwd"); 51 _logResolution("## cwd: $cwd");
48 if ((scriptName.length > 2) && (scriptName[1] == ":")) { 52 if ((scriptName.length > 2) && (scriptName[1] == ":")) {
49 // This is an absolute path. 53 // This is an absolute path.
50 scriptName = "/${scriptName.replaceAll('\\', '/')}"; 54 scriptName = "/${scriptName.replaceAll('\\', '/')}";
51 } else { 55 } else {
52 scriptName = scriptName.replaceAll('\\', '/'); 56 scriptName = scriptName.replaceAll('\\', '/');
53 } 57 }
54 _logResolution("## scriptName: $scriptName"); 58 _logResolution("## scriptName: $scriptName");
55 } 59 }
56 var base = new Uri(scheme: "file", path: cwd.endsWith("/") ? cwd : "$cwd/"); 60 var base = new Uri(scheme: "file", path: cwd.endsWith("/") ? cwd : "$cwd/");
57 var resolved = base.resolve(scriptName); 61 _entrypoint = base.resolve(scriptName);
58 _logResolution("# Resolved to: $resolved"); 62 _logResolution("# Resolved script to: $_entrypoint");
59 return resolved.toString(); 63
64 return _entrypoint.toString();
60 } 65 }
61 66
62 String _resolveUri(String base, String userString) { 67 String _resolveUri(String base, String userString) {
63 var baseUri = new Uri.fromString(base); 68 var baseUri = new Uri.fromString(base);
64 _logResolution("# Resolving: $userString from $base"); 69 _logResolution("# Resolving: $userString from $base");
65 var resolved = baseUri.resolve(userString); 70 var resolved = baseUri.resolve(userString);
66 _logResolution("# Resolved to: $resolved"); 71 _logResolution("# Resolved to: $resolved");
67 return resolved.toString(); 72 return resolved.toString();
68 } 73 }
69 74
70 String _resolveExtensionUri(String base, String userString) { 75 String _resolveExtensionUri(String base, String userString) {
71 var uri = new Uri.fromString(userString); 76 var uri = new Uri.fromString(userString);
72 if ("dart-ext" != uri.scheme) { 77 if ("dart-ext" != uri.scheme) {
73 throw "Not a Dart extension uri: $uri"; 78 throw "Not a Dart extension uri: $uri";
74 } 79 }
75 var schemelessUri = new Uri(path: uri.path); 80 var schemelessUri = new Uri(path: uri.path);
76 var baseUri = new Uri.fromString(base); 81 var baseUri = new Uri.fromString(base);
77 _logResolution("# Resolving: $userString from $base"); 82 _logResolution("# Resolving: $userString from $base");
78 var resolved = baseUri.resolveUri(schemelessUri); 83 var resolved = baseUri.resolveUri(schemelessUri);
79 resolved = new Uri(scheme: 'dart-ext', path: resolved.path); 84 resolved = new Uri(scheme: 'dart-ext', path: resolved.path);
80 _logResolution("# Resolved to: $resolved"); 85 _logResolution("# Resolved to: $resolved");
81 return resolved.toString(); 86 return resolved.toString();
82 } 87 }
83 88
84 String _filePathFromUri(String userUri) { 89 String _filePathFromUri(String userUri) {
85 var uri = new Uri.fromString(userUri); 90 var uri = new Uri.fromString(userUri);
86 _logResolution("# Getting file path from: $uri"); 91 _logResolution("# Getting file path from: $uri");
87 if ("file" != uri.scheme) { 92
88 // Only handling file URIs in standalone binary. 93 switch (uri.scheme) {
89 _logResolution("# Not a file URI."); 94 case 'file': return _filePathFromFileUri(uri);
90 throw "Not a file uri: $uri"; 95 case 'package': return _filePathFromPackageUri(uri);
96
97 default:
98 // Only handling file and package URIs in standalone binary.
99 _logResolution("# Not a file or package URI.");
100 throw "Not a known scheme: $uri";
91 } 101 }
102 }
103
104 String _filePathFromFileUri(Uri uri) {
92 var path = uri.path; 105 var path = uri.path;
93 _logResolution("# Path: $path"); 106 _logResolution("# Path: $path");
94 if (_is_windows) { 107 if (_is_windows) {
95 // Drop the leading / before the drive letter. 108 // Drop the leading / before the drive letter.
96 path = path.substring(1); 109 path = path.substring(1);
97 _logResolution("# path: $path"); 110 _logResolution("# path: $path");
98 } 111 }
99 return path; 112 return path;
100 } 113 }
114
115 String _filePathFromPackageUri(Uri uri) {
116 // Get the path to the package directory.
117 var baseDir = _entrypoint.path;
118
119 // Remove any extension.
120 var lastDot = baseDir.lastIndexOf(".");
121 if (lastDot != -1) {
122 baseDir = baseDir.substring(0, lastDot);
123 }
124
125 var path = "$baseDir.packages/${uri.path}";
126 _logResolution("# Package: $path");
127 return path;
128 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/src/package/PackageTest.dart » ('j') | tests/standalone/src/package/PackageTest.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698