mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
This commit is contained in:
parent
11718620ef
commit
90db661b43
6 changed files with 115 additions and 27 deletions
|
@ -28,6 +28,7 @@
|
|||
#include <dlfcn.h>
|
||||
#include <stdlib.h>
|
||||
#include <Python.h>
|
||||
#include <mach-o/dyld.h>
|
||||
|
||||
|
||||
extern char** environ;
|
||||
|
@ -158,9 +159,44 @@ main(int argc, char **argv) {
|
|||
/* Set the original executable path in the environment. */
|
||||
status = _NSGetExecutablePath(path, &size);
|
||||
if (status == 0) {
|
||||
if (realpath(path, real_path) != NULL) {
|
||||
setenv("__PYVENV_LAUNCHER__", real_path, 1);
|
||||
/*
|
||||
* Note: don't call 'realpath', that will
|
||||
* erase symlink information, and that
|
||||
* breaks "pyvenv --symlink"
|
||||
*
|
||||
* It is nice to have the directory name
|
||||
* as a cleaned up absolute path though,
|
||||
* therefore call realpath on dirname(path)
|
||||
*/
|
||||
char* slash = strrchr(path, '/');
|
||||
if (slash) {
|
||||
char replaced;
|
||||
replaced = slash[1];
|
||||
slash[1] = 0;
|
||||
if (realpath(path, real_path) == NULL) {
|
||||
err(1, "realpath: %s", path);
|
||||
}
|
||||
slash[1] = replaced;
|
||||
if (strlcat(real_path, slash, sizeof(real_path)) > sizeof(real_path)) {
|
||||
errno = EINVAL;
|
||||
err(1, "realpath: %s", path);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (realpath(".", real_path) == NULL) {
|
||||
err(1, "realpath: %s", path);
|
||||
}
|
||||
if (strlcat(real_path, "/", sizeof(real_path)) > sizeof(real_path)) {
|
||||
errno = EINVAL;
|
||||
err(1, "realpath: %s", path);
|
||||
}
|
||||
if (strlcat(real_path, path, sizeof(real_path)) > sizeof(real_path)) {
|
||||
errno = EINVAL;
|
||||
err(1, "realpath: %s", path);
|
||||
}
|
||||
}
|
||||
|
||||
setenv("__PYVENV_LAUNCHER__", real_path, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue