| 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:uri"); | 6 #import("dart:uri"); |
| 7 | 7 |
| 8 void print(arg) { | 8 void print(arg) { |
| 9 _Logger._printString(arg.toString()); | 9 _Logger._printString(arg.toString()); |
| 10 } | 10 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 // Code to deal with URI resolution for the standalone binary. | 26 // Code to deal with URI resolution for the standalone binary. |
| 27 // For Windows we need to massage the paths a bit according to | 27 // For Windows we need to massage the paths a bit according to |
| 28 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx | 28 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx |
| 29 var _is_windows; | 29 var _is_windows; |
| 30 | 30 |
| 31 // The URI that the entrypoint script was loaded from. Remembered so that | 31 // The URI that the entrypoint script was loaded from. Remembered so that |
| 32 // package imports can be resolved relative to it. | 32 // package imports can be resolved relative to it. |
| 33 Uri _entrypoint; | 33 Uri _entrypoint; |
| 34 | 34 |
| 35 // The directory to look in to resolve "package:" scheme URIs. |
| 36 String _packageRoot; |
| 37 |
| 35 void _logResolution(String msg) { | 38 void _logResolution(String msg) { |
| 36 final enabled = false; | 39 final enabled = false; |
| 37 if (enabled) { | 40 if (enabled) { |
| 38 _Logger._printString(msg); | 41 _Logger._printString(msg); |
| 39 } | 42 } |
| 40 } | 43 } |
| 41 | 44 |
| 45 String _setPackageRoot(String packageRoot) { |
| 46 // Note, on Windows we require use of forward slash, and do not |
| 47 // support backslash. |
| 48 if (!packageRoot.endsWith("/")) { |
| 49 packageRoot += "/"; |
| 50 } |
| 51 _packageRoot = packageRoot; |
| 52 } |
| 53 |
| 42 String _resolveScriptUri(String cwd, String scriptName, bool windows) { | 54 String _resolveScriptUri(String cwd, String scriptName, bool windows) { |
| 43 _is_windows = windows; | 55 _is_windows = windows; |
| 44 _logResolution("# Current working directory: $cwd"); | 56 _logResolution("# Current working directory: $cwd"); |
| 45 _logResolution("# ScriptName: $scriptName"); | 57 _logResolution("# ScriptName: $scriptName"); |
| 46 if (windows) { | 58 if (windows) { |
| 47 // Convert | 59 // Convert |
| 48 // C:\one\two\three | 60 // C:\one\two\three |
| 49 // to | 61 // to |
| 50 // /C:/one/two/three | 62 // /C:/one/two/three |
| 51 cwd = "/${cwd.replaceAll('\\', '/')}"; | 63 cwd = "/${cwd.replaceAll('\\', '/')}"; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 String _filePathFromPackageUri(Uri uri) { | 146 String _filePathFromPackageUri(Uri uri) { |
| 135 if (uri.domain != '') { | 147 if (uri.domain != '') { |
| 136 var path = (uri.path != '') ? '${uri.domain}${uri.path}' : uri.domain; | 148 var path = (uri.path != '') ? '${uri.domain}${uri.path}' : uri.domain; |
| 137 var right = 'package:$path'; | 149 var right = 'package:$path'; |
| 138 var wrong = 'package://$path'; | 150 var wrong = 'package://$path'; |
| 139 | 151 |
| 140 throw "URIs using the 'package:' scheme should look like " + | 152 throw "URIs using the 'package:' scheme should look like " + |
| 141 "'$right', not '$wrong'."; | 153 "'$right', not '$wrong'."; |
| 142 } | 154 } |
| 143 | 155 |
| 144 var path = _entrypoint.resolve('packages/${uri.path}').path; | 156 String path; |
| 157 if (_packageRoot !== null) { |
| 158 path = _packageRoot + uri.path; |
| 159 } else { |
| 160 path = _entrypoint.resolve('packages/${uri.path}').path; |
| 161 } |
| 162 |
| 145 _logResolution("# Package: $path"); | 163 _logResolution("# Package: $path"); |
| 146 return path; | 164 return path; |
| 147 } | 165 } |
| OLD | NEW |