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

Side by Side Diff: runtime/bin/builtin.dart

Issue 23199002: Fix absolute paths on Windows without a drive letter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import 'dart:io'; 6 import 'dart:io';
7 7
8 // Corelib 'print' implementation. 8 // Corelib 'print' implementation.
9 void _print(arg) { 9 void _print(arg) {
10 _Logger._printString(arg.toString()); 10 _Logger._printString(arg.toString());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 _requestCompleted(builder.takeBytes(), response); 70 _requestCompleted(builder.takeBytes(), response);
71 }); 71 });
72 }).catchError((error) { 72 }).catchError((error) {
73 _requestFailed(error); 73 _requestFailed(error);
74 }); 74 });
75 } 75 }
76 76
77 77
78 // Are we running on Windows? 78 // Are we running on Windows?
79 var _isWindows = false; 79 var _isWindows = false;
80 var _workingWindowsDrivePrefix;
80 // The current working directory 81 // The current working directory
81 var _workingDirectoryUri; 82 var _workingDirectoryUri;
82 // The URI that the entry point script was loaded from. Remembered so that 83 // The URI that the entry point script was loaded from. Remembered so that
83 // package imports can be resolved relative to it. 84 // package imports can be resolved relative to it.
84 var _entryPointScript; 85 var _entryPointScript;
85 // The directory to look in to resolve "package:" scheme URIs. 86 // The directory to look in to resolve "package:" scheme URIs.
86 var _packageRoot; 87 var _packageRoot;
87 88
88 89
89 void _setWindows() { 90 void _setWindows() {
90 _isWindows = true; 91 _isWindows = true;
91 } 92 }
92 93
93 94
94 _sanitizeWindowsPath(path) { 95 _sanitizeWindowsPath(path) {
zra 2013/08/14 16:38:12 If it's easy/makes sense, maybe collect all Window
95 // For Windows we need to massage the paths a bit according to 96 // For Windows we need to massage the paths a bit according to
96 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx 97 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx
97 // 98 //
98 // Convert 99 // Convert
99 // C:\one\two\three 100 // C:\one\two\three
100 // to 101 // to
101 // /C:/one/two/three 102 // /C:/one/two/three
102 103
103 if (_isWindows == false) { 104 if (_isWindows == false) {
104 // Do nothing when not running Windows. 105 // Do nothing when not running Windows.
(...skipping 11 matching lines...) Expand all
116 } 117 }
117 118
118 _enforceTrailingSlash(uri) { 119 _enforceTrailingSlash(uri) {
119 // Ensure we have a trailing slash character. 120 // Ensure we have a trailing slash character.
120 if (!uri.endsWith('/')) { 121 if (!uri.endsWith('/')) {
121 return '$uri/'; 122 return '$uri/';
122 } 123 }
123 return uri; 124 return uri;
124 } 125 }
125 126
127 _extractDriveLetterPrefix(cwd) {
128 if (!_isWindows) {
129 return null;
130 }
131 if (cwd.length > 1 && cwd[1] == ':') {
132 return '/${cwd[0]}:';
133 }
134 return null;
135 }
126 136
127 void _setWorkingDirectory(cwd) { 137 void _setWorkingDirectory(cwd) {
138 _workingWindowsDrivePrefix = _extractDriveLetterPrefix(cwd);
128 cwd = _sanitizeWindowsPath(cwd); 139 cwd = _sanitizeWindowsPath(cwd);
129 cwd = _enforceTrailingSlash(cwd); 140 cwd = _enforceTrailingSlash(cwd);
130 _workingDirectoryUri = new Uri(scheme: 'file', path: cwd); 141 _workingDirectoryUri = new Uri(scheme: 'file', path: cwd);
131 _logResolution('# Working Directory: $cwd'); 142 _logResolution('# Working Directory: $cwd');
132 } 143 }
133 144
134 145
135 _setPackageRoot(String packageRoot) { 146 _setPackageRoot(String packageRoot) {
136 packageRoot = _enforceTrailingSlash(packageRoot); 147 packageRoot = _enforceTrailingSlash(packageRoot);
137 _packageRoot = _workingDirectoryUri.resolve(packageRoot); 148 _packageRoot = _workingDirectoryUri.resolve(packageRoot);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // 226 //
216 // Drop the leading / before the drive letter. 227 // Drop the leading / before the drive letter.
217 path = path.substring(1); 228 path = path.substring(1);
218 _logResolution('# Path: Removed leading / -> $path'); 229 _logResolution('# Path: Removed leading / -> $path');
219 } 230 }
220 231
221 return path; 232 return path;
222 } 233 }
223 234
224 235
225 String _filePathFromFileUri(Uri uri) { 236 String _filePathFromFileUri(Uri uri) {
zra 2013/08/14 16:38:12 It looks like this code is only running under the
Cutch 2013/08/14 20:29:08 For absolute paths with no scheme, yes.
226 if (!uri.host.isEmpty) { 237 if (!uri.host.isEmpty) {
227 throw "URIs using the 'file:' scheme may not contain a host."; 238 throw "URIs using the 'file:' scheme may not contain a host.";
228 } 239 }
229 240
230 _logResolution('# Path: $uri -> ${uri.path}'); 241 String path = uri.path;
231 return uri.path; 242 _logResolution('# Path: $uri -> ${path}');
243 if (_isWindows && (path.length > 2) && path.startsWith('/') &&
244 (path[2] != ':')) {
zra 2013/08/14 16:38:12 Is this (path[2] != ':') checking that the path is
Cutch 2013/08/14 20:29:08 Done.
245 if (_workingWindowsDrivePrefix == null) {
246 throw 'Could not determine windows drive letter prefix.';
247 }
248 // Absolute path on Windows without a drive letter.
249 _logResolution('# Path: Windows absolute path needs a drive letter.'
250 ' Prepending $_workingWindowsDrivePrefix.');
251 path = '$_workingWindowsDrivePrefix$path';
252 }
253 return path;
232 } 254 }
233 255
234 256
235 String _filePathFromOtherUri(Uri uri) { 257 String _filePathFromOtherUri(Uri uri) {
236 if (!uri.host.isEmpty) { 258 if (!uri.host.isEmpty) {
237 throw 'URIs whose paths are used as file paths may not contain a host.'; 259 throw 'URIs whose paths are used as file paths may not contain a host.';
238 } 260 }
239 261
240 _logResolution('# Path: $uri -> ${uri.path}'); 262 _logResolution('# Path: $uri -> ${uri.path}');
241 return uri.path; 263 return uri.path;
(...skipping 27 matching lines...) Expand all
269 } 291 }
270 _logResolution('# Package: $uri -> $path'); 292 _logResolution('# Package: $uri -> $path');
271 return path; 293 return path;
272 } 294 }
273 295
274 296
275 String _filePathFromHttpUri(Uri uri) { 297 String _filePathFromHttpUri(Uri uri) {
276 _logResolution('# Path: $uri -> $uri'); 298 _logResolution('# Path: $uri -> $uri');
277 return uri.toString(); 299 return uri.toString();
278 } 300 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698