mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-18 03:30:56 +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
e698f247ee
commit
8931774d38
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>
|
2005-03-31 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSString.m: (isAbsolutePath) always treat a path beginning
|
* Source/NSString.m: (isAbsolutePath) always treat a path beginning
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#include "Foundation/NSFileManager.h"
|
#include "Foundation/NSFileManager.h"
|
||||||
#include "Foundation/NSPathUtilities.h"
|
#include "Foundation/NSPathUtilities.h"
|
||||||
#include "Foundation/NSValue.h"
|
#include "Foundation/NSValue.h"
|
||||||
|
#include "GNUstepBase/GSFunctions.h"
|
||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -222,6 +223,18 @@ _bundle_name_first_match(NSString* directory, NSString* name)
|
||||||
return nil;
|
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)
|
@interface NSBundle (Private)
|
||||||
+ (void) _addFrameworkFromClass: (Class)frameworkClass;
|
+ (void) _addFrameworkFromClass: (Class)frameworkClass;
|
||||||
- (NSArray *) _bundleClasses;
|
- (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
|
loaded. If that doesn't work, because the dynamic linker can't
|
||||||
provide this information on this platform (or maybe because the
|
provide this information on this platform (or maybe because the
|
||||||
framework was statically linked into the application), we have a
|
framework was statically linked into the application), we have a
|
||||||
fallback trick :-) we can ask to the NSFramework_xxx class the path
|
fallback trick :-) We look for the framework in the standard
|
||||||
to were the framework bundle was supposed to be installed (this is
|
locations and in the main bundle. This might fail if the framework
|
||||||
recorded the first time when the NSFramework_xxx class is generated
|
is not in a standard location or there is more than one installed
|
||||||
at compile time; it's not completely reliable - for example the
|
framework of the same name (and different versions?).
|
||||||
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.
|
|
||||||
|
|
||||||
So at startup, we scan all classes which were compiled into the
|
So at startup, we scan all classes which were compiled into the
|
||||||
application. For each NSFramework_ class, we call the following
|
application. For each NSFramework_ class, we call the following
|
||||||
|
@ -389,58 +397,28 @@ _bundle_name_first_match(NSString* directory, NSString* name)
|
||||||
* objc_get_symbol_path() is risky (some platforms don't
|
* objc_get_symbol_path() is risky (some platforms don't
|
||||||
* have it at all!), so this hack might be used a lot! It
|
* have it at all!), so this hack might be used a lot! It
|
||||||
* must be quite robust. We try to look for the framework
|
* must be quite robust. We try to look for the framework
|
||||||
* in the standard GNUstep installation dirs. This should
|
* in the standard GNUstep installation dirs and in the main
|
||||||
* be reasonably safe if the user is not being too clever
|
* bundle. This should be reasonably safe if the user is
|
||||||
* ... :-)
|
* not being too clever ... :-)
|
||||||
*/
|
*/
|
||||||
NSString *varEnv, *path;
|
bundlePath = _find_framework(name);
|
||||||
|
if (bundlePath == nil)
|
||||||
/* varEnv is something like GNUSTEP_LOCAL_ROOT. */
|
|
||||||
varEnv = [frameworkClass frameworkEnv];
|
|
||||||
if (varEnv != nil && [varEnv length] > 0)
|
|
||||||
{
|
{
|
||||||
/* FIXME - I don't think we should be reading it from
|
bundlePath = [[NSBundle mainBundle] pathForResource: name
|
||||||
the environment directly! */
|
ofType: @"framework"
|
||||||
bundlePath = [[[NSProcessInfo processInfo] environment]
|
inDirectory: @"Frameworks"];
|
||||||
objectForKey: varEnv];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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. */
|
/* Try creating the bundle. */
|
||||||
|
if (bundlePath != nil)
|
||||||
|
{
|
||||||
bundle = [[self alloc] initWithPath: bundlePath];
|
bundle = [[self alloc] initWithPath: bundlePath];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bundle == nil)
|
if (bundle == nil)
|
||||||
{
|
{
|
||||||
/* TODO: We couldn't locate the framework in the expected
|
NSLog (@"Could not find framework %@ in any standard location", name);
|
||||||
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);
|
|
||||||
return;
|
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
|
* user ID. Needed by setuid processes which change the user they
|
||||||
* are running as.<br />
|
* are running as.<br />
|
||||||
* In GNUstep you should call GSSetUserName() when changing your
|
* 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
|
+ (void) resetStandardUserDefaults
|
||||||
{
|
{
|
||||||
|
@ -686,6 +686,7 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
|
||||||
return [self initWithUser: NSUserName()];
|
return [self initWithUser: NSUserName()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns the path to the user's ".GNUstepDefaults file" */
|
||||||
static NSString *pathForUser(NSString *user)
|
static NSString *pathForUser(NSString *user)
|
||||||
{
|
{
|
||||||
NSString *database = @".GNUstepDefaults";
|
NSString *database = @".GNUstepDefaults";
|
||||||
|
|
Loading…
Reference in a new issue