Chromium Code Reviews| Index: runtime/bin/builtin.dart |
| diff --git a/runtime/bin/builtin.dart b/runtime/bin/builtin.dart |
| index 2a9bd3014d886ff412086023c815603b12b94c01..6fefc4f621e77923bae7b0e23887218556ee07fe 100644 |
| --- a/runtime/bin/builtin.dart |
| +++ b/runtime/bin/builtin.dart |
| @@ -262,3 +262,67 @@ String _filePathFromPackageUri(Uri uri) { |
| _packageRoot; |
| return _filePathFromUri(packageRoot.resolve(uri.path).toString()); |
| } |
| + |
| + |
| +// 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.
|
| +// of a native extension URL as a list [directory, filename, name]. |
| +// The directory part is either a file system path or an HTTP(S) URL. |
| +// The filename part is the extension name, with the platform-dependent |
| +// prefixes and extensions added. |
| +String _extensionPathFromUri(String userUri) { |
| + if (!userUri.startsWith(_DART_EXT)) { |
| + throw 'Unexpected internal error: Extension URI $userUri missing dart-ext:'; |
| + } |
| + userUri = userUri.substring(_DART_EXT.length); |
| + |
| + if (userUri.contains('\\')) { |
| + throw 'Unexpected internal error: Extension URI $userUri contains \\'; |
| + } |
| + |
| + String filename; |
| + String name; |
| + String path; // Will end in '/'. |
| + int index = userUri.lastIndexOf('/'); |
| + if (index == -1) { |
| + name = userUri; |
| + path = './'; |
| + } else if (index == userUri.length - 1) { |
| + throw 'Extension name missing in $extensionUri'; |
| + } else { |
| + name = userUri.substring(index + 1); |
| + path = userUri.substring(0, index + 1); |
| + } |
| + var uri = Uri.parse(path); |
| + _logResolution('# Getting native extension path from: $uri'); |
| + |
| + switch (uri.scheme) { |
| + case '': |
| + case 'file': |
| + path = uri.toFilePath(); |
| + break; |
| + case 'package': |
| + path = _filePathFromPackageUri(uri); |
| + break; |
| + case 'http': |
| + path = uri.toString(); |
| + default: |
| + // Only handling file, http, and package URIs |
| + // in standalone binary. |
| + _logResolution('# Unknown scheme (${uri.scheme}) in $uri.'); |
| + throw 'Not a known scheme: $uri'; |
| + } |
| + |
| + if (Platform.isLinux) { |
| + filename = 'lib$name.so'; |
| + } else if (Platform.isMacOS) { |
| + filename = 'lib$name.dylib'; |
| + } else if (Platform.isWindows) { |
| + filename = '$name.dll'; |
| + } else { |
| + _logResolution( |
| + 'Native extensions not supported on ${Platform.operatingSystem}'); |
| + throw 'Native extensions not supported on ${Platform.operatingSystem}'; |
| + } |
| + |
| + return [path, filename, name]; |
| +} |