Commits

Anthony Tuininga committed 5ade6fc

Added support for a Win32GUIKeepPath base executable as requested by Almar
Klein; reduce the amount of copied code for creating the "KeepPath" base
executables.

  • Participants
  • Parent commits 264c2aa

Comments (0)

Files changed (6)

File doc/releasenotes.rst

    support, please use cx_Freeze 4.2.3.
 
 1) Added support for the final release of Python 3.3.
-2) Clarified the documentation on the --replace-paths option.
+2) Added new base executable Win32GUIKeepPath which enables the use of a Python
+   installation in the Windows GUI subsystem in the same manner as
+   ConsoleKeepPath does for using a console. Thanks to Almar Klein for the
+   initial patch.
+3) Clarified the documentation on the --replace-paths option. Thanks to Thomas
+   Kluyver for the patch.
 
 Bugs fixed:
 * Producing a Mac distribution failed with a variable reference.
     gui = Extension("cx_Freeze.bases.Win32GUI", ["source/bases/Win32GUI.c"],
             include_dirs = includeDirs, depends = fullDepends,
             libraries = ["user32"])
+    guiKeepPath = Extension("cx_Freeze.bases.Win32GUIKeepPath",
+            ["source/bases/Win32GUIKeepPath.c"], include_dirs = includeDirs,
+            depends = depends, libraries = ["user32"])
     extensions.append(gui)
+    extensions.append(guiKeepPath)
     moduleInfo = find_cx_Logging()
     if moduleInfo is not None and sys.version_info[:2] < (3, 0):
         includeDir, libraryDir = moduleInfo

File source/bases/Console.c

 
 
 #include "Common.c"
+#ifndef CX_FREEZE_KEEP_PATH
 #include "BaseModules.c"
+#endif
 
 
 //-----------------------------------------------------------------------------
 {
 #if PY_MAJOR_VERSION >= 3
     char fileName[MAXPATHLEN + 1];
-    wchar_t **wargv, *wfileName; 
+    wchar_t **wargv, *wfileName;
     int i, size;
 #else
     const char *fileName;
     int status;
 
     // initialize Python
+#ifndef CX_FREEZE_KEEP_PATH
     Py_NoSiteFlag = 1;
     Py_FrozenFlag = 1;
     Py_IgnoreEnvironmentFlag = 1;
     PyImport_FrozenModules = gFrozenModules;
+#endif
 #if PY_MAJOR_VERSION >= 3
     setlocale(LC_CTYPE, "");
+#ifndef CX_FREEZE_KEEP_PATH
     Py_SetPythonHome(L"");
+#endif
     wargv = PyMem_Malloc(sizeof(wchar_t*) * argc);
     if (!wargv)
         return 2;
     Py_Initialize();
     PySys_SetArgv(argc, wargv);
 #else
+#ifndef CX_FREEZE_KEEP_PATH
     Py_SetPythonHome("");
+#endif
     Py_SetProgramName(argv[0]);
     fileName = Py_GetProgramFullPath();
     Py_Initialize();

File source/bases/ConsoleKeepPath.c

 // their work.
 //-----------------------------------------------------------------------------
 
-#include <Python.h>
-#include <locale.h>
-#ifdef __WIN32__
-#include <windows.h>
-#endif
+#define CX_FREEZE_KEEP_PATH
+#include "Console.c"
 
-// disable filename globbing on Windows
-#ifdef MS_WINDOWS
-int _CRT_glob = 0;
-#endif
-
-//-----------------------------------------------------------------------------
-// FatalError()
-//   Prints a fatal error.
-//-----------------------------------------------------------------------------
-static int FatalError(
-    const char *message)                // message to print
-{
-    PyErr_Print();
-    Py_FatalError(message);
-    return -1;
-}
-
-
-//-----------------------------------------------------------------------------
-// FatalScriptError()
-//   Prints a fatal error in the initialization script.
-//-----------------------------------------------------------------------------
-static int FatalScriptError(void)
-{
-    PyErr_Print();
-    return -1;
-}
-
-
-#include "Common.c"
-
-
-//-----------------------------------------------------------------------------
-// main()
-//   Main routine for frozen programs.
-//-----------------------------------------------------------------------------
-int main(int argc, char **argv)
-{
-#if PY_MAJOR_VERSION >= 3
-    char fileName[MAXPATHLEN + 1];
-    wchar_t **wargv, *wfileName;
-    int i, size;
-#else
-    const char *fileName;
-#endif
-    int status;
-
-    // initialize Python
-#if PY_MAJOR_VERSION >= 3
-    setlocale(LC_CTYPE, "");
-    wargv = PyMem_Malloc(sizeof(wchar_t*) * argc);
-    if (!wargv)
-        return 2;
-    for (i = 0; i < argc; i++) {
-        size = strlen(argv[i]);
-        wargv[i] = PyMem_Malloc(sizeof(wchar_t) * (size + 1));
-        if (!wargv[i])
-            return 2;
-        status = mbstowcs(wargv[i], argv[i], size + 1);
-        if (status < 0)
-            return 3;
-    }
-    Py_SetProgramName(wargv[0]);
-    wfileName = Py_GetProgramFullPath();
-    wcstombs(fileName, wfileName, MAXPATHLEN);
-    Py_Initialize();
-    PySys_SetArgv(argc, wargv);
-#else
-    Py_SetProgramName(argv[0]);
-    fileName = Py_GetProgramFullPath();
-    Py_Initialize();
-    PySys_SetArgv(argc, argv);
-#endif
-
-    // do the work
-    status = 0;
-    if (ExecuteScript(fileName) < 0)
-        status = 1;
-
-    Py_Finalize();
-    return status;
-}
-

File source/bases/Win32GUI.c

 
 
 #include "Common.c"
+#ifndef CX_FREEZE_KEEP_PATH
 #include "BaseModules.c"
+#endif
 
 
 //-----------------------------------------------------------------------------
     int status;
 
     // initialize Python
+#ifndef CX_FREEZE_KEEP_PATH
     Py_NoSiteFlag = 1;
     Py_FrozenFlag = 1;
     Py_IgnoreEnvironmentFlag = 1;
     PyImport_FrozenModules = gFrozenModules;
+#endif
 #if PY_MAJOR_VERSION >= 3
     setlocale(LC_CTYPE, "");
+#ifndef CX_FREEZE_KEEP_PATH
     Py_SetPythonHome(L"");
+#endif
     wargv = PyMem_Malloc(sizeof(wchar_t*) * __argc);
     if (!wargv)
         return 2;
     Py_Initialize();
     PySys_SetArgv(__argc, wargv);
 #else
+#ifndef CX_FREEZE_KEEP_PATH
     Py_SetPythonHome("");
+#endif
     Py_SetProgramName(__argv[0]);
     fileName = Py_GetProgramFullPath();
     Py_Initialize();

File source/bases/Win32GUIKeepPath.c

+//-----------------------------------------------------------------------------
+// Win32GUIKeepPath.c
+//   Main routine for frozen programs written for the Win32 GUI subsystem which
+// need a Python installation to do their work.
+//-----------------------------------------------------------------------------
+
+#define CX_FREEZE_KEEP_PATH
+#include "Win32GUI.c"
+