def GetRealPathCase(self, path): TmpPath = path.rstrip(os.sep) PathParts = TmpPath.split(os.sep) if len(PathParts) == 0: return path if len(PathParts) == 1: if PathParts[0].strip().endswith(':'): return PathParts[0].upper() # Relative dir, list . current dir Dirs = os.listdir('.') for Dir in Dirs: if Dir.upper() == PathParts[0].upper(): return Dir if PathParts[0].strip().endswith(':'): PathParts[0] = PathParts[0].upper() ParentDir = PathParts[0] RealPath = ParentDir if PathParts[0] == '': RealPath = os.sep ParentDir = os.sep PathParts.remove(PathParts[0]) # need to remove the parent for Part in PathParts: Dirs = os.listdir(ParentDir + os.sep) for Dir in Dirs: if Dir.upper() == Part.upper(): RealPath += os.sep RealPath += Dir break ParentDir += os.sep ParentDir += Dir return RealPath
def GetAllIncludeFiles(Db): IncludeList = GetAllIncludeDirs(Db) IncludeFileList = [] for Dir in IncludeList: if os.path.isdir(Dir): SubDir = os.listdir(Dir) for Item in SubDir: if os.path.isfile(Item): IncludeFileList.append(Item) return IncludeFileList
def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj): GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref") GuidXRefFile = [] PkgGuidDict = {} GuidDict = {} ModuleList = [] FileGuidList = [] VariableGuidSet = set() for Arch in ArchList: PlatformDataBase = BuildDb.BuildObject[ GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] PkgList = GenFdsGlobalVariable.WorkSpace.GetPackageList( GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag) for P in PkgList: PkgGuidDict.update(P.Guids) for Name, Guid in PlatformDataBase.Pcds: Pcd = PlatformDataBase.Pcds[Name, Guid] if Pcd.Type in [TAB_PCDS_DYNAMIC_HII, TAB_PCDS_DYNAMIC_EX_HII]: for SkuId in Pcd.SkuInfoList: Sku = Pcd.SkuInfoList[SkuId] if Sku.VariableGuid in VariableGuidSet: continue VariableGuidSet.add(Sku.VariableGuid) if Sku.VariableGuid and Sku.VariableGuid in PkgGuidDict.keys( ): GuidDict[Sku.VariableGuid] = PkgGuidDict[ Sku.VariableGuid] for ModuleFile in PlatformDataBase.Modules: Module = BuildDb.BuildObject[ModuleFile, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] if Module in ModuleList: continue else: ModuleList.append(Module) if GlobalData.gGuidPattern.match(ModuleFile.BaseName): GuidXRefFile.append("%s %s\n" % (ModuleFile.BaseName, Module.BaseName)) else: GuidXRefFile.append("%s %s\n" % (Module.Guid, Module.BaseName)) GuidDict.update(Module.Protocols) GuidDict.update(Module.Guids) GuidDict.update(Module.Ppis) for FvName in FdfParserObj.Profile.FvDict: for FfsObj in FdfParserObj.Profile.FvDict[FvName].FfsList: if not isinstance(FfsObj, FileStatement): InfPath = PathClass( NormPath( mws.join(GenFdsGlobalVariable.WorkSpaceDir, FfsObj.InfFileName))) FdfModule = BuildDb.BuildObject[ InfPath, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag] if FdfModule in ModuleList: continue else: ModuleList.append(FdfModule) GuidXRefFile.append( "%s %s\n" % (FdfModule.Guid, FdfModule.BaseName)) GuidDict.update(FdfModule.Protocols) GuidDict.update(FdfModule.Guids) GuidDict.update(FdfModule.Ppis) else: FileStatementGuid = FfsObj.NameGuid if FileStatementGuid in FileGuidList: continue else: FileGuidList.append(FileStatementGuid) Name = [] FfsPath = os.path.join(GenFdsGlobalVariable.FvDir, 'Ffs') FfsPath = glob( os.path.join(FfsPath, FileStatementGuid) + TAB_STAR) if not FfsPath: continue if not os.path.exists(FfsPath[0]): continue MatchDict = {} ReFileEnds = compile( '\S+(.ui)$|\S+(fv.sec.txt)$|\S+(.pe32.txt)$|\S+(.te.txt)$|\S+(.pic.txt)$|\S+(.raw.txt)$|\S+(.ffs.txt)$' ) FileList = os.listdir(FfsPath[0]) for File in FileList: Match = ReFileEnds.search(File) if Match: for Index in range(1, 8): if Match.group(Index) and Match.group( Index) in MatchDict: MatchDict[Match.group(Index)].append( File) elif Match.group(Index): MatchDict[Match.group(Index)] = [File] if not MatchDict: continue if '.ui' in MatchDict: for File in MatchDict['.ui']: with open(os.path.join(FfsPath[0], File), 'rb') as F: F.read() length = F.tell() F.seek(4) TmpStr = unpack( '%dh' % ((length - 4) // 2), F.read()) Name = ''.join(chr(c) for c in TmpStr[:-1]) else: FileList = [] if 'fv.sec.txt' in MatchDict: FileList = MatchDict['fv.sec.txt'] elif '.pe32.txt' in MatchDict: FileList = MatchDict['.pe32.txt'] elif '.te.txt' in MatchDict: FileList = MatchDict['.te.txt'] elif '.pic.txt' in MatchDict: FileList = MatchDict['.pic.txt'] elif '.raw.txt' in MatchDict: FileList = MatchDict['.raw.txt'] elif '.ffs.txt' in MatchDict: FileList = MatchDict['.ffs.txt'] else: pass for File in FileList: with open(os.path.join(FfsPath[0], File), 'r') as F: Name.append((F.read().split()[-1])) if not Name: continue Name = ' '.join(Name) if isinstance(Name, type( [])) else Name GuidXRefFile.append("%s %s\n" % (FileStatementGuid, Name)) # Append GUIDs, Protocols, and PPIs to the Xref file GuidXRefFile.append("\n") for key, item in GuidDict.items(): GuidXRefFile.append( "%s %s\n" % (GuidStructureStringToGuidString(item).upper(), key)) if GuidXRefFile: GuidXRefFile = ''.join(GuidXRefFile) SaveFileOnChange(GuidXRefFileName, GuidXRefFile, False) GenFdsGlobalVariable.InfLogger( "\nGUID cross reference file can be found at %s" % GuidXRefFileName) elif os.path.exists(GuidXRefFileName): os.remove(GuidXRefFileName)