#\r
# This file contained the logical of transfer package object to INF files.\r
#\r
-# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials are licensed and made available \r
# under the terms and conditions of the BSD License which accompanies this \r
import codecs\r
import md5\r
from Core.FileHook import __FileHookOpen__\r
-from Library.String import GetSplitValueList\r
+from Library.StringUtils import GetSplitValueList\r
from Library.Parsing import GenSection\r
from Library.Parsing import GetWorkspacePackage\r
from Library.Parsing import ConvertArchForInstall\r
from Library import DataType as DT\r
from GenMetaFile import GenMetaFileMisc\r
from Library.UniClassObject import FormatUniEntry\r
+from Library.StringUtils import GetUniFileName\r
\r
\r
## Transfer Module Object to Inf files\r
#\r
FileHeader = GenHeaderCommentSection(ModuleAbstract, ModuleDescription, ModuleCopyright, ModuleLicense, False, \\r
DT.TAB_COMMENT_EDK1_SPLIT)\r
- GenModuleUNIEncodeFile(ModuleObject, FileHeader)\r
+ ModuleUniFile = GenModuleUNIEncodeFile(ModuleObject, FileHeader)\r
+ if ModuleUniFile:\r
+ ModuleObject.SetModuleUniFile(os.path.basename(ModuleUniFile))\r
\r
#\r
# Judge whether the INF file is an AsBuild INF.\r
Content += GenGuidSections(ModuleObject.GetGuidList())\r
Content += GenBinaries(ModuleObject)\r
Content += GenDepex(ModuleObject)\r
- Content += GenUserExtensions(ModuleObject)\r
+ __UserExtensionsContent = GenUserExtensions(ModuleObject)\r
+ Content += __UserExtensionsContent\r
if ModuleObject.GetEventList() or ModuleObject.GetBootModeList() or ModuleObject.GetHobList():\r
Content += '\n'\r
#\r
# generate [Event], [BootMode], [Hob] section\r
#\r
- Content += GenSpecialSections(ModuleObject.GetEventList(), 'Event')\r
- Content += GenSpecialSections(ModuleObject.GetBootModeList(), 'BootMode')\r
- Content += GenSpecialSections(ModuleObject.GetHobList(), 'Hob')\r
+ Content += GenSpecialSections(ModuleObject.GetEventList(), 'Event', __UserExtensionsContent)\r
+ Content += GenSpecialSections(ModuleObject.GetBootModeList(), 'BootMode', __UserExtensionsContent)\r
+ Content += GenSpecialSections(ModuleObject.GetHobList(), 'Hob', __UserExtensionsContent)\r
SaveFileOnChange(ContainerFile, Content, False)\r
if DistHeader.ReadOnly:\r
os.chmod(ContainerFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)\r
return\r
else:\r
ModuleObject.UNIFlag = True\r
- ContainerFile = os.path.normpath(os.path.join(os.path.dirname(ModuleObject.GetFullPath()),\r
- (ModuleObject.GetBaseName() + '.uni')))\r
+ ContainerFile = GetUniFileName(os.path.dirname(ModuleObject.GetFullPath()), ModuleObject.GetBaseName())\r
+\r
if not os.path.exists(os.path.dirname(ModuleObject.GetFullPath())):\r
os.makedirs(os.path.dirname(ModuleObject.GetFullPath()))\r
\r
# TAB_INF_DEFINES_VERSION_STRING\r
if ModuleObject.UNIFlag:\r
Statement = (u'%s ' % DT.TAB_INF_DEFINES_MODULE_UNI_FILE).ljust(LeftOffset) + \\r
- u'= %s' % ModuleObject.GetBaseName() + '.uni'\r
+ u'= %s' % ModuleObject.GetModuleUniFile()\r
SpecialStatementList.append(Statement)\r
\r
# TAB_INF_DEFINES_MODULE_TYPE\r
Statement = '# Guid: ' + LibraryItem.Guid + ' Version: ' + LibraryItem.Version\r
\r
if len(BinaryFile.SupArchList) == 0:\r
- if LibraryClassDict.has_key('COMMON') and Statement not in LibraryClassDict['COMMON']:\r
+ if 'COMMON' in LibraryClassDict and Statement not in LibraryClassDict['COMMON']:\r
LibraryClassDict['COMMON'].append(Statement)\r
else:\r
LibraryClassDict['COMMON'] = ['## @LIB_INSTANCES']\r
LibraryClassDict['COMMON'].append(Statement)\r
else:\r
for Arch in BinaryFile.SupArchList:\r
- if LibraryClassDict.has_key(Arch):\r
+ if Arch in LibraryClassDict:\r
if Statement not in LibraryClassDict[Arch]:\r
LibraryClassDict[Arch].append(Statement)\r
else:\r
Statement += RelaPath.replace('\\', '/')\r
if FFE:\r
Statement += '|' + FFE\r
- ArchList = PackageDependency.GetSupArchList()\r
- ArchList.sort()\r
+ ArchList = sorted(PackageDependency.GetSupArchList())\r
SortedArch = ' '.join(ArchList)\r
if SortedArch in NewSectionDict:\r
NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r
SourceFile = Source.GetSourceFile()\r
Family = Source.GetFamily()\r
FeatureFlag = Source.GetFeatureFlag()\r
- SupArchList = Source.GetSupArchList()\r
- SupArchList.sort()\r
+ SupArchList = sorted(Source.GetSupArchList())\r
SortedArch = ' '.join(SupArchList)\r
Statement = GenSourceStatement(ConvertPath(SourceFile), Family, FeatureFlag)\r
if SortedArch in NewSectionDict:\r
if UserExtension.GetIdentifier() == 'Depex':\r
continue\r
Statement = UserExtension.GetStatement()\r
- if not Statement:\r
- continue\r
+# Comment the code to support user extension without any statement just the section header in []\r
+# if not Statement:\r
+# continue\r
ArchList = UserExtension.GetSupArchList()\r
for Index in xrange(0, len(ArchList)):\r
ArchList[Index] = ConvertArchForInstall(ArchList[Index])\r
# format of SourceFile|Family|TagName|ToolCode|FeatureFlag\r
#\r
Statement += SourceFile\r
- if TagName == None:\r
+ if TagName is None:\r
TagName = ''\r
- if ToolCode == None:\r
+ if ToolCode is None:\r
ToolCode = ''\r
- if HelpStr == None:\r
+ if HelpStr is None:\r
HelpStr = ''\r
if FeatureFlag:\r
Statement += '|' + Family + '|' + TagName + '|' + ToolCode + '|' + FeatureFlag\r
#\r
# merge duplicate items\r
#\r
- ArchList = Guid.GetSupArchList()\r
- ArchList.sort()\r
+ ArchList = sorted(Guid.GetSupArchList())\r
SortedArch = ' '.join(ArchList)\r
if (Statement, SortedArch) in GuidDict:\r
PreviousComment = GuidDict[Statement, SortedArch]\r
#\r
# merge duplicate items\r
#\r
- ArchList = Object.GetSupArchList()\r
- ArchList.sort()\r
+ ArchList = sorted(Object.GetSupArchList())\r
SortedArch = ' '.join(ArchList)\r
if (Statement, SortedArch) in Dict:\r
PreviousComment = Dict[Statement, SortedArch]\r
#\r
# Merge duplicate entries\r
#\r
- ArchList = Pcd.GetSupArchList()\r
- ArchList.sort()\r
+ ArchList = sorted(Pcd.GetSupArchList())\r
SortedArch = ' '.join(ArchList)\r
if (Statement, SortedArch) in Dict:\r
PreviousComment = Dict[Statement, SortedArch]\r
if FileNameObjList:\r
ArchList = FileNameObjList[0].GetSupArchList()\r
if len(ArchList) == 0:\r
- if PatchPcdDict.has_key(DT.TAB_ARCH_COMMON):\r
+ if DT.TAB_ARCH_COMMON in PatchPcdDict:\r
if Statement not in PatchPcdDict[DT.TAB_ARCH_COMMON]:\r
PatchPcdDict[DT.TAB_ARCH_COMMON].append(Statement)\r
else:\r
PatchPcdDict[DT.TAB_ARCH_COMMON] = [Statement]\r
else:\r
for Arch in ArchList:\r
- if PatchPcdDict.has_key(Arch):\r
+ if Arch in PatchPcdDict:\r
if Statement not in PatchPcdDict[Arch]:\r
PatchPcdDict[Arch].append(Statement)\r
else:\r
ArchList = FileNameObjList[0].GetSupArchList()\r
\r
if len(ArchList) == 0:\r
- if PcdExDict.has_key('COMMON'):\r
+ if 'COMMON' in PcdExDict:\r
PcdExDict['COMMON'].append(Statement)\r
else:\r
PcdExDict['COMMON'] = [Statement]\r
else:\r
for Arch in ArchList:\r
- if PcdExDict.has_key(Arch):\r
+ if Arch in PcdExDict:\r
if Statement not in PcdExDict[Arch]:\r
PcdExDict[Arch].append(Statement)\r
else:\r
## GenSpecialSections\r
# generate special sections for Event/BootMode/Hob\r
#\r
-def GenSpecialSections(ObjectList, SectionName):\r
+def GenSpecialSections(ObjectList, SectionName, UserExtensionsContent=''):\r
#\r
# generate section\r
#\r
else:\r
assert(SectionName)\r
Usage = Obj.GetUsage()\r
+\r
+ # If the content already in UserExtensionsContent then ignore\r
+ if '[%s]' % SectionName in UserExtensionsContent and Type in UserExtensionsContent:\r
+ return ''\r
+\r
Statement = ' ' + Type + ' ## ' + Usage\r
if CommentStr in ['#\n', '#\n#\n']:\r
CommentStr = '#\n#\n#\n'\r
if CommentStr and not CommentStr.endswith('\n#\n'):\r
CommentStr = CommentStr + '#\n'\r
NewStateMent = CommentStr + Statement\r
- SupArch = Obj.GetSupArchList()\r
- SupArch.sort()\r
+ SupArch = sorted(Obj.GetSupArchList())\r
SortedArch = ' '.join(SupArch)\r
if SortedArch in NewSectionDict:\r
NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [NewStateMent]\r
for BuilOptionItem in BinaryFile.AsBuiltList[0].BinaryBuildFlagList:\r
Statement = '#' + BuilOptionItem.AsBuiltOptionFlags\r
if len(BinaryFile.SupArchList) == 0:\r
- if BuildOptionDict.has_key('COMMON'):\r
+ if 'COMMON' in BuildOptionDict:\r
if Statement not in BuildOptionDict['COMMON']:\r
BuildOptionDict['COMMON'].append(Statement)\r
else:\r
BuildOptionDict['COMMON'].append(Statement)\r
else:\r
for Arch in BinaryFile.SupArchList:\r
- if BuildOptionDict.has_key(Arch):\r
+ if Arch in BuildOptionDict:\r
if Statement not in BuildOptionDict[Arch]:\r
BuildOptionDict[Arch].append(Statement)\r
else:\r
FileName = ConvertPath(FileNameObj.GetFilename())\r
FileType = FileNameObj.GetFileType()\r
FFE = FileNameObj.GetFeatureFlag()\r
- ArchList = FileNameObj.GetSupArchList()\r
- ArchList.sort()\r
+ ArchList = sorted(FileNameObj.GetSupArchList())\r
SortedArch = ' '.join(ArchList)\r
Key = (FileName, FileType, FFE, SortedArch)\r
if Key in BinariesDict:\r