]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Efi/getpath.c
AppPkg/Applications/Python: Get Python startup process fully working for EDK II.
[mirror_edk2.git] / AppPkg / Applications / Python / Efi / getpath.c
index ba837bf52219e16d4b566b2ca03d1efde4ee0a23..5a8c52002715129a467652bcf488eb98c733a6f3 100644 (file)
@@ -32,6 +32,7 @@
 **/\r
 #include <Python.h>\r
 #include <osdefs.h>\r
+#include  <ctype.h>\r
 \r
 #ifdef __cplusplus\r
  extern "C" {\r
@@ -126,15 +127,12 @@ isfile(char *filename)
 {\r
     struct stat buf;\r
     if (stat(filename, &buf) != 0) {\r
-      //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d] Not Found: file = \"%s\"\n", __func__, __LINE__, filename);\r
       return 0;\r
     }\r
     //if (!S_ISREG(buf.st_mode))\r
     if (S_ISDIR(buf.st_mode)) {\r
-      //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d] Is DIR: file = \"%s\"\n", __func__, __LINE__, filename);\r
       return 0;\r
     }\r
-    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d] SUCCESS: file = \"%s\"\n", __func__, __LINE__, filename);\r
     return 1;\r
 }\r
 \r
@@ -159,11 +157,9 @@ ismodule(char *filename)
     if (strlen(filename) < MAXPATHLEN) {\r
         strcat(filename, Py_OptimizeFlag ? "o" : "c");\r
         if (isfile(filename)) {\r
-          //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: file = \"%s\"\n", __func__, __LINE__, filename);\r
           return 1;\r
         }\r
     }\r
-    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d] FAIL: file = \"%s\"\n", __func__, __LINE__, filename);\r
     return 0;\r
 }\r
 \r
@@ -304,7 +300,6 @@ isxfile(char *filename)
     char        *newbn;\r
     int          bnlen;\r
 \r
-    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d] ENTER: file = \"%s\"\n", __func__, __LINE__, filename);\r
     bn = basename(filename);            // Separate off the file name component\r
     reduce(filename);                   // and isolate the path component\r
     bnlen = strlen(bn);\r
@@ -315,22 +310,17 @@ isxfile(char *filename)
       bnlen += 4;\r
     }\r
     else if(strcmp(newbn, ".efi") != 0) {\r
-      //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: Bad extension\n", __func__, __LINE__);\r
       return 0;                         // File can not be executable.\r
     }\r
     joinpath(filename, bn);             // Stitch path and file name back together\r
-    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: file = \"%s\"\n", __func__, __LINE__, filename);\r
 \r
     if (stat(filename, &buf) != 0) {    // Now, verify that file exists\r
-      //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: Does not exist\n", __func__, __LINE__);\r
       return 0;\r
     }\r
     if(S_ISDIR(buf.st_mode)) {          // And it is not a directory.\r
-      //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: Is a directory\n", __func__, __LINE__);\r
       return 0;\r
     }\r
 \r
-    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d] EXIT: file = \"%s\"\n", __func__, __LINE__, filename);\r
     return 1;\r
 }\r
 \r
@@ -390,17 +380,12 @@ set_volume(char *Dest, char *path)
 {\r
   size_t    VolLen;\r
 \r
-  //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d] ENTER: path = \"%s\"\n", __func__, __LINE__, path);\r
   if(is_absolute(path)) {\r
     VolLen = strcspn(path, "/\\:");\r
-    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: VolLen = %d\n", __func__, __LINE__, VolLen);\r
     if((VolLen != 0) && (path[VolLen] == ':')) {\r
       (void) strncpyX(Dest, path, VolLen + 1);\r
-      //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: VolLen = %d, Dest = \"%s\" path = \"%s\"\n",\r
-      //                                      __func__, __LINE__, VolLen, Dest, path);\r
     }\r
   }\r
-  //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d] EXIT: Dest = \"%s\"\n", __func__, __LINE__, Dest);\r
 }\r
 \r
 \r
