| OLD | NEW |
| 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 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 // import 'root_library'; happens here from C Code | 9 // import 'root_library'; happens here from C Code |
| 10 | 10 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 var _entryPointScript; | 159 var _entryPointScript; |
| 160 // The directory to look in to resolve "package:" scheme URIs. | 160 // The directory to look in to resolve "package:" scheme URIs. |
| 161 var _packageRoot; | 161 var _packageRoot; |
| 162 | 162 |
| 163 | 163 |
| 164 void _setWindows() { | 164 void _setWindows() { |
| 165 _isWindows = true; | 165 _isWindows = true; |
| 166 } | 166 } |
| 167 | 167 |
| 168 | 168 |
| 169 _sanitizeWindowsPath(path) { |
| 170 // For Windows we need to massage the paths a bit according to |
| 171 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx |
| 172 // |
| 173 // Convert |
| 174 // C:\one\two\three |
| 175 // to |
| 176 // /C:/one/two/three |
| 177 |
| 178 if (_isWindows == false) { |
| 179 // Do nothing when not running Windows. |
| 180 return path; |
| 181 } |
| 182 |
| 183 var fixedPath = "${path.replaceAll('\\', '/')}"; |
| 184 |
| 185 if ((path.length > 2) && (path[1] == ':')) { |
| 186 // Path begins with a drive letter. |
| 187 return '/$fixedPath'; |
| 188 } |
| 189 |
| 190 return fixedPath; |
| 191 } |
| 192 |
| 193 |
| 169 _enforceTrailingSlash(uri) { | 194 _enforceTrailingSlash(uri) { |
| 170 // Ensure we have a trailing slash character. | 195 // Ensure we have a trailing slash character. |
| 171 if (!uri.endsWith('/')) { | 196 if (!uri.endsWith('/')) { |
| 172 return '$uri/'; | 197 return '$uri/'; |
| 173 } | 198 } |
| 174 return uri; | 199 return uri; |
| 175 } | 200 } |
| 176 | 201 |
| 177 | 202 |
| 178 _extractDriveLetterPrefix(cwd) { | 203 _extractDriveLetterPrefix(cwd) { |
| 179 if (!_isWindows) { | 204 if (!_isWindows) { |
| 180 return null; | 205 return null; |
| 181 } | 206 } |
| 182 if (cwd.length > 1 && cwd[1] == ':') { | 207 if (cwd.length > 1 && cwd[1] == ':') { |
| 183 return '/${cwd[0]}:'; | 208 return '/${cwd[0]}:'; |
| 184 } | 209 } |
| 185 return null; | 210 return null; |
| 186 } | 211 } |
| 187 | 212 |
| 188 | 213 |
| 189 void _setWorkingDirectory(cwd) { | 214 void _setWorkingDirectory(cwd) { |
| 190 _workingWindowsDrivePrefix = _extractDriveLetterPrefix(cwd); | 215 _workingWindowsDrivePrefix = _extractDriveLetterPrefix(cwd); |
| 191 _workingDirectoryUri = new Uri.file(cwd); | 216 cwd = _sanitizeWindowsPath(cwd); |
| 192 if (!_workingDirectoryUri.path.endsWith("/")) { | 217 cwd = _enforceTrailingSlash(cwd); |
| 193 var directoryPath = _workingDirectoryUri.path + "/"; | 218 _workingDirectoryUri = new Uri(scheme: 'file', path: cwd); |
| 194 _workingDirectoryUri = _workingDirectoryUri.resolve(directoryPath); | |
| 195 } | |
| 196 | |
| 197 _logResolution('# Working Directory: $cwd'); | 219 _logResolution('# Working Directory: $cwd'); |
| 198 } | 220 } |
| 199 | 221 |
| 200 Uri _uriFromPathOrUri(String location) { | |
| 201 if (location.startsWith('file:') || | |
| 202 location.startsWith('http:') || | |
| 203 location.startsWith('https:')) { | |
| 204 return Uri.parse(location); | |
| 205 } | |
| 206 return new Uri.file(location); | |
| 207 } | |
| 208 | 222 |
| 209 _setPackageRoot(String packageRoot) { | 223 _setPackageRoot(String packageRoot) { |
| 210 packageRoot = _enforceTrailingSlash(packageRoot); | 224 packageRoot = _enforceTrailingSlash(packageRoot); |
| 211 _packageRoot = | 225 if (packageRoot.startsWith('file:') || |
| 212 _workingDirectoryUri.resolveUri(_uriFromPathOrUri(packageRoot)); | 226 packageRoot.startsWith('http:') || |
| 227 packageRoot.startsWith('https:')) { |
| 228 _packageRoot = _workingDirectoryUri.resolve(packageRoot); |
| 229 } else { |
| 230 _packageRoot = _workingDirectoryUri.resolveUri(new Uri.file(packageRoot)); |
| 231 } |
| 213 _logResolution('# Package root: $packageRoot -> $_packageRoot'); | 232 _logResolution('# Package root: $packageRoot -> $_packageRoot'); |
| 214 } | 233 } |
| 215 | 234 |
| 216 | 235 |
| 217 String _resolveScriptUri(String scriptName) { | 236 String _resolveScriptUri(String scriptName) { |
| 218 if (_workingDirectoryUri == null) { | 237 if (_workingDirectoryUri == null) { |
| 219 throw 'No current working directory set.'; | 238 throw 'No current working directory set.'; |
| 220 } | 239 } |
| 221 var scriptUri = _uriFromPathOrUri(scriptName); | 240 scriptName = _sanitizeWindowsPath(scriptName); |
| 241 |
| 242 var scriptUri = Uri.parse(scriptName); |
| 222 if (scriptUri.scheme != '') { | 243 if (scriptUri.scheme != '') { |
| 223 // Script has a scheme, assume that it is fully formed. | 244 // Script has a scheme, assume that it is fully formed. |
| 224 _entryPointScript = scriptUri; | 245 _entryPointScript = scriptUri; |
| 225 } else { | 246 } else { |
| 226 // Script does not have a scheme, assume that it is a path, | 247 // Script does not have a scheme, assume that it is a path, |
| 227 // resolve it against the working directory. | 248 // resolve it against the working directory. |
| 228 _entryPointScript = _workingDirectoryUri.resolve(scriptName); | 249 _entryPointScript = _workingDirectoryUri.resolve(scriptName); |
| 229 } | 250 } |
| 230 _logResolution('# Resolved entry point to: $_entryPointScript'); | 251 _logResolution('# Resolved entry point to: $_entryPointScript'); |
| 231 return _entryPointScript.toString(); | 252 return _entryPointScript.toString(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 assert(_numOutstandingLoadRequests > 0); | 335 assert(_numOutstandingLoadRequests > 0); |
| 315 _numOutstandingLoadRequests--; | 336 _numOutstandingLoadRequests--; |
| 316 _asyncLoadErrorCallback(uri, error); | 337 _asyncLoadErrorCallback(uri, error); |
| 317 } | 338 } |
| 318 | 339 |
| 319 | 340 |
| 320 // Asynchronously loads script data (source or snapshot) through | 341 // Asynchronously loads script data (source or snapshot) through |
| 321 // an http or file uri. | 342 // an http or file uri. |
| 322 _loadDataAsync(String uri) { | 343 _loadDataAsync(String uri) { |
| 323 uri = _resolveScriptUri(uri); | 344 uri = _resolveScriptUri(uri); |
| 324 Uri sourceUri = _uriFromPathOrUri(uri); | 345 Uri sourceUri = Uri.parse(uri); |
| 325 _numOutstandingLoadRequests++; | 346 _numOutstandingLoadRequests++; |
| 326 _logResolution("_loadDataAsync($uri), " | 347 _logResolution("_loadDataAsync($uri), " |
| 327 "${_numOutstandingLoadRequests} requests outstanding"); | 348 "${_numOutstandingLoadRequests} requests outstanding"); |
| 328 if (sourceUri.scheme == 'http') { | 349 if (sourceUri.scheme == 'http') { |
| 329 _httpGet(sourceUri, (data) { | 350 _httpGet(sourceUri, (data) { |
| 330 _loadScript(uri, data); | 351 _loadScript(uri, data); |
| 331 }); | 352 }); |
| 332 } else { | 353 } else { |
| 333 var sourceFile = new File(_filePathFromUri(uri)); | 354 var sourceFile = new File(_filePathFromUri(uri)); |
| 334 sourceFile.readAsBytes().then((data) { | 355 sourceFile.readAsBytes().then((data) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 355 "${_numOutstandingLoadRequests} requests remaining"); | 376 "${_numOutstandingLoadRequests} requests remaining"); |
| 356 if (_numOutstandingLoadRequests == 0) { | 377 if (_numOutstandingLoadRequests == 0) { |
| 357 _signalDoneLoading(); | 378 _signalDoneLoading(); |
| 358 } | 379 } |
| 359 } | 380 } |
| 360 | 381 |
| 361 | 382 |
| 362 // Asynchronously loads source code through an http or file uri. | 383 // Asynchronously loads source code through an http or file uri. |
| 363 _loadSourceAsync(int tag, String uri, String libraryUri) { | 384 _loadSourceAsync(int tag, String uri, String libraryUri) { |
| 364 var filePath = _filePathFromUri(uri); | 385 var filePath = _filePathFromUri(uri); |
| 365 Uri sourceUri = new Uri.file(filePath); | 386 Uri sourceUri = Uri.parse(filePath); |
| 366 _numOutstandingLoadRequests++; | 387 _numOutstandingLoadRequests++; |
| 367 _logResolution("_loadLibrarySource($uri), " | 388 _logResolution("_loadLibrarySource($uri), " |
| 368 "${_numOutstandingLoadRequests} requests outstanding"); | 389 "${_numOutstandingLoadRequests} requests outstanding"); |
| 369 if (sourceUri.scheme == 'http') { | 390 if (sourceUri.scheme == 'http') { |
| 370 _httpGet(sourceUri, (data) { | 391 _httpGet(sourceUri, (data) { |
| 371 var text = UTF8.decode(data); | 392 var text = UTF8.decode(data); |
| 372 _loadLibrarySource(tag, uri, libraryUri, text); | 393 _loadLibrarySource(tag, uri, libraryUri, text); |
| 373 }); | 394 }); |
| 374 } else { | 395 } else { |
| 375 var sourceFile = new File(filePath); | 396 var sourceFile = new File(filePath); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 } else if (Platform.isWindows) { | 442 } else if (Platform.isWindows) { |
| 422 filename = '$name.dll'; | 443 filename = '$name.dll'; |
| 423 } else { | 444 } else { |
| 424 _logResolution( | 445 _logResolution( |
| 425 'Native extensions not supported on ${Platform.operatingSystem}'); | 446 'Native extensions not supported on ${Platform.operatingSystem}'); |
| 426 throw 'Native extensions not supported on ${Platform.operatingSystem}'; | 447 throw 'Native extensions not supported on ${Platform.operatingSystem}'; |
| 427 } | 448 } |
| 428 | 449 |
| 429 return [path, filename, name]; | 450 return [path, filename, name]; |
| 430 } | 451 } |
| OLD | NEW |