improve locating library bundles

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27212 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2008-12-05 15:50:51 +00:00
parent b313d1b576
commit dfa7db4455
2 changed files with 49 additions and 6 deletions

View file

@ -1,3 +1,8 @@
2008-12-05 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSBundle.m: ([bundleForLibrary:version:]) extract version
from end of library name if possible.
2008-12-04 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GSObjCRuntime.m: Fix minor thread-safety issue

View file

@ -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'
*/