@@ -481,16 +466,10 @@ calculate_path(void)
     char *prog = Py_GetProgramName();\r
     char argv0_path[MAXPATHLEN+1];\r
     char zip_path[MAXPATHLEN+1];\r
-    //int pfound, efound; /* 1 if found; -1 if found build directory */\r
     char *buf;\r
     size_t bufsz;\r
     size_t prefixsz;\r
     char *defpath;\r
-    //uint32_t nsexeclength = MAXPATHLEN;\r
-\r
-    //unixify(path);\r
-    //unixify(rtpypath);\r
-    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]:\nENTER prog=\"%s\"\n      path=\"%s\"\n", __func__, __LINE__, prog, path);\r
 \r
 \r
 /* ###########################################################################\r
@@ -520,7 +499,6 @@ calculate_path(void)
                 strncpy(progpath, path, MAXPATHLEN);\r
 \r
         joinpath(progpath, prog);\r
-        //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: progpath = \"%s\"\n", __func__, __LINE__, progpath);\r
         if (isxfile(progpath))\r
                 break;\r
 \r
@@ -539,10 +517,7 @@ calculate_path(void)
     argv0_path[MAXPATHLEN] = '\0';\r
     set_volume(volume_name, argv0_path);\r
 \r
-    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: volume_name = \"%s\"\n", __func__, __LINE__, volume_name);\r
     reduce(argv0_path);\r
-    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: progpath = \"%s\"\n", __func__, __LINE__, progpath);\r
-    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: argv0_path = \"%s\"\n", __func__, __LINE__, argv0_path);\r
     /* At this point, argv0_path is guaranteed to be less than\r
        MAXPATHLEN bytes long.\r
     */\r
@@ -552,17 +527,9 @@ calculate_path(void)
       This is the full path to the platform independent libraries.\r
 ########################################################################### */\r
 \r
-    //if (!(pfound = search_for_prefix(argv0_path, home))) {\r
-    //    if (!Py_FrozenFlag)\r
-    //        fprintf(stderr,\r
-    //            "Could not find platform independent libraries <prefix>\n");\r
         strncpy(prefix, volume_name, MAXPATHLEN);\r
         joinpath(prefix, PREFIX);\r
         joinpath(prefix, lib_python);\r
-    //}\r
-    //else\r
-    //    reduce(prefix);\r
-    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: V = \"%s\", Prefix = \"%s\"\n", __func__, __LINE__, volume_name, prefix);\r
 \r
 /* ###########################################################################\r
       Build the FULL path to the zipped-up Python library.\r
@@ -570,37 +537,20 @@ calculate_path(void)
 \r
     strncpy(zip_path, prefix, MAXPATHLEN);\r
     zip_path[MAXPATHLEN] = '\0';\r
-    //if (pfound > 0) { /* Use the reduced prefix returned by Py_GetPrefix() */\r
-        reduce(zip_path);\r
-        //reduce(zip_path);\r
-    //}\r
-    //else\r
-    //    strncpy(zip_path, PREFIX, MAXPATHLEN);\r
+    reduce(zip_path);\r
     joinpath(zip_path, "python00.zip");\r
     bufsz = strlen(zip_path);   /* Replace "00" with version */\r
     zip_path[bufsz - 6] = VERSION[0];\r
     zip_path[bufsz - 5] = VERSION[1];\r
-    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: Zip_path = \"%s\"\n", __func__, __LINE__, zip_path);\r
 \r
 /* ###########################################################################\r
       Build the FULL path to dynamically loadable libraries.\r
 ########################################################################### */\r
 \r
-    //if (!(efound = search_for_exec_prefix(argv0_path, home))) {\r
-    //    if (!Py_FrozenFlag)\r
-    //        fprintf(stderr,\r
-    //            "Could not find platform dependent libraries <exec_prefix>\n");\r
         strncpy(exec_prefix, volume_name, MAXPATHLEN);\r
         joinpath(exec_prefix, EXEC_PREFIX);\r
         joinpath(exec_prefix, lib_python);\r
