diff options
| author | Glenn Morris | 2012-07-09 17:28:39 -0400 |
|---|---|---|
| committer | Glenn Morris | 2012-07-09 17:28:39 -0400 |
| commit | cbb319513e0da14e7de2e9be121d449b6bcc8d88 (patch) | |
| tree | 755535990ffe26b56cf2057ad7d2016e9048e9e3 /src | |
| parent | 7c4e8ec014e532c3864a7e2494d71a663d96b295 (diff) | |
| download | emacs-cbb319513e0da14e7de2e9be121d449b6bcc8d88.tar.gz emacs-cbb319513e0da14e7de2e9be121d449b6bcc8d88.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/callproc.c | 17 | ||||
| -rw-r--r-- | src/nsterm.h | 1 | ||||
| -rw-r--r-- | src/nsterm.m | 104 |
4 files changed, 84 insertions, 45 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index c4911968e0d..5846fbab92a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,12 @@ | |||
| 1 | 2012-07-09 Glenn Morris <rgm@gnu.org> | 1 | 2012-07-09 Glenn Morris <rgm@gnu.org> |
| 2 | 2 | ||
| 3 | Stop ns builds setting the EMACSPATH environment variable. | ||
| 4 | * nsterm.m (ns_exec_path): New function, split from ns_init_paths. | ||
| 5 | (ns_init_paths): Do not set EMACSPATH. | ||
| 6 | * nsterm.h (ns_exec_path): Add it. | ||
| 7 | * callproc.c (init_callproc_1, init_callproc) [HAVE_NS]: | ||
| 8 | Use ns_exec_path. | ||
| 9 | |||
| 3 | * nsterm.m, nsterm.h (ns_etc_directory): Fix type, empty return. | 10 | * nsterm.m, nsterm.h (ns_etc_directory): Fix type, empty return. |
| 4 | 11 | ||
| 5 | 2012-07-09 Paul Eggert <eggert@cs.ucla.edu> | 12 | 2012-07-09 Paul Eggert <eggert@cs.ucla.edu> |
diff --git a/src/callproc.c b/src/callproc.c index 52825bc9dc2..facca887772 100644 --- a/src/callproc.c +++ b/src/callproc.c | |||
| @@ -1519,6 +1519,7 @@ init_callproc_1 (void) | |||
| 1519 | char *doc_dir = egetenv ("EMACSDOC"); | 1519 | char *doc_dir = egetenv ("EMACSDOC"); |
| 1520 | #ifdef HAVE_NS | 1520 | #ifdef HAVE_NS |
| 1521 | const char *etc_dir = ns_etc_directory (); | 1521 | const char *etc_dir = ns_etc_directory (); |
| 1522 | const char *path_exec = ns_exec_path (); | ||
| 1522 | #endif | 1523 | #endif |
| 1523 | 1524 | ||
| 1524 | Vdata_directory | 1525 | Vdata_directory |
| @@ -1540,8 +1541,13 @@ init_callproc_1 (void) | |||
| 1540 | 1541 | ||
| 1541 | /* Check the EMACSPATH environment variable, defaulting to the | 1542 | /* Check the EMACSPATH environment variable, defaulting to the |
| 1542 | PATH_EXEC path from epaths.h. */ | 1543 | PATH_EXEC path from epaths.h. */ |
| 1543 | Vexec_path = decode_env_path ("EMACSPATH", PATH_EXEC); | 1544 | Vexec_path = decode_env_path ("EMACSPATH", |
| 1545 | #ifdef HAVE_NS | ||
| 1546 | path_exec ? path_exec : | ||
| 1547 | #endif | ||
| 1548 | PATH_EXEC); | ||
| 1544 | Vexec_directory = Ffile_name_as_directory (Fcar (Vexec_path)); | 1549 | Vexec_directory = Ffile_name_as_directory (Fcar (Vexec_path)); |
| 1550 | /* FIXME? For ns, path_exec should go at the front? */ | ||
| 1545 | Vexec_path = nconc2 (decode_env_path ("PATH", ""), Vexec_path); | 1551 | Vexec_path = nconc2 (decode_env_path ("PATH", ""), Vexec_path); |
| 1546 | } | 1552 | } |
| 1547 | 1553 | ||
| @@ -1576,7 +1582,14 @@ init_callproc (void) | |||
| 1576 | /* MSDOS uses wrapped binaries, so don't do this. */ | 1582 | /* MSDOS uses wrapped binaries, so don't do this. */ |
| 1577 | if (NILP (Fmember (tem, Vexec_path))) | 1583 | if (NILP (Fmember (tem, Vexec_path))) |
| 1578 | { | 1584 | { |
| 1579 | Vexec_path = decode_env_path ("EMACSPATH", PATH_EXEC); | 1585 | #ifdef HAVE_NS |
| 1586 | const char *path_exec = ns_exec_path (); | ||
| 1587 | #endif | ||
| 1588 | Vexec_path = decode_env_path ("EMACSPATH", | ||
| 1589 | #ifdef HAVE_NS | ||
| 1590 | path_exec ? path_exec : | ||
| 1591 | #endif | ||
| 1592 | PATH_EXEC); | ||
| 1580 | Vexec_path = Fcons (tem, Vexec_path); | 1593 | Vexec_path = Fcons (tem, Vexec_path); |
| 1581 | Vexec_path = nconc2 (decode_env_path ("PATH", ""), Vexec_path); | 1594 | Vexec_path = nconc2 (decode_env_path ("PATH", ""), Vexec_path); |
| 1582 | } | 1595 | } |
diff --git a/src/nsterm.h b/src/nsterm.h index 969091e334c..939186d0d94 100644 --- a/src/nsterm.h +++ b/src/nsterm.h | |||
| @@ -799,6 +799,7 @@ extern void x_free_frame_resources (struct frame *); | |||
| 799 | extern void ns_run_ascript (void); | 799 | extern void ns_run_ascript (void); |
| 800 | 800 | ||
| 801 | extern const char *ns_etc_directory (void); | 801 | extern const char *ns_etc_directory (void); |
| 802 | extern const char *ns_exec_path (void); | ||
| 802 | extern void ns_init_paths (void); | 803 | extern void ns_init_paths (void); |
| 803 | extern void syms_of_nsterm (void); | 804 | extern void syms_of_nsterm (void); |
| 804 | extern void syms_of_nsfns (void); | 805 | extern void syms_of_nsfns (void); |
diff --git a/src/nsterm.m b/src/nsterm.m index 2b1b67c8b58..6ec9d695334 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -288,10 +288,9 @@ append2 (Lisp_Object list, Lisp_Object item) | |||
| 288 | 288 | ||
| 289 | const char * | 289 | const char * |
| 290 | ns_etc_directory (void) | 290 | ns_etc_directory (void) |
| 291 | { | ||
| 292 | /* If running as a self-contained app bundle, return as a string the | 291 | /* If running as a self-contained app bundle, return as a string the |
| 293 | filename of the etc directory, if present; else nil. */ | 292 | filename of the etc directory, if present; else nil. */ |
| 294 | 293 | { | |
| 295 | NSBundle *bundle = [NSBundle mainBundle]; | 294 | NSBundle *bundle = [NSBundle mainBundle]; |
| 296 | NSString *resourceDir = [bundle resourcePath]; | 295 | NSString *resourceDir = [bundle resourcePath]; |
| 297 | NSString *resourcePath; | 296 | NSString *resourcePath; |
| @@ -306,33 +305,82 @@ ns_etc_directory (void) | |||
| 306 | return NULL; | 305 | return NULL; |
| 307 | } | 306 | } |
| 308 | 307 | ||
| 309 | void | 308 | |
| 310 | ns_init_paths (void) | 309 | const char * |
| 311 | /* -------------------------------------------------------------------------- | 310 | ns_exec_path (void) |
| 312 | Used to allow emacs to find its resources under Emacs.app | 311 | /* If running as a self-contained app bundle, return as a path string |
| 313 | Called from emacs.c at startup. | 312 | the filenames of the libexec and bin directories, ie libexec:bin. |
| 314 | -------------------------------------------------------------------------- */ | 313 | Otherwise, return nil. |
| 314 | Normally, Emacs does not add its own bin/ directory to the PATH. | ||
| 315 | However, a self-contained NS build has a different layout, with | ||
| 316 | bin/ and libexec/ subdirectories in the directory that contains | ||
| 317 | Emacs.app itself. | ||
| 318 | We put libexec first, because init_callproc_1 uses the first | ||
| 319 | element to initialize exec-directory. An alternative would be | ||
| 320 | for init_callproc to check for invocation-directory/libexec. | ||
| 321 | */ | ||
| 315 | { | 322 | { |
| 316 | NSBundle *bundle = [NSBundle mainBundle]; | 323 | NSBundle *bundle = [NSBundle mainBundle]; |
| 317 | NSString *binDir = [bundle bundlePath], *resourceDir = [bundle resourcePath]; | 324 | NSString *resourceDir = [bundle resourcePath]; |
| 325 | NSString *binDir = [bundle bundlePath]; | ||
| 318 | NSString *resourcePath, *resourcePaths; | 326 | NSString *resourcePath, *resourcePaths; |
| 319 | NSRange range; | 327 | NSRange range; |
| 320 | BOOL onWindows = NO; /* how do I determine this? */ | 328 | BOOL onWindows = NO; /* FIXME determine this somehow */ |
| 321 | NSString *pathSeparator = onWindows ? @";" : @":"; | 329 | NSString *pathSeparator = onWindows ? @";" : @":"; |
| 322 | NSFileManager *fileManager = [NSFileManager defaultManager]; | 330 | NSFileManager *fileManager = [NSFileManager defaultManager]; |
| 331 | NSArray *paths; | ||
| 332 | NSEnumerator *pathEnum; | ||
| 323 | BOOL isDir; | 333 | BOOL isDir; |
| 324 | /*NSLog (@"ns_init_paths: '%@'\n%@\n", [[NSBundle mainBundle] bundlePath], [[NSBundle mainBundle] resourcePath]); */ | ||
| 325 | 334 | ||
| 326 | /* get bindir from base */ | ||
| 327 | range = [resourceDir rangeOfString: @"Contents"]; | 335 | range = [resourceDir rangeOfString: @"Contents"]; |
| 328 | if (range.location != NSNotFound) | 336 | if (range.location != NSNotFound) |
| 329 | { | 337 | { |
| 330 | binDir = [binDir stringByAppendingPathComponent: @"Contents"]; | ||
| 331 | #ifdef NS_IMPL_COCOA | 338 | #ifdef NS_IMPL_COCOA |
| 332 | binDir = [binDir stringByAppendingPathComponent: @"MacOS"]; | 339 | binDir = [binDir stringByAppendingPathComponent: @"MacOS"]; |
| 340 | #else | ||
| 341 | binDir = [binDir stringByAppendingPathComponent: @"Contents"]; | ||
| 333 | #endif | 342 | #endif |
| 334 | } | 343 | } |
| 335 | 344 | ||
| 345 | paths = [binDir stringsByAppendingPaths: | ||
| 346 | [NSArray arrayWithObjects: @"libexec", @"bin", nil]]; | ||
| 347 | pathEnum = [paths objectEnumerator]; | ||
| 348 | resourcePaths = @""; | ||
| 349 | |||
| 350 | while (resourcePath = [pathEnum nextObject]) | ||
| 351 | { | ||
| 352 | if ([fileManager fileExistsAtPath: resourcePath isDirectory: &isDir]) | ||
| 353 | if (isDir) | ||
| 354 | { | ||
| 355 | if ([resourcePaths length] > 0) | ||
| 356 | resourcePaths | ||
| 357 | = [resourcePaths stringByAppendingString: pathSeparator]; | ||
| 358 | resourcePaths | ||
| 359 | = [resourcePaths stringByAppendingString: resourcePath]; | ||
| 360 | } | ||
| 361 | } | ||
| 362 | if ([resourcePaths length] > 0) return [resourcePaths UTF8String]; | ||
| 363 | |||
| 364 | return NULL; | ||
| 365 | } | ||
| 366 | |||
| 367 | |||
| 368 | void | ||
| 369 | ns_init_paths (void) | ||
| 370 | /* -------------------------------------------------------------------------- | ||
| 371 | Used to allow emacs to find its resources under Emacs.app | ||
| 372 | Called from emacs.c at startup. | ||
| 373 | -------------------------------------------------------------------------- */ | ||
| 374 | { | ||
| 375 | NSBundle *bundle = [NSBundle mainBundle]; | ||
| 376 | NSString *resourceDir = [bundle resourcePath]; | ||
| 377 | NSString *resourcePath, *resourcePaths; | ||
| 378 | BOOL onWindows = NO; /* FIXME determine this somehow */ | ||
| 379 | NSString *pathSeparator = onWindows ? @";" : @":"; | ||
| 380 | NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
| 381 | BOOL isDir; | ||
| 382 | /*NSLog (@"ns_init_paths: '%@'\n%@\n", [[NSBundle mainBundle] bundlePath], [[NSBundle mainBundle] resourcePath]); */ | ||
| 383 | |||
| 336 | /* the following based on Andrew Choi's init_mac_osx_environment () */ | 384 | /* the following based on Andrew Choi's init_mac_osx_environment () */ |
| 337 | if (!getenv ("EMACSLOADPATH")) | 385 | if (!getenv ("EMACSLOADPATH")) |
| 338 | { | 386 | { |
| @@ -359,36 +407,6 @@ ns_init_paths (void) | |||
| 359 | setenv ("EMACSLOADPATH", [resourcePaths UTF8String], 1); | 407 | setenv ("EMACSLOADPATH", [resourcePaths UTF8String], 1); |
| 360 | /*NSLog (@"loadPath: '%@'\n", resourcePaths); */ | 408 | /*NSLog (@"loadPath: '%@'\n", resourcePaths); */ |
| 361 | } | 409 | } |
| 362 | |||
| 363 | /* Normally, Emacs does not add its own bin/ directory to the PATH. | ||
| 364 | However, a self-contained NS build has a different layout, with | ||
| 365 | bin/ and libexec/ subdirectories in the directory that contains | ||
| 366 | Emacs.app itself. | ||
| 367 | We put libexec first, because init_callproc_1 uses the first | ||
| 368 | element to initialize exec-directory. An alternative would be | ||
| 369 | for init_callproc to check for invocation-directory/libexec. */ | ||
| 370 | if (!getenv ("EMACSPATH")) | ||
| 371 | { | ||
| 372 | NSArray *paths = [binDir stringsByAppendingPaths: | ||
| 373 | [NSArray arrayWithObjects: @"libexec", | ||
| 374 | @"bin", nil]]; | ||
| 375 | NSEnumerator *pathEnum = [paths objectEnumerator]; | ||
| 376 | resourcePaths = @""; | ||
| 377 | while (resourcePath = [pathEnum nextObject]) | ||
| 378 | { | ||
| 379 | if ([fileManager fileExistsAtPath: resourcePath isDirectory: &isDir]) | ||
| 380 | if (isDir) | ||
| 381 | { | ||
| 382 | if ([resourcePaths length] > 0) | ||
| 383 | resourcePaths | ||
| 384 | = [resourcePaths stringByAppendingString: pathSeparator]; | ||
| 385 | resourcePaths | ||
| 386 | = [resourcePaths stringByAppendingString: resourcePath]; | ||
| 387 | } | ||
| 388 | } | ||
| 389 | if ([resourcePaths length] > 0) | ||
| 390 | setenv ("EMACSPATH", [resourcePaths UTF8String], 1); | ||
| 391 | } | ||
| 392 | } | 410 | } |
| 393 | 411 | ||
| 394 | static void | 412 | static void |