Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(531)

Unified Diff: runtime/bin/builtin.dart

Issue 186473003: Refactor native extension shared library lookup. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Move a platform-independent block to extensions.cc Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/bin/dartutils.h » ('j') | runtime/bin/extensions.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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];
+}
« no previous file with comments | « no previous file | runtime/bin/dartutils.h » ('j') | runtime/bin/extensions.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698