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