|
@@ -31,14 +31,12 @@ isDebugBuild = (python.lower().endswith('_d'))
|
|
|
# must be frozen in any main.exe.
|
|
# must be frozen in any main.exe.
|
|
|
startupModules = [
|
|
startupModules = [
|
|
|
'site', 'sitecustomize', 'os', 'encodings.cp1252',
|
|
'site', 'sitecustomize', 'os', 'encodings.cp1252',
|
|
|
- 'org',
|
|
|
|
|
|
|
+ 'encodings.latin_1', 'encodings.utf_8', 'io', 'org',
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
# These are missing modules that we've reported already this session.
|
|
# These are missing modules that we've reported already this session.
|
|
|
reportedMissing = {}
|
|
reportedMissing = {}
|
|
|
|
|
|
|
|
-# Our own Python source trees to watch out for.
|
|
|
|
|
-sourceTrees = ['direct']
|
|
|
|
|
|
|
|
|
|
class CompilationEnvironment:
|
|
class CompilationEnvironment:
|
|
|
""" Create an instance of this class to record the commands to
|
|
""" Create an instance of this class to record the commands to
|
|
@@ -445,7 +443,7 @@ extend_frozen_modules(const struct _frozen *new_modules, int new_count) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
%(dllexport)svoid init%(moduleName)s() {
|
|
%(dllexport)svoid init%(moduleName)s() {
|
|
|
- extend_frozen_modules(_PyImport_FrozenModules, %(newcount)s);
|
|
|
|
|
|
|
+ extend_frozen_modules(_PyImport_FrozenModules, sizeof(_PyImport_FrozenModules) / sizeof(struct _frozen));
|
|
|
Py_InitModule("%(moduleName)s", nullMethods);
|
|
Py_InitModule("%(moduleName)s", nullMethods);
|
|
|
}
|
|
}
|
|
|
"""
|
|
"""
|
|
@@ -458,7 +456,7 @@ programFile = """
|
|
|
|
|
|
|
|
%(moduleDefs)s
|
|
%(moduleDefs)s
|
|
|
|
|
|
|
|
-static struct _frozen _PyImport_FrozenModules[] = {
|
|
|
|
|
|
|
+struct _frozen _PyImport_FrozenModules[] = {
|
|
|
%(moduleList)s
|
|
%(moduleList)s
|
|
|
{NULL, NULL, 0}
|
|
{NULL, NULL, 0}
|
|
|
};
|
|
};
|
|
@@ -485,7 +483,7 @@ okMissing = [
|
|
|
'Carbon.Folder', 'Carbon.Folders', 'HouseGlobals', 'Carbon.File',
|
|
'Carbon.Folder', 'Carbon.Folders', 'HouseGlobals', 'Carbon.File',
|
|
|
'MacOS', '_emx_link', 'ce', 'mac', 'org.python.core', 'os.path',
|
|
'MacOS', '_emx_link', 'ce', 'mac', 'org.python.core', 'os.path',
|
|
|
'os2', 'posix', 'pwd', 'readline', 'riscos', 'riscosenviron',
|
|
'os2', 'posix', 'pwd', 'readline', 'riscos', 'riscosenviron',
|
|
|
- 'riscospath', 'dbm', 'fcntl', 'win32api',
|
|
|
|
|
|
|
+ 'riscospath', 'dbm', 'fcntl', 'win32api', 'usercustomize',
|
|
|
'_winreg', 'ctypes', 'ctypes.wintypes', 'nt','msvcrt',
|
|
'_winreg', 'ctypes', 'ctypes.wintypes', 'nt','msvcrt',
|
|
|
'EasyDialogs', 'SOCKS', 'ic', 'rourl2path', 'termios',
|
|
'EasyDialogs', 'SOCKS', 'ic', 'rourl2path', 'termios',
|
|
|
'OverrideFrom23._Res', 'email', 'email.Utils', 'email.Generator',
|
|
'OverrideFrom23._Res', 'email', 'email.Utils', 'email.Generator',
|
|
@@ -613,20 +611,14 @@ class Freezer:
|
|
|
|
|
|
|
|
self.mf = None
|
|
self.mf = None
|
|
|
|
|
|
|
|
- # Make sure we know how to find "direct".
|
|
|
|
|
- for sourceTree in sourceTrees:
|
|
|
|
|
- try:
|
|
|
|
|
- module = __import__(sourceTree)
|
|
|
|
|
- except:
|
|
|
|
|
- pass
|
|
|
|
|
-
|
|
|
|
|
# Actually, make sure we know how to find all of the
|
|
# Actually, make sure we know how to find all of the
|
|
|
# already-imported modules. (Some of them might do their own
|
|
# already-imported modules. (Some of them might do their own
|
|
|
# special path mangling.)
|
|
# special path mangling.)
|
|
|
for moduleName, module in sys.modules.items():
|
|
for moduleName, module in sys.modules.items():
|
|
|
if module and hasattr(module, '__path__'):
|
|
if module and hasattr(module, '__path__'):
|
|
|
path = getattr(module, '__path__')
|
|
path = getattr(module, '__path__')
|
|
|
- modulefinder.AddPackagePath(moduleName, path[0])
|
|
|
|
|
|
|
+ if path:
|
|
|
|
|
+ modulefinder.AddPackagePath(moduleName, path[0])
|
|
|
|
|
|
|
|
def excludeFrom(self, freezer):
|
|
def excludeFrom(self, freezer):
|
|
|
""" Excludes all modules that have already been processed by
|
|
""" Excludes all modules that have already been processed by
|
|
@@ -827,7 +819,7 @@ class Freezer:
|
|
|
moduleName, filename = filename, implicit = implicit,
|
|
moduleName, filename = filename, implicit = implicit,
|
|
|
guess = guess, fromSource = fromSource, text = text)
|
|
guess = guess, fromSource = fromSource, text = text)
|
|
|
|
|
|
|
|
- def done(self, compileToExe = False):
|
|
|
|
|
|
|
+ def done(self, addStartupModules = False):
|
|
|
""" Call this method after you have added all modules with
|
|
""" Call this method after you have added all modules with
|
|
|
addModule(). You may then call generateCode() or
|
|
addModule(). You may then call generateCode() or
|
|
|
writeMultifile() to dump the resulting output. After a call
|
|
writeMultifile() to dump the resulting output. After a call
|
|
@@ -838,7 +830,9 @@ class Freezer:
|
|
|
|
|
|
|
|
# If we are building an exe, we also need to implicitly
|
|
# If we are building an exe, we also need to implicitly
|
|
|
# bring in Python's startup modules.
|
|
# bring in Python's startup modules.
|
|
|
- if compileToExe:
|
|
|
|
|
|
|
+ if addStartupModules:
|
|
|
|
|
+ self.modules['_frozen_importlib'] = self.ModuleDef('importlib._bootstrap', implicit = True)
|
|
|
|
|
+
|
|
|
for moduleName in startupModules:
|
|
for moduleName in startupModules:
|
|
|
if moduleName not in self.modules:
|
|
if moduleName not in self.modules:
|
|
|
self.modules[moduleName] = self.ModuleDef(moduleName, implicit = True)
|
|
self.modules[moduleName] = self.ModuleDef(moduleName, implicit = True)
|
|
@@ -1071,8 +1065,12 @@ class Freezer:
|
|
|
|
|
|
|
|
def __addPyc(self, multifile, filename, code, compressionLevel):
|
|
def __addPyc(self, multifile, filename, code, compressionLevel):
|
|
|
if code:
|
|
if code:
|
|
|
- data = imp.get_magic() + b'\0\0\0\0' + \
|
|
|
|
|
- marshal.dumps(code)
|
|
|
|
|
|
|
+ data = imp.get_magic() + b'\0\0\0\0'
|
|
|
|
|
+
|
|
|
|
|
+ if sys.version_info >= (3, 0):
|
|
|
|
|
+ data += b'\0\0\0\0'
|
|
|
|
|
+
|
|
|
|
|
+ data += marshal.dumps(code)
|
|
|
|
|
|
|
|
stream = StringStream(data)
|
|
stream = StringStream(data)
|
|
|
multifile.addSubfile(filename, stream, compressionLevel)
|
|
multifile.addSubfile(filename, stream, compressionLevel)
|
|
@@ -1214,22 +1212,9 @@ class Freezer:
|
|
|
multifile.flush()
|
|
multifile.flush()
|
|
|
multifile.repack()
|
|
multifile.repack()
|
|
|
|
|
|
|
|
- def generateCode(self, basename, compileToExe = False):
|
|
|
|
|
- """ After a call to done(), this freezes all of the
|
|
|
|
|
- accumulated python code into either an executable program (if
|
|
|
|
|
- compileToExe is true) or a dynamic library (if compileToExe is
|
|
|
|
|
- false). The basename is the name of the file to write,
|
|
|
|
|
- without the extension.
|
|
|
|
|
-
|
|
|
|
|
- The return value is the newly-generated filename, including
|
|
|
|
|
- the filename extension. Additional extension modules are
|
|
|
|
|
- listed in self.extras. """
|
|
|
|
|
-
|
|
|
|
|
- if compileToExe:
|
|
|
|
|
- # We must have a __main__ module to make an exe file.
|
|
|
|
|
- if not self.__writingModule('__main__'):
|
|
|
|
|
- message = "Can't generate an executable without a __main__ module."
|
|
|
|
|
- raise StandardError, message
|
|
|
|
|
|
|
+ def writeCode(self, filename, initCode = ""):
|
|
|
|
|
+ """ After a call to done(), this freezes all of the accumulated
|
|
|
|
|
+ Python code into a C source file. """
|
|
|
|
|
|
|
|
self.__replacePaths()
|
|
self.__replacePaths()
|
|
|
|
|
|
|
@@ -1247,38 +1232,57 @@ class Freezer:
|
|
|
# Allow importing this module.
|
|
# Allow importing this module.
|
|
|
module = self.mf.modules.get(origName, None)
|
|
module = self.mf.modules.get(origName, None)
|
|
|
code = getattr(module, "__code__", None)
|
|
code = getattr(module, "__code__", None)
|
|
|
- if not code and moduleName in startupModules:
|
|
|
|
|
|
|
+ if code:
|
|
|
|
|
+ code = marshal.dumps(code)
|
|
|
|
|
+
|
|
|
|
|
+ mangledName = self.mangleName(moduleName)
|
|
|
|
|
+ moduleDefs.append(self.makeModuleDef(mangledName, code))
|
|
|
|
|
+ moduleList.append(self.makeModuleListEntry(mangledName, code, moduleName, module))
|
|
|
|
|
+
|
|
|
|
|
+ elif moduleName in startupModules:
|
|
|
# Forbid the loading of this startup module.
|
|
# Forbid the loading of this startup module.
|
|
|
moduleList.append(self.makeForbiddenModuleListEntry(moduleName))
|
|
moduleList.append(self.makeForbiddenModuleListEntry(moduleName))
|
|
|
|
|
+
|
|
|
else:
|
|
else:
|
|
|
- if origName in sourceTrees:
|
|
|
|
|
- # This is one of Panda3D's own Python source
|
|
|
|
|
- # trees. These are a special case: we don't
|
|
|
|
|
- # compile the __init__.py files within them,
|
|
|
|
|
- # since their only purpose is to munge the
|
|
|
|
|
- # __path__ variable anyway. Instead, we
|
|
|
|
|
- # pretend the __init__.py files are empty.
|
|
|
|
|
- code = compile('', moduleName, 'exec')
|
|
|
|
|
-
|
|
|
|
|
- if code:
|
|
|
|
|
- code = marshal.dumps(code)
|
|
|
|
|
-
|
|
|
|
|
- mangledName = self.mangleName(moduleName)
|
|
|
|
|
- moduleDefs.append(self.makeModuleDef(mangledName, code))
|
|
|
|
|
- moduleList.append(self.makeModuleListEntry(mangledName, code, moduleName, module))
|
|
|
|
|
|
|
+ # This is a module with no associated Python
|
|
|
|
|
+ # code. It must be an extension module. Get the
|
|
|
|
|
+ # filename.
|
|
|
|
|
+ extensionFilename = getattr(module, '__file__', None)
|
|
|
|
|
+ if extensionFilename:
|
|
|
|
|
+ self.extras.append((moduleName, extensionFilename))
|
|
|
else:
|
|
else:
|
|
|
|
|
+ # It doesn't even have a filename; it must
|
|
|
|
|
+ # be a built-in module. No worries about
|
|
|
|
|
+ # this one, then.
|
|
|
|
|
+ pass
|
|
|
|
|
|
|
|
- # This is a module with no associated Python
|
|
|
|
|
- # code. It must be an extension module. Get the
|
|
|
|
|
- # filename.
|
|
|
|
|
- extensionFilename = getattr(module, '__file__', None)
|
|
|
|
|
- if extensionFilename:
|
|
|
|
|
- self.extras.append((moduleName, extensionFilename))
|
|
|
|
|
- else:
|
|
|
|
|
- # It doesn't even have a filename; it must
|
|
|
|
|
- # be a built-in module. No worries about
|
|
|
|
|
- # this one, then.
|
|
|
|
|
- pass
|
|
|
|
|
|
|
+ text = programFile % {
|
|
|
|
|
+ 'moduleDefs': '\n'.join(moduleDefs),
|
|
|
|
|
+ 'moduleList': '\n'.join(moduleList),
|
|
|
|
|
+ 'initCode': initCode
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if filename is not None:
|
|
|
|
|
+ file = open(filename, 'w')
|
|
|
|
|
+ file.write(text)
|
|
|
|
|
+ file.close()
|
|
|
|
|
+
|
|
|
|
|
+ def generateCode(self, basename, compileToExe = False):
|
|
|
|
|
+ """ After a call to done(), this freezes all of the
|
|
|
|
|
+ accumulated python code into either an executable program (if
|
|
|
|
|
+ compileToExe is true) or a dynamic library (if compileToExe is
|
|
|
|
|
+ false). The basename is the name of the file to write,
|
|
|
|
|
+ without the extension.
|
|
|
|
|
+
|
|
|
|
|
+ The return value is the newly-generated filename, including
|
|
|
|
|
+ the filename extension. Additional extension modules are
|
|
|
|
|
+ listed in self.extras. """
|
|
|
|
|
+
|
|
|
|
|
+ if compileToExe:
|
|
|
|
|
+ # We must have a __main__ module to make an exe file.
|
|
|
|
|
+ if not self.__writingModule('__main__'):
|
|
|
|
|
+ message = "Can't generate an executable without a __main__ module."
|
|
|
|
|
+ raise StandardError, message
|
|
|
|
|
|
|
|
filename = basename + self.sourceExtension
|
|
filename = basename + self.sourceExtension
|
|
|
|
|
|
|
@@ -1317,21 +1321,12 @@ class Freezer:
|
|
|
|
|
|
|
|
initCode = dllInitCode % {
|
|
initCode = dllInitCode % {
|
|
|
'moduleName' : os.path.basename(basename),
|
|
'moduleName' : os.path.basename(basename),
|
|
|
- 'newcount' : len(moduleList),
|
|
|
|
|
'dllexport' : dllexport,
|
|
'dllexport' : dllexport,
|
|
|
'dllimport' : dllimport,
|
|
'dllimport' : dllimport,
|
|
|
}
|
|
}
|
|
|
compileFunc = self.cenv.compileDll
|
|
compileFunc = self.cenv.compileDll
|
|
|
|
|
|
|
|
- text = programFile % {
|
|
|
|
|
- 'moduleDefs' : '\n'.join(moduleDefs),
|
|
|
|
|
- 'moduleList' : '\n'.join(moduleList),
|
|
|
|
|
- 'initCode' : initCode,
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- file = open(filename, 'w')
|
|
|
|
|
- file.write(text)
|
|
|
|
|
- file.close()
|
|
|
|
|
|
|
+ self.writeCode(filename, initCode=initCode)
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
compileFunc(filename, basename)
|
|
compileFunc(filename, basename)
|
|
@@ -1390,9 +1385,9 @@ class PandaModuleFinder(modulefinder.ModuleFinder):
|
|
|
def __init__(self, *args, **kw):
|
|
def __init__(self, *args, **kw):
|
|
|
modulefinder.ModuleFinder.__init__(self, *args, **kw)
|
|
modulefinder.ModuleFinder.__init__(self, *args, **kw)
|
|
|
|
|
|
|
|
- def find_module(self, name, path, parent=None):
|
|
|
|
|
|
|
+ def find_module(self, name, path, *args, **kwargs):
|
|
|
try:
|
|
try:
|
|
|
- return modulefinder.ModuleFinder.find_module(self, name, path, parent = parent)
|
|
|
|
|
|
|
+ return modulefinder.ModuleFinder.find_module(self, name, path, *args, **kwargs)
|
|
|
except ImportError:
|
|
except ImportError:
|
|
|
# It wasn't found through the normal channels. Maybe it's
|
|
# It wasn't found through the normal channels. Maybe it's
|
|
|
# one of ours, or maybe it's frozen?
|
|
# one of ours, or maybe it's frozen?
|