Browse Source

deploy-ng: support nested extension modules; omit unused panda3d.x modules

rdb 9 years ago
parent
commit
2dab76131c
2 changed files with 20 additions and 16 deletions
  1. 6 12
      direct/src/showutil/FreezeTool.py
  2. 14 4
      direct/src/showutil/dist.py

+ 6 - 12
direct/src/showutil/FreezeTool.py

@@ -1563,9 +1563,10 @@ class Freezer:
 
         if self.platform.startswith('win'):
             target = basename + '.exe'
+            modext = '.pyd'
         else:
             target = basename
-
+            modext = '.so'
 
         # Generate export table.
         moduleBlob = bytes()
@@ -1595,25 +1596,18 @@ class Freezer:
             # it is the former.
             extensionFilename = getattr(module, '__file__', None)
 
-            if extensionFilename or self.linkExtensionModules:
+            if extensionFilename:
                 self.extras.append((moduleName, extensionFilename))
 
             # If it is a submodule of a frozen module, Python will have
             # trouble importing it as a builtin module.  Synthesize a frozen
-            # module that loads it as builtin.
-            if '.' in moduleName and self.linkExtensionModules:
-                code = compile('import sys;del sys.modules["%s"];import imp;imp.init_builtin("%s")' % (moduleName, moduleName), moduleName, 'exec')
+            # module that loads it dynamically.
+            if '.' in moduleName:
+                code = compile('import sys;del sys.modules["%s"];import imp;imp.load_dynamic("%s", "%s%s")' % (moduleName, moduleName, moduleName, modext), moduleName, 'exec')
                 code = marshal.dumps(code)
                 moduleList.append(make_module_list_entry(code, codeOffset, moduleName, module))
                 moduleBlob += code
                 codeOffset += len(code)
-            elif '.' in moduleName:
-                # Nothing we can do about this case except warn the user they
-                # are in for some trouble.
-                print('WARNING: Python cannot import extension modules under '
-                      'frozen Python packages; %s will be inaccessible.  '
-                      'passing either -l to link in extension modules or use '
-                      '-x %s to exclude the entire package.' % (moduleName, moduleName.split('.')[0]))
 
         # Build from pre-built binary stub
         dtool_path = Filename(ExecutionEnvironment.get_dtool_name()).to_os_specific()

+ 14 - 4
direct/src/showutil/dist.py

@@ -38,18 +38,28 @@ class build(distutils.command.build.build):
             # Create runtime
             freezer = FreezeTool.Freezer()
             freezer.addModule('__main__', filename=startfile)
-            freezer.excludeModule('panda3d')
             for exmod in self.distribution.exclude_modules:
                 freezer.excludeModule(exmod)
             freezer.done(addStartupModules=True)
             freezer.generateRuntimeFromStub(basename)
 
+            # Copy extension modules
+            for module, source_path in freezer.extras:
+                if source_path is None:
+                    # Built-in module.
+                    continue
+
+                # Rename panda3d/core.pyd to panda3d.core.pyd
+                basename = os.path.basename(source_path)
+                if '.' in module:
+                    basename = module.rsplit('.', 1)[0] + '.' + basename
+
+                target_path = os.path.join(builddir, basename)
+                distutils.file_util.copy_file(source_path, target_path)
+
             # Copy Panda3D libs
             dtool_fn = p3d.Filename(p3d.ExecutionEnvironment.get_dtool_name())
             libdir = os.path.dirname(dtool_fn.to_os_specific())
-            src = os.path.normpath(os.path.join(libdir, '..', 'panda3d'))
-            dst = os.path.join(builddir, 'panda3d')
-            distutils.dir_util.copy_tree(src, dst)
 
             for item in os.listdir(libdir):
                 if '.so.' in item or item.endswith('.dll') or item.endswith('.dylib') or 'libpandagl' in item: