]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
BaseTools: Clean up source files
[mirror_edk2.git] / BaseTools / Source / Python / UPT / GenMetaFile / GenInfFile.py
CommitLineData
4234283c
LG
1## @file GenInfFile.py\r
2#\r
3# This file contained the logical of transfer package object to INF files.\r
4#\r
64285f15 5# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
4234283c 6#\r
f7496d71
LG
7# This program and the accompanying materials are licensed and made available\r
8# under the terms and conditions of the BSD License which accompanies this\r
9# distribution. The full text of the license may be found at\r
4234283c
LG
10# http://opensource.org/licenses/bsd-license.php\r
11#\r
12# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14#\r
15'''\r
16GenInf\r
17'''\r
421ccda3
HC
18import os\r
19import stat\r
20import codecs\r
21import md5\r
22from Core.FileHook import __FileHookOpen__\r
64285f15 23from Library.StringUtils import GetSplitValueList\r
4234283c
LG
24from Library.Parsing import GenSection\r
25from Library.Parsing import GetWorkspacePackage\r
421ccda3 26from Library.Parsing import ConvertArchForInstall\r
4234283c
LG
27from Library.Misc import SaveFileOnChange\r
28from Library.Misc import IsAllModuleList\r
29from Library.Misc import Sdict\r
30from Library.Misc import ConvertPath\r
31from Library.Misc import ConvertSpec\r
421ccda3
HC
32from Library.Misc import GetRelativePath\r
33from Library.Misc import GetLocalValue\r
4234283c
LG
34from Library.CommentGenerating import GenHeaderCommentSection\r
35from Library.CommentGenerating import GenGenericCommentF\r
36from Library.CommentGenerating import _GetHelpStr\r
37from Library import GlobalData\r
38from Logger import StringTable as ST\r
39from Logger import ToolError\r
40import Logger.Log as Logger\r
41from Library import DataType as DT\r
42from GenMetaFile import GenMetaFileMisc\r
421ccda3 43from Library.UniClassObject import FormatUniEntry\r
64285f15 44from Library.StringUtils import GetUniFileName\r
421ccda3 45\r
4234283c
LG
46\r
47## Transfer Module Object to Inf files\r
48#\r
f7496d71
LG
49# Transfer all contents of a standard Module Object to an Inf file\r
50# @param ModuleObject: A Module Object\r
4234283c 51#\r
421ccda3
HC
52def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None):\r
53 if not GlobalData.gWSPKG_LIST:\r
4234283c 54 GlobalData.gWSPKG_LIST = GetWorkspacePackage()\r
4234283c
LG
55 #\r
56 # Init global information for the file\r
57 #\r
58 ContainerFile = ModuleObject.GetFullPath()\r
421ccda3 59\r
4234283c
LG
60 Content = ''\r
61 #\r
f7496d71
LG
62 # Generate file header, If any Abstract, Description, Copyright or License XML elements are missing,\r
63 # should 1) use the Abstract, Description, Copyright or License from the PackageSurfaceArea.Header elements\r
64 # that the module belongs to, or 2) if this is a stand-alone module that is not included in a PackageSurfaceArea,\r
421ccda3
HC
65 # use the abstract, description, copyright or license from the DistributionPackage.Header elements.\r
66 #\r
67 ModuleAbstract = GetLocalValue(ModuleObject.GetAbstract())\r
68 if not ModuleAbstract and PackageObject:\r
69 ModuleAbstract = GetLocalValue(PackageObject.GetAbstract())\r
70 if not ModuleAbstract and DistHeader:\r
71 ModuleAbstract = GetLocalValue(DistHeader.GetAbstract())\r
72 ModuleDescription = GetLocalValue(ModuleObject.GetDescription())\r
73 if not ModuleDescription and PackageObject:\r
74 ModuleDescription = GetLocalValue(PackageObject.GetDescription())\r
75 if not ModuleDescription and DistHeader:\r
76 ModuleDescription = GetLocalValue(DistHeader.GetDescription())\r
77 ModuleCopyright = ''\r
78 for (Lang, Copyright) in ModuleObject.GetCopyright():\r
79 if Lang:\r
80 pass\r
81 ModuleCopyright = Copyright\r
82 if not ModuleCopyright and PackageObject:\r
83 for (Lang, Copyright) in PackageObject.GetCopyright():\r
84 if Lang:\r
85 pass\r
86 ModuleCopyright = Copyright\r
87 if not ModuleCopyright and DistHeader:\r
88 for (Lang, Copyright) in DistHeader.GetCopyright():\r
89 if Lang:\r
90 pass\r
91 ModuleCopyright = Copyright\r
92 ModuleLicense = ''\r
93 for (Lang, License) in ModuleObject.GetLicense():\r
94 if Lang:\r
95 pass\r
96 ModuleLicense = License\r
97 if not ModuleLicense and PackageObject:\r
98 for (Lang, License) in PackageObject.GetLicense():\r
99 if Lang:\r
100 pass\r
101 ModuleLicense = License\r
102 if not ModuleLicense and DistHeader:\r
103 for (Lang, License) in DistHeader.GetLicense():\r
104 if Lang:\r
105 pass\r
106 ModuleLicense = License\r
107\r
108 #\r
109 # Generate header comment section of INF file\r
f7496d71 110 #\r
421ccda3
HC
111 Content += GenHeaderCommentSection(ModuleAbstract,\r
112 ModuleDescription,\r
113 ModuleCopyright,\r
875cc5bb 114 ModuleLicense).replace('\r\n', '\n')\r
421ccda3
HC
115\r
116 #\r
f7496d71
LG
117 # Generate Binary Header\r
118 #\r
421ccda3
HC
119 for UserExtension in ModuleObject.GetUserExtensionList():\r
120 if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID \\r
121 and UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER:\r
122 ModuleBinaryAbstract = GetLocalValue(UserExtension.GetBinaryAbstract())\r
123 ModuleBinaryDescription = GetLocalValue(UserExtension.GetBinaryDescription())\r
124 ModuleBinaryCopyright = ''\r
125 ModuleBinaryLicense = ''\r
126 for (Lang, Copyright) in UserExtension.GetBinaryCopyright():\r
127 ModuleBinaryCopyright = Copyright\r
128 for (Lang, License) in UserExtension.GetBinaryLicense():\r
129 ModuleBinaryLicense = License\r
130 if ModuleBinaryAbstract and ModuleBinaryDescription and \\r
131 ModuleBinaryCopyright and ModuleBinaryLicense:\r
132 Content += GenHeaderCommentSection(ModuleBinaryAbstract,\r
133 ModuleBinaryDescription,\r
134 ModuleBinaryCopyright,\r
135 ModuleBinaryLicense,\r
136 True)\r
137\r
138 #\r
139 # Generate MODULE_UNI_FILE for module\r
140 #\r
141 FileHeader = GenHeaderCommentSection(ModuleAbstract, ModuleDescription, ModuleCopyright, ModuleLicense, False, \\r
142 DT.TAB_COMMENT_EDK1_SPLIT)\r
f71b1630
HC
143 ModuleUniFile = GenModuleUNIEncodeFile(ModuleObject, FileHeader)\r
144 if ModuleUniFile:\r
145 ModuleObject.SetModuleUniFile(os.path.basename(ModuleUniFile))\r
421ccda3 146\r
4234283c
LG
147 #\r
148 # Judge whether the INF file is an AsBuild INF.\r
149 #\r
150 if ModuleObject.BinaryModule:\r
151 GlobalData.gIS_BINARY_INF = True\r
152 else:\r
153 GlobalData.gIS_BINARY_INF = False\r
4234283c 154 #\r
f7496d71 155 # for each section, maintain a dict, sorted arch will be its key,\r
4234283c
LG
156 # statement list will be its data\r
157 # { 'Arch1 Arch2 Arch3': [statement1, statement2],\r
f7496d71 158 # 'Arch1' : [statement1, statement3]\r
4234283c 159 # }\r
4234283c
LG
160 #\r
161 # Gen section contents\r
162 #\r
163 Content += GenDefines(ModuleObject)\r
164 Content += GenBuildOptions(ModuleObject)\r
165 Content += GenLibraryClasses(ModuleObject)\r
166 Content += GenPackages(ModuleObject)\r
167 Content += GenPcdSections(ModuleObject)\r
168 Content += GenSources(ModuleObject)\r
421ccda3
HC
169 Content += GenProtocolPPiSections(ModuleObject.GetProtocolList(), True)\r
170 Content += GenProtocolPPiSections(ModuleObject.GetPpiList(), False)\r
171 Content += GenGuidSections(ModuleObject.GetGuidList())\r
4234283c
LG
172 Content += GenBinaries(ModuleObject)\r
173 Content += GenDepex(ModuleObject)\r
e0e1cfcb
HC
174 __UserExtensionsContent = GenUserExtensions(ModuleObject)\r
175 Content += __UserExtensionsContent\r
4234283c 176 if ModuleObject.GetEventList() or ModuleObject.GetBootModeList() or ModuleObject.GetHobList():\r
421ccda3 177 Content += '\n'\r
4234283c
LG
178 #\r
179 # generate [Event], [BootMode], [Hob] section\r
180 #\r
e0e1cfcb
HC
181 Content += GenSpecialSections(ModuleObject.GetEventList(), 'Event', __UserExtensionsContent)\r
182 Content += GenSpecialSections(ModuleObject.GetBootModeList(), 'BootMode', __UserExtensionsContent)\r
183 Content += GenSpecialSections(ModuleObject.GetHobList(), 'Hob', __UserExtensionsContent)\r
4234283c 184 SaveFileOnChange(ContainerFile, Content, False)\r
421ccda3
HC
185 if DistHeader.ReadOnly:\r
186 os.chmod(ContainerFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)\r
187 else:\r
188 os.chmod(ContainerFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH|stat.S_IWUSR|stat.S_IWGRP|stat.S_IWOTH)\r
4234283c
LG
189 return ContainerFile\r
190\r
421ccda3
HC
191## GenModuleUNIEncodeFile\r
192# GenModuleUNIEncodeFile, default is a UCS-2LE encode file\r
193#\r
194def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader='', Encoding=DT.TAB_ENCODING_UTF16LE):\r
195 GenUNIFlag = False\r
196 OnlyLANGUAGE_EN_X = True\r
197 BinaryAbstract = []\r
198 BinaryDescription = []\r
199 #\r
f7496d71 200 # If more than one language code is used for any element that would be present in the MODULE_UNI_FILE,\r
421ccda3
HC
201 # then the MODULE_UNI_FILE must be created.\r
202 #\r
203 for (Key, Value) in ModuleObject.GetAbstract() + ModuleObject.GetDescription():\r
204 if Key == DT.TAB_LANGUAGE_EN_X:\r
205 GenUNIFlag = True\r
206 else:\r
207 OnlyLANGUAGE_EN_X = False\r
208\r
209 for UserExtension in ModuleObject.GetUserExtensionList():\r
210 if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID \\r
211 and UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER:\r
212 for (Key, Value) in UserExtension.GetBinaryAbstract():\r
213 if Key == DT.TAB_LANGUAGE_EN_X:\r
214 GenUNIFlag = True\r
215 else:\r
216 OnlyLANGUAGE_EN_X = False\r
217 BinaryAbstract.append((Key, Value))\r
218 for (Key, Value) in UserExtension.GetBinaryDescription():\r
219 if Key == DT.TAB_LANGUAGE_EN_X:\r
220 GenUNIFlag = True\r
221 else:\r
222 OnlyLANGUAGE_EN_X = False\r
223 BinaryDescription.append((Key, Value))\r
224\r
225\r
226 if not GenUNIFlag:\r
227 return\r
228 elif OnlyLANGUAGE_EN_X:\r
229 return\r
230 else:\r
231 ModuleObject.UNIFlag = True\r
06eb3540
HC
232 ContainerFile = GetUniFileName(os.path.dirname(ModuleObject.GetFullPath()), ModuleObject.GetBaseName())\r
233\r
421ccda3
HC
234 if not os.path.exists(os.path.dirname(ModuleObject.GetFullPath())):\r
235 os.makedirs(os.path.dirname(ModuleObject.GetFullPath()))\r
236\r
cf2b2bde
HC
237 Content = UniFileHeader + '\r\n'\r
238 Content += '\r\n'\r
421ccda3 239\r
cf2b2bde 240 Content += FormatUniEntry('#string ' + DT.TAB_INF_ABSTRACT, ModuleObject.GetAbstract(), ContainerFile) + '\r\n'\r
421ccda3
HC
241\r
242 Content += FormatUniEntry('#string ' + DT.TAB_INF_DESCRIPTION, ModuleObject.GetDescription(), ContainerFile) \\r
cf2b2bde 243 + '\r\n'\r
421ccda3
HC
244\r
245 BinaryAbstractString = FormatUniEntry('#string ' + DT.TAB_INF_BINARY_ABSTRACT, BinaryAbstract, ContainerFile)\r
246 if BinaryAbstractString:\r
cf2b2bde 247 Content += BinaryAbstractString + '\r\n'\r
421ccda3
HC
248\r
249 BinaryDescriptionString = FormatUniEntry('#string ' + DT.TAB_INF_BINARY_DESCRIPTION, BinaryDescription, \\r
250 ContainerFile)\r
251 if BinaryDescriptionString:\r
cf2b2bde 252 Content += BinaryDescriptionString + '\r\n'\r
421ccda3
HC
253\r
254 if not os.path.exists(ContainerFile):\r
255 File = codecs.open(ContainerFile, 'wb', Encoding)\r
256 File.write(u'\uFEFF' + Content)\r
257 File.stream.close()\r
258 Md5Sigature = md5.new(__FileHookOpen__(str(ContainerFile), 'rb').read())\r
259 Md5Sum = Md5Sigature.hexdigest()\r
260 if (ContainerFile, Md5Sum) not in ModuleObject.FileList:\r
261 ModuleObject.FileList.append((ContainerFile, Md5Sum))\r
262\r
263 return ContainerFile\r
4234283c
LG
264def GenDefines(ModuleObject):\r
265 #\r
266 # generate [Defines] section\r
267 #\r
875cc5bb 268 LeftOffset = 31\r
421ccda3
HC
269 Content = ''\r
270 NewSectionDict = {}\r
875cc5bb 271\r
4234283c
LG
272 for UserExtension in ModuleObject.GetUserExtensionList():\r
273 DefinesDict = UserExtension.GetDefinesDict()\r
274 if not DefinesDict:\r
275 continue\r
4234283c 276 for Statement in DefinesDict:\r
875cc5bb
HC
277 if Statement.split(DT.TAB_EQUAL_SPLIT) > 1:\r
278 Statement = (u'%s ' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[0]).ljust(LeftOffset) \\r
279 + u'= %s' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[1].lstrip()\r
4234283c
LG
280 SortedArch = DT.TAB_ARCH_COMMON\r
281 if Statement.strip().startswith(DT.TAB_INF_DEFINES_CUSTOM_MAKEFILE):\r
282 pos = Statement.find(DT.TAB_VALUE_SPLIT)\r
283 if pos == -1:\r
284 pos = Statement.find(DT.TAB_EQUAL_SPLIT)\r
285 Makefile = ConvertPath(Statement[pos + 1:].strip())\r
286 Statement = Statement[:pos + 1] + ' ' + Makefile\r
287 if SortedArch in NewSectionDict:\r
288 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r
289 else:\r
421ccda3 290 NewSectionDict[SortedArch] = [Statement]\r
4234283c 291 SpecialStatementList = []\r
875cc5bb 292\r
421ccda3
HC
293 # TAB_INF_DEFINES_INF_VERSION\r
294 Statement = (u'%s ' % DT.TAB_INF_DEFINES_INF_VERSION).ljust(LeftOffset) + u'= %s' % '0x00010017'\r
4234283c
LG
295 SpecialStatementList.append(Statement)\r
296\r
421ccda3 297 # BaseName\r
4234283c
LG
298 BaseName = ModuleObject.GetBaseName()\r
299 if BaseName.startswith('.') or BaseName.startswith('-'):\r
300 BaseName = '_' + BaseName\r
421ccda3 301 Statement = (u'%s ' % DT.TAB_INF_DEFINES_BASE_NAME).ljust(LeftOffset) + u'= %s' % BaseName\r
4234283c 302 SpecialStatementList.append(Statement)\r
f7496d71 303\r
421ccda3
HC
304 # TAB_INF_DEFINES_FILE_GUID\r
305 Statement = (u'%s ' % DT.TAB_INF_DEFINES_FILE_GUID).ljust(LeftOffset) + u'= %s' % ModuleObject.GetGuid()\r
4234283c 306 SpecialStatementList.append(Statement)\r
f7496d71 307\r
421ccda3
HC
308 # TAB_INF_DEFINES_VERSION_STRING\r
309 Statement = (u'%s ' % DT.TAB_INF_DEFINES_VERSION_STRING).ljust(LeftOffset) + u'= %s' % ModuleObject.GetVersion()\r
310 SpecialStatementList.append(Statement)\r
311\r
312 # TAB_INF_DEFINES_VERSION_STRING\r
313 if ModuleObject.UNIFlag:\r
314 Statement = (u'%s ' % DT.TAB_INF_DEFINES_MODULE_UNI_FILE).ljust(LeftOffset) + \\r
f71b1630 315 u'= %s' % ModuleObject.GetModuleUniFile()\r
421ccda3
HC
316 SpecialStatementList.append(Statement)\r
317\r
318 # TAB_INF_DEFINES_MODULE_TYPE\r
4234283c 319 if ModuleObject.GetModuleType():\r
421ccda3 320 Statement = (u'%s ' % DT.TAB_INF_DEFINES_MODULE_TYPE).ljust(LeftOffset) + u'= %s' % ModuleObject.GetModuleType()\r
4234283c 321 SpecialStatementList.append(Statement)\r
421ccda3
HC
322\r
323 # TAB_INF_DEFINES_PCD_IS_DRIVER\r
4234283c 324 if ModuleObject.GetPcdIsDriver():\r
421ccda3
HC
325 Statement = (u'%s ' % DT.TAB_INF_DEFINES_PCD_IS_DRIVER).ljust(LeftOffset) + \\r
326 u'= %s' % ModuleObject.GetPcdIsDriver()\r
4234283c 327 SpecialStatementList.append(Statement)\r
421ccda3
HC
328\r
329 # TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION\r
4234283c 330 if ModuleObject.GetUefiSpecificationVersion():\r
421ccda3
HC
331 Statement = (u'%s ' % DT.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION).ljust(LeftOffset) + \\r
332 u'= %s' % ModuleObject.GetUefiSpecificationVersion()\r
4234283c 333 SpecialStatementList.append(Statement)\r
421ccda3
HC
334\r
335 # TAB_INF_DEFINES_PI_SPECIFICATION_VERSION\r
4234283c 336 if ModuleObject.GetPiSpecificationVersion():\r
421ccda3
HC
337 Statement = (u'%s ' % DT.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION).ljust(LeftOffset) + \\r
338 u'= %s' % ModuleObject.GetPiSpecificationVersion()\r
339 SpecialStatementList.append(Statement)\r
340\r
341 # LibraryClass\r
4234283c
LG
342 for LibraryClass in ModuleObject.GetLibraryClassList():\r
343 if LibraryClass.GetUsage() == DT.USAGE_ITEM_PRODUCES or \\r
344 LibraryClass.GetUsage() == DT.USAGE_ITEM_SOMETIMES_PRODUCES:\r
421ccda3
HC
345 Statement = (u'%s ' % DT.TAB_INF_DEFINES_LIBRARY_CLASS).ljust(LeftOffset) + \\r
346 u'= %s' % LibraryClass.GetLibraryClass()\r
4234283c
LG
347 if LibraryClass.GetSupModuleList():\r
348 Statement += '|' + DT.TAB_SPACE_SPLIT.join(l for l in LibraryClass.GetSupModuleList())\r
349 SpecialStatementList.append(Statement)\r
421ccda3
HC
350\r
351 # Spec Item\r
4234283c
LG
352 for SpecItem in ModuleObject.GetSpecList():\r
353 Spec, Version = SpecItem\r
354 Spec = ConvertSpec(Spec)\r
355 Statement = '%s %s = %s' % (DT.TAB_INF_DEFINES_SPEC, Spec, Version)\r
356 SpecialStatementList.append(Statement)\r
421ccda3
HC
357\r
358 # Extern\r
4234283c
LG
359 ExternList = []\r
360 for Extern in ModuleObject.GetExternList():\r
361 ArchList = Extern.GetSupArchList()\r
362 EntryPoint = Extern.GetEntryPoint()\r
363 UnloadImage = Extern.GetUnloadImage()\r
364 Constructor = Extern.GetConstructor()\r
365 Destructor = Extern.GetDestructor()\r
366 HelpStringList = Extern.GetHelpTextList()\r
367 FFE = Extern.GetFeatureFlag()\r
368 ExternList.append([ArchList, EntryPoint, UnloadImage, Constructor, Destructor, FFE, HelpStringList])\r
4234283c
LG
369 #\r
370 # Add VALID_ARCHITECTURES information\r
371 #\r
372 ValidArchStatement = None\r
373 if ModuleObject.SupArchList:\r
421ccda3 374 ValidArchStatement = '\n' + '# ' + '\n'\r
4234283c
LG
375 ValidArchStatement += '# The following information is for reference only and not required by the build tools.\n'\r
376 ValidArchStatement += '# ' + '\n'\r
377 ValidArchStatement += '# VALID_ARCHITECTURES = %s' % (' '.join(ModuleObject.SupArchList)) + '\n'\r
421ccda3 378 ValidArchStatement += '# '\r
4234283c
LG
379 if DT.TAB_ARCH_COMMON not in NewSectionDict:\r
380 NewSectionDict[DT.TAB_ARCH_COMMON] = []\r
381 NewSectionDict[DT.TAB_ARCH_COMMON] = NewSectionDict[DT.TAB_ARCH_COMMON] + SpecialStatementList\r
382 GenMetaFileMisc.AddExternToDefineSec(NewSectionDict, DT.TAB_ARCH_COMMON, ExternList)\r
383 if ValidArchStatement is not None:\r
384 NewSectionDict[DT.TAB_ARCH_COMMON] = NewSectionDict[DT.TAB_ARCH_COMMON] + [ValidArchStatement]\r
4234283c 385 Content += GenSection('Defines', NewSectionDict)\r
4234283c
LG
386 return Content\r
387\r
388def GenLibraryClasses(ModuleObject):\r
389 #\r
390 # generate [LibraryClasses] section\r
391 #\r
392 Content = ''\r
393 NewSectionDict = {}\r
394 if not GlobalData.gIS_BINARY_INF:\r
395 for LibraryClass in ModuleObject.GetLibraryClassList():\r
396 if LibraryClass.GetUsage() == DT.USAGE_ITEM_PRODUCES:\r
397 continue\r
398 #\r
399 # Generate generic comment\r
400 #\r
401 HelpTextList = LibraryClass.GetHelpTextList()\r
402 HelpStr = _GetHelpStr(HelpTextList)\r
403 CommentStr = GenGenericCommentF(HelpStr)\r
404 Statement = CommentStr\r
405 Name = LibraryClass.GetLibraryClass()\r
406 FFE = LibraryClass.GetFeatureFlag()\r
407 Statement += Name\r
408 if FFE:\r
421ccda3 409 Statement += '|' + FFE\r
4234283c
LG
410 ModuleList = LibraryClass.GetSupModuleList()\r
411 ArchList = LibraryClass.GetSupArchList()\r
412 for Index in xrange(0, len(ArchList)):\r
413 ArchList[Index] = ConvertArchForInstall(ArchList[Index])\r
414 ArchList.sort()\r
415 SortedArch = ' '.join(ArchList)\r
4234283c
LG
416 KeyList = []\r
417 if not ModuleList or IsAllModuleList(ModuleList):\r
421ccda3 418 KeyList = [SortedArch]\r
4234283c
LG
419 else:\r
420 ModuleString = DT.TAB_VALUE_SPLIT.join(l for l in ModuleList)\r
421 if not ArchList:\r
422 SortedArch = DT.TAB_ARCH_COMMON\r
423 KeyList = [SortedArch + '.' + ModuleString]\r
424 else:\r
425 KeyList = [Arch + '.' + ModuleString for Arch in ArchList]\r
4234283c
LG
426 for Key in KeyList:\r
427 if Key in NewSectionDict:\r
428 NewSectionDict[Key] = NewSectionDict[Key] + [Statement]\r
429 else:\r
430 NewSectionDict[Key] = [Statement]\r
431 Content += GenSection('LibraryClasses', NewSectionDict)\r
432 else:\r
433 LibraryClassDict = {}\r
434 for BinaryFile in ModuleObject.GetBinaryFileList():\r
435 if not BinaryFile.AsBuiltList:\r
436 continue\r
437 for LibraryItem in BinaryFile.AsBuiltList[0].LibraryInstancesList:\r
421ccda3
HC
438 Statement = '# Guid: ' + LibraryItem.Guid + ' Version: ' + LibraryItem.Version\r
439\r
4234283c 440 if len(BinaryFile.SupArchList) == 0:\r
27c4ceb4 441 if 'COMMON' in LibraryClassDict and Statement not in LibraryClassDict['COMMON']:\r
4234283c
LG
442 LibraryClassDict['COMMON'].append(Statement)\r
443 else:\r
444 LibraryClassDict['COMMON'] = ['## @LIB_INSTANCES']\r
445 LibraryClassDict['COMMON'].append(Statement)\r
446 else:\r
447 for Arch in BinaryFile.SupArchList:\r
27c4ceb4 448 if Arch in LibraryClassDict:\r
421ccda3
HC
449 if Statement not in LibraryClassDict[Arch]:\r
450 LibraryClassDict[Arch].append(Statement)\r
451 else:\r
452 continue\r
4234283c
LG
453 else:\r
454 LibraryClassDict[Arch] = ['## @LIB_INSTANCES']\r
455 LibraryClassDict[Arch].append(Statement)\r
4234283c 456 Content += GenSection('LibraryClasses', LibraryClassDict)\r
421ccda3 457\r
4234283c
LG
458 return Content\r
459\r
460def GenPackages(ModuleObject):\r
461 Content = ''\r
462 #\r
463 # generate [Packages] section\r
464 #\r
465 NewSectionDict = Sdict()\r
421ccda3 466 WorkspaceDir = GlobalData.gWORKSPACE\r
4234283c
LG
467 for PackageDependency in ModuleObject.GetPackageDependencyList():\r
468 #\r
469 # Generate generic comment\r
470 #\r
471 CommentStr = ''\r
472 HelpText = PackageDependency.GetHelpText()\r
473 if HelpText:\r
474 HelpStr = HelpText.GetString()\r
421ccda3 475 CommentStr = GenGenericCommentF(HelpStr)\r
4234283c
LG
476 Statement = CommentStr\r
477 Guid = PackageDependency.GetGuid()\r
478 Version = PackageDependency.GetVersion()\r
479 FFE = PackageDependency.GetFeatureFlag()\r
421ccda3 480 Path = ''\r
4234283c
LG
481 #\r
482 # find package path/name\r
f7496d71 483 #\r
4234283c
LG
484 for PkgInfo in GlobalData.gWSPKG_LIST:\r
485 if Guid == PkgInfo[1]:\r
486 if (not Version) or (Version == PkgInfo[2]):\r
487 Path = PkgInfo[3]\r
488 break\r
489 #\r
490 # get relative path\r
491 #\r
421ccda3 492 RelaPath = GetRelativePath(Path, WorkspaceDir)\r
4234283c
LG
493 Statement += RelaPath.replace('\\', '/')\r
494 if FFE:\r
421ccda3 495 Statement += '|' + FFE\r
0d1f5b2b 496 ArchList = sorted(PackageDependency.GetSupArchList())\r
4234283c
LG
497 SortedArch = ' '.join(ArchList)\r
498 if SortedArch in NewSectionDict:\r
499 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r
500 else:\r
421ccda3 501 NewSectionDict[SortedArch] = [Statement]\r
4234283c 502 Content += GenSection('Packages', NewSectionDict)\r
4234283c
LG
503 return Content\r
504\r
505def GenSources(ModuleObject):\r
506 #\r
507 # generate [Sources] section\r
508 #\r
509 Content = ''\r
510 NewSectionDict = {}\r
421ccda3 511 for Source in ModuleObject.GetSourceFileList():\r
4234283c
LG
512 SourceFile = Source.GetSourceFile()\r
513 Family = Source.GetFamily()\r
514 FeatureFlag = Source.GetFeatureFlag()\r
0d1f5b2b 515 SupArchList = sorted(Source.GetSupArchList())\r
421ccda3 516 SortedArch = ' '.join(SupArchList)\r
4234283c
LG
517 Statement = GenSourceStatement(ConvertPath(SourceFile), Family, FeatureFlag)\r
518 if SortedArch in NewSectionDict:\r
519 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r
520 else:\r
521 NewSectionDict[SortedArch] = [Statement]\r
4234283c 522 Content += GenSection('Sources', NewSectionDict)\r
421ccda3 523\r
4234283c
LG
524 return Content\r
525\r
526def GenDepex(ModuleObject):\r
527 #\r
528 # generate [Depex] section\r
529 #\r
530 NewSectionDict = Sdict()\r
531 Content = ''\r
532 for Depex in ModuleObject.GetPeiDepex() + ModuleObject.GetDxeDepex() + ModuleObject.GetSmmDepex():\r
533 HelpTextList = Depex.GetHelpTextList()\r
534 HelpStr = _GetHelpStr(HelpTextList)\r
535 CommentStr = GenGenericCommentF(HelpStr)\r
536 SupArchList = Depex.GetSupArchList()\r
537 SupModList = Depex.GetModuleType()\r
538 Expression = Depex.GetDepex()\r
539 Statement = CommentStr + Expression\r
4234283c
LG
540 SupArchList.sort()\r
541 KeyList = []\r
542 if not SupArchList:\r
543 SupArchList.append(DT.TAB_ARCH_COMMON.lower())\r
544 if not SupModList:\r
545 KeyList = SupArchList\r
546 else:\r
547 for ModuleType in SupModList:\r
548 for Arch in SupArchList:\r
549 KeyList.append(ConvertArchForInstall(Arch) + '.' + ModuleType)\r
4234283c
LG
550 for Key in KeyList:\r
551 if Key in NewSectionDict:\r
552 NewSectionDict[Key] = NewSectionDict[Key] + [Statement]\r
553 else:\r
554 NewSectionDict[Key] = [Statement]\r
4234283c 555 Content += GenSection('Depex', NewSectionDict, False)\r
f7496d71 556\r
4234283c 557 return Content\r
4234283c
LG
558## GenUserExtensions\r
559#\r
560# GenUserExtensions\r
561#\r
562def GenUserExtensions(ModuleObject):\r
563 NewSectionDict = {}\r
564 for UserExtension in ModuleObject.GetUserExtensionList():\r
421ccda3
HC
565 if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID and \\r
566 UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER:\r
567 continue\r
4234283c
LG
568 if UserExtension.GetIdentifier() == 'Depex':\r
569 continue\r
570 Statement = UserExtension.GetStatement()\r
490433ab
HC
571# Comment the code to support user extension without any statement just the section header in []\r
572# if not Statement:\r
573# continue\r
4234283c
LG
574 ArchList = UserExtension.GetSupArchList()\r
575 for Index in xrange(0, len(ArchList)):\r
576 ArchList[Index] = ConvertArchForInstall(ArchList[Index])\r
577 ArchList.sort()\r
4234283c
LG
578 KeyList = []\r
579 CommonPreFix = ''\r
580 if UserExtension.GetUserID():\r
581 CommonPreFix = UserExtension.GetUserID()\r
582 if CommonPreFix.find('.') > -1:\r
583 CommonPreFix = '"' + CommonPreFix + '"'\r
584 if UserExtension.GetIdentifier():\r
585 CommonPreFix += '.' + '"' + UserExtension.GetIdentifier() + '"'\r
586 if ArchList:\r
587 KeyList = [CommonPreFix + '.' + Arch for Arch in ArchList]\r
588 else:\r
421ccda3 589 KeyList = [CommonPreFix]\r
4234283c
LG
590 for Key in KeyList:\r
591 if Key in NewSectionDict:\r
592 NewSectionDict[Key] = NewSectionDict[Key] + [Statement]\r
593 else:\r
594 NewSectionDict[Key] = [Statement]\r
595 Content = GenSection('UserExtensions', NewSectionDict, False)\r
421ccda3 596\r
4234283c 597 return Content\r
421ccda3 598\r
4234283c
LG
599# GenSourceStatement\r
600#\r
601# @param SourceFile: string of source file path/name\r
602# @param Family: string of source file family field\r
603# @param FeatureFlag: string of source file FeatureFlag field\r
604# @param TagName: string of source file TagName field\r
605# @param ToolCode: string of source file ToolCode field\r
606# @param HelpStr: string of source file HelpStr field\r
607#\r
608# @retval Statement: The generated statement for source\r
609#\r
421ccda3 610def GenSourceStatement(SourceFile, Family, FeatureFlag, TagName=None,\r
4234283c
LG
611 ToolCode=None, HelpStr=None):\r
612 Statement = ''\r
613 if HelpStr:\r
421ccda3 614 Statement += GenGenericCommentF(HelpStr)\r
4234283c
LG
615 #\r
616 # format of SourceFile|Family|TagName|ToolCode|FeatureFlag\r
617 #\r
618 Statement += SourceFile\r
4231a819 619 if TagName is None:\r
4234283c 620 TagName = ''\r
4231a819 621 if ToolCode is None:\r
4234283c 622 ToolCode = ''\r
4231a819 623 if HelpStr is None:\r
4234283c 624 HelpStr = ''\r
4234283c
LG
625 if FeatureFlag:\r
626 Statement += '|' + Family + '|' + TagName + '|' + ToolCode + '|' + FeatureFlag\r
627 elif ToolCode:\r
628 Statement += '|' + Family + '|' + TagName + '|' + ToolCode\r
629 elif TagName:\r
630 Statement += '|' + Family + '|' + TagName\r
631 elif Family:\r
632 Statement += '|' + Family\r
4234283c
LG
633 return Statement\r
634\r
635# GenBinaryStatement\r
636#\r
637# @param Key: (FileName, FileType, FFE, SortedArch)\r
638# @param Value: (Target, Family, TagName, Comment)\r
639#\r
640#\r
421ccda3 641def GenBinaryStatement(Key, Value, SubTypeGuidValue=None):\r
4234283c
LG
642 (FileName, FileType, FFE, SortedArch) = Key\r
643 if SortedArch:\r
644 pass\r
645 if Value:\r
646 (Target, Family, TagName, Comment) = Value\r
647 else:\r
648 Target = ''\r
649 Family = ''\r
650 TagName = ''\r
651 Comment = ''\r
4234283c
LG
652 if Comment:\r
653 Statement = GenGenericCommentF(Comment)\r
654 else:\r
655 Statement = ''\r
421ccda3
HC
656 if FileType == 'SUBTYPE_GUID' and SubTypeGuidValue:\r
657 Statement += FileType + '|' + SubTypeGuidValue + '|' + FileName\r
658 else:\r
659 Statement += FileType + '|' + FileName\r
4234283c
LG
660 if FileType in DT.BINARY_FILE_TYPE_UI_LIST + DT.BINARY_FILE_TYPE_VER_LIST:\r
661 if FFE:\r
662 Statement += '|' + Target + '|' + FFE\r
663 elif Target:\r
664 Statement += '|' + Target\r
665 else:\r
666 if FFE:\r
667 Statement += '|' + Target + '|' + Family + '|' + TagName + '|' + FFE\r
668 elif TagName:\r
669 Statement += '|' + Target + '|' + Family + '|' + TagName\r
670 elif Family:\r
671 Statement += '|' + Target + '|' + Family\r
672 elif Target:\r
673 Statement += '|' + Target\r
4234283c 674 return Statement\r
4234283c 675## GenGuidSections\r
f7496d71 676#\r
4234283c
LG
677# @param GuidObjList: List of GuidObject\r
678# @retVal Content: The generated section contents\r
679#\r
680def GenGuidSections(GuidObjList):\r
681 #\r
682 # generate [Guids] section\r
683 #\r
421ccda3 684 Content = ''\r
4234283c 685 GuidDict = Sdict()\r
4234283c
LG
686 for Guid in GuidObjList:\r
687 HelpTextList = Guid.GetHelpTextList()\r
688 HelpStr = _GetHelpStr(HelpTextList)\r
4234283c
LG
689 CName = Guid.GetCName()\r
690 FFE = Guid.GetFeatureFlag()\r
691 Statement = CName\r
692 if FFE:\r
693 Statement += '|' + FFE\r
4234283c
LG
694 Usage = Guid.GetUsage()\r
695 GuidType = Guid.GetGuidTypeList()[0]\r
696 VariableName = Guid.GetVariableName()\r
4234283c 697 #\r
421ccda3 698 # Differentiate the generic comment and usage comment as multiple generic comment need to be put at first\r
4234283c
LG
699 #\r
700 if Usage == DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED:\r
701 # generate list of generic comment\r
702 Comment = GenGenericCommentF(HelpStr)\r
703 else:\r
704 # generate list of other comment\r
705 Comment = HelpStr.replace('\n', ' ')\r
706 Comment = Comment.strip()\r
707 if Comment:\r
708 Comment = ' # ' + Comment\r
709 else:\r
710 Comment = ''\r
4234283c 711 if Usage != DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED:\r
76d47511 712 Comment = '## ' + Usage + Comment\r
4234283c
LG
713 elif GuidType == 'Variable':\r
714 Comment = '## ' + Usage + ' ## ' + GuidType + ':' + VariableName + Comment\r
715 else:\r
716 Comment = '## ' + Usage + ' ## ' + GuidType + Comment\r
421ccda3 717\r
4234283c
LG
718 if Comment:\r
719 Comment += '\n'\r
4234283c
LG
720 #\r
721 # merge duplicate items\r
722 #\r
0d1f5b2b 723 ArchList = sorted(Guid.GetSupArchList())\r
4234283c
LG
724 SortedArch = ' '.join(ArchList)\r
725 if (Statement, SortedArch) in GuidDict:\r
726 PreviousComment = GuidDict[Statement, SortedArch]\r
421ccda3 727 Comment = PreviousComment + Comment\r
4234283c 728 GuidDict[Statement, SortedArch] = Comment\r
421ccda3 729 NewSectionDict = GenMetaFileMisc.TransferDict(GuidDict, 'INF_GUID')\r
4234283c
LG
730 #\r
731 # generate the section contents\r
732 #\r
733 if NewSectionDict:\r
734 Content = GenSection('Guids', NewSectionDict)\r
421ccda3 735\r
4234283c
LG
736 return Content\r
737\r
738## GenProtocolPPiSections\r
f7496d71 739#\r
4234283c
LG
740# @param ObjList: List of ProtocolObject or Ppi Object\r
741# @retVal Content: The generated section contents\r
742#\r
743def GenProtocolPPiSections(ObjList, IsProtocol):\r
744 Content = ''\r
745 Dict = Sdict()\r
746 for Object in ObjList:\r
747 HelpTextList = Object.GetHelpTextList()\r
748 HelpStr = _GetHelpStr(HelpTextList)\r
4234283c
LG
749 CName = Object.GetCName()\r
750 FFE = Object.GetFeatureFlag()\r
751 Statement = CName\r
752 if FFE:\r
753 Statement += '|' + FFE\r
4234283c
LG
754 Usage = Object.GetUsage()\r
755 Notify = Object.GetNotify()\r
4234283c 756 #\r
421ccda3 757 # Differentiate the generic comment and usage comment as consecutive generic comment need to be put together\r
4234283c
LG
758 #\r
759 if Usage == DT.ITEM_UNDEFINED and Notify == '':\r
760 # generate list of generic comment\r
761 Comment = GenGenericCommentF(HelpStr)\r
762 else:\r
763 # generate list of other comment\r
764 Comment = HelpStr.replace('\n', ' ')\r
765 Comment = Comment.strip()\r
766 if Comment:\r
767 Comment = ' # ' + Comment\r
768 else:\r
769 Comment = ''\r
4234283c
LG
770 if Usage == DT.ITEM_UNDEFINED and not Comment and Notify == '':\r
771 Comment = ''\r
772 else:\r
773 if Notify:\r
774 Comment = '## ' + Usage + ' ## ' + 'NOTIFY' + Comment\r
775 else:\r
776 Comment = '## ' + Usage + Comment\r
4234283c
LG
777 if Comment:\r
778 Comment += '\n'\r
4234283c
LG
779 #\r
780 # merge duplicate items\r
781 #\r
0d1f5b2b 782 ArchList = sorted(Object.GetSupArchList())\r
4234283c
LG
783 SortedArch = ' '.join(ArchList)\r
784 if (Statement, SortedArch) in Dict:\r
785 PreviousComment = Dict[Statement, SortedArch]\r
786 Comment = PreviousComment + Comment\r
787 Dict[Statement, SortedArch] = Comment\r
421ccda3 788 NewSectionDict = GenMetaFileMisc.TransferDict(Dict, 'INF_PPI_PROTOCOL')\r
4234283c
LG
789 #\r
790 # generate the section contents\r
791 #\r
792 if NewSectionDict:\r
793 if IsProtocol:\r
794 Content = GenSection('Protocols', NewSectionDict)\r
795 else:\r
796 Content = GenSection('Ppis', NewSectionDict)\r
421ccda3 797\r
4234283c
LG
798 return Content\r
799\r
800## GenPcdSections\r
801#\r
802#\r
803def GenPcdSections(ModuleObject):\r
804 Content = ''\r
805 if not GlobalData.gIS_BINARY_INF:\r
806 #\r
f7496d71 807 # for each Pcd Itemtype, maintain a dict so the same type will be grouped\r
4234283c
LG
808 # together\r
809 #\r
810 ItemTypeDict = {}\r
811 for Pcd in ModuleObject.GetPcdList():\r
812 HelpTextList = Pcd.GetHelpTextList()\r
813 HelpStr = _GetHelpStr(HelpTextList)\r
4234283c
LG
814 Statement = ''\r
815 CName = Pcd.GetCName()\r
816 TokenSpaceGuidCName = Pcd.GetTokenSpaceGuidCName()\r
817 DefaultValue = Pcd.GetDefaultValue()\r
818 ItemType = Pcd.GetItemType()\r
819 if ItemType in ItemTypeDict:\r
820 Dict = ItemTypeDict[ItemType]\r
821 else:\r
822 Dict = Sdict()\r
823 ItemTypeDict[ItemType] = Dict\r
4234283c
LG
824 FFE = Pcd.GetFeatureFlag()\r
825 Statement += TokenSpaceGuidCName + '.' + CName\r
826 if DefaultValue:\r
827 Statement += '|' + DefaultValue\r
828 if FFE:\r
829 Statement += '|' + FFE\r
830 elif FFE:\r
831 Statement += '||' + FFE\r
4234283c
LG
832 #\r
833 # Generate comment\r
834 #\r
835 Usage = Pcd.GetValidUsage()\r
4234283c 836 # if FeatureFlag Pcd, then assume all Usage is CONSUMES\r
4234283c
LG
837 if ItemType == DT.TAB_INF_FEATURE_PCD:\r
838 Usage = DT.USAGE_ITEM_CONSUMES\r
421ccda3 839 if Usage == DT.ITEM_UNDEFINED:\r
4234283c
LG
840 # generate list of generic comment\r
841 Comment = GenGenericCommentF(HelpStr)\r
842 else:\r
843 # generate list of other comment\r
844 Comment = HelpStr.replace('\n', ' ')\r
845 Comment = Comment.strip()\r
846 if Comment:\r
847 Comment = ' # ' + Comment\r
848 else:\r
849 Comment = ''\r
4234283c 850 Comment = '## ' + Usage + Comment\r
4234283c
LG
851 if Comment:\r
852 Comment += '\n'\r
4234283c
LG
853 #\r
854 # Merge duplicate entries\r
855 #\r
0d1f5b2b 856 ArchList = sorted(Pcd.GetSupArchList())\r
4234283c
LG
857 SortedArch = ' '.join(ArchList)\r
858 if (Statement, SortedArch) in Dict:\r
859 PreviousComment = Dict[Statement, SortedArch]\r
860 Comment = PreviousComment + Comment\r
421ccda3 861 Dict[Statement, SortedArch] = Comment\r
4234283c 862 for ItemType in ItemTypeDict:\r
4234283c 863 # First we need to transfer the Dict to use SortedArch as key\r
4234283c 864 Dict = ItemTypeDict[ItemType]\r
421ccda3 865 NewSectionDict = GenMetaFileMisc.TransferDict(Dict, 'INF_PCD')\r
4234283c
LG
866 if NewSectionDict:\r
867 Content += GenSection(ItemType, NewSectionDict)\r
868 #\r
f7496d71 869 # For AsBuild INF files\r
4234283c
LG
870 #\r
871 else:\r
872 Content += GenAsBuiltPacthPcdSections(ModuleObject)\r
873 Content += GenAsBuiltPcdExSections(ModuleObject)\r
421ccda3 874\r
4234283c
LG
875 return Content\r
876\r
877## GenPcdSections\r
878#\r
879#\r
880def GenAsBuiltPacthPcdSections(ModuleObject):\r
881 PatchPcdDict = {}\r
882 for BinaryFile in ModuleObject.GetBinaryFileList():\r
883 if not BinaryFile.AsBuiltList:\r
421ccda3
HC
884 continue\r
885 for PatchPcd in BinaryFile.AsBuiltList[0].PatchPcdList:\r
4234283c
LG
886 TokenSpaceName = ''\r
887 PcdCName = PatchPcd.CName\r
888 PcdValue = PatchPcd.DefaultValue\r
889 PcdOffset = PatchPcd.Offset\r
890 TokenSpaceGuidValue = PatchPcd.TokenSpaceGuidValue\r
891 Token = PatchPcd.Token\r
892 HelpTextList = PatchPcd.HelpTextList\r
893 HelpString = ''\r
894 for HelpStringItem in HelpTextList:\r
895 for HelpLine in GetSplitValueList(HelpStringItem.String, '\n'):\r
421ccda3
HC
896 HelpString += '## ' + HelpLine + '\n'\r
897 TokenSpaceName, PcdCName = GenMetaFileMisc.ObtainPcdName(ModuleObject.PackageDependencyList,\r
898 TokenSpaceGuidValue,\r
4234283c 899 Token)\r
421ccda3
HC
900 if TokenSpaceName == '' or PcdCName == '':\r
901 Logger.Error("Upt",\r
4234283c 902 ToolError.RESOURCE_NOT_AVAILABLE,\r
421ccda3
HC
903 ST.ERR_INSTALL_FILE_DEC_FILE_ERROR % (TokenSpaceGuidValue, Token),\r
904 File=ModuleObject.GetFullPath())\r
905 Statement = HelpString + TokenSpaceName + '.' + PcdCName + ' | ' + PcdValue + ' | ' + \\r
906 PcdOffset + DT.TAB_SPACE_SPLIT\r
907 #\r
f7496d71 908 # Use binary file's Arch to be Pcd's Arch\r
421ccda3
HC
909 #\r
910 ArchList = []\r
911 FileNameObjList = BinaryFile.GetFileNameList()\r
912 if FileNameObjList:\r
913 ArchList = FileNameObjList[0].GetSupArchList()\r
914 if len(ArchList) == 0:\r
27c4ceb4 915 if DT.TAB_ARCH_COMMON in PatchPcdDict:\r
421ccda3
HC
916 if Statement not in PatchPcdDict[DT.TAB_ARCH_COMMON]:\r
917 PatchPcdDict[DT.TAB_ARCH_COMMON].append(Statement)\r
4234283c 918 else:\r
421ccda3 919 PatchPcdDict[DT.TAB_ARCH_COMMON] = [Statement]\r
4234283c 920 else:\r
421ccda3 921 for Arch in ArchList:\r
27c4ceb4 922 if Arch in PatchPcdDict:\r
421ccda3
HC
923 if Statement not in PatchPcdDict[Arch]:\r
924 PatchPcdDict[Arch].append(Statement)\r
4234283c
LG
925 else:\r
926 PatchPcdDict[Arch] = [Statement]\r
421ccda3 927 return GenSection(DT.TAB_INF_PATCH_PCD, PatchPcdDict)\r
4234283c
LG
928## GenPcdSections\r
929#\r
930#\r
931def GenAsBuiltPcdExSections(ModuleObject):\r
932 PcdExDict = {}\r
933 for BinaryFile in ModuleObject.GetBinaryFileList():\r
934 if not BinaryFile.AsBuiltList:\r
421ccda3 935 continue\r
4234283c
LG
936 for PcdExItem in BinaryFile.AsBuiltList[0].PcdExValueList:\r
937 TokenSpaceName = ''\r
938 PcdCName = PcdExItem.CName\r
4234283c
LG
939 TokenSpaceGuidValue = PcdExItem.TokenSpaceGuidValue\r
940 Token = PcdExItem.Token\r
941 HelpTextList = PcdExItem.HelpTextList\r
942 HelpString = ''\r
943 for HelpStringItem in HelpTextList:\r
944 for HelpLine in GetSplitValueList(HelpStringItem.String, '\n'):\r
421ccda3
HC
945 HelpString += '## ' + HelpLine + '\n'\r
946 TokenSpaceName, PcdCName = GenMetaFileMisc.ObtainPcdName(ModuleObject.PackageDependencyList,\r
4234283c 947 TokenSpaceGuidValue, Token)\r
421ccda3 948 if TokenSpaceName == '' or PcdCName == '':\r
4234283c
LG
949 Logger.Error("Upt",\r
950 ToolError.RESOURCE_NOT_AVAILABLE,\r
421ccda3
HC
951 ST.ERR_INSTALL_FILE_DEC_FILE_ERROR % (TokenSpaceGuidValue, Token),\r
952 File=ModuleObject.GetFullPath())\r
953\r
954 Statement = HelpString + TokenSpaceName + DT.TAB_SPLIT + PcdCName + DT.TAB_SPACE_SPLIT\r
955\r
956 #\r
f7496d71 957 # Use binary file's Arch to be Pcd's Arch\r
421ccda3
HC
958 #\r
959 ArchList = []\r
960 FileNameObjList = BinaryFile.GetFileNameList()\r
961 if FileNameObjList:\r
962 ArchList = FileNameObjList[0].GetSupArchList()\r
963\r
964 if len(ArchList) == 0:\r
27c4ceb4 965 if 'COMMON' in PcdExDict:\r
4234283c
LG
966 PcdExDict['COMMON'].append(Statement)\r
967 else:\r
968 PcdExDict['COMMON'] = [Statement]\r
969 else:\r
421ccda3 970 for Arch in ArchList:\r
27c4ceb4 971 if Arch in PcdExDict:\r
421ccda3
HC
972 if Statement not in PcdExDict[Arch]:\r
973 PcdExDict[Arch].append(Statement)\r
4234283c
LG
974 else:\r
975 PcdExDict[Arch] = [Statement]\r
976 return GenSection('PcdEx', PcdExDict)\r
421ccda3 977\r
4234283c
LG
978## GenSpecialSections\r
979# generate special sections for Event/BootMode/Hob\r
980#\r
e0e1cfcb 981def GenSpecialSections(ObjectList, SectionName, UserExtensionsContent=''):\r
4234283c
LG
982 #\r
983 # generate section\r
984 #\r
985 Content = ''\r
986 NewSectionDict = {}\r
987 for Obj in ObjectList:\r
988 #\r
989 # Generate comment\r
990 #\r
991 CommentStr = ''\r
992 HelpTextList = Obj.GetHelpTextList()\r
993 HelpStr = _GetHelpStr(HelpTextList)\r
994 CommentStr = GenGenericCommentF(HelpStr)\r
4234283c
LG
995 if SectionName == 'Hob':\r
996 Type = Obj.GetHobType()\r
997 elif SectionName == 'Event':\r
998 Type = Obj.GetEventType()\r
999 elif SectionName == 'BootMode':\r
1000 Type = Obj.GetSupportedBootModes()\r
1001 else:\r
1002 assert(SectionName)\r
4234283c 1003 Usage = Obj.GetUsage()\r
e0e1cfcb
HC
1004\r
1005 # If the content already in UserExtensionsContent then ignore\r
1006 if '[%s]' % SectionName in UserExtensionsContent and Type in UserExtensionsContent:\r
1007 return ''\r
1008\r
4234283c 1009 Statement = ' ' + Type + ' ## ' + Usage\r
4234283c
LG
1010 if CommentStr in ['#\n', '#\n#\n']:\r
1011 CommentStr = '#\n#\n#\n'\r
1012 #\r
421ccda3 1013 # the first head comment line should start with '##\n', if it starts with '#\n', then add one '#'\r
4234283c
LG
1014 # else add '##\n' to meet the format defined in INF spec\r
1015 #\r
1016 if CommentStr.startswith('#\n'):\r
1017 CommentStr = '#' + CommentStr\r
1018 elif CommentStr:\r
1019 CommentStr = '##\n' + CommentStr\r
4234283c 1020 if CommentStr and not CommentStr.endswith('\n#\n'):\r
421ccda3 1021 CommentStr = CommentStr + '#\n'\r
4234283c 1022 NewStateMent = CommentStr + Statement\r
0d1f5b2b 1023 SupArch = sorted(Obj.GetSupArchList())\r
4234283c
LG
1024 SortedArch = ' '.join(SupArch)\r
1025 if SortedArch in NewSectionDict:\r
1026 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [NewStateMent]\r
1027 else:\r
1028 NewSectionDict[SortedArch] = [NewStateMent]\r
4234283c
LG
1029 SectionContent = GenSection(SectionName, NewSectionDict)\r
1030 SectionContent = SectionContent.strip()\r
1031 if SectionContent:\r
1032 Content = '# ' + ('\n' + '# ').join(GetSplitValueList(SectionContent, '\n'))\r
1033 Content = Content.lstrip()\r
1034 #\r
76d47511 1035 # add a return to differentiate it between other possible sections\r
f7496d71 1036 #\r
421ccda3 1037 if Content:\r
76d47511 1038 Content += '\n'\r
4234283c 1039 return Content\r
4234283c
LG
1040## GenBuildOptions\r
1041#\r
1042#\r
1043def GenBuildOptions(ModuleObject):\r
1044 Content = ''\r
1045 if not ModuleObject.BinaryModule:\r
1046 #\r
1047 # generate [BuildOptions] section\r
1048 #\r
1049 NewSectionDict = {}\r
1050 for UserExtension in ModuleObject.GetUserExtensionList():\r
1051 BuildOptionDict = UserExtension.GetBuildOptionDict()\r
1052 if not BuildOptionDict:\r
1053 continue\r
1054 for Arch in BuildOptionDict:\r
1055 if Arch in NewSectionDict:\r
1056 NewSectionDict[Arch] = NewSectionDict[Arch] + [BuildOptionDict[Arch]]\r
1057 else:\r
1058 NewSectionDict[Arch] = [BuildOptionDict[Arch]]\r
4234283c
LG
1059 Content = GenSection('BuildOptions', NewSectionDict)\r
1060 else:\r
1061 BuildOptionDict = {}\r
1062 for BinaryFile in ModuleObject.GetBinaryFileList():\r
1063 if not BinaryFile.AsBuiltList:\r
1064 continue\r
1065 for BuilOptionItem in BinaryFile.AsBuiltList[0].BinaryBuildFlagList:\r
421ccda3 1066 Statement = '#' + BuilOptionItem.AsBuiltOptionFlags\r
4234283c 1067 if len(BinaryFile.SupArchList) == 0:\r
27c4ceb4 1068 if 'COMMON' in BuildOptionDict:\r
4234283c
LG
1069 if Statement not in BuildOptionDict['COMMON']:\r
1070 BuildOptionDict['COMMON'].append(Statement)\r
1071 else:\r
1072 BuildOptionDict['COMMON'] = ['## @AsBuilt']\r
1073 BuildOptionDict['COMMON'].append(Statement)\r
1074 else:\r
1075 for Arch in BinaryFile.SupArchList:\r
27c4ceb4 1076 if Arch in BuildOptionDict:\r
4234283c
LG
1077 if Statement not in BuildOptionDict[Arch]:\r
1078 BuildOptionDict[Arch].append(Statement)\r
1079 else:\r
1080 BuildOptionDict[Arch] = ['## @AsBuilt']\r
1081 BuildOptionDict[Arch].append(Statement)\r
4234283c 1082 Content = GenSection('BuildOptions', BuildOptionDict)\r
4234283c 1083\r
421ccda3 1084 return Content\r
4234283c
LG
1085## GenBinaries\r
1086#\r
1087#\r
1088def GenBinaries(ModuleObject):\r
1089 NewSectionDict = {}\r
1090 BinariesDict = []\r
1091 for UserExtension in ModuleObject.GetUserExtensionList():\r
1092 BinariesDict = UserExtension.GetBinariesDict()\r
1093 if BinariesDict:\r
1094 break\r
4234283c
LG
1095 for BinaryFile in ModuleObject.GetBinaryFileList():\r
1096 FileNameObjList = BinaryFile.GetFileNameList()\r
1097 for FileNameObj in FileNameObjList:\r
1098 FileName = ConvertPath(FileNameObj.GetFilename())\r
1099 FileType = FileNameObj.GetFileType()\r
1100 FFE = FileNameObj.GetFeatureFlag()\r
0d1f5b2b 1101 ArchList = sorted(FileNameObj.GetSupArchList())\r
421ccda3 1102 SortedArch = ' '.join(ArchList)\r
4234283c 1103 Key = (FileName, FileType, FFE, SortedArch)\r
4234283c
LG
1104 if Key in BinariesDict:\r
1105 ValueList = BinariesDict[Key]\r
1106 for ValueItem in ValueList:\r
1107 Statement = GenBinaryStatement(Key, ValueItem)\r
1108 if SortedArch in NewSectionDict:\r
1109 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r
1110 else:\r
1111 NewSectionDict[SortedArch] = [Statement]\r
1112 #\r
f7496d71 1113 # as we already generated statement for this DictKey here set the Valuelist to be empty\r
421ccda3 1114 # to avoid generate duplicate entries as the DictKey may have multiple entries\r
4234283c
LG
1115 #\r
1116 BinariesDict[Key] = []\r
1117 else:\r
421ccda3
HC
1118 if FileType == 'SUBTYPE_GUID' and FileNameObj.GetGuidValue():\r
1119 Statement = GenBinaryStatement(Key, None, FileNameObj.GetGuidValue())\r
1120 else:\r
1121 Statement = GenBinaryStatement(Key, None)\r
4234283c
LG
1122 if SortedArch in NewSectionDict:\r
1123 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r
1124 else:\r
421ccda3
HC
1125 NewSectionDict[SortedArch] = [Statement]\r
1126 Content = GenSection('Binaries', NewSectionDict)\r
1127\r
1128 return Content\r