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 ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None): if not GlobalData.gWSPKG_LIST: GlobalData.gWSPKG_LIST = GetWorkspacePackage() # # Init global information for the file # ContainerFile = ModuleObject.GetFullPath() Content = '' # # Generate file header, If any Abstract, Description, Copyright or License XML elements are missing, # should 1) use the Abstract, Description, Copyright or License from the PackageSurfaceArea.Header elements # that the module belongs to, or 2) if this is a stand-alone module that is not included in a PackageSurfaceArea, # use the abstract, description, copyright or license from the DistributionPackage.Header elements. # ModuleAbstract = GetLocalValue(ModuleObject.GetAbstract()) if not ModuleAbstract and PackageObject: ModuleAbstract = GetLocalValue(PackageObject.GetAbstract()) if not ModuleAbstract and DistHeader: ModuleAbstract = GetLocalValue(DistHeader.GetAbstract()) ModuleDescription = GetLocalValue(ModuleObject.GetDescription()) if not ModuleDescription and PackageObject: ModuleDescription = GetLocalValue(PackageObject.GetDescription()) if not ModuleDescription and DistHeader: ModuleDescription = GetLocalValue(DistHeader.GetDescription()) ModuleCopyright = '' for (Lang, Copyright) in ModuleObject.GetCopyright(): if Lang: pass ModuleCopyright = Copyright if not ModuleCopyright and PackageObject: for (Lang, Copyright) in PackageObject.GetCopyright(): if Lang: pass ModuleCopyright = Copyright if not ModuleCopyright and DistHeader: for (Lang, Copyright) in DistHeader.GetCopyright(): if Lang: pass ModuleCopyright = Copyright ModuleLicense = '' for (Lang, License) in ModuleObject.GetLicense(): if Lang: pass ModuleLicense = License if not ModuleLicense and PackageObject: for (Lang, License) in PackageObject.GetLicense(): if Lang: pass ModuleLicense = License if not ModuleLicense and DistHeader: for (Lang, License) in DistHeader.GetLicense(): if Lang: pass ModuleLicense = License # # Generate header comment section of INF file # Content += GenHeaderCommentSection(ModuleAbstract, ModuleDescription, ModuleCopyright, ModuleLicense).replace('\r\n', '\n') # # Generate Binary Header # for UserExtension in ModuleObject.GetUserExtensionList(): if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID \ and UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER: ModuleBinaryAbstract = GetLocalValue( UserExtension.GetBinaryAbstract()) ModuleBinaryDescription = GetLocalValue( UserExtension.GetBinaryDescription()) ModuleBinaryCopyright = '' ModuleBinaryLicense = '' for (Lang, Copyright) in UserExtension.GetBinaryCopyright(): ModuleBinaryCopyright = Copyright for (Lang, License) in UserExtension.GetBinaryLicense(): ModuleBinaryLicense = License if ModuleBinaryAbstract and ModuleBinaryDescription and \ ModuleBinaryCopyright and ModuleBinaryLicense: Content += GenHeaderCommentSection(ModuleBinaryAbstract, ModuleBinaryDescription, ModuleBinaryCopyright, ModuleBinaryLicense, True) # # Generate MODULE_UNI_FILE for module # FileHeader = GenHeaderCommentSection(ModuleAbstract, ModuleDescription, ModuleCopyright, ModuleLicense, False, \ DT.TAB_COMMENT_EDK1_SPLIT) GenModuleUNIEncodeFile(ModuleObject, FileHeader) # # Judge whether the INF file is an AsBuild INF. # if ModuleObject.BinaryModule: GlobalData.gIS_BINARY_INF = True else: GlobalData.gIS_BINARY_INF = False # # 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] # } # # Gen section contents # Content += GenDefines(ModuleObject) Content += GenBuildOptions(ModuleObject) Content += GenLibraryClasses(ModuleObject) Content += GenPackages(ModuleObject) Content += GenPcdSections(ModuleObject) Content += GenSources(ModuleObject) Content += GenProtocolPPiSections(ModuleObject.GetProtocolList(), True) Content += GenProtocolPPiSections(ModuleObject.GetPpiList(), False) Content += GenGuidSections(ModuleObject.GetGuidList()) Content += GenBinaries(ModuleObject) Content += GenDepex(ModuleObject) Content += GenUserExtensions(ModuleObject) if ModuleObject.GetEventList() or ModuleObject.GetBootModeList( ) or ModuleObject.GetHobList(): Content += '\n' # # generate [Event], [BootMode], [Hob] section # Content += GenSpecialSections(ModuleObject.GetEventList(), 'Event') Content += GenSpecialSections(ModuleObject.GetBootModeList(), 'BootMode') Content += GenSpecialSections(ModuleObject.GetHobList(), 'Hob') 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 ModuleToInf(ModuleObject): if not GlobalData.gWSPKG_LIST: GlobalData.gWSPKG_LIST = GetWorkspacePackage() # # Init global information for the file # ContainerFile = ModuleObject.GetFullPath() Content = '' # # generate header comment section # Content += GenHeaderCommentSection(ModuleObject.GetAbstract(), ModuleObject.GetDescription(), ModuleObject.GetCopyright(), ModuleObject.GetLicense()) # # Judge whether the INF file is an AsBuild INF. # if ModuleObject.BinaryModule: GlobalData.gIS_BINARY_INF = True else: GlobalData.gIS_BINARY_INF = False # # 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] # } # # # Gen section contents # Content += GenDefines(ModuleObject) Content += GenBuildOptions(ModuleObject) Content += GenLibraryClasses(ModuleObject) Content += GenPackages(ModuleObject) Content += GenPcdSections(ModuleObject) Content += GenSources(ModuleObject) Content += GenProtocolPPiSections(ModuleObject.GetProtocolList(), True) Content += GenProtocolPPiSections(ModuleObject.GetPpiList(), False) Content += GenGuidSections(ModuleObject.GetGuidList()) Content += GenBinaries(ModuleObject) Content += GenDepex(ModuleObject) Content += GenUserExtensions(ModuleObject) if ModuleObject.GetEventList() or ModuleObject.GetBootModeList( ) or ModuleObject.GetHobList(): Content += '\n\n' # # generate [Event], [BootMode], [Hob] section # Content += GenSpecialSections(ModuleObject.GetEventList(), 'Event') Content += GenSpecialSections(ModuleObject.GetBootModeList(), 'BootMode') Content += GenSpecialSections(ModuleObject.GetHobList(), 'Hob') SaveFileOnChange(ContainerFile, Content, False) return ContainerFile
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