Great. Thanks for extracting that macro; it was pretty ugly before.
I merged a slightly modified version of this patch into trunk.
Also, I changed Kernel#framework(path) to Kernel#framework(path, search_network=false), to avoid network lookups by default, which can significantly slow down lookups on network-less machines.
Laurent
On Feb 28, 2008, at 2:36 PM, Benjamin Stiglitz wrote:
From: Benjamin Stiglitz <stig@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
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel