[MacRuby-devel] [PATCH] Fix for #10, better support for framework load paths
Benjamin Stiglitz
ben at tanjero.com
Thu Feb 28 14:36:50 PST 2008
From: Benjamin Stiglitz <stig at apple.com>
---
objc.m | 38 +++++++++++++++++++++-----------------
1 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/objc.m b/objc.m
index 328bfa2..6af0dcc 100644
--- a/objc.m
+++ b/objc.m
@@ -1869,8 +1869,7 @@ rb_require_framework(VALUE recv, VALUE framework)
}
else {
/* framework name is given */
- char path[PATH_MAX];
- static char *home = NULL;
+ const char *path;
#define TRY_LOAD_PATH() \
do { \
@@ -1881,23 +1880,28 @@ rb_require_framework(VALUE recv, VALUE framework)
} \
while(0)
- if (home == NULL)
- home = getenv("HOME");
- if (home != NULL) {
- snprintf(path, sizeof path, "%s/%s.framework", home, cstr);
- TRY_LOAD_PATH();
+ NSString *frameworkName = [[[NSFileManager defaultManager] stringWithFileSystemRepresentation:cstr length:strlen(cstr)] stringByAppendingPathExtension:@"framework"];
+
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ NSArray *libraryDirs = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask, YES);
+ NSUInteger dirIndex, dirCount = [libraryDirs count];
+ for (dirIndex = 0; dirIndex < dirCount; ++dirIndex) {
+ NSString *libraryDir = [libraryDirs objectAtIndex:dirIndex];
+ path = [[[libraryDir stringByAppendingPathComponent:@"Frameworks"] stringByAppendingPathComponent:frameworkName] fileSystemRepresentation];
+ TRY_LOAD_PATH();
+ path = [[[libraryDir stringByAppendingPathComponent:@"PrivateFrameworks"] stringByAppendingPathComponent:frameworkName] fileSystemRepresentation];
+ TRY_LOAD_PATH();
}
- snprintf(path, sizeof path,
- "/System/Library/Frameworks/%s.framework", cstr);
- TRY_LOAD_PATH();
-
- snprintf(path, sizeof path, "/Library/Frameworks/%s.framework", cstr);
- TRY_LOAD_PATH();
-
- snprintf(path, sizeof path,
- "/System/Library/PrivateFrameworks/%s.framework", cstr);
- TRY_LOAD_PATH();
+ NSArray *developerDirs = NSSearchPathForDirectoriesInDomains(NSDeveloperDirectory, NSAllDomainsMask, YES);
+ dirCount = [developerDirs count];
+ for (dirIndex = 0; dirIndex < dirCount; ++dirIndex) {
+ NSString *libraryDir = [[developerDirs objectAtIndex:dirIndex] stringByAppendingPathComponent:@"Library"];
+ path = [[[libraryDir stringByAppendingPathComponent:@"Frameworks"] stringByAppendingPathComponent:frameworkName] fileSystemRepresentation];
+ TRY_LOAD_PATH();
+ path = [[[libraryDir stringByAppendingPathComponent:@"PrivateFrameworks"] stringByAppendingPathComponent:frameworkName] fileSystemRepresentation];
+ TRY_LOAD_PATH();
+ }
#undef TRY_LOAD_PATH
--
1.5.4.2
More information about the MacRuby-devel
mailing list