mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
* Source/NSBundle.m (_find_framework): New function.
[NSBundle +_addFrameworkFromClass:]): Use it. Based on patch from Sheldon Gill. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21024 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8f0bd54874
commit
85adc3f11c
3 changed files with 39 additions and 54 deletions
|
@ -1,3 +1,9 @@
|
|||
2005-03-31 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Source/NSBundle.m (_find_framework): New function.
|
||||
([NSBundle +_addFrameworkFromClass:]): Use it. Based on patch
|
||||
from Sheldon Gill.
|
||||
|
||||
2005-03-31 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSString.m: (isAbsolutePath) always treat a path beginning
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include "Foundation/NSFileManager.h"
|
||||
#include "Foundation/NSPathUtilities.h"
|
||||
#include "Foundation/NSValue.h"
|
||||
#include "GNUstepBase/GSFunctions.h"
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
@ -222,6 +223,18 @@ _bundle_name_first_match(NSString* directory, NSString* name)
|
|||
return nil;
|
||||
}
|
||||
|
||||
/* Try to locate name framework in standard places
|
||||
which are like /Library/Frameworks/(name).framework */
|
||||
static inline NSString *
|
||||
_find_framework(NSString *name)
|
||||
{
|
||||
NSArray *paths;
|
||||
|
||||
paths = NSSearchPathForDirectoriesInDomains(GSFrameworksDirectory,
|
||||
NSAllDomainsMask,YES);
|
||||
return GSFindNamedFile(paths, name, @"framework");
|
||||
}
|
||||
|
||||
@interface NSBundle (Private)
|
||||
+ (void) _addFrameworkFromClass: (Class)frameworkClass;
|
||||
- (NSArray *) _bundleClasses;
|
||||
|
@ -255,15 +268,10 @@ _bundle_name_first_match(NSString* directory, NSString* name)
|
|||
loaded. If that doesn't work, because the dynamic linker can't
|
||||
provide this information on this platform (or maybe because the
|
||||
framework was statically linked into the application), we have a
|
||||
fallback trick :-) we can ask to the NSFramework_xxx class the path
|
||||
to were the framework bundle was supposed to be installed (this is
|
||||
recorded the first time when the NSFramework_xxx class is generated
|
||||
at compile time; it's not completely reliable - for example the
|
||||
programmer might change it later on by specifying a different
|
||||
GNUSTEP_INSTALLATION_DIR when installing ... (TODO - modify
|
||||
gnustep-make so that it issues a warning if you do that, suggesting
|
||||
you to recompile before installing!)), and search for the framework
|
||||
there.
|
||||
fallback trick :-) We look for the framework in the standard
|
||||
locations and in the main bundle. This might fail if the framework
|
||||
is not in a standard location or there is more than one installed
|
||||
framework of the same name (and different versions?).
|
||||
|
||||
So at startup, we scan all classes which were compiled into the
|
||||
application. For each NSFramework_ class, we call the following
|
||||
|
@ -374,7 +382,7 @@ _bundle_name_first_match(NSString* directory, NSString* name)
|
|||
bundle = [[self alloc] initWithPath: bundlePath];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Failed - buu - try the fallback trick. */
|
||||
if (bundle == nil)
|
||||
{
|
||||
|
@ -389,58 +397,28 @@ _bundle_name_first_match(NSString* directory, NSString* name)
|
|||
* objc_get_symbol_path() is risky (some platforms don't
|
||||
* have it at all!), so this hack might be used a lot! It
|
||||
* must be quite robust. We try to look for the framework
|
||||
* in the standard GNUstep installation dirs. This should
|
||||
* be reasonably safe if the user is not being too clever
|
||||
* ... :-)
|
||||
* in the standard GNUstep installation dirs and in the main
|
||||
* bundle. This should be reasonably safe if the user is
|
||||
* not being too clever ... :-)
|
||||
*/
|
||||
NSString *varEnv, *path;
|
||||
|
||||
/* varEnv is something like GNUSTEP_LOCAL_ROOT. */
|
||||
varEnv = [frameworkClass frameworkEnv];
|
||||
if (varEnv != nil && [varEnv length] > 0)
|
||||
bundlePath = _find_framework(name);
|
||||
if (bundlePath == nil)
|
||||
{
|
||||
/* FIXME - I don't think we should be reading it from
|
||||
the environment directly! */
|
||||
bundlePath = [[[NSProcessInfo processInfo] environment]
|
||||
objectForKey: varEnv];
|
||||
bundlePath = [[NSBundle mainBundle] pathForResource: name
|
||||
ofType: @"framework"
|
||||
inDirectory: @"Frameworks"];
|
||||
}
|
||||
|
||||
/* FIXME - path is something like ?. */
|
||||
path = [frameworkClass frameworkPath];
|
||||
if (path && [path length])
|
||||
{
|
||||
if (bundlePath)
|
||||
{
|
||||
bundlePath = [bundlePath stringByAppendingPathComponent:
|
||||
path];
|
||||
}
|
||||
else
|
||||
{
|
||||
bundlePath = path;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bundlePath = [bundlePath stringByAppendingPathComponent:
|
||||
@"Library/Frameworks"];
|
||||
}
|
||||
|
||||
bundlePath = [bundlePath stringByAppendingPathComponent:
|
||||
[NSString stringWithFormat:
|
||||
@"%@.framework",
|
||||
name]];
|
||||
|
||||
/* Try creating the bundle. */
|
||||
bundle = [[self alloc] initWithPath: bundlePath];
|
||||
if (bundlePath != nil)
|
||||
{
|
||||
bundle = [[self alloc] initWithPath: bundlePath];
|
||||
}
|
||||
}
|
||||
|
||||
if (bundle == nil)
|
||||
{
|
||||
/* TODO: We couldn't locate the framework in the expected
|
||||
location. NICOLA: We should be trying to locate it in
|
||||
some other obvious location, iterating over
|
||||
user/network/local/system dirs ... TODO. */
|
||||
NSLog (@"Problem locating framework %@", name);
|
||||
NSLog (@"Could not find framework %@ in any standard location", name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -264,7 +264,7 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
|
|||
* user ID. Needed by setuid processes which change the user they
|
||||
* are running as.<br />
|
||||
* In GNUstep you should call GSSetUserName() when changing your
|
||||
* effective user ID, and that class will call this function for you.
|
||||
* effective user ID, and that function will call this function for you.
|
||||
*/
|
||||
+ (void) resetStandardUserDefaults
|
||||
{
|
||||
|
@ -686,6 +686,7 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
|
|||
return [self initWithUser: NSUserName()];
|
||||
}
|
||||
|
||||
/* Returns the path to the user's ".GNUstepDefaults file" */
|
||||
static NSString *pathForUser(NSString *user)
|
||||
{
|
||||
NSString *database = @".GNUstepDefaults";
|
||||
|
|
Loading…
Reference in a new issue