From 752487a7ff78c8c377daf61ba3fc6976cdb03ea6 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 14 Aug 2009 00:14:47 +0000 Subject: [PATCH] now build on linux --- direct/src/showutil/FreezeTool.py | 6 +-- direct/src/showutil/Packager.py | 75 +++++++++++++++++++++++++++++-- direct/src/showutil/pfreeze.py | 2 +- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/direct/src/showutil/FreezeTool.py b/direct/src/showutil/FreezeTool.py index 4a7e4026d7..d3026c5eea 100644 --- a/direct/src/showutil/FreezeTool.py +++ b/direct/src/showutil/FreezeTool.py @@ -611,7 +611,7 @@ class Freezer: # A normal, explicit module name. 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 addModule(). You may then call generateCode() or writeMultifile() to dump the resulting output. After a call @@ -620,9 +620,9 @@ class Freezer: 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. - if '__main__' in self.modules: + if compileToExe: for moduleName in startupModules: if moduleName not in self.modules: self.modules[moduleName] = self.ModuleDef(self.MTAuto, moduleName) diff --git a/direct/src/showutil/Packager.py b/direct/src/showutil/Packager.py index 55ab778fa1..43c1ef586c 100644 --- a/direct/src/showutil/Packager.py +++ b/direct/src/showutil/Packager.py @@ -314,7 +314,8 @@ class Packager: self.sourceFilenames[file.filename] = file 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 self.files.append(file) @@ -484,7 +485,63 @@ class Packager: and executables that might include implicit dependencies on other so's. Tries to determine those dependencies, 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): """ 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, "LD_LIBRARY_PATH") self.addPosixSearchPath(self.dllPath, "PATH") + self.dllPath.appendDirectory('/lib') + self.dllPath.appendDirectory('/usr/lib') else: self.addPosixSearchPath(self.dllPath, "LD_LIBRARY_PATH") self.addPosixSearchPath(self.dllPath, "PATH") + self.dllPath.appendDirectory('/lib') + self.dllPath.appendDirectory('/usr/lib') # The platform string. self.platform = PandaSystem.getPlatform() @@ -961,6 +1022,14 @@ class Packager: # filenames. self.excludeSystemGlobs = [ 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. @@ -1773,7 +1842,7 @@ class Packager: freezer.addModule(package.mainModule, newName = '__main__') else: freezer.modules['__main__'] = freezer.modules[package.mainModule] - freezer.done() + freezer.done(compileToExe = compileToExe) if not package.dryRun: dirname = '' diff --git a/direct/src/showutil/pfreeze.py b/direct/src/showutil/pfreeze.py index cbe2da4e0d..20093cc26a 100755 --- a/direct/src/showutil/pfreeze.py +++ b/direct/src/showutil/pfreeze.py @@ -113,7 +113,7 @@ else: freezer.addModule(startfile, newName = '__main__') compileToExe = True -freezer.done() +freezer.done(compileToExe = compileToExe) if outputType == 'mf': freezer.writeMultifile(basename)