From f8a62eda202350be3895607d774e3a1dfe120054 Mon Sep 17 00:00:00 2001 From: rfm Date: Fri, 5 Dec 2008 15:50:51 +0000 Subject: [PATCH] improve locating library bundles git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27212 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/NSBundle.m | 50 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 77d863636..d649f1c4b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-12-05 Richard Frith-Macdonald + + * Source/NSBundle.m: ([bundleForLibrary:version:]) extract version + from end of library name if possible. + 2008-12-04 Richard Frith-Macdonald * Source/Additions/GSObjCRuntime.m: Fix minor thread-safety issue diff --git a/Source/NSBundle.m b/Source/NSBundle.m index e5e7d4f6f..ece4a214a 100644 --- a/Source/NSBundle.m +++ b/Source/NSBundle.m @@ -1179,10 +1179,6 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory) * Get the library bundle ... if there wasn't one then we * will assume the class was in the program executable and * return the mainBundle instead. - * - * FIXME: This will not work well with versioned library - * resources. It used to work fine (maybe) with unversioned - * library resources. */ bundle = [NSBundle bundleForLibrary: lib]; if (bundle == nil) @@ -2293,16 +2289,58 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory) NSEnumerator *enumerator; NSString *path; NSFileManager *fm = [NSFileManager defaultManager]; + NSRange r; /* * Eliminate any base path or extensions. */ libraryName = [libraryName lastPathComponent]; - do + +#if defined(__MINGW32__) + /* A dll is usually of the form 'xxx-maj_min.dll' + * so we can extract the version info and use it. + */ + if ([[libraryName pathExtension] isEqual: @"dll"]) + { + libraryName = [libraryName stringByDeletingPathExtension]; + r = [libraryName rangeOfString: @"-" options: NSBackwardsSearch]; + if (r.length > 0) + { + NSString *ver; + + ver = [[libraryName substringFromIndex: NSMaxRange(r)] + stringByReplacingString: @"_" withString: @"."]; + libraryName = [libraryName substringToIndex: r.location]; + if (interfaceVersion == nil) + { + ver = interfaceVersion; + } + } + } +#else + /* A .so is usually of the form 'libxxx.so.maj.min.sub' + * so we can extract the version info and use it. + */ + r = [libraryName rangeOfString: @".so."]; + if (r.length > 0) + { + NSString *s = [libraryName substringFromIndex: NSMaxRange(r)]; + NSArray *a = [s componentsSeparatedByString: @"."]; + + libraryName = [libraryName substringToIndex: r.location]; + if (interfaceVersion == nil && [a count] >= 2) + { + interfaceVersion = [NSString stringWithFormat: @"%@.%@", + [a objectAtIndex: 0], [a objectAtIndex: 1]]; + } + } +#endif + + while ([[libraryName pathExtension] length] > 0); { libraryName = [libraryName stringByDeletingPathExtension]; } - while ([[libraryName pathExtension] length] > 0); + /* * Discard leading 'lib' */