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