Chromium Code Reviews| 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 'root_library'; happens here from C Code | 8 // import 'root_library'; happens here from C Code |
| 9 | 9 |
| 10 // The root library (aka the script) is imported into this library. The | 10 // The root library (aka the script) is imported into this library. The |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 var uri = userString.substring(_DART_EXT.length); | 214 var uri = userString.substring(_DART_EXT.length); |
| 215 return '$_DART_EXT${baseUri.resolve(uri)}'; | 215 return '$_DART_EXT${baseUri.resolve(uri)}'; |
| 216 } else { | 216 } else { |
| 217 return '${baseUri.resolve(userString)}'; | 217 return '${baseUri.resolve(userString)}'; |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 | 221 |
| 222 // Returns either a file path or a URI starting with http:, as a String. | 222 // Returns either a file path or a URI starting with http:, as a String. |
| 223 String _filePathFromUri(String userUri) { | 223 String _filePathFromUri(String userUri) { |
| 224 if (userUri.startsWith(_DART_EXT)) { | |
| 225 userUri = userUri.substring(_DART_EXT.length); | |
| 226 } | |
| 227 var uri = Uri.parse(userUri); | 224 var uri = Uri.parse(userUri); |
| 228 _logResolution('# Getting file path from: $uri'); | 225 _logResolution('# Getting file path from: $uri'); |
| 229 | 226 |
| 230 var path; | 227 var path; |
| 231 switch (uri.scheme) { | 228 switch (uri.scheme) { |
| 232 case '': | 229 case '': |
| 233 case 'file': | 230 case 'file': |
| 234 return uri.toFilePath(); | 231 return uri.toFilePath(); |
| 235 break; | 232 break; |
| 236 case 'package': | 233 case 'package': |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 255 | 252 |
| 256 throw "URIs using the 'package:' scheme should look like " | 253 throw "URIs using the 'package:' scheme should look like " |
| 257 "'$right', not '$wrong'."; | 254 "'$right', not '$wrong'."; |
| 258 } | 255 } |
| 259 | 256 |
| 260 var packageRoot = _packageRoot == null ? | 257 var packageRoot = _packageRoot == null ? |
| 261 _entryPointScript.resolve('packages/') : | 258 _entryPointScript.resolve('packages/') : |
| 262 _packageRoot; | 259 _packageRoot; |
| 263 return _filePathFromUri(packageRoot.resolve(uri.path).toString()); | 260 return _filePathFromUri(packageRoot.resolve(uri.path).toString()); |
| 264 } | 261 } |
| 262 | |
| 263 | |
| 264 // Returns the directory part, the filename part, and the name | |
| 265 // of a native extension URL as a list [directory, filename, name]. | |
| 266 // The directory part is either a file system path or an HTTP(S) URL. | |
| 267 // The filename part is the extension name, with the platform-dependent | |
| 268 // prefixes and extensions added. | |
| 269 String _extensionPathFromUri(String userUri) { | |
|
Ivan Posva
2014/03/04 20:03:56
Please remove the types in this file. They will on
| |
| 270 if (!userUri.startsWith(_DART_EXT)) { | |
| 271 throw 'Unexpected internal error: Extension URI $userUri missing dart-ext:'; | |
| 272 } | |
| 273 userUri = userUri.substring(_DART_EXT.length); | |
| 274 | |
| 275 if (userUri.contains('\\')) { | |
| 276 throw 'Unexpected internal error: Extension URI $userUri contains \\'; | |
| 277 } | |
| 278 | |
| 279 String filename; | |
| 280 String name; | |
| 281 String path; // Will end in '/'. | |
| 282 int index = userUri.lastIndexOf('/'); | |
| 283 if (index == -1) { | |
| 284 name = userUri; | |
| 285 path = './'; | |
| 286 } else if (index == userUri.length - 1) { | |
| 287 throw 'Extension name missing in $extensionUri'; | |
| 288 } else { | |
| 289 name = userUri.substring(index + 1); | |
| 290 path = userUri.substring(0, index + 1); | |
| 291 } | |
| 292 | |
| 293 path = _filePathFromUri(path); | |
| 294 | |
| 295 if (Platform.isLinux || Platform.isAndroid) { | |
| 296 filename = 'lib$name.so'; | |
|
Ivan Posva
2014/03/04 20:03:56
We will also have to have a plan to deal with diff
| |
| 297 } else if (Platform.isMacOS) { | |
| 298 filename = 'lib$name.dylib'; | |
| 299 } else if (Platform.isWindows) { | |
| 300 filename = '$name.dll'; | |
| 301 } else { | |
| 302 _logResolution( | |
| 303 'Native extensions not supported on ${Platform.operatingSystem}'); | |
| 304 throw 'Native extensions not supported on ${Platform.operatingSystem}'; | |
| 305 } | |
| 306 | |
| 307 return [path, filename, name]; | |
| 308 } | |
| OLD | NEW |