| 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 | 6 |
| 7 void print(arg) { | 7 void print(arg) { |
| 8 _Logger._printString(arg.toString()); | 8 _Logger._printString(arg.toString()); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 var _is_windows; | 28 var _is_windows; |
| 29 | 29 |
| 30 void _logResolution(String msg) { | 30 void _logResolution(String msg) { |
| 31 final enabled = false; | 31 final enabled = false; |
| 32 if (enabled) { | 32 if (enabled) { |
| 33 _Logger._printString(msg); | 33 _Logger._printString(msg); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 // TODO(iposva): Make these private once the Dart API is fixed. | 37 // TODO(iposva): Make these private once the Dart API is fixed. |
| 38 String resolveScriptUri(String cwd, String scriptName, bool windows) { | 38 String _resolveScriptUri(String cwd, String scriptName, bool windows) { |
| 39 _is_windows = windows; | 39 _is_windows = windows; |
| 40 _logResolution("# Current working directory: $cwd"); | 40 _logResolution("# Current working directory: $cwd"); |
| 41 _logResolution("# ScriptName: $scriptName"); | 41 _logResolution("# ScriptName: $scriptName"); |
| 42 if (windows) { | 42 if (windows) { |
| 43 // Convert | 43 // Convert |
| 44 // C:\one\two\three | 44 // C:\one\two\three |
| 45 // to | 45 // to |
| 46 // /C:/one/two/three | 46 // /C:/one/two/three |
| 47 cwd = "/${cwd.replaceAll('\\', '/')}"; | 47 cwd = "/${cwd.replaceAll('\\', '/')}"; |
| 48 _logResolution("## cwd: $cwd"); | 48 _logResolution("## cwd: $cwd"); |
| 49 if ((scriptName.length > 2) && (scriptName[1] == ":")) { | 49 if ((scriptName.length > 2) && (scriptName[1] == ":")) { |
| 50 // This is an absolute path. | 50 // This is an absolute path. |
| 51 scriptName = "/${scriptName.replaceAll('\\', '/')}"; | 51 scriptName = "/${scriptName.replaceAll('\\', '/')}"; |
| 52 } else { | 52 } else { |
| 53 scriptName = scriptName.replaceAll('\\', '/'); | 53 scriptName = scriptName.replaceAll('\\', '/'); |
| 54 } | 54 } |
| 55 _logResolution("## scriptName: $scriptName"); | 55 _logResolution("## scriptName: $scriptName"); |
| 56 } | 56 } |
| 57 var base = new Uri(scheme: "file", path: cwd.endsWith("/") ? cwd : "$cwd/"); | 57 var base = new Uri(scheme: "file", path: cwd.endsWith("/") ? cwd : "$cwd/"); |
| 58 var resolved = base.resolve(scriptName); | 58 var resolved = base.resolve(scriptName); |
| 59 _logResolution("# Resolved to: $resolved"); | 59 _logResolution("# Resolved to: $resolved"); |
| 60 return resolved.toString(); | 60 return resolved.toString(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 String resolveUri(String base, String userString) { | 63 String _resolveUri(String base, String userString) { |
| 64 var baseUri = new Uri.fromString(base); | 64 var baseUri = new Uri.fromString(base); |
| 65 _logResolution("# Resolving: $userString from $base"); | 65 _logResolution("# Resolving: $userString from $base"); |
| 66 var resolved = baseUri.resolve(userString); | 66 var resolved = baseUri.resolve(userString); |
| 67 _logResolution("# Resolved to: $resolved"); | 67 _logResolution("# Resolved to: $resolved"); |
| 68 return resolved.toString(); | 68 return resolved.toString(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 String resolveExtensionUri(String base, String userString) { | 71 String _resolveExtensionUri(String base, String userString) { |
| 72 var uri = new Uri.fromString(userString); | 72 var uri = new Uri.fromString(userString); |
| 73 if ("dart-ext" != uri.scheme) { | 73 if ("dart-ext" != uri.scheme) { |
| 74 throw "Not a Dart extension uri: $uri"; | 74 throw "Not a Dart extension uri: $uri"; |
| 75 } | 75 } |
| 76 var schemelessUri = new Uri(path: uri.path); | 76 var schemelessUri = new Uri(path: uri.path); |
| 77 var baseUri = new Uri.fromString(base); | 77 var baseUri = new Uri.fromString(base); |
| 78 _logResolution("# Resolving: $userString from $base"); | 78 _logResolution("# Resolving: $userString from $base"); |
| 79 var resolved = baseUri.resolveUri(schemelessUri); | 79 var resolved = baseUri.resolveUri(schemelessUri); |
| 80 resolved = new Uri(scheme: 'dart-ext', path: resolved.path); | 80 resolved = new Uri(scheme: 'dart-ext', path: resolved.path); |
| 81 _logResolution("# Resolved to: $resolved"); | 81 _logResolution("# Resolved to: $resolved"); |
| 82 return resolved.toString(); | 82 return resolved.toString(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 String filePathFromUri(String userUri) { | 85 String _filePathFromUri(String userUri) { |
| 86 var uri = new Uri.fromString(userUri); | 86 var uri = new Uri.fromString(userUri); |
| 87 _logResolution("# Getting file path from: $uri"); | 87 _logResolution("# Getting file path from: $uri"); |
| 88 if ("file" != uri.scheme) { | 88 if ("file" != uri.scheme) { |
| 89 // Only handling file URIs in standalone binary. | 89 // Only handling file URIs in standalone binary. |
| 90 _logResolution("# Not a file URI."); | 90 _logResolution("# Not a file URI."); |
| 91 throw "Not a file uri: $uri"; | 91 throw "Not a file uri: $uri"; |
| 92 } | 92 } |
| 93 var path = uri.path; | 93 var path = uri.path; |
| 94 _logResolution("# Path: $path"); | 94 _logResolution("# Path: $path"); |
| 95 if (_is_windows) { | 95 if (_is_windows) { |
| 96 // Drop the leading / before the drive letter. | 96 // Drop the leading / before the drive letter. |
| 97 path = path.substring(1); | 97 path = path.substring(1); |
| 98 _logResolution("# path: $path"); | 98 _logResolution("# path: $path"); |
| 99 } | 99 } |
| 100 return path; | 100 return path; |
| 101 } | 101 } |
| OLD | NEW |