2
0
David Rose 16 жил өмнө
parent
commit
752487a7ff

+ 3 - 3
direct/src/showutil/FreezeTool.py

@@ -611,7 +611,7 @@ class Freezer:
             # A normal, explicit module name.
             # A normal, explicit module name.
             self.modules[newName] = self.ModuleDef(token, moduleName, filename = filename)
             self.modules[newName] = self.ModuleDef(token, moduleName, filename = filename)
 
 
-    def done(self):
+    def done(self, compileToExe = 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
@@ -620,9 +620,9 @@ class Freezer:
         
         
         assert self.mf == None
         assert self.mf == None
 
 
-        # If we have a __main__ module, 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 '__main__' in self.modules:
+        if compileToExe:
             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(self.MTAuto, moduleName)
                     self.modules[moduleName] = self.ModuleDef(self.MTAuto, moduleName)

+ 72 - 3
direct/src/showutil/Packager.py

@@ -314,7 +314,8 @@ class Packager:
             self.sourceFilenames[file.filename] = file
             self.sourceFilenames[file.filename] = file
 
 
             if not file.filename.exists():
             if not file.filename.exists():
-                self.packager.notify.warning("No such file: %s" % (file.filename))
+                if not file.isExcluded(self):
+                    self.packager.notify.warning("No such file: %s" % (file.filename))
                 return
                 return
             
             
             self.files.append(file)
             self.files.append(file)
@@ -484,7 +485,63 @@ class Packager:
             and executables that might include implicit dependencies
             and executables that might include implicit dependencies
             on other so's.  Tries to determine those dependencies,
             on other so's.  Tries to determine those dependencies,
             and adds them back into the filelist. """
             and adds them back into the filelist. """
-            pass
+
+            # We walk through the list as we modify it.  That's OK,
+            # because we want to follow the transitive closure of
+            # dependencies anyway.
+            for file in self.files:
+                if not file.executable:
+                    continue
+                
+                if file.isExcluded(self):
+                    # Skip this file.
+                    continue
+
+                tempFile = Filename.temporary('', 'p3d_')
+                command = 'ldd "%s" >"%s"' % (
+                    file.filename.toOsSpecific(),
+                    tempFile.toOsSpecific())
+                try:
+                    os.system(command)
+                except:
+                    pass
+                filenames = None
+
+                if tempFile.exists():
+                    filenames = self.__parseDependenciesPosix(tempFile)
+                if filenames is None:
+                    print "Unable to determine dependencies from %s" % (file.filename)
+                    continue
+
+                # Attempt to resolve the dependent filename relative
+                # to the original filename, before we resolve it along
+                # the PATH.
+                path = DSearchPath(Filename(file.filename.getDirname()))
+
+                for filename in filenames:
+                    filename = Filename.fromOsSpecific(filename)
+                    filename.resolveFilename(path)
+                    self.addFile(filename, newName = filename.getBasename(),
+                                 executable = True)
+                    
+        def __parseDependenciesPosix(self, tempFile):
+            """ Reads the indicated temporary file, the output from
+            ldd, to determine the list of so's this executable file
+            depends on. """
+
+            lines = open(tempFile.toOsSpecific(), 'rU').readlines()
+
+            filenames = []
+            for line in lines:
+                line = line.strip()
+                s = line.find(' => ')
+                if s == -1:
+                    continue
+
+                line = line[:s].strip()
+                filenames.append(line)
+
+            return filenames
 
 
         def addExtensionModules(self):
         def addExtensionModules(self):
             """ Adds the extension modules detected by the freezer to
             """ Adds the extension modules detected by the freezer to
@@ -872,9 +929,13 @@ class Packager:
             self.addPosixSearchPath(self.dllPath, "DYLD_LIBRARY_PATH")
             self.addPosixSearchPath(self.dllPath, "DYLD_LIBRARY_PATH")
             self.addPosixSearchPath(self.dllPath, "LD_LIBRARY_PATH")
             self.addPosixSearchPath(self.dllPath, "LD_LIBRARY_PATH")
             self.addPosixSearchPath(self.dllPath, "PATH")
             self.addPosixSearchPath(self.dllPath, "PATH")
+            self.dllPath.appendDirectory('/lib')
+            self.dllPath.appendDirectory('/usr/lib')
         else:
         else:
             self.addPosixSearchPath(self.dllPath, "LD_LIBRARY_PATH")
             self.addPosixSearchPath(self.dllPath, "LD_LIBRARY_PATH")
             self.addPosixSearchPath(self.dllPath, "PATH")
             self.addPosixSearchPath(self.dllPath, "PATH")
+            self.dllPath.appendDirectory('/lib')
+            self.dllPath.appendDirectory('/usr/lib')
 
 
         # The platform string.
         # The platform string.
         self.platform = PandaSystem.getPlatform()
         self.platform = PandaSystem.getPlatform()
@@ -961,6 +1022,14 @@ class Packager:
         # filenames.
         # filenames.
         self.excludeSystemGlobs = [
         self.excludeSystemGlobs = [
             GlobPattern('d3dx9_*.dll'),
             GlobPattern('d3dx9_*.dll'),
+
+            GlobPattern('linux-gate.so*'),
+            GlobPattern('libdl.so*'),
+            GlobPattern('libm.so*'),
+            GlobPattern('libc.so*'),
+            GlobPattern('libGL.so*'),
+            GlobPattern('libGLU.so*'),
+            GlobPattern('libX*.so*'),
             ]
             ]
 
 
         # A Loader for loading models.
         # A Loader for loading models.
@@ -1773,7 +1842,7 @@ class Packager:
                 freezer.addModule(package.mainModule, newName = '__main__')
                 freezer.addModule(package.mainModule, newName = '__main__')
             else:
             else:
                 freezer.modules['__main__'] = freezer.modules[package.mainModule]
                 freezer.modules['__main__'] = freezer.modules[package.mainModule]
-        freezer.done()
+        freezer.done(compileToExe = compileToExe)
 
 
         if not package.dryRun:
         if not package.dryRun:
             dirname = ''
             dirname = ''

+ 1 - 1
direct/src/showutil/pfreeze.py

@@ -113,7 +113,7 @@ else:
     freezer.addModule(startfile, newName = '__main__')
     freezer.addModule(startfile, newName = '__main__')
     compileToExe = True
     compileToExe = True
 
 
-freezer.done()
+freezer.done(compileToExe = compileToExe)
 
 
 if outputType == 'mf':
 if outputType == 'mf':
     freezer.writeMultifile(basename)
     freezer.writeMultifile(basename)