def GenerateModulePage(self, pObj, infObj, configFile, isLib): """ Generate page for a module/library. @param infObj INF file object for module/library @param configFile doxygen config file object @param isLib Whether this module is libary @param module doxygen page object """ workspace = pObj.GetWorkspace() refDecObjs = [] for obj in infObj.GetSectionObjectsByName('packages'): decObj = dec.DECFile(os.path.join(workspace, obj.GetPath())) if not decObj: ErrorMsg ('Fail to create pacakge object for %s' % obj.GetPackageName()) continue if not decObj.Parse(): ErrorMsg ('Fail to load package object for %s' % obj.GetPackageName()) continue refDecObjs.append(decObj) modPage = doxygen.Page('%s' % infObj.GetBaseName(), 'module_%s' % infObj.GetBaseName()) modPage.AddDescription(infObj.GetFileHeader()) basicInfSection = doxygen.Section('BasicModuleInformation', 'Basic Module Information') desc = "<TABLE>" for obj in infObj.GetSectionObjectsByName('defines'): key = obj.GetKey() value = obj.GetValue() if key not in _inf_key_description_mapping_table.keys(): continue if key == 'LIBRARY_CLASS' and value.find('|') != -1: clsname, types = value.split('|') desc += '<TR>' desc += '<TD><B>%s</B></TD>' % _inf_key_description_mapping_table[key] desc += '<TD>%s</TD>' % clsname desc += '</TR>' desc += '<TR>' desc += '<TD><B>Supported Module Types</B></TD>' desc += '<TD>%s</TD>' % types desc += '</TR>' else: desc += '<TR>' desc += '<TD><B>%s</B></TD>' % _inf_key_description_mapping_table[key] if key == 'EFI_SPECIFICATION_VERSION' and value == '0x00020000': value = '2.0' desc += '<TD>%s</TD>' % value desc += '</TR>' desc += '</TABLE>' basicInfSection.AddDescription(desc) modPage.AddSection(basicInfSection) # Add protocol section data = [] for obj in infObj.GetSectionObjectsByName('pcd', self._arch): data.append(obj.GetPcdName().strip()) if len(data) != 0: s = doxygen.Section('Pcds', 'Pcds') desc = "<TABLE>" desc += '<TR><TD><B>PCD Name</B></TD><TD><B>TokenSpace</B></TD><TD><B>Package</B></TD></TR>' for item in data: desc += '<TR>' desc += '<TD>%s</TD>' % item.split('.')[1] desc += '<TD>%s</TD>' % item.split('.')[0] pkgbasename = self.SearchPcdPackage(item, workspace, refDecObjs) desc += '<TD>%s</TD>' % pkgbasename desc += '</TR>' desc += "</TABLE>" s.AddDescription(desc) modPage.AddSection(s) # Add protocol section #sects = infObj.GetSectionByString('protocol') data = [] #for sect in sects: for obj in infObj.GetSectionObjectsByName('protocol', self._arch): data.append(obj.GetName().strip()) if len(data) != 0: s = doxygen.Section('Protocols', 'Protocols') desc = "<TABLE>" desc += '<TR><TD><B>Name</B></TD><TD><B>Package</B></TD></TR>' for item in data: desc += '<TR>' desc += '<TD>%s</TD>' % item pkgbasename = self.SearchProtocolPackage(item, workspace, refDecObjs) desc += '<TD>%s</TD>' % pkgbasename desc += '</TR>' desc += "</TABLE>" s.AddDescription(desc) modPage.AddSection(s) # Add ppi section #sects = infObj.GetSectionByString('ppi') data = [] #for sect in sects: for obj in infObj.GetSectionObjectsByName('ppi', self._arch): data.append(obj.GetName().strip()) if len(data) != 0: s = doxygen.Section('Ppis', 'Ppis') desc = "<TABLE>" desc += '<TR><TD><B>Name</B></TD><TD><B>Package</B></TD></TR>' for item in data: desc += '<TR>' desc += '<TD>%s</TD>' % item pkgbasename = self.SearchPpiPackage(item, workspace, refDecObjs) desc += '<TD>%s</TD>' % pkgbasename desc += '</TR>' desc += "</TABLE>" s.AddDescription(desc) modPage.AddSection(s) # Add guid section #sects = infObj.GetSectionByString('guid') data = [] #for sect in sects: for obj in infObj.GetSectionObjectsByName('guid', self._arch): data.append(obj.GetName().strip()) if len(data) != 0: s = doxygen.Section('Guids', 'Guids') desc = "<TABLE>" desc += '<TR><TD><B>Name</B></TD><TD><B>Package</B></TD></TR>' for item in data: desc += '<TR>' desc += '<TD>%s</TD>' % item pkgbasename = self.SearchGuidPackage(item, workspace, refDecObjs) desc += '<TD>%s</TD>' % pkgbasename desc += '</TR>' desc += "</TABLE>" s.AddDescription(desc) modPage.AddSection(s) section = doxygen.Section('LibraryClasses', 'Library Classes') desc = "<TABLE>" desc += '<TR><TD><B>Name</B></TD><TD><B>Type</B></TD><TD><B>Package</B></TD><TD><B>Header File</B></TD></TR>' if isLib: desc += '<TR>' desc += '<TD>%s</TD>' % infObj.GetProduceLibraryClass() desc += '<TD>Produce</TD>' try: pkgname, hPath = self.SearchLibraryClassHeaderFile(infObj.GetProduceLibraryClass(), workspace, refDecObjs) except: self.Log ('fail to get package header file for lib class %s' % infObj.GetProduceLibraryClass()) pkgname = 'NULL' hPath = 'NULL' desc += '<TD>%s</TD>' % pkgname if hPath != "NULL": desc += '<TD>\link %s \endlink</TD>' % hPath else: desc += '<TD>%s</TD>' % hPath desc += '</TR>' for lcObj in infObj.GetSectionObjectsByName('libraryclasses', self._arch): desc += '<TR>' desc += '<TD>%s</TD>' % lcObj.GetClass() retarr = self.SearchLibraryClassHeaderFile(lcObj.GetClass(), workspace, refDecObjs) if retarr is not None: pkgname, hPath = retarr else: self.Log('Fail find the library class %s definition from module %s dependent package!' % (lcObj.GetClass(), infObj.GetFilename()), 'error') pkgname = 'NULL' hPath = 'NULL' desc += '<TD>Consume</TD>' desc += '<TD>%s</TD>' % pkgname desc += '<TD>\link %s \endlink</TD>' % hPath desc += '</TR>' desc += "</TABLE>" section.AddDescription(desc) modPage.AddSection(section) section = doxygen.Section('SourceFiles', 'Source Files') section.AddDescription('<ul>\n') for obj in infObj.GetSourceObjects(self._arch, self._tooltag): sPath = infObj.GetModuleRootPath() sPath = os.path.join(sPath, obj.GetSourcePath()).replace('\\', '/').strip() if sPath.lower().endswith('.uni') or sPath.lower().endswith('.s') or sPath.lower().endswith('.asm') or sPath.lower().endswith('.nasm'): newPath = self.TranslateUniFile(sPath) configFile.AddFile(newPath) newPath = newPath[len(pObj.GetWorkspace()) + 1:] section.AddDescription('<li> \link %s \endlink </li>' % newPath) else: self.ProcessSourceFileForInclude(sPath, pObj, configFile, infObj) sPath = sPath[len(pObj.GetWorkspace()) + 1:] section.AddDescription('<li>\link %s \endlink </li>' % sPath) section.AddDescription('</ul>\n') modPage.AddSection(section) #sects = infObj.GetSectionByString('depex') data = [] #for sect in sects: for obj in infObj.GetSectionObjectsByName('depex'): data.append(str(obj)) if len(data) != 0: s = doxygen.Section('DependentSection', 'Module Dependencies') s.AddDescription('<br>'.join(data)) modPage.AddSection(s) return modPage
def ProcessSourceFileForInclude(self, path, pObj, configFile, infObj=None): """ @param path the analysising file full path @param pObj package object @param configFile doxygen config file. """ if gInGui: wx.Yield() if not os.path.exists(path): ErrorMsg('Source file path %s does not exist!' % path) return if configFile.FileExists(path): return try: f = open(path, 'r') lines = f.readlines() f.close() except IOError: ErrorMsg('Fail to open file %s' % path) return configFile.AddFile(path) no = 0 for no in xrange(len(lines)): if len(lines[no].strip()) == 0: continue if lines[no].strip()[:2] in ['##', '//', '/*', '*/']: continue index = lines[no].lower().find('include') #mo = IncludePattern.finditer(lines[no].lower()) mo = re.match(r"^#\s*include\s+[<\"]([\\/\w.]+)[>\"]$", lines[no].strip().lower()) if not mo: continue mo = re.match(r"^[#\w\s]+[<\"]([\\/\w.]+)[>\"]$", lines[no].strip()) filePath = mo.groups()[0] if filePath is None or len(filePath) == 0: continue # find header file in module's path firstly. fullPath = None if os.path.exists(os.path.join(os.path.dirname(path), filePath)): # Find the file in current directory fullPath = os.path.join(os.path.dirname(path), filePath).replace('\\', '/') else: # find in depedent package's include path incObjs = pObj.GetFileObj().GetSectionObjectsByName('includes') for incObj in incObjs: incPath = os.path.join(pObj.GetFileObj().GetPackageRootPath(), incObj.GetPath()).strip() incPath = os.path.realpath(os.path.join(incPath, filePath)) if os.path.exists(incPath): fullPath = incPath break if infObj is not None: pkgInfObjs = infObj.GetSectionObjectsByName('packages') for obj in pkgInfObjs: decObj = dec.DECFile(os.path.join(pObj.GetWorkspace(), obj.GetPath())) if not decObj: ErrorMsg ('Fail to create pacakge object for %s' % obj.GetPackageName()) continue if not decObj.Parse(): ErrorMsg ('Fail to load package object for %s' % obj.GetPackageName()) continue incObjs = decObj.GetSectionObjectsByName('includes') for incObj in incObjs: incPath = os.path.join(decObj.GetPackageRootPath(), incObj.GetPath()).replace('\\', '/') if os.path.exists(os.path.join(incPath, filePath)): fullPath = os.path.join(os.path.join(incPath, filePath)) break if fullPath is not None: break if fullPath is None and self.IsVerbose(): self.Log('Can not resolve header file %s for file %s in package %s\n' % (filePath, path, pObj.GetFileObj().GetFilename()), 'error') return else: fullPath = fullPath.replace('\\', '/') if self.IsVerbose(): self.Log('Preprocessing: Add include file %s for file %s\n' % (fullPath, path)) #LogMsg ('Preprocessing: Add include file %s for file %s' % (fullPath, path)) self.ProcessSourceFileForInclude(fullPath, pObj, configFile, infObj)