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

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

Issue 57923004: Allow Windows network share paths for the script path and the package root. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 | runtime/bin/extensions.cc » ('j') | runtime/bin/extensions.cc » ('J')
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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 _workingWindowsDrivePrefix = _extractDriveLetterPrefix(cwd); 149 _workingWindowsDrivePrefix = _extractDriveLetterPrefix(cwd);
150 cwd = _sanitizeWindowsPath(cwd); 150 cwd = _sanitizeWindowsPath(cwd);
151 cwd = _enforceTrailingSlash(cwd); 151 cwd = _enforceTrailingSlash(cwd);
152 _workingDirectoryUri = new Uri(scheme: 'file', path: cwd); 152 _workingDirectoryUri = new Uri(scheme: 'file', path: cwd);
153 _logResolution('# Working Directory: $cwd'); 153 _logResolution('# Working Directory: $cwd');
154 } 154 }
155 155
156 156
157 _setPackageRoot(String packageRoot) { 157 _setPackageRoot(String packageRoot) {
158 packageRoot = _enforceTrailingSlash(packageRoot); 158 packageRoot = _enforceTrailingSlash(packageRoot);
159 _packageRoot = _workingDirectoryUri.resolve(packageRoot); 159 if (packageRoot.startsWith('file:') ||
160 packageRoot.startsWith('http:') ||
161 packageRoot.startsWith('https:')) {
162 _packageRoot = _workingDirectoryUri.resolve(packageRoot);
163 } else {
164 _packageRoot = _workingDirectoryUri.resolveUri(new Uri.file(packageRoot));
165 }
160 _logResolution('# Package root: $packageRoot -> $_packageRoot'); 166 _logResolution('# Package root: $packageRoot -> $_packageRoot');
161 } 167 }
162 168
163 169
164 String _resolveScriptUri(String scriptName) { 170 String _resolveScriptUri(String scriptName) {
165 if (_workingDirectoryUri == null) { 171 if (_workingDirectoryUri == null) {
166 throw 'No current working directory set.'; 172 throw 'No current working directory set.';
167 } 173 }
168 scriptName = _sanitizeWindowsPath(scriptName); 174 scriptName = _sanitizeWindowsPath(scriptName);
169 175
(...skipping 30 matching lines...) Expand all
200 } 206 }
201 resolved = new Uri(scheme: 'dart-ext', path: path); 207 resolved = new Uri(scheme: 'dart-ext', path: path);
202 } else { 208 } else {
203 resolved = baseUri.resolve(userString); 209 resolved = baseUri.resolve(userString);
204 } 210 }
205 _logResolution('# Resolved to: $resolved'); 211 _logResolution('# Resolved to: $resolved');
206 return resolved.toString(); 212 return resolved.toString();
207 } 213 }
208 214
209 215
216 // Returns either a file path or a URI starting with http:, as a String.
210 String _filePathFromUri(String userUri) { 217 String _filePathFromUri(String userUri) {
211 var uri = Uri.parse(userUri); 218 var uri = Uri.parse(userUri);
212 _logResolution('# Getting file path from: $uri'); 219 _logResolution('# Getting file path from: $uri');
213 220
214 var path; 221 var path;
215 switch (uri.scheme) { 222 switch (uri.scheme) {
223 case '':
216 case 'file': 224 case 'file':
217 path = _filePathFromFileUri(uri); 225 return uri.toFilePath();
218 break; 226 break;
219 case 'dart-ext': 227 case 'dart-ext':
220 path = _filePathFromOtherUri(uri); 228 return new Uri(scheme: 'file',
229 host: uri.host,
230 path: uri.path).toFilePath();
221 break; 231 break;
222 case 'package': 232 case 'package':
223 path = _filePathFromPackageUri(uri); 233 return _filePathFromPackageUri(uri);
224 break; 234 break;
225 case 'http': 235 case 'http':
226 path = _filePathFromHttpUri(uri); 236 return uri.toString();
227 break;
228 default: 237 default:
229 // Only handling file and package URIs in standalone binary. 238 // Only handling file, dart-ext, http, and package URIs
239 // in standalone binary.
230 _logResolution('# Unknown scheme (${uri.scheme}) in $uri.'); 240 _logResolution('# Unknown scheme (${uri.scheme}) in $uri.');
231 throw 'Not a known scheme: $uri'; 241 throw 'Not a known scheme: $uri';
232 } 242 }
233
234 if (_isWindows && path.startsWith('/')) {
235 // For Windows we need to massage the paths a bit according to
236 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx
237 //
238 // Drop the leading / before the drive letter.
239 // TODO(14577): Handle paths like \\server\share\dir\file.
240 path = path.substring(1);
241 _logResolution('# Path: Removed leading / -> $path');
242 }
243
244 return path;
245 } 243 }
246 244
247 245
248 String _filePathFromFileUri(Uri uri) {
249 if (!uri.host.isEmpty) {
250 throw "URIs using the 'file:' scheme may not contain a host.";
251 }
252
253 String path = uri.path;
254 _logResolution('# Path: $uri -> ${path}');
255 // Check that the path is not already in the form of /X:.
256 if (_isWindows && (path.length > 2) && path.startsWith('/') &&
257 (path[2] != ':')) {
258 // Absolute path on Windows without a drive letter.
259 if (_workingWindowsDrivePrefix == null) {
260 throw 'Could not determine windows drive letter prefix.';
261 }
262 _logResolution('# Path: Windows absolute path needs a drive letter.'
263 ' Prepending $_workingWindowsDrivePrefix.');
264 path = '$_workingWindowsDrivePrefix$path';
265 }
266 return path;
267 }
268
269
270 String _filePathFromOtherUri(Uri uri) {
271 if (!uri.host.isEmpty) {
272 throw 'URIs whose paths are used as file paths may not contain a host.';
273 }
274
275 _logResolution('# Path: $uri -> ${uri.path}');
276 return uri.path;
277 }
278
279
280 String _filePathFromPackageUri(Uri uri) { 246 String _filePathFromPackageUri(Uri uri) {
281 if (!uri.host.isEmpty) { 247 if (!uri.host.isEmpty) {
282 var path = (uri.path != '') ? '${uri.host}${uri.path}' : uri.host; 248 var path = (uri.path != '') ? '${uri.host}${uri.path}' : uri.host;
283 var right = 'package:$path'; 249 var right = 'package:$path';
284 var wrong = 'package://$path'; 250 var wrong = 'package://$path';
285 251
286 throw "URIs using the 'package:' scheme should look like " 252 throw "URIs using the 'package:' scheme should look like "
287 "'$right', not '$wrong'."; 253 "'$right', not '$wrong'.";
288 } 254 }
289 255
290 var packageUri; 256 var packageRoot = _packageRoot == null ?
291 var path; 257 _entryPointScript.resolve('packages/') :
292 if (_packageRoot != null) { 258 _packageRoot;
293 // Resolve against package root. 259 return _filePathFromUri(packageRoot.resolve(uri.path).toString());
294 packageUri = _packageRoot.resolve(uri.path);
295 } else {
296 // Resolve against working directory.
297 packageUri = _entryPointScript.resolve('packages/${uri.path}');
298 }
299
300 if (packageUri.scheme == 'file') {
301 path = packageUri.path;
302 } else {
303 path = packageUri.toString();
304 }
305 _logResolution('# Package: $uri -> $path');
306 return path;
307 } 260 }
308
309
310 String _filePathFromHttpUri(Uri uri) {
311 _logResolution('# Path: $uri -> $uri');
312 return uri.toString();
313 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/extensions.cc » ('j') | runtime/bin/extensions.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698