def GenDepex(ModuleObject): # # generate [Depex] section # NewSectionDict = Sdict() Content = '' for Depex in ModuleObject.GetPeiDepex() + ModuleObject.GetDxeDepex( ) + ModuleObject.GetSmmDepex(): HelpTextList = Depex.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr) SupArchList = Depex.GetSupArchList() SupModList = Depex.GetModuleType() Expression = Depex.GetDepex() Statement = CommentStr + Expression SupArchList.sort() KeyList = [] if not SupArchList: SupArchList.append(DT.TAB_ARCH_COMMON.lower()) if not SupModList: KeyList = SupArchList else: for ModuleType in SupModList: for Arch in SupArchList: KeyList.append( ConvertArchForInstall(Arch) + '.' + ModuleType) for Key in KeyList: if Key in NewSectionDict: NewSectionDict[Key] = NewSectionDict[Key] + [Statement] else: NewSectionDict[Key] = [Statement] Content += GenSection('Depex', NewSectionDict, False) return Content
def GenSpecialSections(ObjectList, SectionName, UserExtensionsContent=''): # # generate section # Content = '' NewSectionDict = {} for Obj in ObjectList: # # Generate comment # CommentStr = '' HelpTextList = Obj.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr) if SectionName == 'Hob': Type = Obj.GetHobType() elif SectionName == 'Event': Type = Obj.GetEventType() elif SectionName == 'BootMode': Type = Obj.GetSupportedBootModes() else: assert(SectionName) Usage = Obj.GetUsage() # If the content already in UserExtensionsContent then ignore if '[%s]' % SectionName in UserExtensionsContent and Type in UserExtensionsContent: return '' Statement = ' ' + Type + ' ## ' + Usage if CommentStr in ['#\n', '#\n#\n']: CommentStr = '#\n#\n#\n' # # the first head comment line should start with '##\n', if it starts with '#\n', then add one '#' # else add '##\n' to meet the format defined in INF spec # if CommentStr.startswith('#\n'): CommentStr = '#' + CommentStr elif CommentStr: CommentStr = '##\n' + CommentStr if CommentStr and not CommentStr.endswith('\n#\n'): CommentStr = CommentStr + '#\n' NewStateMent = CommentStr + Statement SupArch = Obj.GetSupArchList() SupArch.sort() SortedArch = ' '.join(SupArch) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [NewStateMent] else: NewSectionDict[SortedArch] = [NewStateMent] SectionContent = GenSection(SectionName, NewSectionDict) SectionContent = SectionContent.strip() if SectionContent: Content = '# ' + ('\n' + '# ').join(GetSplitValueList(SectionContent, '\n')) Content = Content.lstrip() # # add a return to differentiate it between other possible sections # if Content: Content += '\n' return Content
def testNormalCase5(self): ExpectedStr = 'Hello world1' HelpTextObj = TextObject() HelpTextObj.SetLang(TAB_LANGUAGE_EN_US) HelpTextObj.SetString(ExpectedStr) HelpTextList = [HelpTextObj] HelpStr = 'Hello unknown world' HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) HelpTextList.append(HelpTextObj) HelpStr = 'Hello mysterious world' HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) HelpTextList.append(HelpTextObj) Result = _GetHelpStr(HelpTextList) self.assertEqual(Result, ExpectedStr) HelpTextList.sort() self.assertEqual(Result, ExpectedStr) HelpTextList.sort(reverse=True) self.assertEqual(Result, ExpectedStr)
def GenDepex(ModuleObject): # # generate [Depex] section # NewSectionDict = Sdict() Content = '' for Depex in ModuleObject.GetPeiDepex() + ModuleObject.GetDxeDepex() + ModuleObject.GetSmmDepex(): HelpTextList = Depex.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr) SupArchList = Depex.GetSupArchList() SupModList = Depex.GetModuleType() Expression = Depex.GetDepex() Statement = CommentStr + Expression SupArchList.sort() KeyList = [] if not SupArchList: SupArchList.append(DT.TAB_ARCH_COMMON.lower()) if not SupModList: KeyList = SupArchList else: for ModuleType in SupModList: for Arch in SupArchList: KeyList.append(ConvertArchForInstall(Arch) + '.' + ModuleType) for Key in KeyList: if Key in NewSectionDict: NewSectionDict[Key] = NewSectionDict[Key] + [Statement] else: NewSectionDict[Key] = [Statement] Content += GenSection('Depex', NewSectionDict, False) return Content
def testNormalCase5(self): ExpectedStr = 'Hello world1' HelpTextObj = TextObject() HelpTextObj.SetLang(LANGUAGE_EN_US) HelpTextObj.SetString(ExpectedStr) HelpTextList = [HelpTextObj] HelpStr = 'Hello unknown world' HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) HelpTextList.append(HelpTextObj) HelpStr = 'Hello mysterious world' HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) HelpTextList.append(HelpTextObj) Result = _GetHelpStr(HelpTextList) self.assertEqual(Result, ExpectedStr) HelpTextList.sort() self.assertEqual(Result, ExpectedStr) HelpTextList.sort(reverse=True) self.assertEqual(Result, ExpectedStr)
def GenGuidSections(GuidObjList): # # generate [Guids] section # Content = '' GuidDict = Sdict() for Guid in GuidObjList: HelpTextList = Guid.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CName = Guid.GetCName() FFE = Guid.GetFeatureFlag() Statement = CName if FFE: Statement += '|' + FFE Usage = Guid.GetUsage() GuidType = Guid.GetGuidTypeList()[0] VariableName = Guid.GetVariableName() # # Differentiate the generic comment and usage comment as multiple generic comment need to be put at first # if Usage == DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED: # generate list of generic comment Comment = GenGenericCommentF(HelpStr) else: # generate list of other comment Comment = HelpStr.replace('\n', ' ') Comment = Comment.strip() if Comment: Comment = ' # ' + Comment else: Comment = '' if Usage != DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED: Comment = '## ' + Usage + Comment elif GuidType == 'Variable': Comment = '## ' + Usage + ' ## ' + GuidType + ':' + VariableName + Comment else: Comment = '## ' + Usage + ' ## ' + GuidType + Comment if Comment: Comment += '\n' # # merge duplicate items # ArchList = Guid.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if (Statement, SortedArch) in GuidDict: PreviousComment = GuidDict[Statement, SortedArch] Comment = PreviousComment + Comment GuidDict[Statement, SortedArch] = Comment NewSectionDict = GenMetaFileMisc.TransferDict(GuidDict, 'INF_GUID') # # generate the section contents # if NewSectionDict: Content = GenSection('Guids', NewSectionDict) return Content
def GenProtocolPPiSections(ObjList, IsProtocol): Content = '' Dict = Sdict() for Object in ObjList: HelpTextList = Object.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CName = Object.GetCName() FFE = Object.GetFeatureFlag() Statement = CName if FFE: Statement += '|' + FFE Usage = Object.GetUsage() Notify = Object.GetNotify() # # Differentiate the generic comment and usage comment as consecutive generic comment need to be put together # if Usage == DT.ITEM_UNDEFINED and Notify == '': # generate list of generic comment Comment = GenGenericCommentF(HelpStr) else: # generate list of other comment Comment = HelpStr.replace('\n', ' ') Comment = Comment.strip() if Comment: Comment = ' # ' + Comment else: Comment = '' if Usage == DT.ITEM_UNDEFINED and not Comment and Notify == '': Comment = '' else: if Notify: Comment = '## ' + Usage + ' ## ' + 'NOTIFY' + Comment else: Comment = '## ' + Usage + Comment if Comment: Comment += '\n' # # merge duplicate items # ArchList = Object.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if (Statement, SortedArch) in Dict: PreviousComment = Dict[Statement, SortedArch] Comment = PreviousComment + Comment Dict[Statement, SortedArch] = Comment NewSectionDict = GenMetaFileMisc.TransferDict(Dict, 'INF_PPI_PROTOCOL') # # generate the section contents # if NewSectionDict: if IsProtocol: Content = GenSection('Protocols', NewSectionDict) else: Content = GenSection('Ppis', NewSectionDict) return Content
def testNormalCase1(self): HelpStr = 'Hello world' HelpTextObj = TextObject() HelpTextObj.SetLang(LANGUAGE_EN_US) HelpTextObj.SetString(HelpStr) HelpTextList = [HelpTextObj] Result = _GetHelpStr(HelpTextList) self.assertEqual(Result, HelpStr)
def testNormalCase1(self): HelpStr = 'Hello world' HelpTextObj = TextObject() HelpTextObj.SetLang(TAB_LANGUAGE_EN_US) HelpTextObj.SetString(HelpStr) HelpTextList = [HelpTextObj] Result = _GetHelpStr(HelpTextList) self.assertEqual(Result, HelpStr)
def GenSpecialSections(ObjectList, SectionName): # # generate section # Content = "" NewSectionDict = {} for Obj in ObjectList: # # Generate comment # CommentStr = "" HelpTextList = Obj.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr) if SectionName == "Hob": Type = Obj.GetHobType() elif SectionName == "Event": Type = Obj.GetEventType() elif SectionName == "BootMode": Type = Obj.GetSupportedBootModes() else: assert SectionName Usage = Obj.GetUsage() Statement = " " + Type + " ## " + Usage if CommentStr in ["#\n", "#\n#\n"]: CommentStr = "#\n#\n#\n" # # the first head comment line should start with '##\n', if it starts with '#\n', then add one '#' # else add '##\n' to meet the format defined in INF spec # if CommentStr.startswith("#\n"): CommentStr = "#" + CommentStr elif CommentStr: CommentStr = "##\n" + CommentStr if CommentStr and not CommentStr.endswith("\n#\n"): CommentStr = CommentStr + "#\n" NewStateMent = CommentStr + Statement SupArch = Obj.GetSupArchList() SupArch.sort() SortedArch = " ".join(SupArch) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [NewStateMent] else: NewSectionDict[SortedArch] = [NewStateMent] SectionContent = GenSection(SectionName, NewSectionDict) SectionContent = SectionContent.strip() if SectionContent: Content = "# " + ("\n" + "# ").join(GetSplitValueList(SectionContent, "\n")) Content = Content.lstrip() # # add two empty line after the generated section content to differentiate it between other possible sections # if Content: Content += "\n#\n#\n" return Content
def testNormalCase4(self): ExpectedStr = 'Hello world1' HelpTextObj = TextObject() HelpTextObj.SetLang('eng') HelpTextObj.SetString(ExpectedStr) HelpTextList = [HelpTextObj] HelpStr = 'Hello world' HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) HelpTextList.append(HelpTextObj) Result = _GetHelpStr(HelpTextList) self.assertEqual(Result, ExpectedStr)
def testNormalCase4(self): ExpectedStr = 'Hello world1' HelpTextObj = TextObject() HelpTextObj.SetLang(TAB_LANGUAGE_ENG) HelpTextObj.SetString(ExpectedStr) HelpTextList = [HelpTextObj] HelpStr = 'Hello world' HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) HelpTextList.append(HelpTextObj) Result = _GetHelpStr(HelpTextList) self.assertEqual(Result, ExpectedStr)
def testNormalCase3(self): HelpStr = "Hello world" HelpTextObj = TextObject() HelpTextObj.SetLang("") HelpTextObj.SetString(HelpStr) HelpTextList = [HelpTextObj] ExpectedStr = "Hello world1" HelpTextObj = TextObject() HelpTextObj.SetLang("eng") HelpTextObj.SetString(ExpectedStr) HelpTextList.append(HelpTextObj) Result = _GetHelpStr(HelpTextList) self.assertEqual(Result, ExpectedStr)
def testNormalCase3(self): HelpStr = 'Hello world' HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) HelpTextList = [HelpTextObj] ExpectedStr = 'Hello world1' HelpTextObj = TextObject() HelpTextObj.SetLang('eng') HelpTextObj.SetString(ExpectedStr) HelpTextList.append(HelpTextObj) Result = _GetHelpStr(HelpTextList) self.assertEqual(Result, ExpectedStr)
def testNormalCase3(self): HelpStr = 'Hello world' HelpTextObj = TextObject() HelpTextObj.SetLang('') HelpTextObj.SetString(HelpStr) HelpTextList = [HelpTextObj] ExpectedStr = 'Hello world1' HelpTextObj = TextObject() HelpTextObj.SetLang(TAB_LANGUAGE_ENG) HelpTextObj.SetString(ExpectedStr) HelpTextList.append(HelpTextObj) Result = _GetHelpStr(HelpTextList) self.assertEqual(Result, ExpectedStr)
def GenGuidProtocolPpi(Package, Content): # # generate [Guids] section # NewSectionDict = {} LeftOffset = 46 # Get the line offset need # If the real one < the min one, use the min one # else use the real one for Guid in Package.GetGuidList(): if len(Guid.GetCName()) > LeftOffset: LeftOffset = len(Guid.GetCName()) # Generate for Guid in Package.GetGuidList(): # # Generate generic comment # HelpTextList = Guid.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr, 2) Statement = CommentStr CName = Guid.GetCName() Value = GuidStringToGuidStructureString(Guid.GetGuid()) Statement += CName.ljust(LeftOffset) + ' = ' + Value # # generate tail comment # if Guid.GetSupModuleList(): Statement += GenDecTailComment(Guid.GetSupModuleList()) ArchList = sorted(Guid.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('Guids', NewSectionDict, True, True) # # generate [Protocols] section # NewSectionDict = {} LeftOffset = 46 # Get the line offset need # If the real one < the min one, use the min one # else use the real one for Protocol in Package.GetProtocolList(): if len(Protocol.GetCName()) > LeftOffset: LeftOffset = len(Protocol.GetCName()) for Protocol in Package.GetProtocolList(): # # Generate generic comment # HelpTextList = Protocol.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr, 2) Statement = CommentStr CName = Protocol.GetCName() Value = GuidStringToGuidStructureString(Protocol.GetGuid()) Statement += CName.ljust(LeftOffset) + ' = ' + Value # # generate tail comment # if Protocol.GetSupModuleList(): Statement += GenDecTailComment(Protocol.GetSupModuleList()) ArchList = sorted(Protocol.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('Protocols', NewSectionDict, True, True) # # generate [Ppis] section # NewSectionDict = {} LeftOffset = 46 # Get the line offset need # If the real one < the min one, use the min one # else use the real one for Ppi in Package.GetPpiList(): if len(Ppi.GetCName()) > LeftOffset: LeftOffset = len(Ppi.GetCName()) for Ppi in Package.GetPpiList(): # # Generate generic comment # HelpTextList = Ppi.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr, 2) Statement = CommentStr CName = Ppi.GetCName() Value = GuidStringToGuidStructureString(Ppi.GetGuid()) Statement += CName.ljust(LeftOffset) + ' = ' + Value # # generate tail comment # if Ppi.GetSupModuleList(): Statement += GenDecTailComment(Ppi.GetSupModuleList()) ArchList = sorted(Ppi.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('Ppis', NewSectionDict, True, True) return Content
def PackageToDec(Package): # # Init global information for the file # ContainerFile = Package.GetFullPath() Content = '' # # generate header comment section # Content += GenHeaderCommentSection(Package.GetAbstract(), \ Package.GetDescription(), \ Package.GetCopyright(), \ Package.GetLicense()) # # for each section, maintain a dict, sorted arch will be its key, #statement list will be its data # { 'Arch1 Arch2 Arch3': [statement1, statement2], # 'Arch1' : [statement1, statement3] # } # # # generate [Defines] section # NewSectionDict = {TAB_ARCH_COMMON : []} SpecialItemList = [] Statement = '%s = %s' % (TAB_DEC_DEFINES_DEC_SPECIFICATION, '0x00010017') SpecialItemList.append(Statement) BaseName = Package.GetBaseName() if BaseName.startswith('.') or BaseName.startswith('-'): BaseName = '_' + BaseName Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_NAME, BaseName) SpecialItemList.append(Statement) Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_VERSION, Package.GetVersion()) SpecialItemList.append(Statement) Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_GUID, Package.GetGuid()) SpecialItemList.append(Statement) for SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + SpecialItemList Content += GenSection('Defines', NewSectionDict) # # generate [Includes] section # NewSectionDict = {} IncludeArchList = Package.GetIncludeArchList() if IncludeArchList: for Path, ArchList in IncludeArchList: Statement = Path ArchList.sort() SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [ConvertPath(Statement)] else: NewSectionDict[SortedArch] = [ConvertPath(Statement)] Content += GenSection('Includes', NewSectionDict) Content = GenGuidProtocolPpi(Package, Content) # # generate [LibraryClasses] section # NewSectionDict = {} for LibraryClass in Package.GetLibraryClassList(): # # Generate generic comment # HelpTextList = LibraryClass.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) if HelpStr: HelpStr = '@libraryclass ' + HelpStr CommentStr = GenGenericCommentF(HelpStr, 2) Statement = CommentStr Name = LibraryClass.GetLibraryClass() IncludeHeader = LibraryClass.GetIncludeHeader() Statement += Name + '|' + ConvertPath(IncludeHeader) # # generate tail comment # if LibraryClass.GetSupModuleList(): Statement += \ GenDecTailComment(LibraryClass.GetSupModuleList()) ArchList = LibraryClass.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('LibraryClasses', NewSectionDict) Content = GenPcd(Package, Content) # # generate [UserExtensions] section # NewSectionDict = {} for UserExtension in Package.GetUserExtensionList(): Statement = UserExtension.GetStatement() if not Statement: continue SectionList = [] SectionName = 'UserExtensions' UserId = UserExtension.GetUserID() if UserId: if '.' in UserId: UserId = '"' + UserId + '"' SectionName += '.' + UserId if UserExtension.GetIdentifier(): SectionName += '.' + '"' + UserExtension.GetIdentifier() + '"' if not UserExtension.GetSupArchList(): SectionList.append(SectionName) else: for Arch in UserExtension.GetSupArchList(): SectionList.append(SectionName + '.' + Arch) SectionName = ', '.join(SectionList) SectionName = ''.join(['[', SectionName, ']\n']) Content += '\n\n' + SectionName + Statement SaveFileOnChange(ContainerFile, Content, False) return ContainerFile
def GenPcdSections(ModuleObject): Content = '' if not GlobalData.gIS_BINARY_INF: # # for each Pcd Itemtype, maintain a dict so the same type will be grouped # together # ItemTypeDict = {} for Pcd in ModuleObject.GetPcdList(): HelpTextList = Pcd.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) Statement = '' CName = Pcd.GetCName() TokenSpaceGuidCName = Pcd.GetTokenSpaceGuidCName() DefaultValue = Pcd.GetDefaultValue() ItemType = Pcd.GetItemType() if ItemType in ItemTypeDict: Dict = ItemTypeDict[ItemType] else: Dict = Sdict() ItemTypeDict[ItemType] = Dict FFE = Pcd.GetFeatureFlag() Statement += TokenSpaceGuidCName + '.' + CName if DefaultValue: Statement += '|' + DefaultValue if FFE: Statement += '|' + FFE elif FFE: Statement += '||' + FFE # # Generate comment # Usage = Pcd.GetValidUsage() # if FeatureFlag Pcd, then assume all Usage is CONSUMES if ItemType == DT.TAB_INF_FEATURE_PCD: Usage = DT.USAGE_ITEM_CONSUMES if Usage == DT.ITEM_UNDEFINED: # generate list of generic comment Comment = GenGenericCommentF(HelpStr) else: # generate list of other comment Comment = HelpStr.replace('\n', ' ') Comment = Comment.strip() if Comment: Comment = ' # ' + Comment else: Comment = '' Comment = '## ' + Usage + Comment if Comment: Comment += '\n' # # Merge duplicate entries # ArchList = Pcd.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if (Statement, SortedArch) in Dict: PreviousComment = Dict[Statement, SortedArch] Comment = PreviousComment + Comment Dict[Statement, SortedArch] = Comment for ItemType in ItemTypeDict: # First we need to transfer the Dict to use SortedArch as key Dict = ItemTypeDict[ItemType] NewSectionDict = GenMetaFileMisc.TransferDict(Dict, 'INF_PCD') if NewSectionDict: Content += GenSection(ItemType, NewSectionDict) # # For AsBuild INF files # else: Content += GenAsBuiltPacthPcdSections(ModuleObject) Content += GenAsBuiltPcdExSections(ModuleObject) return Content
def GenLibraryClasses(ModuleObject): # # generate [LibraryClasses] section # Content = '' NewSectionDict = {} if not GlobalData.gIS_BINARY_INF: for LibraryClass in ModuleObject.GetLibraryClassList(): if LibraryClass.GetUsage() == DT.USAGE_ITEM_PRODUCES: continue # # Generate generic comment # HelpTextList = LibraryClass.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr) Statement = CommentStr Name = LibraryClass.GetLibraryClass() FFE = LibraryClass.GetFeatureFlag() Statement += Name if FFE: Statement += '|' + FFE ModuleList = LibraryClass.GetSupModuleList() ArchList = LibraryClass.GetSupArchList() for Index in xrange(0, len(ArchList)): ArchList[Index] = ConvertArchForInstall(ArchList[Index]) ArchList.sort() SortedArch = ' '.join(ArchList) KeyList = [] if not ModuleList or IsAllModuleList(ModuleList): KeyList = [SortedArch] else: ModuleString = DT.TAB_VALUE_SPLIT.join(l for l in ModuleList) if not ArchList: SortedArch = DT.TAB_ARCH_COMMON KeyList = [SortedArch + '.' + ModuleString] else: KeyList = [Arch + '.' + ModuleString for Arch in ArchList] for Key in KeyList: if Key in NewSectionDict: NewSectionDict[Key] = NewSectionDict[Key] + [Statement] else: NewSectionDict[Key] = [Statement] Content += GenSection('LibraryClasses', NewSectionDict) else: LibraryClassDict = {} for BinaryFile in ModuleObject.GetBinaryFileList(): if not BinaryFile.AsBuiltList: continue for LibraryItem in BinaryFile.AsBuiltList[0].LibraryInstancesList: Statement = '# Guid: ' + LibraryItem.Guid + ' Version: ' + LibraryItem.Version if len(BinaryFile.SupArchList) == 0: if LibraryClassDict.has_key('COMMON') and Statement not in LibraryClassDict['COMMON']: LibraryClassDict['COMMON'].append(Statement) else: LibraryClassDict['COMMON'] = ['## @LIB_INSTANCES'] LibraryClassDict['COMMON'].append(Statement) else: for Arch in BinaryFile.SupArchList: if LibraryClassDict.has_key(Arch): if Statement not in LibraryClassDict[Arch]: LibraryClassDict[Arch].append(Statement) else: continue else: LibraryClassDict[Arch] = ['## @LIB_INSTANCES'] LibraryClassDict[Arch].append(Statement) Content += GenSection('LibraryClasses', LibraryClassDict) return Content
def GenGuidProtocolPpi(Package, Content): # # generate [Guids] section # NewSectionDict = {} for Guid in Package.GetGuidList(): # # Generate generic comment # HelpTextList = Guid.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr, 2) Statement = CommentStr CName = Guid.GetCName() Value = GuidStringToGuidStructureString(Guid.GetGuid()) Statement += CName + ' = ' + Value # # generate tail comment # if Guid.GetSupModuleList(): Statement += GenDecTailComment(Guid.GetSupModuleList()) ArchList = Guid.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('Guids', NewSectionDict) # # generate [Protocols] section # NewSectionDict = {} for Protocol in Package.GetProtocolList(): # # Generate generic comment # HelpTextList = Protocol.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr, 2) Statement = CommentStr CName = Protocol.GetCName() Value = GuidStringToGuidStructureString(Protocol.GetGuid()) Statement += CName + ' = ' + Value # # generate tail comment # if Protocol.GetSupModuleList(): Statement += GenDecTailComment(Protocol.GetSupModuleList()) ArchList = Protocol.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('Protocols', NewSectionDict) # # generate [Ppis] section # NewSectionDict = {} for Ppi in Package.GetPpiList(): # # Generate generic comment # HelpTextList = Ppi.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr, 2) Statement = CommentStr CName = Ppi.GetCName() Value = GuidStringToGuidStructureString(Ppi.GetGuid()) Statement += CName + ' = ' + Value # # generate tail comment # if Ppi.GetSupModuleList(): Statement += GenDecTailComment(Ppi.GetSupModuleList()) ArchList = Ppi.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('Ppis', NewSectionDict) return Content
def GenLibraryClasses(ModuleObject): # # generate [LibraryClasses] section # Content = '' NewSectionDict = {} if not GlobalData.gIS_BINARY_INF: for LibraryClass in ModuleObject.GetLibraryClassList(): if LibraryClass.GetUsage() == DT.USAGE_ITEM_PRODUCES: continue # # Generate generic comment # HelpTextList = LibraryClass.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr) Statement = CommentStr Name = LibraryClass.GetLibraryClass() FFE = LibraryClass.GetFeatureFlag() Statement += Name if FFE: Statement += '|' + FFE ModuleList = LibraryClass.GetSupModuleList() ArchList = LibraryClass.GetSupArchList() for Index in xrange(0, len(ArchList)): ArchList[Index] = ConvertArchForInstall(ArchList[Index]) ArchList.sort() SortedArch = ' '.join(ArchList) KeyList = [] if not ModuleList or IsAllModuleList(ModuleList): KeyList = [SortedArch] else: ModuleString = DT.TAB_VALUE_SPLIT.join(l for l in ModuleList) if not ArchList: SortedArch = DT.TAB_ARCH_COMMON KeyList = [SortedArch + '.' + ModuleString] else: KeyList = [Arch + '.' + ModuleString for Arch in ArchList] for Key in KeyList: if Key in NewSectionDict: NewSectionDict[Key] = NewSectionDict[Key] + [Statement] else: NewSectionDict[Key] = [Statement] Content += GenSection('LibraryClasses', NewSectionDict) else: LibraryClassDict = {} for BinaryFile in ModuleObject.GetBinaryFileList(): if not BinaryFile.AsBuiltList: continue for LibraryItem in BinaryFile.AsBuiltList[0].LibraryInstancesList: Statement = '# Guid: ' + LibraryItem.Guid + ' Version: ' + LibraryItem.Version if len(BinaryFile.SupArchList) == 0: if LibraryClassDict.has_key('COMMON'): LibraryClassDict['COMMON'].append(Statement) else: LibraryClassDict['COMMON'] = ['## @LIB_INSTANCES'] LibraryClassDict['COMMON'].append(Statement) else: for Arch in BinaryFile.SupArchList: if LibraryClassDict.has_key(Arch): LibraryClassDict[Arch].append(Statement) else: LibraryClassDict[Arch] = ['## @LIB_INSTANCES'] LibraryClassDict[Arch].append(Statement) Content += GenSection('LibraryClasses', LibraryClassDict) return Content
def PackageToDec(Package): # # Init global information for the file # ContainerFile = Package.GetFullPath() Content = '' # # generate header comment section # Content += GenHeaderCommentSection(Package.GetAbstract(), \ Package.GetDescription(), \ Package.GetCopyright(), \ Package.GetLicense()) # # for each section, maintain a dict, sorted arch will be its key, #statement list will be its data # { 'Arch1 Arch2 Arch3': [statement1, statement2], # 'Arch1' : [statement1, statement3] # } # # # generate [Defines] section # NewSectionDict = {TAB_ARCH_COMMON: []} SpecialItemList = [] Statement = '%s = %s' % (TAB_DEC_DEFINES_DEC_SPECIFICATION, '0x00010017') SpecialItemList.append(Statement) BaseName = Package.GetBaseName() if BaseName.startswith('.') or BaseName.startswith('-'): BaseName = '_' + BaseName Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_NAME, BaseName) SpecialItemList.append(Statement) Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_VERSION, Package.GetVersion()) SpecialItemList.append(Statement) Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_GUID, Package.GetGuid()) SpecialItemList.append(Statement) for SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + SpecialItemList Content += GenSection('Defines', NewSectionDict) # # generate [Includes] section # NewSectionDict = {} IncludeArchList = Package.GetIncludeArchList() if IncludeArchList: for Path, ArchList in IncludeArchList: Statement = Path ArchList.sort() SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [ConvertPath(Statement)] else: NewSectionDict[SortedArch] = [ConvertPath(Statement)] Content += GenSection('Includes', NewSectionDict) Content = GenGuidProtocolPpi(Package, Content) # # generate [LibraryClasses] section # NewSectionDict = {} for LibraryClass in Package.GetLibraryClassList(): # # Generate generic comment # HelpTextList = LibraryClass.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) if HelpStr: HelpStr = '@libraryclass ' + HelpStr CommentStr = GenGenericCommentF(HelpStr, 2) Statement = CommentStr Name = LibraryClass.GetLibraryClass() IncludeHeader = LibraryClass.GetIncludeHeader() Statement += Name + '|' + ConvertPath(IncludeHeader) # # generate tail comment # if LibraryClass.GetSupModuleList(): Statement += \ GenDecTailComment(LibraryClass.GetSupModuleList()) ArchList = LibraryClass.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('LibraryClasses', NewSectionDict) Content = GenPcd(Package, Content) # # generate [UserExtensions] section # NewSectionDict = {} for UserExtension in Package.GetUserExtensionList(): Statement = UserExtension.GetStatement() if not Statement: continue SectionList = [] SectionName = 'UserExtensions' UserId = UserExtension.GetUserID() if UserId: if '.' in UserId: UserId = '"' + UserId + '"' SectionName += '.' + UserId if UserExtension.GetIdentifier(): SectionName += '.' + '"' + UserExtension.GetIdentifier() + '"' if not UserExtension.GetSupArchList(): SectionList.append(SectionName) else: for Arch in UserExtension.GetSupArchList(): SectionList.append(SectionName + '.' + Arch) SectionName = ', '.join(SectionList) SectionName = ''.join(['[', SectionName, ']\n']) Content += '\n\n' + SectionName + Statement SaveFileOnChange(ContainerFile, Content, False) return ContainerFile
def GenPcd(Package, Content): # # generate [Pcd] section # <TokenSpcCName>.<TokenCName>|<Value>|<DatumType>|<Token> # ValidUsageDict = {} for Pcd in Package.GetPcdList(): # # Generate generic comment # HelpTextList = Pcd.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CommentStr = GenGenericCommentF(HelpStr, 2) PromptList = Pcd.GetPromptList() PromptStr = _GetHelpStr(PromptList) CommentStr += GenGenericCommentF(PromptStr.strip(), 1, True) PcdErrList = Pcd.GetPcdErrorsList() for PcdErr in PcdErrList: CommentStr += GenPcdErrComment(PcdErr) Statement = CommentStr CName = Pcd.GetCName() TokenSpaceGuidCName = Pcd.GetTokenSpaceGuidCName() DefaultValue = Pcd.GetDefaultValue() DatumType = Pcd.GetDatumType() Token = Pcd.GetToken() ValidUsage = Pcd.GetValidUsage() if ValidUsage == 'FeaturePcd': ValidUsage = 'PcdsFeatureFlag' elif ValidUsage == 'PatchPcd': ValidUsage = 'PcdsPatchableInModule' elif ValidUsage == 'FixedPcd': ValidUsage = 'PcdsFixedAtBuild' elif ValidUsage == 'Pcd': ValidUsage = 'PcdsDynamic' elif ValidUsage == 'PcdEx': ValidUsage = 'PcdsDynamicEx' if ValidUsage in ValidUsageDict: NewSectionDict = ValidUsageDict[ValidUsage] else: NewSectionDict = {} ValidUsageDict[ValidUsage] = NewSectionDict Statement += TokenSpaceGuidCName + '.' + CName Statement += '|' + DefaultValue Statement += '|' + DatumType Statement += '|' + Token # # generate tail comment # if Pcd.GetSupModuleList(): Statement += GenDecTailComment(Pcd.GetSupModuleList()) ArchList = sorted(Pcd.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] for ValidUsage in ValidUsageDict: Content += GenSection(ValidUsage, ValidUsageDict[ValidUsage], True, True) return Content
def PackageToDec(Package, DistHeader=None): # # Init global information for the file # ContainerFile = Package.GetFullPath() Content = '' # # Generate file header # PackageAbstract = GetLocalValue(Package.GetAbstract()) PackageDescription = GetLocalValue(Package.GetDescription()) PackageCopyright = '' PackageLicense = '' for (Lang, Copyright) in Package.GetCopyright(): if Lang: pass PackageCopyright = Copyright for (Lang, License) in Package.GetLicense(): if Lang: pass PackageLicense = License if not PackageAbstract and DistHeader: PackageAbstract = GetLocalValue(DistHeader.GetAbstract()) if not PackageDescription and DistHeader: PackageDescription = GetLocalValue(DistHeader.GetDescription()) if not PackageCopyright and DistHeader: for (Lang, Copyright) in DistHeader.GetCopyright(): PackageCopyright = Copyright if not PackageLicense and DistHeader: for (Lang, License) in DistHeader.GetLicense(): PackageLicense = License # # Generate header comment section of DEC file # Content += GenHeaderCommentSection(PackageAbstract, \ PackageDescription, \ PackageCopyright, \ PackageLicense).replace('\r\n', '\n') # # Generate Binary header # for UserExtension in Package.GetUserExtensionList(): if UserExtension.GetUserID() == TAB_BINARY_HEADER_USERID \ and UserExtension.GetIdentifier() == TAB_BINARY_HEADER_IDENTIFIER: PackageBinaryAbstract = GetLocalValue( UserExtension.GetBinaryAbstract()) PackageBinaryDescription = GetLocalValue( UserExtension.GetBinaryDescription()) PackageBinaryCopyright = '' PackageBinaryLicense = '' for (Lang, Copyright) in UserExtension.GetBinaryCopyright(): PackageBinaryCopyright = Copyright for (Lang, License) in UserExtension.GetBinaryLicense(): PackageBinaryLicense = License if PackageBinaryAbstract and PackageBinaryDescription and \ PackageBinaryCopyright and PackageBinaryLicense: Content += GenHeaderCommentSection(PackageBinaryAbstract, PackageBinaryDescription, PackageBinaryCopyright, PackageBinaryLicense, True) # # Generate PACKAGE_UNI_FILE for the Package # FileHeader = GenHeaderCommentSection(PackageAbstract, PackageDescription, PackageCopyright, PackageLicense, False, \ TAB_COMMENT_EDK1_SPLIT) GenPackageUNIEncodeFile(Package, FileHeader) # # for each section, maintain a dict, sorted arch will be its key, #statement list will be its data # { 'Arch1 Arch2 Arch3': [statement1, statement2], # 'Arch1' : [statement1, statement3] # } # # # generate [Defines] section # LeftOffset = 31 NewSectionDict = {TAB_ARCH_COMMON: []} SpecialItemList = [] Statement = (u'%s ' % TAB_DEC_DEFINES_DEC_SPECIFICATION ).ljust(LeftOffset) + u'= %s' % '0x00010017' SpecialItemList.append(Statement) BaseName = Package.GetBaseName() if BaseName.startswith('.') or BaseName.startswith('-'): BaseName = '_' + BaseName Statement = (u'%s ' % TAB_DEC_DEFINES_PACKAGE_NAME ).ljust(LeftOffset) + u'= %s' % BaseName SpecialItemList.append(Statement) Statement = (u'%s ' % TAB_DEC_DEFINES_PACKAGE_VERSION ).ljust(LeftOffset) + u'= %s' % Package.GetVersion() SpecialItemList.append(Statement) Statement = (u'%s ' % TAB_DEC_DEFINES_PACKAGE_GUID ).ljust(LeftOffset) + u'= %s' % Package.GetGuid() SpecialItemList.append(Statement) if Package.UNIFlag: Statement = (u'%s ' % TAB_DEC_DEFINES_PKG_UNI_FILE).ljust( LeftOffset) + u'= %s' % Package.GetBaseName() + '.uni' SpecialItemList.append(Statement) for SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + SpecialItemList Content += GenSection('Defines', NewSectionDict) # # generate [Includes] section # NewSectionDict = {} IncludeArchList = Package.GetIncludeArchList() if IncludeArchList: for Path, ArchList in IncludeArchList: Statement = Path ArchList.sort() SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [ConvertPath(Statement)] else: NewSectionDict[SortedArch] = [ConvertPath(Statement)] Content += GenSection('Includes', NewSectionDict) # # generate [guids][protocols][ppis] sections # Content = GenGuidProtocolPpi(Package, Content) # # generate [LibraryClasses] section # NewSectionDict = {} for LibraryClass in Package.GetLibraryClassList(): # # Generate generic comment # HelpTextList = LibraryClass.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) if HelpStr: HelpStr = '@libraryclass' + HelpStr CommentStr = GenGenericCommentF(HelpStr, 2, False, True) Statement = CommentStr Name = LibraryClass.GetLibraryClass() IncludeHeader = LibraryClass.GetIncludeHeader() Statement += Name + '|' + ConvertPath(IncludeHeader) # # generate tail comment # if LibraryClass.GetSupModuleList(): Statement += \ GenDecTailComment(LibraryClass.GetSupModuleList()) ArchList = sorted(LibraryClass.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('LibraryClasses', NewSectionDict, True, True) # # Generate '# [Error.<TokenSpcCName>]' section # Content = GenPcdErrorMsgSection(Package, Content) Content = GenPcd(Package, Content) # # generate [UserExtensions] section # NewSectionDict = {} for UserExtension in Package.GetUserExtensionList(): if UserExtension.GetUserID() == TAB_BINARY_HEADER_USERID and \ UserExtension.GetIdentifier() == TAB_BINARY_HEADER_IDENTIFIER: continue # Generate Private Section first if UserExtension.GetUserID( ) == DT.TAB_INTEL and UserExtension.GetIdentifier() == DT.TAB_PRIVATE: Content += '\n' + UserExtension.GetStatement() continue Statement = UserExtension.GetStatement() if not Statement: continue else: LineList = Statement.split('\n') NewStatement = "" for Line in LineList: NewStatement += " %s\n" % Line SectionList = [] SectionName = 'UserExtensions' UserId = UserExtension.GetUserID() if UserId: if '.' in UserId: UserId = '"' + UserId + '"' SectionName += '.' + UserId if UserExtension.GetIdentifier(): SectionName += '.' + '"' + UserExtension.GetIdentifier() + '"' if not UserExtension.GetSupArchList(): SectionList.append(SectionName) else: for Arch in UserExtension.GetSupArchList(): SectionList.append(SectionName + '.' + Arch) SectionName = ', '.join(SectionList) SectionName = ''.join(['[', SectionName, ']\n']) Content += '\n' + SectionName + NewStatement SaveFileOnChange(ContainerFile, Content, False) if DistHeader.ReadOnly: os.chmod(ContainerFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) else: os.chmod( ContainerFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH) return ContainerFile
def PackageToDec(Package, DistHeader = None): # # Init global information for the file # ContainerFile = Package.GetFullPath() Content = '' # # Generate file header # PackageAbstract = GetLocalValue(Package.GetAbstract()) PackageDescription = GetLocalValue(Package.GetDescription()) PackageCopyright = '' PackageLicense = '' for (Lang, Copyright) in Package.GetCopyright(): if Lang: pass PackageCopyright = Copyright for (Lang, License) in Package.GetLicense(): if Lang: pass PackageLicense = License if not PackageAbstract and DistHeader: PackageAbstract = GetLocalValue(DistHeader.GetAbstract()) if not PackageDescription and DistHeader: PackageDescription = GetLocalValue(DistHeader.GetDescription()) if not PackageCopyright and DistHeader: for (Lang, Copyright) in DistHeader.GetCopyright(): PackageCopyright = Copyright if not PackageLicense and DistHeader: for (Lang, License) in DistHeader.GetLicense(): PackageLicense = License # # Generate header comment section of DEC file # Content += GenHeaderCommentSection(PackageAbstract, \ PackageDescription, \ PackageCopyright, \ PackageLicense).replace('\r\n', '\n') # # Generate Binary header # for UserExtension in Package.GetUserExtensionList(): if UserExtension.GetUserID() == TAB_BINARY_HEADER_USERID \ and UserExtension.GetIdentifier() == TAB_BINARY_HEADER_IDENTIFIER: PackageBinaryAbstract = GetLocalValue(UserExtension.GetBinaryAbstract()) PackageBinaryDescription = GetLocalValue(UserExtension.GetBinaryDescription()) PackageBinaryCopyright = '' PackageBinaryLicense = '' for (Lang, Copyright) in UserExtension.GetBinaryCopyright(): PackageBinaryCopyright = Copyright for (Lang, License) in UserExtension.GetBinaryLicense(): PackageBinaryLicense = License if PackageBinaryAbstract and PackageBinaryDescription and \ PackageBinaryCopyright and PackageBinaryLicense: Content += GenHeaderCommentSection(PackageBinaryAbstract, PackageBinaryDescription, PackageBinaryCopyright, PackageBinaryLicense, True) # # Generate PACKAGE_UNI_FILE for the Package # FileHeader = GenHeaderCommentSection(PackageAbstract, PackageDescription, PackageCopyright, PackageLicense, False, \ TAB_COMMENT_EDK1_SPLIT) GenPackageUNIEncodeFile(Package, FileHeader) # # for each section, maintain a dict, sorted arch will be its key, #statement list will be its data # { 'Arch1 Arch2 Arch3': [statement1, statement2], # 'Arch1' : [statement1, statement3] # } # # # generate [Defines] section # LeftOffset = 31 NewSectionDict = {TAB_ARCH_COMMON : []} SpecialItemList = [] Statement = (u'%s ' % TAB_DEC_DEFINES_DEC_SPECIFICATION).ljust(LeftOffset) + u'= %s' % '0x00010017' SpecialItemList.append(Statement) BaseName = Package.GetBaseName() if BaseName.startswith('.') or BaseName.startswith('-'): BaseName = '_' + BaseName Statement = (u'%s ' % TAB_DEC_DEFINES_PACKAGE_NAME).ljust(LeftOffset) + u'= %s' % BaseName SpecialItemList.append(Statement) Statement = (u'%s ' % TAB_DEC_DEFINES_PACKAGE_VERSION).ljust(LeftOffset) + u'= %s' % Package.GetVersion() SpecialItemList.append(Statement) Statement = (u'%s ' % TAB_DEC_DEFINES_PACKAGE_GUID).ljust(LeftOffset) + u'= %s' % Package.GetGuid() SpecialItemList.append(Statement) if Package.UNIFlag: Statement = (u'%s ' % TAB_DEC_DEFINES_PKG_UNI_FILE).ljust(LeftOffset) + u'= %s' % Package.GetBaseName() + '.uni' SpecialItemList.append(Statement) for SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + SpecialItemList Content += GenSection('Defines', NewSectionDict) # # generate [Includes] section # NewSectionDict = {} IncludeArchList = Package.GetIncludeArchList() if IncludeArchList: for Path, ArchList in IncludeArchList: Statement = Path ArchList.sort() SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [ConvertPath(Statement)] else: NewSectionDict[SortedArch] = [ConvertPath(Statement)] Content += GenSection('Includes', NewSectionDict) # # generate [guids][protocols][ppis] sections # Content = GenGuidProtocolPpi(Package, Content) # # generate [LibraryClasses] section # NewSectionDict = {} for LibraryClass in Package.GetLibraryClassList(): # # Generate generic comment # HelpTextList = LibraryClass.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) if HelpStr: HelpStr = '@libraryclass' + HelpStr CommentStr = GenGenericCommentF(HelpStr, 2, False, True) Statement = CommentStr Name = LibraryClass.GetLibraryClass() IncludeHeader = LibraryClass.GetIncludeHeader() Statement += Name + '|' + ConvertPath(IncludeHeader) # # generate tail comment # if LibraryClass.GetSupModuleList(): Statement += \ GenDecTailComment(LibraryClass.GetSupModuleList()) ArchList = sorted(LibraryClass.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('LibraryClasses', NewSectionDict, True, True) # # Generate '# [Error.<TokenSpcCName>]' section # Content = GenPcdErrorMsgSection(Package, Content) Content = GenPcd(Package, Content) # # generate [UserExtensions] section # NewSectionDict = {} for UserExtension in Package.GetUserExtensionList(): if UserExtension.GetUserID() == TAB_BINARY_HEADER_USERID and \ UserExtension.GetIdentifier() == TAB_BINARY_HEADER_IDENTIFIER: continue # Generate Private Section first if UserExtension.GetUserID() == DT.TAB_INTEL and UserExtension.GetIdentifier() == DT.TAB_PRIVATE: Content += '\n' + UserExtension.GetStatement() continue Statement = UserExtension.GetStatement() if not Statement: continue else: LineList = Statement.split('\n') NewStatement = "" for Line in LineList: NewStatement += " %s\n" % Line SectionList = [] SectionName = 'UserExtensions' UserId = UserExtension.GetUserID() if UserId: if '.' in UserId: UserId = '"' + UserId + '"' SectionName += '.' + UserId if UserExtension.GetIdentifier(): SectionName += '.' + '"' + UserExtension.GetIdentifier() + '"' if not UserExtension.GetSupArchList(): SectionList.append(SectionName) else: for Arch in UserExtension.GetSupArchList(): SectionList.append(SectionName + '.' + Arch) SectionName = ', '.join(SectionList) SectionName = ''.join(['[', SectionName, ']\n']) Content += '\n' + SectionName + NewStatement SaveFileOnChange(ContainerFile, Content, False) if DistHeader.ReadOnly: os.chmod(ContainerFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH) else: os.chmod(ContainerFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH|stat.S_IWUSR|stat.S_IWGRP|stat.S_IWOTH) return ContainerFile
def GenProtocolPPiSections(ObjList, IsProtocol): Content = "" Dict = Sdict() for Object in ObjList: HelpTextList = Object.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CName = Object.GetCName() FFE = Object.GetFeatureFlag() Statement = CName if FFE: Statement += "|" + FFE Usage = Object.GetUsage() Notify = Object.GetNotify() # # we need to differentiate the generic comment and usage comment # as consecutive generic comment need to be put together # if Usage == DT.ITEM_UNDEFINED and Notify == "": # generate list of generic comment Comment = GenGenericCommentF(HelpStr) else: # generate list of other comment Comment = HelpStr.replace("\n", " ") Comment = Comment.strip() if Comment: Comment = " # " + Comment else: Comment = "" if Usage == DT.ITEM_UNDEFINED and not Comment and Notify == "": Comment = "" else: if Notify: Comment = "## " + Usage + " ## " + "NOTIFY" + Comment else: Comment = "## " + Usage + Comment if Comment: Comment += "\n" # # merge duplicate items # ArchList = Object.GetSupArchList() ArchList.sort() SortedArch = " ".join(ArchList) if (Statement, SortedArch) in Dict: PreviousComment = Dict[Statement, SortedArch] Comment = PreviousComment + Comment Dict[Statement, SortedArch] = Comment NewSectionDict = GenMetaFileMisc.TransferDict(Dict) # # generate the section contents # if NewSectionDict: if IsProtocol: Content = GenSection("Protocols", NewSectionDict) else: Content = GenSection("Ppis", NewSectionDict) return Content
def GenPcdSections(ModuleObject): Content = '' if not GlobalData.gIS_BINARY_INF: # # for each Pcd Itemtype, maintain a dict so the same type will be grouped # together # ItemTypeDict = {} for Pcd in ModuleObject.GetPcdList(): HelpTextList = Pcd.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) Statement = '' CName = Pcd.GetCName() TokenSpaceGuidCName = Pcd.GetTokenSpaceGuidCName() DefaultValue = Pcd.GetDefaultValue() ItemType = Pcd.GetItemType() if ItemType in ItemTypeDict: Dict = ItemTypeDict[ItemType] else: Dict = Sdict() ItemTypeDict[ItemType] = Dict FFE = Pcd.GetFeatureFlag() Statement += TokenSpaceGuidCName + '.' + CName if DefaultValue: Statement += '|' + DefaultValue if FFE: Statement += '|' + FFE elif FFE: Statement += '||' + FFE # # Generate comment # Usage = Pcd.GetValidUsage() # # if FeatureFlag Pcd, then assume all Usage is CONSUMES # if ItemType == DT.TAB_INF_FEATURE_PCD: Usage = DT.USAGE_ITEM_CONSUMES if Usage == DT.ITEM_UNDEFINED or (ItemType == DT.TAB_INF_FEATURE_PCD): # generate list of generic comment Comment = GenGenericCommentF(HelpStr) else: # generate list of other comment Comment = HelpStr.replace('\n', ' ') Comment = Comment.strip() if Comment: Comment = ' # ' + Comment else: Comment = '' Comment = '## ' + Usage + Comment if Comment: Comment += '\n' # # Merge duplicate entries # ArchList = Pcd.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if (Statement, SortedArch) in Dict: PreviousComment = Dict[Statement, SortedArch] Comment = PreviousComment + Comment Dict[Statement, SortedArch] = Comment for ItemType in ItemTypeDict: # # First we need to transfer the Dict to use SortedArch as key # Dict = ItemTypeDict[ItemType] NewSectionDict = GenMetaFileMisc.TransferDict(Dict) if NewSectionDict: Content += GenSection(ItemType, NewSectionDict) # # For AsBuild INF files # else: Content += GenAsBuiltPacthPcdSections(ModuleObject) Content += GenAsBuiltPcdExSections(ModuleObject) return Content
def GenGuidSections(GuidObjList): # # generate [Guids] section # Content = "" GuidDict = Sdict() for Guid in GuidObjList: HelpTextList = Guid.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) CName = Guid.GetCName() FFE = Guid.GetFeatureFlag() Statement = CName if FFE: Statement += "|" + FFE Usage = Guid.GetUsage() GuidType = Guid.GetGuidTypeList()[0] VariableName = Guid.GetVariableName() # # we need to differentiate the generic comment and usage comment # as multiple generic comment need to be put at first # if Usage == DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED: # generate list of generic comment Comment = GenGenericCommentF(HelpStr) else: # generate list of other comment Comment = HelpStr.replace("\n", " ") Comment = Comment.strip() if Comment: Comment = " # " + Comment else: Comment = "" if Usage != DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED: Comment = "## " + Usage + Comment elif GuidType == "Variable": Comment = "## " + Usage + " ## " + GuidType + ":" + VariableName + Comment else: Comment = "## " + Usage + " ## " + GuidType + Comment if Comment: Comment += "\n" # # merge duplicate items # ArchList = Guid.GetSupArchList() ArchList.sort() SortedArch = " ".join(ArchList) if (Statement, SortedArch) in GuidDict: PreviousComment = GuidDict[Statement, SortedArch] Comment = PreviousComment + Comment GuidDict[Statement, SortedArch] = Comment NewSectionDict = GenMetaFileMisc.TransferDict(GuidDict) # # generate the section contents # if NewSectionDict: Content = GenSection("Guids", NewSectionDict) return Content