Stop ns builds setting the EMACSPATH environment variable
Ref bugs 4309, 6401, etc * src/nsterm.m (ns_exec_path): New function, split from ns_init_paths. (ns_init_paths): Do not set EMACSPATH. * src/nsterm.h (ns_exec_path): Add it. * src/callproc.c (init_callproc_1, init_callproc) [HAVE_NS]: Use ns_exec_path.
This commit is contained in:
parent
7c4e8ec014
commit
cbb319513e
4 changed files with 86 additions and 47 deletions
|
@ -1,5 +1,12 @@
|
|||
2012-07-09 Glenn Morris <rgm@gnu.org>
|
||||
|
||||
Stop ns builds setting the EMACSPATH environment variable.
|
||||
* nsterm.m (ns_exec_path): New function, split from ns_init_paths.
|
||||
(ns_init_paths): Do not set EMACSPATH.
|
||||
* nsterm.h (ns_exec_path): Add it.
|
||||
* callproc.c (init_callproc_1, init_callproc) [HAVE_NS]:
|
||||
Use ns_exec_path.
|
||||
|
||||
* nsterm.m, nsterm.h (ns_etc_directory): Fix type, empty return.
|
||||
|
||||
2012-07-09 Paul Eggert <eggert@cs.ucla.edu>
|
||||
|
|
|
@ -1519,6 +1519,7 @@ init_callproc_1 (void)
|
|||
char *doc_dir = egetenv ("EMACSDOC");
|
||||
#ifdef HAVE_NS
|
||||
const char *etc_dir = ns_etc_directory ();
|
||||
const char *path_exec = ns_exec_path ();
|
||||
#endif
|
||||
|
||||
Vdata_directory
|
||||
|
@ -1540,8 +1541,13 @@ init_callproc_1 (void)
|
|||
|
||||
/* Check the EMACSPATH environment variable, defaulting to the
|
||||
PATH_EXEC path from epaths.h. */
|
||||
Vexec_path = decode_env_path ("EMACSPATH", PATH_EXEC);
|
||||
Vexec_path = decode_env_path ("EMACSPATH",
|
||||
#ifdef HAVE_NS
|
||||
path_exec ? path_exec :
|
||||
#endif
|
||||
PATH_EXEC);
|
||||
Vexec_directory = Ffile_name_as_directory (Fcar (Vexec_path));
|
||||
/* FIXME? For ns, path_exec should go at the front? */
|
||||
Vexec_path = nconc2 (decode_env_path ("PATH", ""), Vexec_path);
|
||||
}
|
||||
|
||||
|
@ -1576,7 +1582,14 @@ init_callproc (void)
|
|||
/* MSDOS uses wrapped binaries, so don't do this. */
|
||||
if (NILP (Fmember (tem, Vexec_path)))
|
||||
{
|
||||
Vexec_path = decode_env_path ("EMACSPATH", PATH_EXEC);
|
||||
#ifdef HAVE_NS
|
||||
const char *path_exec = ns_exec_path ();
|
||||
#endif
|
||||
Vexec_path = decode_env_path ("EMACSPATH",
|
||||
#ifdef HAVE_NS
|
||||
path_exec ? path_exec :
|
||||
#endif
|
||||
PATH_EXEC);
|
||||
Vexec_path = Fcons (tem, Vexec_path);
|
||||
Vexec_path = nconc2 (decode_env_path ("PATH", ""), Vexec_path);
|
||||
}
|
||||
|
|
|
@ -799,6 +799,7 @@ extern void x_free_frame_resources (struct frame *);
|
|||
extern void ns_run_ascript (void);
|
||||
|
||||
extern const char *ns_etc_directory (void);
|
||||
extern const char *ns_exec_path (void);
|
||||
extern void ns_init_paths (void);
|
||||
extern void syms_of_nsterm (void);
|
||||
extern void syms_of_nsfns (void);
|
||||
|
|
108
src/nsterm.m
108
src/nsterm.m
|
@ -288,10 +288,9 @@ Updated by Christian Limpach (chris@nice.ch)
|
|||
|
||||
const char *
|
||||
ns_etc_directory (void)
|
||||
{
|
||||
/* If running as a self-contained app bundle, return as a string the
|
||||
filename of the etc directory, if present; else nil. */
|
||||
|
||||
{
|
||||
NSBundle *bundle = [NSBundle mainBundle];
|
||||
NSString *resourceDir = [bundle resourcePath];
|
||||
NSString *resourcePath;
|
||||
|
@ -306,6 +305,66 @@ Updated by Christian Limpach (chris@nice.ch)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
const char *
|
||||
ns_exec_path (void)
|
||||
/* If running as a self-contained app bundle, return as a path string
|
||||
the filenames of the libexec and bin directories, ie libexec:bin.
|
||||
Otherwise, return nil.
|
||||
Normally, Emacs does not add its own bin/ directory to the PATH.
|
||||
However, a self-contained NS build has a different layout, with
|
||||
bin/ and libexec/ subdirectories in the directory that contains
|
||||
Emacs.app itself.
|
||||
We put libexec first, because init_callproc_1 uses the first
|
||||
element to initialize exec-directory. An alternative would be
|
||||
for init_callproc to check for invocation-directory/libexec.
|
||||
*/
|
||||
{
|
||||
NSBundle *bundle = [NSBundle mainBundle];
|
||||
NSString *resourceDir = [bundle resourcePath];
|
||||
NSString *binDir = [bundle bundlePath];
|
||||
NSString *resourcePath, *resourcePaths;
|
||||
NSRange range;
|
||||
BOOL onWindows = NO; /* FIXME determine this somehow */
|
||||
NSString *pathSeparator = onWindows ? @";" : @":";
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSArray *paths;
|
||||
NSEnumerator *pathEnum;
|
||||
BOOL isDir;
|
||||
|
||||
range = [resourceDir rangeOfString: @"Contents"];
|
||||
if (range.location != NSNotFound)
|
||||
{
|
||||
#ifdef NS_IMPL_COCOA
|
||||
binDir = [binDir stringByAppendingPathComponent: @"MacOS"];
|
||||
#else
|
||||
binDir = [binDir stringByAppendingPathComponent: @"Contents"];
|
||||
#endif
|
||||
}
|
||||
|
||||
paths = [binDir stringsByAppendingPaths:
|
||||
[NSArray arrayWithObjects: @"libexec", @"bin", nil]];
|
||||
pathEnum = [paths objectEnumerator];
|
||||
resourcePaths = @"";
|
||||
|
||||
while (resourcePath = [pathEnum nextObject])
|
||||
{
|
||||
if ([fileManager fileExistsAtPath: resourcePath isDirectory: &isDir])
|
||||
if (isDir)
|
||||
{
|
||||
if ([resourcePaths length] > 0)
|
||||
resourcePaths
|
||||
= [resourcePaths stringByAppendingString: pathSeparator];
|
||||
resourcePaths
|
||||
= [resourcePaths stringByAppendingString: resourcePath];
|
||||
}
|
||||
}
|
||||
if ([resourcePaths length] > 0) return [resourcePaths UTF8String];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ns_init_paths (void)
|
||||
/* --------------------------------------------------------------------------
|
||||
|
@ -314,25 +373,14 @@ Updated by Christian Limpach (chris@nice.ch)
|
|||
-------------------------------------------------------------------------- */
|
||||
{
|
||||
NSBundle *bundle = [NSBundle mainBundle];
|
||||
NSString *binDir = [bundle bundlePath], *resourceDir = [bundle resourcePath];
|
||||
NSString *resourceDir = [bundle resourcePath];
|
||||
NSString *resourcePath, *resourcePaths;
|
||||
NSRange range;
|
||||
BOOL onWindows = NO; /* how do I determine this? */
|
||||
BOOL onWindows = NO; /* FIXME determine this somehow */
|
||||
NSString *pathSeparator = onWindows ? @";" : @":";
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
BOOL isDir;
|
||||
/*NSLog (@"ns_init_paths: '%@'\n%@\n", [[NSBundle mainBundle] bundlePath], [[NSBundle mainBundle] resourcePath]); */
|
||||
|
||||
/* get bindir from base */
|
||||
range = [resourceDir rangeOfString: @"Contents"];
|
||||
if (range.location != NSNotFound)
|
||||
{
|
||||
binDir = [binDir stringByAppendingPathComponent: @"Contents"];
|
||||
#ifdef NS_IMPL_COCOA
|
||||
binDir = [binDir stringByAppendingPathComponent: @"MacOS"];
|
||||
#endif
|
||||
}
|
||||
|
||||
/* the following based on Andrew Choi's init_mac_osx_environment () */
|
||||
if (!getenv ("EMACSLOADPATH"))
|
||||
{
|
||||
|
@ -359,36 +407,6 @@ Updated by Christian Limpach (chris@nice.ch)
|
|||
setenv ("EMACSLOADPATH", [resourcePaths UTF8String], 1);
|
||||
/*NSLog (@"loadPath: '%@'\n", resourcePaths); */
|
||||
}
|
||||
|
||||
/* Normally, Emacs does not add its own bin/ directory to the PATH.
|
||||
However, a self-contained NS build has a different layout, with
|
||||
bin/ and libexec/ subdirectories in the directory that contains
|
||||
Emacs.app itself.
|
||||
We put libexec first, because init_callproc_1 uses the first
|
||||
element to initialize exec-directory. An alternative would be
|
||||
for init_callproc to check for invocation-directory/libexec. */
|
||||
if (!getenv ("EMACSPATH"))
|
||||
{
|
||||
NSArray *paths = [binDir stringsByAppendingPaths:
|
||||
[NSArray arrayWithObjects: @"libexec",
|
||||
@"bin", nil]];
|
||||
NSEnumerator *pathEnum = [paths objectEnumerator];
|
||||
resourcePaths = @"";
|
||||
while (resourcePath = [pathEnum nextObject])
|
||||
{
|
||||
if ([fileManager fileExistsAtPath: resourcePath isDirectory: &isDir])
|
||||
if (isDir)
|
||||
{
|
||||
if ([resourcePaths length] > 0)
|
||||
resourcePaths
|
||||
= [resourcePaths stringByAppendingString: pathSeparator];
|
||||
resourcePaths
|
||||
= [resourcePaths stringByAppendingString: resourcePath];
|
||||
}
|
||||
}
|
||||
if ([resourcePaths length] > 0)
|
||||
setenv ("EMACSPATH", [resourcePaths UTF8String], 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Add table
Reference in a new issue