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

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() {
(...skipping 25 matching lines...) Expand all
115 return fixedPath; 116 return fixedPath;
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
zra 2013/08/15 15:03:42 Not sure what the Dart style is, but everywhere el
Cutch 2013/08/15 15:44:23 It's not specified but I should be consistent :)
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
zra 2013/08/15 15:03:42 Here, too.
Cutch 2013/08/15 15:44:23 Done.
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 231
221 return path; 232 return path;
222 } 233 }
223 234
224 235
225 String _filePathFromFileUri(Uri uri) { 236 String _filePathFromFileUri(Uri uri) {
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 // Check that the path is not already in the form of /X:.
244 if (_isWindows && (path.length > 2) && path.startsWith('/') &&
245 (path[2] != ':')) {
246 // Absolute path on Windows without a drive letter.
247 if (_workingWindowsDrivePrefix == null) {
248 throw 'Could not determine windows drive letter prefix.';
249 }
250 _logResolution('# Path: Windows absolute path needs a drive letter.'
251 ' Prepending $_workingWindowsDrivePrefix.');
252 path = '$_workingWindowsDrivePrefix$path';
253 }
254 return path;
232 } 255 }
233 256
234 257
235 String _filePathFromOtherUri(Uri uri) { 258 String _filePathFromOtherUri(Uri uri) {
236 if (!uri.host.isEmpty) { 259 if (!uri.host.isEmpty) {
237 throw 'URIs whose paths are used as file paths may not contain a host.'; 260 throw 'URIs whose paths are used as file paths may not contain a host.';
238 } 261 }
239 262
240 _logResolution('# Path: $uri -> ${uri.path}'); 263 _logResolution('# Path: $uri -> ${uri.path}');
241 return uri.path; 264 return uri.path;
(...skipping 27 matching lines...) Expand all
269 } 292 }
270 _logResolution('# Package: $uri -> $path'); 293 _logResolution('# Package: $uri -> $path');
271 return path; 294 return path;
272 } 295 }
273 296
274 297
275 String _filePathFromHttpUri(Uri uri) { 298 String _filePathFromHttpUri(Uri uri) {
276 _logResolution('# Path: $uri -> $uri'); 299 _logResolution('# Path: $uri -> $uri');
277 return uri.toString(); 300 return uri.toString();
278 } 301 }
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