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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 | 255 |
| 256 throw "URIs using the 'package:' scheme should look like " | 256 throw "URIs using the 'package:' scheme should look like " |
| 257 "'$right', not '$wrong'."; | 257 "'$right', not '$wrong'."; |
| 258 } | 258 } |
| 259 | 259 |
| 260 var packageRoot = _packageRoot == null ? | 260 var packageRoot = _packageRoot == null ? |
| 261 _entryPointScript.resolve('packages/') : | 261 _entryPointScript.resolve('packages/') : |
| 262 _packageRoot; | 262 _packageRoot; |
| 263 return _filePathFromUri(packageRoot.resolve(uri.path).toString()); | 263 return _filePathFromUri(packageRoot.resolve(uri.path).toString()); |
| 264 } | 264 } |
| 265 | |
| 266 | |
| 267 // Returns the directory part, the filename part, and the name | |
|
Søren Gjesse
2014/03/04 13:09:02
How about calling "directory part" for location?
Bill Hesse
2014/03/04 14:36:31
Done.
| |
| 268 // of a native extension URL as a list [directory, filename, name]. | |
| 269 // The directory part is either a file system path or an HTTP(S) URL. | |
| 270 // The filename part is the extension name, with the platform-dependent | |
| 271 // prefixes and extensions added. | |
| 272 String _extensionPathFromUri(String userUri) { | |
| 273 if (!userUri.startsWith(_DART_EXT)) { | |
| 274 throw 'Unexpected internal error: Extension URI $userUri missing dart-ext:'; | |
| 275 } | |
| 276 userUri = userUri.substring(_DART_EXT.length); | |
| 277 | |
| 278 if (userUri.contains('\\')) { | |
| 279 throw 'Unexpected internal error: Extension URI $userUri contains \\'; | |
| 280 } | |
| 281 | |
| 282 String filename; | |
| 283 String name; | |
| 284 String path; // Will end in '/'. | |
| 285 int index = userUri.lastIndexOf('/'); | |
| 286 if (index == -1) { | |
| 287 name = userUri; | |
| 288 path = './'; | |
| 289 } else if (index == userUri.length - 1) { | |
| 290 throw 'Extension name missing in $extensionUri'; | |
| 291 } else { | |
| 292 name = userUri.substring(index + 1); | |
| 293 path = userUri.substring(0, index + 1); | |
| 294 } | |
| 295 var uri = Uri.parse(path); | |
| 296 _logResolution('# Getting native extension path from: $uri'); | |
| 297 | |
| 298 switch (uri.scheme) { | |
| 299 case '': | |
| 300 case 'file': | |
| 301 path = uri.toFilePath(); | |
| 302 break; | |
| 303 case 'package': | |
| 304 path = _filePathFromPackageUri(uri); | |
| 305 break; | |
| 306 case 'http': | |
| 307 path = uri.toString(); | |
| 308 default: | |
| 309 // Only handling file, http, and package URIs | |
| 310 // in standalone binary. | |
| 311 _logResolution('# Unknown scheme (${uri.scheme}) in $uri.'); | |
| 312 throw 'Not a known scheme: $uri'; | |
| 313 } | |
| 314 | |
| 315 if (Platform.isLinux) { | |
| 316 filename = 'lib$name.so'; | |
| 317 } else if (Platform.isMacOS) { | |
| 318 filename = 'lib$name.dylib'; | |
| 319 } else if (Platform.isWindows) { | |
| 320 filename = '$name.dll'; | |
| 321 } else { | |
| 322 _logResolution( | |
| 323 'Native extensions not supported on ${Platform.operatingSystem}'); | |
| 324 throw 'Native extensions not supported on ${Platform.operatingSystem}'; | |
| 325 } | |
| 326 | |
| 327 return [path, filename, name]; | |
| 328 } | |
| OLD | NEW |