]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
BaseTools/UPT: Fix an issue of adding Event twice
[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
e0e1cfcb 5# Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>\r
4234283c
LG
6#\r
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
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
4234283c
LG
23from Library.String import GetSplitValueList\r
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
06eb3540 44from Library.String import GetUniFileName\r
421ccda3 45\r
4234283c
LG
46\r
47## Transfer Module Object to Inf files\r
48#\r
49# Transfer all contents of a standard Module Object to an Inf file \r
50# @param ModuleObject: A Module Object \r
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
421ccda3
HC
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
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
4234283c 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
117 # Generate Binary Header \r
118 # \r
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
143 GenModuleUNIEncodeFile(ModuleObject, FileHeader)\r
144\r
4234283c
LG
145 #\r
146 # Judge whether the INF file is an AsBuild INF.\r
147 #\r
148 if ModuleObject.BinaryModule:\r
149 GlobalData.gIS_BINARY_INF = True\r
150 else:\r
151 GlobalData.gIS_BINARY_INF = False\r
4234283c
LG
152 #\r
153 # for each section, maintain a dict, sorted arch will be its key, \r
154 # statement list will be its data\r
155 # { 'Arch1 Arch2 Arch3': [statement1, statement2],\r
156 # 'Arch1' : [statement1, statement3] \r
157 # }\r
4234283c
LG
158 #\r
159 # Gen section contents\r
160 #\r
161 Content += GenDefines(ModuleObject)\r
162 Content += GenBuildOptions(ModuleObject)\r
163 Content += GenLibraryClasses(ModuleObject)\r
164 Content += GenPackages(ModuleObject)\r
165 Content += GenPcdSections(ModuleObject)\r
166 Content += GenSources(ModuleObject)\r
421ccda3
HC
167 Content += GenProtocolPPiSections(ModuleObject.GetProtocolList(), True)\r
168 Content += GenProtocolPPiSections(ModuleObject.GetPpiList(), False)\r
169 Content += GenGuidSections(ModuleObject.GetGuidList())\r
4234283c
LG
170 Content += GenBinaries(ModuleObject)\r
171 Content += GenDepex(ModuleObject)\r
e0e1cfcb
HC
172 __UserExtensionsContent = GenUserExtensions(ModuleObject)\r
173 Content += __UserExtensionsContent\r
4234283c 174 if ModuleObject.GetEventList() or ModuleObject.GetBootModeList() or ModuleObject.GetHobList():\r
421ccda3 175 Content += '\n'\r
4234283c
LG
176 #\r
177 # generate [Event], [BootMode], [Hob] section\r
178 #\r
e0e1cfcb
HC
179 Content += GenSpecialSections(ModuleObject.GetEventList(), 'Event', __UserExtensionsContent)\r
180 Content += GenSpecialSections(ModuleObject.GetBootModeList(), 'BootMode', __UserExtensionsContent)\r
181 Content += GenSpecialSections(ModuleObject.GetHobList(), 'Hob', __UserExtensionsContent)\r
4234283c 182 SaveFileOnChange(ContainerFile, Content, False)\r
421ccda3
HC
183 if DistHeader.ReadOnly:\r
184 os.chmod(ContainerFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)\r
185 else:\r
186 os.chmod(ContainerFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH|stat.S_IWUSR|stat.S_IWGRP|stat.S_IWOTH)\r
4234283c
LG
187 return ContainerFile\r
188\r
421ccda3
HC
189## GenModuleUNIEncodeFile\r
190# GenModuleUNIEncodeFile, default is a UCS-2LE encode file\r
191#\r
192def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader='', Encoding=DT.TAB_ENCODING_UTF16LE):\r
193 GenUNIFlag = False\r
194 OnlyLANGUAGE_EN_X = True\r
195 BinaryAbstract = []\r
196 BinaryDescription = []\r
197 #\r
198 # If more than one language code is used for any element that would be present in the MODULE_UNI_FILE, \r
199 # then the MODULE_UNI_FILE must be created.\r
200 #\r
201 for (Key, Value) in ModuleObject.GetAbstract() + ModuleObject.GetDescription():\r
202 if Key == DT.TAB_LANGUAGE_EN_X:\r
203 GenUNIFlag = True\r
204 else:\r
205 OnlyLANGUAGE_EN_X = False\r
206\r
207 for UserExtension in ModuleObject.GetUserExtensionList():\r
208 if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID \\r
209 and UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER:\r
210 for (Key, Value) in UserExtension.GetBinaryAbstract():\r
211 if Key == DT.TAB_LANGUAGE_EN_X:\r
212 GenUNIFlag = True\r
213 else:\r
214 OnlyLANGUAGE_EN_X = False\r
215 BinaryAbstract.append((Key, Value))\r
216 for (Key, Value) in UserExtension.GetBinaryDescription():\r
217 if Key == DT.TAB_LANGUAGE_EN_X:\r
218 GenUNIFlag = True\r
219 else:\r
220 OnlyLANGUAGE_EN_X = False\r
221 BinaryDescription.append((Key, Value))\r
222\r
223\r
224 if not GenUNIFlag:\r
225 return\r
226 elif OnlyLANGUAGE_EN_X:\r
227 return\r
228 else:\r
229 ModuleObject.UNIFlag = True\r
06eb3540
HC
230 ContainerFile = GetUniFileName(os.path.dirname(ModuleObject.GetFullPath()), ModuleObject.GetBaseName())\r
231\r
421ccda3
HC
232 if not os.path.exists(os.path.dirname(ModuleObject.GetFullPath())):\r
233 os.makedirs(os.path.dirname(ModuleObject.GetFullPath()))\r
234\r
cf2b2bde
HC
235 Content = UniFileHeader + '\r\n'\r
236 Content += '\r\n'\r
421ccda3 237\r
cf2b2bde 238 Content += FormatUniEntry('#string ' + DT.TAB_INF_ABSTRACT, ModuleObject.GetAbstract(), ContainerFile) + '\r\n'\r
421ccda3
HC
239\r
240 Content += FormatUniEntry('#string ' + DT.TAB_INF_DESCRIPTION, ModuleObject.GetDescription(), ContainerFile) \\r
cf2b2bde 241 + '\r\n'\r
421ccda3
HC
242\r
243 BinaryAbstractString = FormatUniEntry('#string ' + DT.TAB_INF_BINARY_ABSTRACT, BinaryAbstract, ContainerFile)\r
244 if BinaryAbstractString:\r
cf2b2bde 245 Content += BinaryAbstractString + '\r\n'\r
421ccda3
HC
246\r
247 BinaryDescriptionString = FormatUniEntry('#string ' + DT.TAB_INF_BINARY_DESCRIPTION, BinaryDescription, \\r
248 ContainerFile)\r
249 if BinaryDescriptionString:\r
cf2b2bde 250 Content += BinaryDescriptionString + '\r\n'\r
421ccda3
HC
251\r
252 if not os.path.exists(ContainerFile):\r
253 File = codecs.open(ContainerFile, 'wb', Encoding)\r
254 File.write(u'\uFEFF' + Content)\r
255 File.stream.close()\r
256 Md5Sigature = md5.new(__FileHookOpen__(str(ContainerFile), 'rb').read())\r
257 Md5Sum = Md5Sigature.hexdigest()\r
258 if (ContainerFile, Md5Sum) not in ModuleObject.FileList:\r
259 ModuleObject.FileList.append((ContainerFile, Md5Sum))\r
260\r
261 return ContainerFile\r
4234283c
LG
262def GenDefines(ModuleObject):\r
263 #\r
264 # generate [Defines] section\r
265 #\r
875cc5bb 266 LeftOffset = 31\r
421ccda3
HC
267 Content = ''\r
268 NewSectionDict = {}\r
875cc5bb 269\r
4234283c
LG
270 for UserExtension in ModuleObject.GetUserExtensionList():\r
271 DefinesDict = UserExtension.GetDefinesDict()\r
272 if not DefinesDict:\r
273 continue\r
4234283c 274 for Statement in DefinesDict:\r
875cc5bb
HC
275 if Statement.split(DT.TAB_EQUAL_SPLIT) > 1:\r
276 Statement = (u'%s ' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[0]).ljust(LeftOffset) \\r
277 + u'= %s' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[1].lstrip()\r
4234283c
LG
278 SortedArch = DT.TAB_ARCH_COMMON\r
279 if Statement.strip().startswith(DT.TAB_INF_DEFINES_CUSTOM_MAKEFILE):\r
280 pos = Statement.find(DT.TAB_VALUE_SPLIT)\r
281 if pos == -1:\r
282 pos = Statement.find(DT.TAB_EQUAL_SPLIT)\r
283 Makefile = ConvertPath(Statement[pos + 1:].strip())\r
284 Statement = Statement[:pos + 1] + ' ' + Makefile\r
285 if SortedArch in NewSectionDict:\r
286 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r
287 else:\r
421ccda3 288 NewSectionDict[SortedArch] = [Statement]\r
4234283c 289 SpecialStatementList = []\r
875cc5bb 290\r
421ccda3
HC
291 # TAB_INF_DEFINES_INF_VERSION\r
292 Statement = (u'%s ' % DT.TAB_INF_DEFINES_INF_VERSION).ljust(LeftOffset) + u'= %s' % '0x00010017'\r
4234283c
LG
293 SpecialStatementList.append(Statement)\r
294\r
421ccda3 295 # BaseName\r
4234283c
LG
296 BaseName = ModuleObject.GetBaseName()\r
297 if BaseName.startswith('.') or BaseName.startswith('-'):\r
298 BaseName = '_' + BaseName\r
421ccda3 299 Statement = (u'%s ' % DT.TAB_INF_DEFINES_BASE_NAME).ljust(LeftOffset) + u'= %s' % BaseName\r
4234283c 300 SpecialStatementList.append(Statement)\r
421ccda3
HC
301 \r
302 # TAB_INF_DEFINES_FILE_GUID\r
303 Statement = (u'%s ' % DT.TAB_INF_DEFINES_FILE_GUID).ljust(LeftOffset) + u'= %s' % ModuleObject.GetGuid()\r
4234283c
LG
304 SpecialStatementList.append(Statement)\r
305 \r
421ccda3
HC
306 # TAB_INF_DEFINES_VERSION_STRING\r
307 Statement = (u'%s ' % DT.TAB_INF_DEFINES_VERSION_STRING).ljust(LeftOffset) + u'= %s' % ModuleObject.GetVersion()\r
308 SpecialStatementList.append(Statement)\r
309\r
310 # TAB_INF_DEFINES_VERSION_STRING\r
311 if ModuleObject.UNIFlag:\r
312 Statement = (u'%s ' % DT.TAB_INF_DEFINES_MODULE_UNI_FILE).ljust(LeftOffset) + \\r
313 u'= %s' % ModuleObject.GetBaseName() + '.uni'\r
314 SpecialStatementList.append(Statement)\r
315\r
316 # TAB_INF_DEFINES_MODULE_TYPE\r
4234283c 317 if ModuleObject.GetModuleType():\r
421ccda3 318 Statement = (u'%s ' % DT.TAB_INF_DEFINES_MODULE_TYPE).ljust(LeftOffset) + u'= %s' % ModuleObject.GetModuleType()\r
4234283c 319 SpecialStatementList.append(Statement)\r
421ccda3
HC
320\r
321 # TAB_INF_DEFINES_PCD_IS_DRIVER\r
4234283c 322 if ModuleObject.GetPcdIsDriver():\r
421ccda3
HC
323 Statement = (u'%s ' % DT.TAB_INF_DEFINES_PCD_IS_DRIVER).ljust(LeftOffset) + \\r
324 u'= %s' % ModuleObject.GetPcdIsDriver()\r
4234283c 325 SpecialStatementList.append(Statement)\r
421ccda3
HC
326\r
327 # TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION\r
4234283c 328 if ModuleObject.GetUefiSpecificationVersion():\r
421ccda3
HC
329 Statement = (u'%s ' % DT.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION).ljust(LeftOffset) + \\r
330 u'= %s' % ModuleObject.GetUefiSpecificationVersion()\r
4234283c 331 SpecialStatementList.append(Statement)\r
421ccda3
HC
332\r
333 # TAB_INF_DEFINES_PI_SPECIFICATION_VERSION\r
4234283c 334 if ModuleObject.GetPiSpecificationVersion():\r
421ccda3
HC
335 Statement = (u'%s ' % DT.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION).ljust(LeftOffset) + \\r
336 u'= %s' % ModuleObject.GetPiSpecificationVersion()\r
337 SpecialStatementList.append(Statement)\r
338\r
339 # LibraryClass\r
4234283c
LG
340 for LibraryClass in ModuleObject.GetLibraryClassList():\r
341 if LibraryClass.GetUsage() == DT.USAGE_ITEM_PRODUCES or \\r
342 LibraryClass.GetUsage() == DT.USAGE_ITEM_SOMETIMES_PRODUCES:\r
421ccda3
HC
343 Statement = (u'%s ' % DT.TAB_INF_DEFINES_LIBRARY_CLASS).ljust(LeftOffset) + \\r
344 u'= %s' % LibraryClass.GetLibraryClass()\r
4234283c
LG
345 if LibraryClass.GetSupModuleList():\r
346 Statement += '|' + DT.TAB_SPACE_SPLIT.join(l for l in LibraryClass.GetSupModuleList())\r
347 SpecialStatementList.append(Statement)\r
421ccda3
HC
348\r
349 # Spec Item\r
4234283c
LG
350 for SpecItem in ModuleObject.GetSpecList():\r
351 Spec, Version = SpecItem\r
352 Spec = ConvertSpec(Spec)\r
353 Statement = '%s %s = %s' % (DT.TAB_INF_DEFINES_SPEC, Spec, Version)\r
354 SpecialStatementList.append(Statement)\r
421ccda3
HC
355\r
356 # Extern\r
4234283c
LG
357 ExternList = []\r
358 for Extern in ModuleObject.GetExternList():\r
359 ArchList = Extern.GetSupArchList()\r
360 EntryPoint = Extern.GetEntryPoint()\r
361 UnloadImage = Extern.GetUnloadImage()\r
362 Constructor = Extern.GetConstructor()\r
363 Destructor = Extern.GetDestructor()\r
364 HelpStringList = Extern.GetHelpTextList()\r
365 FFE = Extern.GetFeatureFlag()\r
366 ExternList.append([ArchList, EntryPoint, UnloadImage, Constructor, Destructor, FFE, HelpStringList])\r
4234283c
LG
367 #\r
368 # Add VALID_ARCHITECTURES information\r
369 #\r
370 ValidArchStatement = None\r
371 if ModuleObject.SupArchList:\r
421ccda3 372 ValidArchStatement = '\n' + '# ' + '\n'\r
4234283c
LG
373 ValidArchStatement += '# The following information is for reference only and not required by the build tools.\n'\r
374 ValidArchStatement += '# ' + '\n'\r
375 ValidArchStatement += '# VALID_ARCHITECTURES = %s' % (' '.join(ModuleObject.SupArchList)) + '\n'\r
421ccda3 376 ValidArchStatement += '# '\r
4234283c
LG
377 if DT.TAB_ARCH_COMMON not in NewSectionDict:\r
378 NewSectionDict[DT.TAB_ARCH_COMMON] = []\r
379 NewSectionDict[DT.TAB_ARCH_COMMON] = NewSectionDict[DT.TAB_ARCH_COMMON] + SpecialStatementList\r
380 GenMetaFileMisc.AddExternToDefineSec(NewSectionDict, DT.TAB_ARCH_COMMON, ExternList)\r
381 if ValidArchStatement is not None:\r
382 NewSectionDict[DT.TAB_ARCH_COMMON] = NewSectionDict[DT.TAB_ARCH_COMMON] + [ValidArchStatement]\r
4234283c 383 Content += GenSection('Defines', NewSectionDict)\r
4234283c
LG
384 return Content\r
385\r
386def GenLibraryClasses(ModuleObject):\r
387 #\r
388 # generate [LibraryClasses] section\r
389 #\r
390 Content = ''\r
391 NewSectionDict = {}\r
392 if not GlobalData.gIS_BINARY_INF:\r
393 for LibraryClass in ModuleObject.GetLibraryClassList():\r
394 if LibraryClass.GetUsage() == DT.USAGE_ITEM_PRODUCES:\r
395 continue\r
396 #\r
397 # Generate generic comment\r
398 #\r
399 HelpTextList = LibraryClass.GetHelpTextList()\r
400 HelpStr = _GetHelpStr(HelpTextList)\r
401 CommentStr = GenGenericCommentF(HelpStr)\r
402 Statement = CommentStr\r
403 Name = LibraryClass.GetLibraryClass()\r
404 FFE = LibraryClass.GetFeatureFlag()\r
405 Statement += Name\r
406 if FFE:\r
421ccda3 407 Statement += '|' + FFE\r
4234283c
LG
408 ModuleList = LibraryClass.GetSupModuleList()\r
409 ArchList = LibraryClass.GetSupArchList()\r
410 for Index in xrange(0, len(ArchList)):\r
411 ArchList[Index] = ConvertArchForInstall(ArchList[Index])\r
412 ArchList.sort()\r
413 SortedArch = ' '.join(ArchList)\r
4234283c
LG
414 KeyList = []\r
415 if not ModuleList or IsAllModuleList(ModuleList):\r
421ccda3 416 KeyList = [SortedArch]\r
4234283c
LG
417 else:\r
418 ModuleString = DT.TAB_VALUE_SPLIT.join(l for l in ModuleList)\r
419 if not ArchList:\r
420 SortedArch = DT.TAB_ARCH_COMMON\r
421 KeyList = [SortedArch + '.' + ModuleString]\r
422 else:\r
423 KeyList = [Arch + '.' + ModuleString for Arch in ArchList]\r
4234283c
LG
424 for Key in KeyList:\r
425 if Key in NewSectionDict:\r
426 NewSectionDict[Key] = NewSectionDict[Key] + [Statement]\r
427 else:\r
428 NewSectionDict[Key] = [Statement]\r
429 Content += GenSection('LibraryClasses', NewSectionDict)\r
430 else:\r
431 LibraryClassDict = {}\r
432 for BinaryFile in ModuleObject.GetBinaryFileList():\r
433 if not BinaryFile.AsBuiltList:\r
434 continue\r
435 for LibraryItem in BinaryFile.AsBuiltList[0].LibraryInstancesList:\r
421ccda3
HC
436 Statement = '# Guid: ' + LibraryItem.Guid + ' Version: ' + LibraryItem.Version\r
437\r
4234283c 438 if len(BinaryFile.SupArchList) == 0:\r
421ccda3 439 if LibraryClassDict.has_key('COMMON') and Statement not in LibraryClassDict['COMMON']:\r
4234283c
LG
440 LibraryClassDict['COMMON'].append(Statement)\r
441 else:\r
442 LibraryClassDict['COMMON'] = ['## @LIB_INSTANCES']\r
443 LibraryClassDict['COMMON'].append(Statement)\r
444 else:\r
445 for Arch in BinaryFile.SupArchList:\r
446 if LibraryClassDict.has_key(Arch):\r
421ccda3
HC
447 if Statement not in LibraryClassDict[Arch]:\r
448 LibraryClassDict[Arch].append(Statement)\r
449 else:\r
450 continue\r
4234283c
LG
451 else:\r
452 LibraryClassDict[Arch] = ['## @LIB_INSTANCES']\r
453 LibraryClassDict[Arch].append(Statement)\r
4234283c 454 Content += GenSection('LibraryClasses', LibraryClassDict)\r
421ccda3 455\r
4234283c
LG
456 return Content\r
457\r
458def GenPackages(ModuleObject):\r
459 Content = ''\r
460 #\r
461 # generate [Packages] section\r
462 #\r
463 NewSectionDict = Sdict()\r
421ccda3 464 WorkspaceDir = GlobalData.gWORKSPACE\r
4234283c
LG
465 for PackageDependency in ModuleObject.GetPackageDependencyList():\r
466 #\r
467 # Generate generic comment\r
468 #\r
469 CommentStr = ''\r
470 HelpText = PackageDependency.GetHelpText()\r
471 if HelpText:\r
472 HelpStr = HelpText.GetString()\r
421ccda3 473 CommentStr = GenGenericCommentF(HelpStr)\r
4234283c
LG
474 Statement = CommentStr\r
475 Guid = PackageDependency.GetGuid()\r
476 Version = PackageDependency.GetVersion()\r
477 FFE = PackageDependency.GetFeatureFlag()\r
421ccda3 478 Path = ''\r
4234283c
LG
479 #\r
480 # find package path/name\r
481 # \r
482 for PkgInfo in GlobalData.gWSPKG_LIST:\r
483 if Guid == PkgInfo[1]:\r
484 if (not Version) or (Version == PkgInfo[2]):\r
485 Path = PkgInfo[3]\r
486 break\r
487 #\r
488 # get relative path\r
489 #\r
421ccda3 490 RelaPath = GetRelativePath(Path, WorkspaceDir)\r
4234283c
LG
491 Statement += RelaPath.replace('\\', '/')\r
492 if FFE:\r
421ccda3 493 Statement += '|' + FFE\r
4234283c
LG
494 ArchList = PackageDependency.GetSupArchList()\r
495 ArchList.sort()\r
496 SortedArch = ' '.join(ArchList)\r
497 if SortedArch in NewSectionDict:\r
498 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r
499 else:\r
421ccda3 500 NewSectionDict[SortedArch] = [Statement]\r
4234283c 501 Content += GenSection('Packages', NewSectionDict)\r
4234283c
LG
502 return Content\r
503\r
504def GenSources(ModuleObject):\r
505 #\r
506 # generate [Sources] section\r
507 #\r
508 Content = ''\r
509 NewSectionDict = {}\r
421ccda3 510 for Source in ModuleObject.GetSourceFileList():\r
4234283c
LG
511 SourceFile = Source.GetSourceFile()\r
512 Family = Source.GetFamily()\r
513 FeatureFlag = Source.GetFeatureFlag()\r
514 SupArchList = Source.GetSupArchList()\r
515 SupArchList.sort()\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
LG
555 Content += GenSection('Depex', NewSectionDict, False)\r
556 \r
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
571 if not Statement:\r
572 continue\r
4234283c
LG
573 ArchList = UserExtension.GetSupArchList()\r
574 for Index in xrange(0, len(ArchList)):\r
575 ArchList[Index] = ConvertArchForInstall(ArchList[Index])\r
576 ArchList.sort()\r
4234283c
LG
577 KeyList = []\r
578 CommonPreFix = ''\r
579 if UserExtension.GetUserID():\r
580 CommonPreFix = UserExtension.GetUserID()\r
581 if CommonPreFix.find('.') > -1:\r
582 CommonPreFix = '"' + CommonPreFix + '"'\r
583 if UserExtension.GetIdentifier():\r
584 CommonPreFix += '.' + '"' + UserExtension.GetIdentifier() + '"'\r
585 if ArchList:\r
586 KeyList = [CommonPreFix + '.' + Arch for Arch in ArchList]\r
587 else:\r
421ccda3 588 KeyList = [CommonPreFix]\r
4234283c
LG
589 for Key in KeyList:\r
590 if Key in NewSectionDict:\r
591 NewSectionDict[Key] = NewSectionDict[Key] + [Statement]\r
592 else:\r
593 NewSectionDict[Key] = [Statement]\r
594 Content = GenSection('UserExtensions', NewSectionDict, False)\r
421ccda3 595\r
4234283c 596 return Content\r
421ccda3 597\r
4234283c
LG
598# GenSourceStatement\r
599#\r
600# @param SourceFile: string of source file path/name\r
601# @param Family: string of source file family field\r
602# @param FeatureFlag: string of source file FeatureFlag field\r
603# @param TagName: string of source file TagName field\r
604# @param ToolCode: string of source file ToolCode field\r
605# @param HelpStr: string of source file HelpStr field\r
606#\r
607# @retval Statement: The generated statement for source\r
608#\r
421ccda3 609def GenSourceStatement(SourceFile, Family, FeatureFlag, TagName=None,\r
4234283c
LG
610 ToolCode=None, HelpStr=None):\r
611 Statement = ''\r
612 if HelpStr:\r
421ccda3 613 Statement += GenGenericCommentF(HelpStr)\r
4234283c
LG
614 #\r
615 # format of SourceFile|Family|TagName|ToolCode|FeatureFlag\r
616 #\r
617 Statement += SourceFile\r
4234283c
LG
618 if TagName == None:\r
619 TagName = ''\r
620 if ToolCode == None:\r
621 ToolCode = ''\r
622 if HelpStr == None:\r
623 HelpStr = ''\r
4234283c
LG
624 if FeatureFlag:\r
625 Statement += '|' + Family + '|' + TagName + '|' + ToolCode + '|' + FeatureFlag\r
626 elif ToolCode:\r
627 Statement += '|' + Family + '|' + TagName + '|' + ToolCode\r
628 elif TagName:\r
629 Statement += '|' + Family + '|' + TagName\r
630 elif Family:\r
631 Statement += '|' + Family\r
4234283c
LG
632 return Statement\r
633\r
634# GenBinaryStatement\r
635#\r
636# @param Key: (FileName, FileType, FFE, SortedArch)\r
637# @param Value: (Target, Family, TagName, Comment)\r
638#\r
639#\r
421ccda3 640def GenBinaryStatement(Key, Value, SubTypeGuidValue=None):\r
4234283c
LG
641 (FileName, FileType, FFE, SortedArch) = Key\r
642 if SortedArch:\r
643 pass\r
644 if Value:\r
645 (Target, Family, TagName, Comment) = Value\r
646 else:\r
647 Target = ''\r
648 Family = ''\r
649 TagName = ''\r
650 Comment = ''\r
4234283c
LG
651 if Comment:\r
652 Statement = GenGenericCommentF(Comment)\r
653 else:\r
654 Statement = ''\r
421ccda3
HC
655 if FileType == 'SUBTYPE_GUID' and SubTypeGuidValue:\r
656 Statement += FileType + '|' + SubTypeGuidValue + '|' + FileName\r
657 else:\r
658 Statement += FileType + '|' + FileName\r
4234283c
LG
659 if FileType in DT.BINARY_FILE_TYPE_UI_LIST + DT.BINARY_FILE_TYPE_VER_LIST:\r
660 if FFE:\r
661 Statement += '|' + Target + '|' + FFE\r
662 elif Target:\r
663 Statement += '|' + Target\r
664 else:\r
665 if FFE:\r
666 Statement += '|' + Target + '|' + Family + '|' + TagName + '|' + FFE\r
667 elif TagName:\r
668 Statement += '|' + Target + '|' + Family + '|' + TagName\r
669 elif Family:\r
670 Statement += '|' + Target + '|' + Family\r
671 elif Target:\r
672 Statement += '|' + Target\r
4234283c 673 return Statement\r
4234283c
LG
674## GenGuidSections\r
675# \r
676# @param GuidObjList: List of GuidObject\r
677# @retVal Content: The generated section contents\r
678#\r
679def GenGuidSections(GuidObjList):\r
680 #\r
681 # generate [Guids] section\r
682 #\r
421ccda3 683 Content = ''\r
4234283c 684 GuidDict = Sdict()\r
4234283c
LG
685 for Guid in GuidObjList:\r
686 HelpTextList = Guid.GetHelpTextList()\r
687 HelpStr = _GetHelpStr(HelpTextList)\r
4234283c
LG
688 CName = Guid.GetCName()\r
689 FFE = Guid.GetFeatureFlag()\r
690 Statement = CName\r
691 if FFE:\r
692 Statement += '|' + FFE\r
4234283c
LG
693 Usage = Guid.GetUsage()\r
694 GuidType = Guid.GetGuidTypeList()[0]\r
695 VariableName = Guid.GetVariableName()\r
4234283c 696 #\r
421ccda3 697 # Differentiate the generic comment and usage comment as multiple generic comment need to be put at first\r
4234283c
LG
698 #\r
699 if Usage == DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED:\r
700 # generate list of generic comment\r
701 Comment = GenGenericCommentF(HelpStr)\r
702 else:\r
703 # generate list of other comment\r
704 Comment = HelpStr.replace('\n', ' ')\r
705 Comment = Comment.strip()\r
706 if Comment:\r
707 Comment = ' # ' + Comment\r
708 else:\r
709 Comment = ''\r
4234283c 710 if Usage != DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED:\r
76d47511 711 Comment = '## ' + Usage + Comment\r
4234283c
LG
712 elif GuidType == 'Variable':\r
713 Comment = '## ' + Usage + ' ## ' + GuidType + ':' + VariableName + Comment\r
714 else:\r
715 Comment = '## ' + Usage + ' ## ' + GuidType + Comment\r
421ccda3 716\r
4234283c
LG
717 if Comment:\r
718 Comment += '\n'\r
4234283c
LG
719 #\r
720 # merge duplicate items\r
721 #\r
722 ArchList = Guid.GetSupArchList()\r
723 ArchList.sort()\r
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
739# \r
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
782 ArchList = Object.GetSupArchList()\r
783 ArchList.sort()\r
784 SortedArch = ' '.join(ArchList)\r
785 if (Statement, SortedArch) in Dict:\r
786 PreviousComment = Dict[Statement, SortedArch]\r
787 Comment = PreviousComment + Comment\r
788 Dict[Statement, SortedArch] = Comment\r
421ccda3 789 NewSectionDict = GenMetaFileMisc.TransferDict(Dict, 'INF_PPI_PROTOCOL')\r
4234283c
LG
790 #\r
791 # generate the section contents\r
792 #\r
793 if NewSectionDict:\r
794 if IsProtocol:\r
795 Content = GenSection('Protocols', NewSectionDict)\r
796 else:\r
797 Content = GenSection('Ppis', NewSectionDict)\r
421ccda3 798\r
4234283c
LG
799 return Content\r
800\r
801## GenPcdSections\r
802#\r
803#\r
804def GenPcdSections(ModuleObject):\r
805 Content = ''\r
806 if not GlobalData.gIS_BINARY_INF:\r
807 #\r
808 # for each Pcd Itemtype, maintain a dict so the same type will be grouped \r
809 # together\r
810 #\r
811 ItemTypeDict = {}\r
812 for Pcd in ModuleObject.GetPcdList():\r
813 HelpTextList = Pcd.GetHelpTextList()\r
814 HelpStr = _GetHelpStr(HelpTextList)\r
4234283c
LG
815 Statement = ''\r
816 CName = Pcd.GetCName()\r
817 TokenSpaceGuidCName = Pcd.GetTokenSpaceGuidCName()\r
818 DefaultValue = Pcd.GetDefaultValue()\r
819 ItemType = Pcd.GetItemType()\r
820 if ItemType in ItemTypeDict:\r
821 Dict = ItemTypeDict[ItemType]\r
822 else:\r
823 Dict = Sdict()\r
824 ItemTypeDict[ItemType] = Dict\r
4234283c
LG
825 FFE = Pcd.GetFeatureFlag()\r
826 Statement += TokenSpaceGuidCName + '.' + CName\r
827 if DefaultValue:\r
828 Statement += '|' + DefaultValue\r
829 if FFE:\r
830 Statement += '|' + FFE\r
831 elif FFE:\r
832 Statement += '||' + FFE\r
4234283c
LG
833 #\r
834 # Generate comment\r
835 #\r
836 Usage = Pcd.GetValidUsage()\r
4234283c 837 # if FeatureFlag Pcd, then assume all Usage is CONSUMES\r
4234283c
LG
838 if ItemType == DT.TAB_INF_FEATURE_PCD:\r
839 Usage = DT.USAGE_ITEM_CONSUMES\r
421ccda3 840 if Usage == DT.ITEM_UNDEFINED:\r
4234283c
LG
841 # generate list of generic comment\r
842 Comment = GenGenericCommentF(HelpStr)\r
843 else:\r
844 # generate list of other comment\r
845 Comment = HelpStr.replace('\n', ' ')\r
846 Comment = Comment.strip()\r
847 if Comment:\r
848 Comment = ' # ' + Comment\r
849 else:\r
850 Comment = ''\r
4234283c 851 Comment = '## ' + Usage + Comment\r
4234283c
LG
852 if Comment:\r
853 Comment += '\n'\r
4234283c
LG
854 #\r
855 # Merge duplicate entries\r
856 #\r
857 ArchList = Pcd.GetSupArchList()\r
858 ArchList.sort()\r
859 SortedArch = ' '.join(ArchList)\r
860 if (Statement, SortedArch) in Dict:\r
861 PreviousComment = Dict[Statement, SortedArch]\r
862 Comment = PreviousComment + Comment\r
421ccda3 863 Dict[Statement, SortedArch] = Comment\r
4234283c 864 for ItemType in ItemTypeDict:\r
4234283c 865 # First we need to transfer the Dict to use SortedArch as key\r
4234283c 866 Dict = ItemTypeDict[ItemType]\r
421ccda3 867 NewSectionDict = GenMetaFileMisc.TransferDict(Dict, 'INF_PCD')\r
4234283c
LG
868 if NewSectionDict:\r
869 Content += GenSection(ItemType, NewSectionDict)\r
870 #\r
871 # For AsBuild INF files \r
872 #\r
873 else:\r
874 Content += GenAsBuiltPacthPcdSections(ModuleObject)\r
875 Content += GenAsBuiltPcdExSections(ModuleObject)\r
421ccda3 876\r
4234283c
LG
877 return Content\r
878\r
879## GenPcdSections\r
880#\r
881#\r
882def GenAsBuiltPacthPcdSections(ModuleObject):\r
883 PatchPcdDict = {}\r
884 for BinaryFile in ModuleObject.GetBinaryFileList():\r
885 if not BinaryFile.AsBuiltList:\r
421ccda3
HC
886 continue\r
887 for PatchPcd in BinaryFile.AsBuiltList[0].PatchPcdList:\r
4234283c
LG
888 TokenSpaceName = ''\r
889 PcdCName = PatchPcd.CName\r
890 PcdValue = PatchPcd.DefaultValue\r
891 PcdOffset = PatchPcd.Offset\r
892 TokenSpaceGuidValue = PatchPcd.TokenSpaceGuidValue\r
893 Token = PatchPcd.Token\r
894 HelpTextList = PatchPcd.HelpTextList\r
895 HelpString = ''\r
896 for HelpStringItem in HelpTextList:\r
897 for HelpLine in GetSplitValueList(HelpStringItem.String, '\n'):\r
421ccda3
HC
898 HelpString += '## ' + HelpLine + '\n'\r
899 TokenSpaceName, PcdCName = GenMetaFileMisc.ObtainPcdName(ModuleObject.PackageDependencyList,\r
900 TokenSpaceGuidValue,\r
4234283c 901 Token)\r
421ccda3
HC
902 if TokenSpaceName == '' or PcdCName == '':\r
903 Logger.Error("Upt",\r
4234283c 904 ToolError.RESOURCE_NOT_AVAILABLE,\r
421ccda3
HC
905 ST.ERR_INSTALL_FILE_DEC_FILE_ERROR % (TokenSpaceGuidValue, Token),\r
906 File=ModuleObject.GetFullPath())\r
907 Statement = HelpString + TokenSpaceName + '.' + PcdCName + ' | ' + PcdValue + ' | ' + \\r
908 PcdOffset + DT.TAB_SPACE_SPLIT\r
909 #\r
910 # Use binary file's Arch to be Pcd's Arch \r
911 #\r
912 ArchList = []\r
913 FileNameObjList = BinaryFile.GetFileNameList()\r
914 if FileNameObjList:\r
915 ArchList = FileNameObjList[0].GetSupArchList()\r
916 if len(ArchList) == 0:\r
917 if PatchPcdDict.has_key(DT.TAB_ARCH_COMMON):\r
918 if Statement not in PatchPcdDict[DT.TAB_ARCH_COMMON]:\r
919 PatchPcdDict[DT.TAB_ARCH_COMMON].append(Statement)\r
4234283c 920 else:\r
421ccda3 921 PatchPcdDict[DT.TAB_ARCH_COMMON] = [Statement]\r
4234283c 922 else:\r
421ccda3 923 for Arch in ArchList:\r
4234283c 924 if PatchPcdDict.has_key(Arch):\r
421ccda3
HC
925 if Statement not in PatchPcdDict[Arch]:\r
926 PatchPcdDict[Arch].append(Statement)\r
4234283c
LG
927 else:\r
928 PatchPcdDict[Arch] = [Statement]\r
421ccda3 929 return GenSection(DT.TAB_INF_PATCH_PCD, PatchPcdDict)\r
4234283c
LG
930## GenPcdSections\r
931#\r
932#\r
933def GenAsBuiltPcdExSections(ModuleObject):\r
934 PcdExDict = {}\r
935 for BinaryFile in ModuleObject.GetBinaryFileList():\r
936 if not BinaryFile.AsBuiltList:\r
421ccda3 937 continue\r
4234283c
LG
938 for PcdExItem in BinaryFile.AsBuiltList[0].PcdExValueList:\r
939 TokenSpaceName = ''\r
940 PcdCName = PcdExItem.CName\r
4234283c
LG
941 TokenSpaceGuidValue = PcdExItem.TokenSpaceGuidValue\r
942 Token = PcdExItem.Token\r
943 HelpTextList = PcdExItem.HelpTextList\r
944 HelpString = ''\r
945 for HelpStringItem in HelpTextList:\r
946 for HelpLine in GetSplitValueList(HelpStringItem.String, '\n'):\r
421ccda3
HC
947 HelpString += '## ' + HelpLine + '\n'\r
948 TokenSpaceName, PcdCName = GenMetaFileMisc.ObtainPcdName(ModuleObject.PackageDependencyList,\r
4234283c 949 TokenSpaceGuidValue, Token)\r
421ccda3 950 if TokenSpaceName == '' or PcdCName == '':\r
4234283c
LG
951 Logger.Error("Upt",\r
952 ToolError.RESOURCE_NOT_AVAILABLE,\r
421ccda3
HC
953 ST.ERR_INSTALL_FILE_DEC_FILE_ERROR % (TokenSpaceGuidValue, Token),\r
954 File=ModuleObject.GetFullPath())\r
955\r
956 Statement = HelpString + TokenSpaceName + DT.TAB_SPLIT + PcdCName + DT.TAB_SPACE_SPLIT\r
957\r
958 #\r
959 # Use binary file's Arch to be Pcd's Arch \r
960 #\r
961 ArchList = []\r
962 FileNameObjList = BinaryFile.GetFileNameList()\r
963 if FileNameObjList:\r
964 ArchList = FileNameObjList[0].GetSupArchList()\r
965\r
966 if len(ArchList) == 0:\r
4234283c
LG
967 if PcdExDict.has_key('COMMON'):\r
968 PcdExDict['COMMON'].append(Statement)\r
969 else:\r
970 PcdExDict['COMMON'] = [Statement]\r
971 else:\r
421ccda3 972 for Arch in ArchList:\r
4234283c 973 if PcdExDict.has_key(Arch):\r
421ccda3
HC
974 if Statement not in PcdExDict[Arch]:\r
975 PcdExDict[Arch].append(Statement)\r
4234283c
LG
976 else:\r
977 PcdExDict[Arch] = [Statement]\r
978 return GenSection('PcdEx', PcdExDict)\r
421ccda3 979\r
4234283c
LG
980## GenSpecialSections\r
981# generate special sections for Event/BootMode/Hob\r
982#\r
e0e1cfcb 983def GenSpecialSections(ObjectList, SectionName, UserExtensionsContent=''):\r
4234283c
LG
984 #\r
985 # generate section\r
986 #\r
987 Content = ''\r
988 NewSectionDict = {}\r
989 for Obj in ObjectList:\r
990 #\r
991 # Generate comment\r
992 #\r
993 CommentStr = ''\r
994 HelpTextList = Obj.GetHelpTextList()\r
995 HelpStr = _GetHelpStr(HelpTextList)\r
996 CommentStr = GenGenericCommentF(HelpStr)\r
4234283c
LG
997 if SectionName == 'Hob':\r
998 Type = Obj.GetHobType()\r
999 elif SectionName == 'Event':\r
1000 Type = Obj.GetEventType()\r
1001 elif SectionName == 'BootMode':\r
1002 Type = Obj.GetSupportedBootModes()\r
1003 else:\r
1004 assert(SectionName)\r
4234283c 1005 Usage = Obj.GetUsage()\r
e0e1cfcb
HC
1006\r
1007 # If the content already in UserExtensionsContent then ignore\r
1008 if '[%s]' % SectionName in UserExtensionsContent and Type in UserExtensionsContent:\r
1009 return ''\r
1010\r
4234283c 1011 Statement = ' ' + Type + ' ## ' + Usage\r
4234283c
LG
1012 if CommentStr in ['#\n', '#\n#\n']:\r
1013 CommentStr = '#\n#\n#\n'\r
1014 #\r
421ccda3 1015 # the first head comment line should start with '##\n', if it starts with '#\n', then add one '#'\r
4234283c
LG
1016 # else add '##\n' to meet the format defined in INF spec\r
1017 #\r
1018 if CommentStr.startswith('#\n'):\r
1019 CommentStr = '#' + CommentStr\r
1020 elif CommentStr:\r
1021 CommentStr = '##\n' + CommentStr\r
4234283c 1022 if CommentStr and not CommentStr.endswith('\n#\n'):\r
421ccda3 1023 CommentStr = CommentStr + '#\n'\r
4234283c
LG
1024 NewStateMent = CommentStr + Statement\r
1025 SupArch = Obj.GetSupArchList()\r
1026 SupArch.sort()\r
1027 SortedArch = ' '.join(SupArch)\r
1028 if SortedArch in NewSectionDict:\r
1029 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [NewStateMent]\r
1030 else:\r
1031 NewSectionDict[SortedArch] = [NewStateMent]\r
4234283c
LG
1032 SectionContent = GenSection(SectionName, NewSectionDict)\r
1033 SectionContent = SectionContent.strip()\r
1034 if SectionContent:\r
1035 Content = '# ' + ('\n' + '# ').join(GetSplitValueList(SectionContent, '\n'))\r
1036 Content = Content.lstrip()\r
1037 #\r
76d47511 1038 # add a return to differentiate it between other possible sections\r
421ccda3
HC
1039 # \r
1040 if Content:\r
76d47511 1041 Content += '\n'\r
4234283c 1042 return Content\r
4234283c
LG
1043## GenBuildOptions\r
1044#\r
1045#\r
1046def GenBuildOptions(ModuleObject):\r
1047 Content = ''\r
1048 if not ModuleObject.BinaryModule:\r
1049 #\r
1050 # generate [BuildOptions] section\r
1051 #\r
1052 NewSectionDict = {}\r
1053 for UserExtension in ModuleObject.GetUserExtensionList():\r
1054 BuildOptionDict = UserExtension.GetBuildOptionDict()\r
1055 if not BuildOptionDict:\r
1056 continue\r
1057 for Arch in BuildOptionDict:\r
1058 if Arch in NewSectionDict:\r
1059 NewSectionDict[Arch] = NewSectionDict[Arch] + [BuildOptionDict[Arch]]\r
1060 else:\r
1061 NewSectionDict[Arch] = [BuildOptionDict[Arch]]\r
4234283c
LG
1062 Content = GenSection('BuildOptions', NewSectionDict)\r
1063 else:\r
1064 BuildOptionDict = {}\r
1065 for BinaryFile in ModuleObject.GetBinaryFileList():\r
1066 if not BinaryFile.AsBuiltList:\r
1067 continue\r
1068 for BuilOptionItem in BinaryFile.AsBuiltList[0].BinaryBuildFlagList:\r
421ccda3 1069 Statement = '#' + BuilOptionItem.AsBuiltOptionFlags\r
4234283c
LG
1070 if len(BinaryFile.SupArchList) == 0:\r
1071 if BuildOptionDict.has_key('COMMON'):\r
1072 if Statement not in BuildOptionDict['COMMON']:\r
1073 BuildOptionDict['COMMON'].append(Statement)\r
1074 else:\r
1075 BuildOptionDict['COMMON'] = ['## @AsBuilt']\r
1076 BuildOptionDict['COMMON'].append(Statement)\r
1077 else:\r
1078 for Arch in BinaryFile.SupArchList:\r
1079 if BuildOptionDict.has_key(Arch):\r
1080 if Statement not in BuildOptionDict[Arch]:\r
1081 BuildOptionDict[Arch].append(Statement)\r
1082 else:\r
1083 BuildOptionDict[Arch] = ['## @AsBuilt']\r
1084 BuildOptionDict[Arch].append(Statement)\r
4234283c 1085 Content = GenSection('BuildOptions', BuildOptionDict)\r
4234283c 1086\r
421ccda3 1087 return Content\r
4234283c
LG
1088## GenBinaries\r
1089#\r
1090#\r
1091def GenBinaries(ModuleObject):\r
1092 NewSectionDict = {}\r
1093 BinariesDict = []\r
1094 for UserExtension in ModuleObject.GetUserExtensionList():\r
1095 BinariesDict = UserExtension.GetBinariesDict()\r
1096 if BinariesDict:\r
1097 break\r
4234283c
LG
1098 for BinaryFile in ModuleObject.GetBinaryFileList():\r
1099 FileNameObjList = BinaryFile.GetFileNameList()\r
1100 for FileNameObj in FileNameObjList:\r
1101 FileName = ConvertPath(FileNameObj.GetFilename())\r
1102 FileType = FileNameObj.GetFileType()\r
1103 FFE = FileNameObj.GetFeatureFlag()\r
1104 ArchList = FileNameObj.GetSupArchList()\r
1105 ArchList.sort()\r
421ccda3 1106 SortedArch = ' '.join(ArchList)\r
4234283c 1107 Key = (FileName, FileType, FFE, SortedArch)\r
4234283c
LG
1108 if Key in BinariesDict:\r
1109 ValueList = BinariesDict[Key]\r
1110 for ValueItem in ValueList:\r
1111 Statement = GenBinaryStatement(Key, ValueItem)\r
1112 if SortedArch in NewSectionDict:\r
1113 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r
1114 else:\r
1115 NewSectionDict[SortedArch] = [Statement]\r
1116 #\r
421ccda3
HC
1117 # as we already generated statement for this DictKey here set the Valuelist to be empty \r
1118 # to avoid generate duplicate entries as the DictKey may have multiple entries\r
4234283c
LG
1119 #\r
1120 BinariesDict[Key] = []\r
1121 else:\r
421ccda3
HC
1122 if FileType == 'SUBTYPE_GUID' and FileNameObj.GetGuidValue():\r
1123 Statement = GenBinaryStatement(Key, None, FileNameObj.GetGuidValue())\r
1124 else:\r
1125 Statement = GenBinaryStatement(Key, None)\r
4234283c
LG
1126 if SortedArch in NewSectionDict:\r
1127 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r
1128 else:\r
421ccda3
HC
1129 NewSectionDict[SortedArch] = [Statement]\r
1130 Content = GenSection('Binaries', NewSectionDict)\r
1131\r
1132 return Content\r