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

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 18 matching lines...) Expand all
108 var fixedPath = "${path.replaceAll('\\', '/')}"; 109 var fixedPath = "${path.replaceAll('\\', '/')}";
109 110
110 if ((path.length > 2) && (path[1] == ':')) { 111 if ((path.length > 2) && (path[1] == ':')) {
111 // Path begins with a drive letter. 112 // Path begins with a drive letter.
112 return '/$fixedPath'; 113 return '/$fixedPath';
113 } 114 }
114 115
115 return fixedPath; 116 return fixedPath;
116 } 117 }
117 118
119
118 _enforceTrailingSlash(uri) { 120 _enforceTrailingSlash(uri) {
119 // Ensure we have a trailing slash character. 121 // Ensure we have a trailing slash character.
120 if (!uri.endsWith('/')) { 122 if (!uri.endsWith('/')) {
121 return '$uri/'; 123 return '$uri/';
122 } 124 }
123 return uri; 125 return uri;
124 } 126 }
125 127
126 128
129 _extractDriveLetterPrefix(cwd) {
130 if (!_isWindows) {
131 return null;
132 }
133 if (cwd.length > 1 && cwd[1] == ':') {
134 return '/${cwd[0]}:';
135 }
136 return null;
137 }
138
139
127 void _setWorkingDirectory(cwd) { 140 void _setWorkingDirectory(cwd) {
141 _workingWindowsDrivePrefix = _extractDriveLetterPrefix(cwd);
128 cwd = _sanitizeWindowsPath(cwd); 142 cwd = _sanitizeWindowsPath(cwd);
129 cwd = _enforceTrailingSlash(cwd); 143 cwd = _enforceTrailingSlash(cwd);
130 _workingDirectoryUri = new Uri(scheme: 'file', path: cwd); 144 _workingDirectoryUri = new Uri(scheme: 'file', path: cwd);
131 _logResolution('# Working Directory: $cwd'); 145 _logResolution('# Working Directory: $cwd');
132 } 146 }
133 147
134 148
135 _setPackageRoot(String packageRoot) { 149 _setPackageRoot(String packageRoot) {
136 packageRoot = _enforceTrailingSlash(packageRoot); 150 packageRoot = _enforceTrailingSlash(packageRoot);
137 _packageRoot = _workingDirectoryUri.resolve(packageRoot); 151 _packageRoot = _workingDirectoryUri.resolve(packageRoot);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 234
221 return path; 235 return path;
222 } 236 }
223 237
224 238
225 String _filePathFromFileUri(Uri uri) { 239 String _filePathFromFileUri(Uri uri) {
226 if (!uri.host.isEmpty) { 240 if (!uri.host.isEmpty) {
227 throw "URIs using the 'file:' scheme may not contain a host."; 241 throw "URIs using the 'file:' scheme may not contain a host.";
228 } 242 }
229 243
230 _logResolution('# Path: $uri -> ${uri.path}'); 244 String path = uri.path;
231 return uri.path; 245 _logResolution('# Path: $uri -> ${path}');
246 // Check that the path is not already in the form of /X:.
247 if (_isWindows && (path.length > 2) && path.startsWith('/') &&
248 (path[2] != ':')) {
249 // Absolute path on Windows without a drive letter.
250 if (_workingWindowsDrivePrefix == null) {
251 throw 'Could not determine windows drive letter prefix.';
252 }
253 _logResolution('# Path: Windows absolute path needs a drive letter.'
254 ' Prepending $_workingWindowsDrivePrefix.');
255 path = '$_workingWindowsDrivePrefix$path';
256 }
257 return path;
232 } 258 }
233 259
234 260
235 String _filePathFromOtherUri(Uri uri) { 261 String _filePathFromOtherUri(Uri uri) {
236 if (!uri.host.isEmpty) { 262 if (!uri.host.isEmpty) {
237 throw 'URIs whose paths are used as file paths may not contain a host.'; 263 throw 'URIs whose paths are used as file paths may not contain a host.';
238 } 264 }
239 265
240 _logResolution('# Path: $uri -> ${uri.path}'); 266 _logResolution('# Path: $uri -> ${uri.path}');
241 return uri.path; 267 return uri.path;
(...skipping 27 matching lines...) Expand all
269 } 295 }
270 _logResolution('# Package: $uri -> $path'); 296 _logResolution('# Package: $uri -> $path');
271 return path; 297 return path;
272 } 298 }
273 299
274 300
275 String _filePathFromHttpUri(Uri uri) { 301 String _filePathFromHttpUri(Uri uri) {
276 _logResolution('# Path: $uri -> $uri'); 302 _logResolution('# Path: $uri -> $uri');
277 return uri.toString(); 303 return uri.toString();
278 } 304 }
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