]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
BaseTools/UPT: Fix a parser issue
[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
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
4234283c
LG
619 if TagName == None:\r
620 TagName = ''\r
621 if ToolCode == None:\r
622 ToolCode = ''\r
623 if HelpStr == None:\r
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
LG
675## GenGuidSections\r
676# \r
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
723 ArchList = Guid.GetSupArchList()\r
724 ArchList.sort()\r
725 SortedArch = ' '.join(ArchList)\r
726 if (Statement, SortedArch) in GuidDict:\r
727 PreviousComment = GuidDict[Statement, SortedArch]\r
421ccda3 728 Comment = PreviousComment + Comment\r
4234283c 729 GuidDict[Statement, SortedArch] = Comment\r
421ccda3 730 NewSectionDict = GenMetaFileMisc.TransferDict(GuidDict, 'INF_GUID')\r
4234283c
LG
731 #\r
732 # generate the section contents\r
733 #\r
734 if NewSectionDict:\r
735 Content = GenSection('Guids', NewSectionDict)\r
421ccda3 736\r
4234283c
LG
737 return Content\r
738\r
739## GenProtocolPPiSections\r
740# \r
741# @param ObjList: List of ProtocolObject or Ppi Object\r
742# @retVal Content: The generated section contents\r
743#\r
744def GenProtocolPPiSections(ObjList, IsProtocol):\r
745 Content = ''\r
746 Dict = Sdict()\r
747 for Object in ObjList:\r
748 HelpTextList = Object.GetHelpTextList()\r
749 HelpStr = _GetHelpStr(HelpTextList)\r
4234283c
LG
750 CName = Object.GetCName()\r
751 FFE = Object.GetFeatureFlag()\r
752 Statement = CName\r
753 if FFE:\r
754 Statement += '|' + FFE\r
4234283c
LG
755 Usage = Object.GetUsage()\r
756 Notify = Object.GetNotify()\r
4234283c 757 #\r
421ccda3 758 # Differentiate the generic comment and usage comment as consecutive generic comment need to be put together\r
4234283c
LG
759 #\r
760 if Usage == DT.ITEM_UNDEFINED and Notify == '':\r
761 # generate list of generic comment\r
762 Comment = GenGenericCommentF(HelpStr)\r
763 else:\r
764 # generate list of other comment\r
765 Comment = HelpStr.replace('\n', ' ')\r
766 Comment = Comment.strip()\r
767 if Comment:\r
768 Comment = ' # ' + Comment\r
769 else:\r
770 Comment = ''\r
4234283c
LG
771 if Usage == DT.ITEM_UNDEFINED and not Comment and Notify == '':\r
772 Comment = ''\r
773 else:\r
774 if Notify:\r
775 Comment = '## ' + Usage + ' ## ' + 'NOTIFY' + Comment\r
776 else:\r
777 Comment = '## ' + Usage + Comment\r
4234283c
LG
778 if Comment:\r
779 Comment += '\n'\r
4234283c
LG
780 #\r
781 # merge duplicate items\r
782 #\r
783 ArchList = Object.GetSupArchList()\r
784 ArchList.sort()\r
785 SortedArch = ' '.join(ArchList)\r
786 if (Statement, SortedArch) in Dict:\r
787 PreviousComment = Dict[Statement, SortedArch]\r
788 Comment = PreviousComment + Comment\r
789 Dict[Statement, SortedArch] = Comment\r
421ccda3 790 NewSectionDict = GenMetaFileMisc.TransferDict(Dict, 'INF_PPI_PROTOCOL')\r
4234283c
LG
791 #\r
792 # generate the section contents\r
793 #\r
794 if NewSectionDict:\r
795 if IsProtocol:\r
796 Content = GenSection('Protocols', NewSectionDict)\r
797 else:\r
798 Content = GenSection('Ppis', NewSectionDict)\r
421ccda3 799\r
4234283c
LG
800 return Content\r
801\r
802## GenPcdSections\r
803#\r
804#\r
805def GenPcdSections(ModuleObject):\r
806 Content = ''\r
807 if not GlobalData.gIS_BINARY_INF:\r
808 #\r
809 # for each Pcd Itemtype, maintain a dict so the same type will be grouped \r
810 # together\r
811 #\r
812 ItemTypeDict = {}\r
813 for Pcd in ModuleObject.GetPcdList():\r
814 HelpTextList = Pcd.GetHelpTextList()\r
815 HelpStr = _GetHelpStr(HelpTextList)\r
4234283c
LG
816 Statement = ''\r
817 CName = Pcd.GetCName()\r
818 TokenSpaceGuidCName = Pcd.GetTokenSpaceGuidCName()\r
819 DefaultValue = Pcd.GetDefaultValue()\r
820 ItemType = Pcd.GetItemType()\r
821 if ItemType in ItemTypeDict:\r
822 Dict = ItemTypeDict[ItemType]\r
823 else:\r
824 Dict = Sdict()\r
825 ItemTypeDict[ItemType] = Dict\r
4234283c
LG
826 FFE = Pcd.GetFeatureFlag()\r
827 Statement += TokenSpaceGuidCName + '.' + CName\r
828 if DefaultValue:\r
829 Statement += '|' + DefaultValue\r
830 if FFE:\r
831 Statement += '|' + FFE\r
832 elif FFE:\r
833 Statement += '||' + FFE\r
4234283c
LG
834 #\r
835 # Generate comment\r
836 #\r
837 Usage = Pcd.GetValidUsage()\r
4234283c 838 # if FeatureFlag Pcd, then assume all Usage is CONSUMES\r
4234283c
LG
839 if ItemType == DT.TAB_INF_FEATURE_PCD:\r
840 Usage = DT.USAGE_ITEM_CONSUMES\r
421ccda3 841 if Usage == DT.ITEM_UNDEFINED:\r
4234283c
LG
842 # generate list of generic comment\r
843 Comment = GenGenericCommentF(HelpStr)\r
844 else:\r
845 # generate list of other comment\r
846 Comment = HelpStr.replace('\n', ' ')\r
847 Comment = Comment.strip()\r
848 if Comment:\r
849 Comment = ' # ' + Comment\r
850 else:\r
851 Comment = ''\r
4234283c 852 Comment = '## ' + Usage + Comment\r
4234283c
LG
853 if Comment:\r
854 Comment += '\n'\r
4234283c
LG
855 #\r
856 # Merge duplicate entries\r
857 #\r
858 ArchList = Pcd.GetSupArchList()\r
859 ArchList.sort()\r
860 SortedArch = ' '.join(ArchList)\r
861 if (Statement, SortedArch) in Dict:\r
862 PreviousComment = Dict[Statement, SortedArch]\r
863 Comment = PreviousComment + Comment\r
421ccda3 864 Dict[Statement, SortedArch] = Comment\r
4234283c 865 for ItemType in ItemTypeDict:\r
4234283c 866 # First we need to transfer the Dict to use SortedArch as key\r
4234283c 867 Dict = ItemTypeDict[ItemType]\r
421ccda3 868 NewSectionDict = GenMetaFileMisc.TransferDict(Dict, 'INF_PCD')\r
4234283c
LG
869 if NewSectionDict:\r
870 Content += GenSection(ItemType, NewSectionDict)\r
871 #\r
872 # For AsBuild INF files \r
873 #\r
874 else:\r
875 Content += GenAsBuiltPacthPcdSections(ModuleObject)\r
876 Content += GenAsBuiltPcdExSections(ModuleObject)\r
421ccda3 877\r
4234283c
LG
878 return Content\r
879\r
880## GenPcdSections\r
881#\r
882#\r
883def GenAsBuiltPacthPcdSections(ModuleObject):\r
884 PatchPcdDict = {}\r
885 for BinaryFile in ModuleObject.GetBinaryFileList():\r
886 if not BinaryFile.AsBuiltList:\r
421ccda3
HC
887 continue\r
888 for PatchPcd in BinaryFile.AsBuiltList[0].PatchPcdList:\r
4234283c
LG
889 TokenSpaceName = ''\r
890 PcdCName = PatchPcd.CName\r
891 PcdValue = PatchPcd.DefaultValue\r
892 PcdOffset = PatchPcd.Offset\r
893 TokenSpaceGuidValue = PatchPcd.TokenSpaceGuidValue\r
894 Token = PatchPcd.Token\r
895 HelpTextList = PatchPcd.HelpTextList\r
896 HelpString = ''\r
897 for HelpStringItem in HelpTextList:\r
898 for HelpLine in GetSplitValueList(HelpStringItem.String, '\n'):\r
421ccda3
HC
899 HelpString += '## ' + HelpLine + '\n'\r
900 TokenSpaceName, PcdCName = GenMetaFileMisc.ObtainPcdName(ModuleObject.PackageDependencyList,\r
901 TokenSpaceGuidValue,\r
4234283c 902 Token)\r
421ccda3
HC
903 if TokenSpaceName == '' or PcdCName == '':\r
904 Logger.Error("Upt",\r
4234283c 905 ToolError.RESOURCE_NOT_AVAILABLE,\r
421ccda3
HC
906 ST.ERR_INSTALL_FILE_DEC_FILE_ERROR % (TokenSpaceGuidValue, Token),\r
907 File=ModuleObject.GetFullPath())\r
908 Statement = HelpString + TokenSpaceName + '.' + PcdCName + ' | ' + PcdValue + ' | ' + \\r
909 PcdOffset + DT.TAB_SPACE_SPLIT\r
910 #\r
911 # Use binary file's Arch to be Pcd's Arch \r
912 #\r
913 ArchList = []\r
914 FileNameObjList = BinaryFile.GetFileNameList()\r
915 if FileNameObjList:\r
916 ArchList = FileNameObjList[0].GetSupArchList()\r
917 if len(ArchList) == 0:\r
918 if PatchPcdDict.has_key(DT.TAB_ARCH_COMMON):\r
919 if Statement not in PatchPcdDict[DT.TAB_ARCH_COMMON]:\r
920 PatchPcdDict[DT.TAB_ARCH_COMMON].append(Statement)\r
4234283c 921 else:\r
421ccda3 922 PatchPcdDict[DT.TAB_ARCH_COMMON] = [Statement]\r
4234283c 923 else:\r
421ccda3 924 for Arch in ArchList:\r
4234283c 925 if PatchPcdDict.has_key(Arch):\r
421ccda3
HC
926 if Statement not in PatchPcdDict[Arch]:\r
927 PatchPcdDict[Arch].append(Statement)\r
4234283c
LG
928 else:\r
929 PatchPcdDict[Arch] = [Statement]\r
421ccda3 930 return GenSection(DT.TAB_INF_PATCH_PCD, PatchPcdDict)\r
4234283c
LG
931## GenPcdSections\r
932#\r
933#\r
934def GenAsBuiltPcdExSections(ModuleObject):\r
935 PcdExDict = {}\r
936 for BinaryFile in ModuleObject.GetBinaryFileList():\r
937 if not BinaryFile.AsBuiltList:\r
421ccda3 938 continue\r
4234283c
LG
939 for PcdExItem in BinaryFile.AsBuiltList[0].PcdExValueList:\r
940 TokenSpaceName = ''\r
941 PcdCName = PcdExItem.CName\r
4234283c
LG
942 TokenSpaceGuidValue = PcdExItem.TokenSpaceGuidValue\r
943 Token = PcdExItem.Token\r
944 HelpTextList = PcdExItem.HelpTextList\r
945 HelpString = ''\r
946 for HelpStringItem in HelpTextList:\r
947 for HelpLine in GetSplitValueList(HelpStringItem.String, '\n'):\r
421ccda3
HC
948 HelpString += '## ' + HelpLine + '\n'\r
949 TokenSpaceName, PcdCName = GenMetaFileMisc.ObtainPcdName(ModuleObject.PackageDependencyList,\r
4234283c 950 TokenSpaceGuidValue, Token)\r
421ccda3 951 if TokenSpaceName == '' or PcdCName == '':\r
4234283c
LG
952 Logger.Error("Upt",\r
953 ToolError.RESOURCE_NOT_AVAILABLE,\r
421ccda3
HC
954 ST.ERR_INSTALL_FILE_DEC_FILE_ERROR % (TokenSpaceGuidValue, Token),\r
955 File=ModuleObject.GetFullPath())\r
956\r
957 Statement = HelpString + TokenSpaceName + DT.TAB_SPLIT + PcdCName + DT.TAB_SPACE_SPLIT\r
958\r
959 #\r
960 # Use binary file's Arch to be Pcd's Arch \r
961 #\r
962 ArchList = []\r
963 FileNameObjList = BinaryFile.GetFileNameList()\r
964 if FileNameObjList:\r
965 ArchList = FileNameObjList[0].GetSupArchList()\r
966\r
967 if len(ArchList) == 0:\r
4234283c
LG
968 if PcdExDict.has_key('COMMON'):\r
969 PcdExDict['COMMON'].append(Statement)\r
970 else:\r
971 PcdExDict['COMMON'] = [Statement]\r
972 else:\r
421ccda3 973 for Arch in ArchList:\r
4234283c 974 if PcdExDict.has_key(Arch):\r
421ccda3
HC
975 if Statement not in PcdExDict[Arch]:\r
976 PcdExDict[Arch].append(Statement)\r
4234283c
LG
977 else:\r
978 PcdExDict[Arch] = [Statement]\r
979 return GenSection('PcdEx', PcdExDict)\r
421ccda3 980\r
4234283c
LG
981## GenSpecialSections\r
982# generate special sections for Event/BootMode/Hob\r
983#\r
e0e1cfcb 984def GenSpecialSections(ObjectList, SectionName, UserExtensionsContent=''):\r
4234283c
LG
985 #\r
986 # generate section\r
987 #\r
988 Content = ''\r
989 NewSectionDict = {}\r
990 for Obj in ObjectList:\r
991 #\r
992 # Generate comment\r
993 #\r
994 CommentStr = ''\r
995 HelpTextList = Obj.GetHelpTextList()\r
996 HelpStr = _GetHelpStr(HelpTextList)\r
997 CommentStr = GenGenericCommentF(HelpStr)\r
4234283c
LG
998 if SectionName == 'Hob':\r
999 Type = Obj.GetHobType()\r
1000 elif SectionName == 'Event':\r
1001 Type = Obj.GetEventType()\r
1002 elif SectionName == 'BootMode':\r
1003 Type = Obj.GetSupportedBootModes()\r
1004 else:\r
1005 assert(SectionName)\r
4234283c 1006 Usage = Obj.GetUsage()\r
e0e1cfcb
HC
1007\r
1008 # If the content already in UserExtensionsContent then ignore\r
1009 if '[%s]' % SectionName in UserExtensionsContent and Type in UserExtensionsContent:\r
1010 return ''\r
1011\r
4234283c 1012 Statement = ' ' + Type + ' ## ' + Usage\r
4234283c
LG
1013 if CommentStr in ['#\n', '#\n#\n']:\r
1014 CommentStr = '#\n#\n#\n'\r
1015 #\r
421ccda3 1016 # the first head comment line should start with '##\n', if it starts with '#\n', then add one '#'\r
4234283c
LG
1017 # else add '##\n' to meet the format defined in INF spec\r
1018 #\r
1019 if CommentStr.startswith('#\n'):\r
1020 CommentStr = '#' + CommentStr\r
1021 elif CommentStr:\r
1022 CommentStr = '##\n' + CommentStr\r
4234283c 1023 if CommentStr and not CommentStr.endswith('\n#\n'):\r
421ccda3 1024 CommentStr = CommentStr + '#\n'\r
4234283c
LG
1025 NewStateMent = CommentStr + Statement\r
1026 SupArch = Obj.GetSupArchList()\r
1027 SupArch.sort()\r
1028 SortedArch = ' '.join(SupArch)\r
1029 if SortedArch in NewSectionDict:\r
1030 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [NewStateMent]\r
1031 else:\r
1032 NewSectionDict[SortedArch] = [NewStateMent]\r
4234283c
LG
1033 SectionContent = GenSection(SectionName, NewSectionDict)\r
1034 SectionContent = SectionContent.strip()\r
1035 if SectionContent:\r
1036 Content = '# ' + ('\n' + '# ').join(GetSplitValueList(SectionContent, '\n'))\r
1037 Content = Content.lstrip()\r
1038 #\r
76d47511 1039 # add a return to differentiate it between other possible sections\r
421ccda3
HC
1040 # \r
1041 if Content:\r
76d47511 1042 Content += '\n'\r
4234283c 1043 return Content\r
4234283c
LG
1044## GenBuildOptions\r
1045#\r
1046#\r
1047def GenBuildOptions(ModuleObject):\r
1048 Content = ''\r
1049 if not ModuleObject.BinaryModule:\r
1050 #\r
1051 # generate [BuildOptions] section\r
1052 #\r
1053 NewSectionDict = {}\r
1054 for UserExtension in ModuleObject.GetUserExtensionList():\r
1055 BuildOptionDict = UserExtension.GetBuildOptionDict()\r
1056 if not BuildOptionDict:\r
1057 continue\r
1058 for Arch in BuildOptionDict:\r
1059 if Arch in NewSectionDict:\r
1060 NewSectionDict[Arch] = NewSectionDict[Arch] + [BuildOptionDict[Arch]]\r
1061 else:\r
1062 NewSectionDict[Arch] = [BuildOptionDict[Arch]]\r
4234283c
LG
1063 Content = GenSection('BuildOptions', NewSectionDict)\r
1064 else:\r
1065 BuildOptionDict = {}\r
1066 for BinaryFile in ModuleObject.GetBinaryFileList():\r
1067 if not BinaryFile.AsBuiltList:\r
1068 continue\r
1069 for BuilOptionItem in BinaryFile.AsBuiltList[0].BinaryBuildFlagList:\r
421ccda3 1070 Statement = '#' + BuilOptionItem.AsBuiltOptionFlags\r
4234283c
LG
1071 if len(BinaryFile.SupArchList) == 0:\r
1072 if BuildOptionDict.has_key('COMMON'):\r
1073 if Statement not in BuildOptionDict['COMMON']:\r
1074 BuildOptionDict['COMMON'].append(Statement)\r
1075 else:\r
1076 BuildOptionDict['COMMON'] = ['## @AsBuilt']\r
1077 BuildOptionDict['COMMON'].append(Statement)\r
1078 else:\r
1079 for Arch in BinaryFile.SupArchList:\r
1080 if BuildOptionDict.has_key(Arch):\r
1081 if Statement not in BuildOptionDict[Arch]:\r
1082 BuildOptionDict[Arch].append(Statement)\r
1083 else:\r
1084 BuildOptionDict[Arch] = ['## @AsBuilt']\r
1085 BuildOptionDict[Arch].append(Statement)\r
4234283c 1086 Content = GenSection('BuildOptions', BuildOptionDict)\r
4234283c 1087\r
421ccda3 1088 return Content\r
4234283c
LG
1089## GenBinaries\r
1090#\r
1091#\r
1092def GenBinaries(ModuleObject):\r
1093 NewSectionDict = {}\r
1094 BinariesDict = []\r
1095 for UserExtension in ModuleObject.GetUserExtensionList():\r
1096 BinariesDict = UserExtension.GetBinariesDict()\r
1097 if BinariesDict:\r
1098 break\r
4234283c
LG
1099 for BinaryFile in ModuleObject.GetBinaryFileList():\r
1100 FileNameObjList = BinaryFile.GetFileNameList()\r
1101 for FileNameObj in FileNameObjList:\r
1102 FileName = ConvertPath(FileNameObj.GetFilename())\r
1103 FileType = FileNameObj.GetFileType()\r
1104 FFE = FileNameObj.GetFeatureFlag()\r
1105 ArchList = FileNameObj.GetSupArchList()\r
1106 ArchList.sort()\r
421ccda3 1107 SortedArch = ' '.join(ArchList)\r
4234283c 1108 Key = (FileName, FileType, FFE, SortedArch)\r
4234283c
LG
1109 if Key in BinariesDict:\r
1110 ValueList = BinariesDict[Key]\r
1111 for ValueItem in ValueList:\r
1112 Statement = GenBinaryStatement(Key, ValueItem)\r
1113 if SortedArch in NewSectionDict:\r
1114 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r
1115 else:\r
1116 NewSectionDict[SortedArch] = [Statement]\r
1117 #\r
421ccda3
HC
1118 # as we already generated statement for this DictKey here set the Valuelist to be empty \r
1119 # to avoid generate duplicate entries as the DictKey may have multiple entries\r
4234283c
LG
1120 #\r
1121 BinariesDict[Key] = []\r
1122 else:\r
421ccda3
HC
1123 if FileType == 'SUBTYPE_GUID' and FileNameObj.GetGuidValue():\r
1124 Statement = GenBinaryStatement(Key, None, FileNameObj.GetGuidValue())\r
1125 else:\r
1126 Statement = GenBinaryStatement(Key, None)\r
4234283c
LG
1127 if SortedArch in NewSectionDict:\r
1128 NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r
1129 else:\r
421ccda3
HC
1130 NewSectionDict[SortedArch] = [Statement]\r
1131 Content = GenSection('Binaries', NewSectionDict)\r
1132\r
1133 return Content\r