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