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