mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
deploy-ng: fix issues with Python 3 / Windows / Unicode, add deploy-stubw
This commit is contained in:
parent
e85a2aa140
commit
31136124c7
@ -32,6 +32,7 @@ isDebugBuild = (python.lower().endswith('_d'))
|
|||||||
# must be frozen in any main.exe.
|
# must be frozen in any main.exe.
|
||||||
startupModules = [
|
startupModules = [
|
||||||
'encodings.cp1252', 'encodings.latin_1', 'encodings.utf_8',
|
'encodings.cp1252', 'encodings.latin_1', 'encodings.utf_8',
|
||||||
|
'encodings.mbcs', 'encodings.cp850',
|
||||||
]
|
]
|
||||||
if sys.version_info >= (3, 0):
|
if sys.version_info >= (3, 0):
|
||||||
startupModules += ['io', 'marshal', 'importlib.machinery', 'importlib.util']
|
startupModules += ['io', 'marshal', 'importlib.machinery', 'importlib.util']
|
||||||
@ -1683,7 +1684,10 @@ class PandaModuleFinder(modulefinder.ModuleFinder):
|
|||||||
Returns None if the module could not be found. """
|
Returns None if the module could not be found. """
|
||||||
|
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
return open(path, mode)
|
if sys.version_info >= (3, 0) and 'b' not in mode:
|
||||||
|
return open(path, mode, encoding='utf8')
|
||||||
|
else:
|
||||||
|
return open(path, mode)
|
||||||
|
|
||||||
# Is there a zip file along the path?
|
# Is there a zip file along the path?
|
||||||
dir, dirname = os.path.split(path)
|
dir, dirname = os.path.split(path)
|
||||||
@ -1707,7 +1711,7 @@ class PandaModuleFinder(modulefinder.ModuleFinder):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
if sys.version_info >= (3, 0) and 'b' not in mode:
|
if sys.version_info >= (3, 0) and 'b' not in mode:
|
||||||
return TextIOWrapper(fp)
|
return TextIOWrapper(fp, encoding='utf8')
|
||||||
return fp
|
return fp
|
||||||
|
|
||||||
# Look at the parent directory.
|
# Look at the parent directory.
|
||||||
|
@ -2661,16 +2661,16 @@ p3d_init = """"Python bindings for the Panda3D libraries"
|
|||||||
|
|
||||||
if GetTarget() == 'windows':
|
if GetTarget() == 'windows':
|
||||||
p3d_init += """
|
p3d_init += """
|
||||||
import os
|
if '__file__' in locals():
|
||||||
|
import os
|
||||||
|
|
||||||
bindir = os.path.join(os.path.dirname(__file__), '..', 'bin')
|
bindir = os.path.join(os.path.dirname(__file__), '..', 'bin')
|
||||||
if os.path.isfile(os.path.join(bindir, 'libpanda.dll')):
|
if os.path.isfile(os.path.join(bindir, 'libpanda.dll')):
|
||||||
if not os.environ.get('PATH'):
|
if not os.environ.get('PATH'):
|
||||||
os.environ['PATH'] = bindir
|
os.environ['PATH'] = bindir
|
||||||
else:
|
else:
|
||||||
os.environ['PATH'] = bindir + os.pathsep + os.environ['PATH']
|
os.environ['PATH'] = bindir + os.pathsep + os.environ['PATH']
|
||||||
|
del os, bindir
|
||||||
del os, bindir
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not PkgSkip("PYTHON"):
|
if not PkgSkip("PYTHON"):
|
||||||
@ -6384,6 +6384,11 @@ if PkgSkip("PYTHON") == 0:
|
|||||||
TargetAdd('deploy-stub.exe', input='frozen_dllmain.obj')
|
TargetAdd('deploy-stub.exe', input='frozen_dllmain.obj')
|
||||||
TargetAdd('deploy-stub.exe', opts=['PYTHON', 'DEPLOYSTUB', 'NOICON'])
|
TargetAdd('deploy-stub.exe', opts=['PYTHON', 'DEPLOYSTUB', 'NOICON'])
|
||||||
|
|
||||||
|
if GetTarget() == 'windows':
|
||||||
|
TargetAdd('deploy-stubw.exe', input='deploy-stub.obj')
|
||||||
|
TargetAdd('deploy-stubw.exe', input='frozen_dllmain.obj')
|
||||||
|
TargetAdd('deploy-stubw.exe', opts=['SUBSYSTEM:WINDOWS', 'PYTHON', 'DEPLOYSTUB', 'NOICON'])
|
||||||
|
|
||||||
#
|
#
|
||||||
# Generate the models directory and samples directory
|
# Generate the models directory and samples directory
|
||||||
#
|
#
|
||||||
|
@ -16,29 +16,37 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
extern void PyWinFreeze_ExeInit(void);
|
extern void PyWinFreeze_ExeInit(void);
|
||||||
extern void PyWinFreeze_ExeTerm(void);
|
extern void PyWinFreeze_ExeTerm(void);
|
||||||
|
|
||||||
extern DL_IMPORT(int) PyImport_ExtendInittab(struct _inittab *newtab);
|
|
||||||
|
|
||||||
static struct _inittab extensions[] = {
|
static struct _inittab extensions[] = {
|
||||||
{0, 0},
|
{0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
#define WIN_UNICODE
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static unsigned char *modblob = NULL;
|
static unsigned char *modblob = NULL;
|
||||||
|
|
||||||
/* Main program */
|
/* Main program */
|
||||||
|
|
||||||
int
|
#ifdef WIN_UNICODE
|
||||||
Py_FrozenMain(int argc, char **argv)
|
int Py_FrozenMain(int argc, wchar_t **argv)
|
||||||
|
#else
|
||||||
|
int Py_FrozenMain(int argc, char **argv)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
int n, sts = 1;
|
int n, sts = 1;
|
||||||
int inspect = 0;
|
int inspect = 0;
|
||||||
int unbuffered = 0;
|
int unbuffered = 0;
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3 && !defined(WIN_UNICODE)
|
||||||
int i;
|
int i;
|
||||||
char *oldloc;
|
char *oldloc;
|
||||||
wchar_t **argv_copy = NULL;
|
wchar_t **argv_copy = NULL;
|
||||||
@ -66,7 +74,7 @@ Py_FrozenMain(int argc, char **argv)
|
|||||||
setbuf(stderr, (char *)NULL);
|
setbuf(stderr, (char *)NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3 && !defined(WIN_UNICODE)
|
||||||
oldloc = setlocale(LC_ALL, NULL);
|
oldloc = setlocale(LC_ALL, NULL);
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
@ -87,7 +95,7 @@ Py_FrozenMain(int argc, char **argv)
|
|||||||
#endif /* MS_WINDOWS */
|
#endif /* MS_WINDOWS */
|
||||||
|
|
||||||
if (argc >= 1) {
|
if (argc >= 1) {
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3 && !defined(WIN_UNICODE)
|
||||||
Py_SetProgramName(argv_copy[0]);
|
Py_SetProgramName(argv_copy[0]);
|
||||||
#else
|
#else
|
||||||
Py_SetProgramName(argv[0]);
|
Py_SetProgramName(argv[0]);
|
||||||
@ -103,7 +111,7 @@ Py_FrozenMain(int argc, char **argv)
|
|||||||
fprintf(stderr, "Python %s\n%s\n",
|
fprintf(stderr, "Python %s\n%s\n",
|
||||||
Py_GetVersion(), Py_GetCopyright());
|
Py_GetVersion(), Py_GetCopyright());
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3 && !defined(WIN_UNICODE)
|
||||||
PySys_SetArgv(argc, argv_copy);
|
PySys_SetArgv(argc, argv_copy);
|
||||||
#else
|
#else
|
||||||
PySys_SetArgv(argc, argv);
|
PySys_SetArgv(argc, argv);
|
||||||
@ -127,7 +135,7 @@ Py_FrozenMain(int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
Py_Finalize();
|
Py_Finalize();
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3 && !defined(WIN_UNICODE)
|
||||||
error:
|
error:
|
||||||
if (argv_copy2) {
|
if (argv_copy2) {
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
@ -143,11 +151,22 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
#if defined(_WIN32) && PY_MAJOR_VERSION >= 3
|
||||||
main(int argc, char *argv[]) {
|
int wmain(int argc, wchar_t *argv[]) {
|
||||||
|
#else
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
#endif
|
||||||
struct _frozen *_PyImport_FrozenModules;
|
struct _frozen *_PyImport_FrozenModules;
|
||||||
unsigned int listoff, modsoff, fsize, modsize, listsize, nummods, modidx;
|
unsigned int listoff, modsoff, fsize, modsize, listsize, nummods, modidx;
|
||||||
FILE *runtime = fopen(argv[0], "rb");
|
FILE *runtime;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
wchar_t buffer[2048];
|
||||||
|
GetModuleFileNameW(NULL, buffer, 2048);
|
||||||
|
runtime = _wfopen(buffer, L"rb");
|
||||||
|
#else
|
||||||
|
runtime = fopen(argv[0], "rb");
|
||||||
|
#endif
|
||||||
|
|
||||||
// Get offsets
|
// Get offsets
|
||||||
fseek(runtime, -12, SEEK_END);
|
fseek(runtime, -12, SEEK_END);
|
||||||
@ -199,3 +218,13 @@ main(int argc, char *argv[]) {
|
|||||||
PyImport_FrozenModules = _PyImport_FrozenModules;
|
PyImport_FrozenModules = _PyImport_FrozenModules;
|
||||||
return Py_FrozenMain(argc, argv);
|
return Py_FrozenMain(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN_UNICODE
|
||||||
|
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t *lpCmdLine, int nCmdShow) {
|
||||||
|
return wmain(__argc, __wargv);
|
||||||
|
}
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpCmdLine, int nCmdShow) {
|
||||||
|
return main(__argc, __argv);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user