-        joinpath(exec_prefix, "dynaload");\r
-    //}\r
-    /* If we found EXEC_PREFIX do *not* reduce it!  (Yet.) */\r
-    //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: Exec_prefix = \"%s\"\n", __func__, __LINE__, exec_prefix);\r
-\r
-    //if ((!pfound || !efound) && !Py_FrozenFlag)\r
-    //    fprintf(stderr,\r
-    //            "Consider setting $PYTHONHOME to <prefix>[%c<exec_prefix>]\n", DELIM);\r
+        joinpath(exec_prefix, "lib-dynload");\r
 \r
 /* ###########################################################################\r
       Build the module search path.\r
@@ -611,7 +561,6 @@ calculate_path(void)
      * If we're loading relative to the build directory,\r
      * return the compiled-in defaults instead.\r
      */\r
-    //if (pfound > 0) {\r
     reduce(prefix);\r
     reduce(prefix);\r
     /* The prefix is the root directory, but reduce() chopped\r
@@ -624,11 +573,6 @@ calculate_path(void)
       prefix[bufsz] = SEP;\r
       prefix[bufsz+1] = 0;\r
     }\r
-    //}\r
-    //else\r
-    //    strncpy(prefix, PREFIX, MAXPATHLEN);\r
-\r
-//if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: prefix = \"%s\"\n", __func__, __LINE__, prefix);\r
 \r
     /* Calculate size of return buffer.\r
      */\r
@@ -655,7 +599,6 @@ calculate_path(void)
         }\r
         defpath = delim + 1;\r
     }\r
-//if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: defpath = \"%s\"\n", __func__, __LINE__, defpath);\r
 \r
     bufsz += strlen(zip_path) + 1;\r
     bufsz += strlen(exec_prefix) + 1;\r
@@ -670,7 +613,6 @@ calculate_path(void)
         module_search_path = PYTHONPATH;\r
     }\r
     else {\r
-      //if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]:\n", __func__, __LINE__);\r
         /* Run-time value of $PYTHONPATH goes first */\r
         if (rtpypath) {\r
             strcpy(buf, rtpypath);\r
@@ -678,12 +620,10 @@ calculate_path(void)
         }\r
         else\r
             buf[0] = '\0';\r
-//if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: RTpath = \"%s\"\n", __func__, __LINE__, buf);\r
 \r
         /* Next is the default zip path */\r
         strcat(buf, zip_path);\r
         strcat(buf, delimiter);\r
-//if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: +Zip = \"%s\"\n", __func__, __LINE__, buf);\r
 \r
         /* Next goes merge of compile-time $PYTHONPATH with\r
          * dynamically located prefix.\r
@@ -710,17 +650,13 @@ calculate_path(void)
             defpath = delim + 1;\r
         }\r
         strcat(buf, delimiter);\r
-//if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: +Merge = \"%s\"\n", __func__, __LINE__, buf);\r
 \r
         /* Finally, on goes the directory for dynamic-load modules */\r
         strcat(buf, exec_prefix);\r
 \r
         /* And publish the results */\r
         module_search_path = buf;\r
-//if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: module_search_path = \"%s\"\n", __func__, __LINE__, module_search_path);\r
     }\r
-\r
-    //if (efound > 0) {\r
         /*  At this point, exec_prefix is set to VOL:/Efi/StdLib/lib/python.27/dynalib.\r
             We want to get back to the root value, so we have to remove the final three\r
             segments to get VOL:/Efi/StdLib.  Because we don't know what VOL is, and\r
@@ -737,9 +673,6 @@ calculate_path(void)
           exec_prefix[bufsz] = SEP;\r
           exec_prefix[bufsz+1] = 0;\r
         }\r
-    //}\r
-    //else\r
-    //    strncpy(exec_prefix, EXEC_PREFIX, MAXPATHLEN);\r
     if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: module_search_path = \"%s\"\n", __func__, __LINE__, module_search_path);\r
     if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: prefix             = \"%s\"\n", __func__, __LINE__, prefix);\r
     if (Py_VerboseFlag) PySys_WriteStderr("%s[%d]: exec_prefix        = \"%s\"\n", __func__, __LINE__, exec_prefix);\r