## @file GenInfFile.py
#
# This file contained the logical of transfer package object to INF files.
#
# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
'''
GenInf
'''
## Transfer Module Object to Inf files
#
# Transfer all contents of a standard Module Object to an Inf file
# @param ModuleObject: A Module Object
#
if not GlobalData.gWSPKG_LIST:
#
# Init global information for the file
#
Content = ''
#
# generate header comment section
#
#
# Judge whether the INF file is an AsBuild INF.
#
else:
#
# 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 += '\n\n'
#
# generate [Event], [BootMode], [Hob] section
#
return ContainerFile
#
# generate [Defines] section
#
Content = ''
NewSectionDict = {}
if not DefinesDict:
continue
for Statement in DefinesDict:
if pos == -1:
if SortedArch in NewSectionDict:
else:
SpecialStatementList = []
#
# Add INF_VERSION statement firstly
#
Statement = 'INF_VERSION = 0x00010017'
if ModuleObject.GetModuleType():
if ModuleObject.GetPcdIsDriver():
Statement = '%s = %s' % (DT.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION, ModuleObject.GetPiSpecificationVersion())
if LibraryClass.GetSupModuleList():
ExternList = []
ExternList.append([ArchList, EntryPoint, UnloadImage, Constructor, Destructor, FFE, HelpStringList])
#
# Add VALID_ARCHITECTURES information
#
ValidArchStatement = None
ValidArchStatement += '# The following information is for reference only and not required by the build tools.\n'
if ValidArchStatement is not None:
return Content
#
# generate [LibraryClasses] section
#
Content = ''
NewSectionDict = {}
if not GlobalData.gIS_BINARY_INF:
continue
#
# Generate generic comment
#
if FFE:
KeyList = []
KeyList = [SortedArch]
else:
if not ArchList:
else:
if Key in NewSectionDict:
else:
else:
LibraryClassDict = {}
if not BinaryFile.AsBuiltList:
continue
else:
else:
else:
return Content
Content = ''
#
# generate [Packages] section
#
NewSectionDict = Sdict()
#
# Generate generic comment
#
CommentStr = ''
if HelpText:
#
#
break
#
# get relative path
#
if FFE:
if SortedArch in NewSectionDict:
else:
return Content
#
# generate [Sources] section
#
Content = ''
NewSectionDict = {}
if SortedArch in NewSectionDict:
else:
return Content
#
# generate [Depex] section
#
NewSectionDict = Sdict()
Content = ''
KeyList = []
if not SupArchList:
if not SupModList:
else:
for ModuleType in SupModList:
for Arch in SupArchList:
if Key in NewSectionDict:
else:
return Content
## GenUserExtensions
#
# GenUserExtensions
#
NewSectionDict = {}
continue
if not Statement:
continue
KeyList = []
CommonPreFix = ''
if UserExtension.GetUserID():
if UserExtension.GetIdentifier():
if ArchList:
else:
KeyList = [CommonPreFix]
if Key in NewSectionDict:
else:
return Content
# GenSourceStatement
#
# @param Family: string of source file family field
# @param FeatureFlag: string of source file FeatureFlag field
# @param TagName: string of source file TagName field
# @param ToolCode: string of source file ToolCode field
# @param HelpStr: string of source file HelpStr field
#
# @retval Statement: The generated statement for source
#
Statement = ''
if HelpStr:
#
# format of SourceFile|Family|TagName|ToolCode|FeatureFlag
#
if TagName == None:
TagName = ''
if ToolCode == None:
ToolCode = ''
if HelpStr == None:
HelpStr = ''
if FeatureFlag:
elif ToolCode:
elif TagName:
elif Family:
return Statement
# GenBinaryStatement
#
# @param Key: (FileName, FileType, FFE, SortedArch)
# @param Value: (Target, Family, TagName, Comment)
#
#
if SortedArch:
pass
if Value:
else:
Target = ''
Family = ''
TagName = ''
Comment = ''
if Comment:
else:
Statement = ''
if FFE:
elif Target:
else:
if FFE:
elif TagName:
elif Family:
elif Target:
return Statement
## GenGuidSections
#
# @param GuidObjList: List of GuidObject
# @retVal Content: The generated section contents
#
#
# generate [Guids] section
#
Content = ''
for Guid in GuidObjList:
if FFE:
#
# we need to differentiate the generic comment and usage comment
# as multiple generic comment need to be put at first
#
# generate list of generic comment
else:
# generate list of other comment
if Comment:
else:
Comment = ''
elif GuidType == 'Variable':
else:
if Comment:
Comment += '\n'
#
# merge duplicate items
#
#
# generate the section contents
#
if NewSectionDict:
return Content
## GenProtocolPPiSections
#
# @param ObjList: List of ProtocolObject or Ppi Object
# @retVal Content: The generated section contents
#
Content = ''
if FFE:
#
# we need to differentiate the generic comment and usage comment
# as consecutive generic comment need to be put together
#
# generate list of generic comment
else:
# generate list of other comment
if Comment:
else:
Comment = ''
Comment = ''
else:
if Notify:
else:
if Comment:
Comment += '\n'
#
# merge duplicate items
#
#
# generate the section contents
#
if NewSectionDict:
if IsProtocol:
else:
return Content
## GenPcdSections
#
#
Content = ''
if not GlobalData.gIS_BINARY_INF:
#
# for each Pcd Itemtype, maintain a dict so the same type will be grouped
# together
#
ItemTypeDict = {}
Statement = ''
if ItemType in ItemTypeDict:
else:
if DefaultValue:
if FFE:
elif FFE:
#
# Generate comment
#
#
# if FeatureFlag Pcd, then assume all Usage is CONSUMES
#
# generate list of generic comment
else:
# generate list of other comment
if Comment:
else:
Comment = ''
if Comment:
Comment += '\n'
#
# Merge duplicate entries
#
for ItemType in ItemTypeDict:
#
# First we need to transfer the Dict to use SortedArch as key
#
if NewSectionDict:
#
# For AsBuild INF files
#
else:
return Content
## GenPcdSections
#
#
PatchPcdDict = {}
if not BinaryFile.AsBuiltList:
continue
TokenSpaceName = ''
HelpString = ''
for HelpStringItem in HelpTextList:
Statement = HelpString[:-3] + TokenSpaceName + '.' + PcdCName + ' | ' + PcdValue + ' | ' + PcdOffset
else:
else:
else:
## GenPcdSections
#
#
PcdExDict = {}
if not BinaryFile.AsBuiltList:
continue
TokenSpaceName = ''
HelpString = ''
for HelpStringItem in HelpTextList:
else:
else:
else:
## GenSpecialSections
#
#
# generate section
#
Content = ''
NewSectionDict = {}
for Obj in ObjectList:
#
# Generate comment
#
CommentStr = ''
if SectionName == 'Hob':
elif SectionName == 'Event':
elif SectionName == 'BootMode':
else:
assert(SectionName)
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
#
elif CommentStr:
if SortedArch in NewSectionDict:
else:
if SectionContent:
#
# add two empty line after the generated section content to differentiate
# it between other possible sections
#
if Content:
Content += '\n#\n#\n'
return Content
## GenBuildOptions
#
#
Content = ''
if not ModuleObject.BinaryModule:
#
# generate [BuildOptions] section
#
NewSectionDict = {}
if not BuildOptionDict:
continue
for Arch in BuildOptionDict:
if Arch in NewSectionDict:
else:
else:
BuildOptionDict = {}
if not BinaryFile.AsBuiltList:
continue
else:
else:
else:
return Content
## GenBinaries
#
#
NewSectionDict = {}
BinariesDict = []
if BinariesDict:
break
for FileNameObj in FileNameObjList:
if Key in BinariesDict:
if SortedArch in NewSectionDict:
else:
#
# as we already generated statement for this DictKey
# here set the Valuelist to be empty to avoid generate duplicate entries
# as the DictKey may have multiple entries
#
BinariesDict[Key] = []
else:
if SortedArch in NewSectionDict:
else: