Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(11)

Unified Diff: PC/getpathp.c

Issue 3871: cross and native build of python for mingw32 with distutils
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Objects/exceptions.c ('k') | PC/msvcrtmodule.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/PC/getpathp.c Mon Dec 17 20:46:29 2012 +0100
+++ b/PC/getpathp.c Tue Dec 18 21:47:22 2012 -0500
@@ -94,6 +94,7 @@
static wchar_t prefix[MAXPATHLEN+1];
static wchar_t progpath[MAXPATHLEN+1];
static wchar_t dllpath[MAXPATHLEN+1];
+static wchar_t mingw_dynload_path[MAXPATHLEN+1];
static wchar_t *module_search_path = NULL;
@@ -470,6 +471,106 @@
return result;
}
+// Threadsafe mingw path conversion call
+// Returns true if path found and converted.
+int mingw_posix2win_path(wchar_t *mingwpath, wchar_t *destination, int size)
+{
+ FILE *fp;
+ int status;
+ wchar_t cmd[MAXPATHLEN+32]={0};
+ wchar_t results[MAXPATHLEN+1]={0};
+ wchar_t mingw_lib64_path[MAXPATHLEN+1]={0};
+
+ // not quite sure yet why swprintf with size fails. will have
+ // to use default swprintf for now.
+ swprintf(cmd, L"bash -c \"cd %ls 2>&1 && pwd -W\"", mingwpath);
+
+ /* Open the command for reading. */
+ fp = wpopen(cmd, L"r");
+
+ if (fp == NULL) {
+ return 0;
+ } else {
+ /* Read the output a line at a time - output it. */
+ while (fgetws(results, sizeof(results)-1, fp) != NULL) {
+ if (wcsstr(results, L"No such file")==NULL) {
+ results[wcslen(results)-1]='\0';
+ wcsncat(destination, results, size);
+ } else {
+ return 0;
+ }
+ }
+
+ /* close */
+ pclose(fp);
+ }
+
+ return 1;
+}
+
+void get_mingw_path(wchar_t *destination, int size)
+{
+ static wchar_t mingw_path[MAXPATHLEN+1]={0};
+
+ //mingw64 path is mounted under /mingw in msys
+ if (wcslen(mingw_path)==0)
+ if (!mingw_posix2win_path(L"/mingw", mingw_path, sizeof(mingw_path)))
+ mingw_posix2win_path(L"/", mingw_path, sizeof(mingw_path));
+
+ if (wcslen(mingw_path)>=0) {
+ wcsncat(destination, mingw_path, size);
+ }
+}
+
+void get_mingw_lib_path(wchar_t *destination, int size)
+{
+ wchar_t mingw_base_path[MAXPATHLEN+1]={0};
+
+ get_mingw_path(mingw_base_path, sizeof(mingw_base_path));
+
+ if (wcslen(mingw_base_path)>=0) {
+ wcsncpy(destination, mingw_base_path, size);
+ wcsncat(destination, L"/lib", size);
+ }
+}
+
+void get_mingw_os_test_path(wchar_t *destination, int size)
+{
+ wchar_t mingw_py_path[MAXPATHLEN+1]={0};
+
+ swprintf(mingw_py_path, L"lib/python%d.%d/", PY_MAJOR_VERSION,PY_MINOR_VERSION);
+
+ wcsncpy(destination, mingw_py_path, size);
+ wcsncat(destination, L"os.py", size);
+}
+
+void get_mingw_python_path(wchar_t *destination, int size)
+{
+ wchar_t mingw_lib_path[MAXPATHLEN+1]={0};
+ wchar_t mingw_py_path[MAXPATHLEN+1]={0};
+
+ get_mingw_lib_path(mingw_lib_path, sizeof(mingw_lib_path));
+
+ swprintf(mingw_py_path, L"/python%d.%d", PY_MAJOR_VERSION,PY_MINOR_VERSION);
+
+ if (wcslen(mingw_lib_path)>=0) {
+ wcsncpy(destination, mingw_lib_path, size);
+ wcsncat(destination, mingw_py_path, size);
+ }
+}
+
+void get_mingw_libdynload_path(wchar_t *destination, int size)
+{
+ wchar_t mingw_lib_path[MAXPATHLEN+1]={0};
+
+ get_mingw_python_path(mingw_lib_path, sizeof(mingw_lib_path));
+
+ if (wcslen(mingw_lib_path)>=0) {
+ wcsncpy(destination, mingw_lib_path, size);
+ wcsncat(destination, L"/lib-dynload", size);
+ }
+}
+
static void
calculate_path(void)
{
@@ -569,6 +670,17 @@
}
skiphome = pythonhome==NULL ? 0 : 1;
+
+# ifdef __MINGW32__
+ wchar_t mingw_lib_path[MAXPATHLEN+1]={0};
+ get_mingw_lib_path(mingw_lib_path, sizeof(mingw_lib_path));
+
+ wchar_t mingw_python_path[MAXPATHLEN+1]={0};
+ get_mingw_python_path(mingw_python_path, sizeof(mingw_python_path));
+
+ get_mingw_libdynload_path(mingw_dynload_path, sizeof(mingw_dynload_path));
+# endif
+
#ifdef Py_ENABLE_SHARED
machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, skiphome);
userpath = getpythonregpath(HKEY_CURRENT_USER, skiphome);
@@ -576,7 +688,8 @@
/* We only use the default relative PYTHONPATH if we havent
anything better to use! */
skipdefault = envpath!=NULL || pythonhome!=NULL || \
- machinepath!=NULL || userpath!=NULL;
+ machinepath!=NULL || userpath!=NULL || \
+ (wcslen(mingw_lib_path)>=0);
#endif
/* We need to construct a path from the following parts.
@@ -604,19 +717,33 @@
}
else
bufsz = 0;
+
bufsz += wcslen(PYTHONPATH) + 1;
bufsz += wcslen(argv0_path) + 1;
+
#ifdef MS_WINDOWS
if (userpath)
bufsz += wcslen(userpath) + 1;
if (machinepath)
bufsz += wcslen(machinepath) + 1;
bufsz += wcslen(zip_path) + 1;
+
+# ifdef __MINGW32__
+ if (wcslen(mingw_lib_path)>=0)
+ bufsz += wcslen(mingw_lib_path) + 1;
+ if (wcslen(mingw_python_path)>=0)
+ bufsz += wcslen(mingw_python_path) + 1;
+ if (wcslen(mingw_dynload_path)>=0)
+ bufsz += wcslen(mingw_dynload_path) + 1;
+# endif
+
#endif
+
if (envpath != NULL)
bufsz += wcslen(envpath) + 1;
module_search_path = buf = malloc(bufsz*sizeof(wchar_t));
+
if (buf == NULL) {
/* We can't exit, so print a warning and limp along */
fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n");
@@ -660,6 +787,36 @@
*buf++ = DELIM;
free(machinepath);
}
+#ifdef __MINGW32__
+ if (search_for_prefix(argv0_path, LANDMARK) == 0)
+ {
+ if (wcslen(mingw_lib_path)>0) {
+ wcscpy(buf, mingw_lib_path);
+ buf = wcschr(buf, L'\0');
+ *buf++ = DELIM;
+ }
+
+ if (wcslen(mingw_python_path)>0) {
+ wcscpy(buf, mingw_python_path);
+ buf = wcschr(buf, L'\0');
+ *buf++ = DELIM;
+ }
+
+ if (wcslen(mingw_dynload_path)>0) {
+ wcscpy(buf, mingw_dynload_path);
+ buf = wcschr(buf, L'\0');
+ *buf++ = DELIM;
+ }
+
+ wchar_t mingw_path[MAXPATHLEN+1]={0};
+ wchar_t os_test_path[MAXPATHLEN+1]={0};
+
+ get_mingw_path(mingw_path, sizeof(mingw_path));
+ get_mingw_os_test_path(os_test_path, sizeof(os_test_path));
+
+ search_for_prefix(mingw_path, os_test_path);
+ }
+#endif
if (pythonhome == NULL) {
if (!skipdefault) {
wcscpy(buf, PYTHONPATH);
@@ -778,6 +935,9 @@
wchar_t *
Py_GetExecPrefix(void)
{
+ if (wcslen(mingw_dynload_path)>0)
+ return mingw_dynload_path;
+
return Py_GetPrefix();
}
« no previous file with comments | « Objects/exceptions.c ('k') | PC/msvcrtmodule.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+