]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Common/InfClassObjectLight.py
Sync BaseTool trunk (version r2397) into EDKII BaseTools. The change mainly includes
[mirror_edk2.git] / BaseTools / Source / Python / Common / InfClassObjectLight.py
1 ## @file
2 # This file is used to define each component of INF file
3 #
4 # Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 ##
15 # Import Modules
16 #
17 import os
18 import re
19 import EdkLogger
20
21 from CommonDataClass.ModuleClass import *
22 from CommonDataClass import CommonClass
23 from String import *
24 from DataType import *
25 from BuildToolError import *
26 from Misc import sdict
27 from Misc import GetFiles
28 from Parsing import *
29
30 # Global variable
31 Section = {TAB_UNKNOWN.upper() : MODEL_UNKNOWN,
32 TAB_INF_DEFINES.upper() : MODEL_META_DATA_HEADER,
33 TAB_BUILD_OPTIONS.upper() : MODEL_META_DATA_BUILD_OPTION,
34 TAB_INCLUDES.upper() : MODEL_EFI_INCLUDE,
35 TAB_LIBRARIES.upper() : MODEL_EFI_LIBRARY_INSTANCE,
36 TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,
37 TAB_PACKAGES.upper() : MODEL_META_DATA_PACKAGE,
38 TAB_NMAKE.upper() : MODEL_META_DATA_NMAKE,
39 TAB_INF_FIXED_PCD.upper() : MODEL_PCD_FIXED_AT_BUILD,
40 TAB_INF_PATCH_PCD.upper() : MODEL_PCD_PATCHABLE_IN_MODULE,
41 TAB_INF_FEATURE_PCD.upper() : MODEL_PCD_FEATURE_FLAG,
42 TAB_INF_PCD_EX.upper() : MODEL_PCD_DYNAMIC_EX,
43 TAB_INF_PCD.upper() : MODEL_PCD_DYNAMIC,
44 TAB_SOURCES.upper() : MODEL_EFI_SOURCE_FILE,
45 TAB_GUIDS.upper() : MODEL_EFI_GUID,
46 TAB_PROTOCOLS.upper() : MODEL_EFI_PROTOCOL,
47 TAB_PPIS.upper() : MODEL_EFI_PPI,
48 TAB_DEPEX.upper() : MODEL_EFI_DEPEX,
49 TAB_BINARIES.upper() : MODEL_EFI_BINARY_FILE,
50 TAB_USER_EXTENSIONS.upper() : MODEL_META_DATA_USER_EXTENSION
51 }
52
53 gComponentType2ModuleType = {
54 "LIBRARY" : "BASE",
55 "SECURITY_CORE" : "SEC",
56 "PEI_CORE" : "PEI_CORE",
57 "COMBINED_PEIM_DRIVER" : "PEIM",
58 "PIC_PEIM" : "PEIM",
59 "RELOCATABLE_PEIM" : "PEIM",
60 "PE32_PEIM" : "PEIM",
61 "BS_DRIVER" : "DXE_DRIVER",
62 "RT_DRIVER" : "DXE_RUNTIME_DRIVER",
63 "SAL_RT_DRIVER" : "DXE_SAL_DRIVER",
64 "APPLICATION" : "UEFI_APPLICATION",
65 "LOGO" : "BASE",
66 }
67
68 class InfHeader(ModuleHeaderClass):
69 _Mapping_ = {
70 # Required Fields
71 TAB_INF_DEFINES_BASE_NAME : "Name",
72 TAB_INF_DEFINES_FILE_GUID : "Guid",
73 TAB_INF_DEFINES_MODULE_TYPE : "ModuleType",
74 TAB_INF_DEFINES_EFI_SPECIFICATION_VERSION : "UefiSpecificationVersion",
75 TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION : "UefiSpecificationVersion",
76 TAB_INF_DEFINES_EDK_RELEASE_VERSION : "EdkReleaseVersion",
77
78 # Optional Fields
79 TAB_INF_DEFINES_INF_VERSION : "InfVersion",
80 TAB_INF_DEFINES_BINARY_MODULE : "BinaryModule",
81 TAB_INF_DEFINES_COMPONENT_TYPE : "ComponentType",
82 TAB_INF_DEFINES_MAKEFILE_NAME : "MakefileName",
83 TAB_INF_DEFINES_BUILD_NUMBER : "BuildNumber",
84 TAB_INF_DEFINES_BUILD_TYPE : "BuildType",
85 TAB_INF_DEFINES_FFS_EXT : "FfsExt",
86 TAB_INF_DEFINES_FV_EXT : "FvExt",
87 TAB_INF_DEFINES_SOURCE_FV : "SourceFv",
88 TAB_INF_DEFINES_VERSION_NUMBER : "VersionNumber",
89 TAB_INF_DEFINES_VERSION_STRING : "VersionString",
90 TAB_INF_DEFINES_VERSION : "Version",
91 TAB_INF_DEFINES_PCD_IS_DRIVER : "PcdIsDriver",
92 TAB_INF_DEFINES_TIANO_EDK_FLASHMAP_H : "TianoEdkFlashMap_h",
93 TAB_INF_DEFINES_SHADOW : "Shadow",
94 }
95
96 def __init__(self):
97 ModuleHeaderClass.__init__(self)
98 self.VersionNumber = ''
99 self.VersionString = ''
100 #print self.__dict__
101 def __setitem__(self, key, value):
102 self.__dict__[self._Mapping_[key]] = value
103 def __getitem__(self, key):
104 return self.__dict__[self._Mapping_[key]]
105 ## "in" test support
106 def __contains__(self, key):
107 return key in self._Mapping_
108
109 ## InfObject
110 #
111 # This class defined basic Inf object which is used by inheriting
112 #
113 # @param object: Inherited from object class
114 #
115 class InfObject(object):
116 def __init__(self):
117 object.__init__()
118
119 ## Inf
120 #
121 # This class defined the structure used in Inf object
122 #
123 # @param InfObject: Inherited from InfObject class
124 # @param Ffilename: Input value for Ffilename of Inf file, default is None
125 # @param IsMergeAllArches: Input value for IsMergeAllArches
126 # True is to merge all arches
127 # Fales is not to merge all arches
128 # default is False
129 # @param IsToModule: Input value for IsToModule
130 # True is to transfer to ModuleObject automatically
131 # False is not to transfer to ModuleObject automatically
132 # default is False
133 # @param WorkspaceDir: Input value for current workspace directory, default is None
134 #
135 # @var Identification: To store value for Identification, it is a structure as Identification
136 # @var UserExtensions: To store value for UserExtensions
137 # @var Module: To store value for Module, it is a structure as ModuleClass
138 # @var WorkspaceDir: To store value for WorkspaceDir
139 # @var KeyList: To store value for KeyList, a list for all Keys used in Inf
140 #
141 class Inf(InfObject):
142 def __init__(self, Filename=None, IsToModule=False, WorkspaceDir=None, PackageDir=None, SupArchList=DataType.ARCH_LIST):
143 self.Identification = IdentificationClass()
144 self.Module = ModuleClass()
145 self.WorkspaceDir = WorkspaceDir
146 self.PackageDir = PackageDir
147 self.SupArchList = SupArchList
148
149 self.KeyList = [
150 TAB_SOURCES, TAB_BUILD_OPTIONS, TAB_BINARIES, TAB_INCLUDES, TAB_GUIDS,
151 TAB_PROTOCOLS, TAB_PPIS, TAB_LIBRARY_CLASSES, TAB_PACKAGES, TAB_INF_FIXED_PCD,
152 TAB_INF_PATCH_PCD, TAB_INF_FEATURE_PCD, TAB_INF_PCD, TAB_INF_PCD_EX,
153 TAB_DEPEX, TAB_INF_DEFINES
154 ]
155 # Upper all KEYs to ignore case sensitive when parsing
156 self.KeyList = map(lambda c: c.upper(), self.KeyList)
157
158 # Init RecordSet
159 self.RecordSet = {}
160 for Key in self.KeyList:
161 self.RecordSet[Section[Key]] = []
162
163 # Init Comment
164 self.SectionHeaderCommentDict = {}
165
166 # Load Inf file if filename is not None
167 if Filename != None:
168 self.LoadInfFile(Filename)
169
170 # Transfer to Module Object if IsToModule is True
171 if IsToModule:
172 self.InfToModule()
173
174 ## Module Object to INF file
175 def ModuleToInf(self, Module):
176 Inf = ''
177 InfList = sdict()
178 SectionHeaderCommentDict = {}
179 if Module == None:
180 return Inf
181
182 ModuleHeader = Module.ModuleHeader
183 TmpList = []
184 # Common define items
185 if ModuleHeader.Name:
186 TmpList.append(TAB_INF_DEFINES_BASE_NAME + ' = ' + ModuleHeader.Name)
187 if ModuleHeader.Guid:
188 TmpList.append(TAB_INF_DEFINES_FILE_GUID + ' = ' + ModuleHeader.Guid)
189 if ModuleHeader.Version:
190 TmpList.append(TAB_INF_DEFINES_VERSION_STRING + ' = ' + ModuleHeader.Version)
191 if ModuleHeader.ModuleType:
192 TmpList.append(TAB_INF_DEFINES_MODULE_TYPE + ' = ' + ModuleHeader.ModuleType)
193 if ModuleHeader.PcdIsDriver:
194 TmpList.append(TAB_INF_DEFINES_PCD_IS_DRIVER + ' = ' + ModuleHeader.PcdIsDriver)
195 # Externs
196 for Item in Module.Externs:
197 if Item.EntryPoint:
198 TmpList.append(TAB_INF_DEFINES_ENTRY_POINT + ' = ' + Item.EntryPoint)
199 if Item.UnloadImage:
200 TmpList.append(TAB_INF_DEFINES_UNLOAD_IMAGE + ' = ' + Item.UnloadImage)
201 if Item.Constructor:
202 TmpList.append(TAB_INF_DEFINES_CONSTRUCTOR + ' = ' + Item.Constructor)
203 if Item.Destructor:
204 TmpList.append(TAB_INF_DEFINES_DESTRUCTOR + ' = ' + Item.Destructor)
205 # Other define items
206 if Module.UserExtensions != None:
207 for Item in Module.UserExtensions.Defines:
208 TmpList.append(Item)
209 InfList['Defines'] = TmpList
210 if ModuleHeader.Description != '':
211 SectionHeaderCommentDict['Defines'] = ModuleHeader.Description
212
213 if Module.UserExtensions != None:
214 InfList['BuildOptions'] = Module.UserExtensions.BuildOptions
215
216 for Item in Module.Includes:
217 Key = 'Includes.' + GetStringOfList(Item.SupArchList)
218 Value = GetHelpTextList(Item.HelpTextList)
219 Value.append(Item.FilePath)
220 GenMetaDatSectionItem(Key, Value, InfList)
221
222 for Item in Module.LibraryClasses:
223 Key = 'LibraryClasses.' + GetStringOfList(Item.SupArchList)
224 Value = GetHelpTextList(Item.HelpTextList)
225 NewValue = Item.LibraryClass
226 if Item.RecommendedInstance:
227 NewValue = NewValue + '|' + Item.RecommendedInstance
228 if Item.FeatureFlag:
229 NewValue = NewValue + '|' + Item.FeatureFlag
230 Value.append(NewValue)
231 GenMetaDatSectionItem(Key, Value, InfList)
232
233 for Item in Module.PackageDependencies:
234 Key = 'Packages.' + GetStringOfList(Item.SupArchList)
235 Value = GetHelpTextList(Item.HelpTextList)
236 Value.append(Item.FilePath)
237 GenMetaDatSectionItem(Key, Value, InfList)
238
239 for Item in Module.PcdCodes:
240 Key = 'Pcds' + Item.ItemType + '.' + GetStringOfList(Item.SupArchList)
241 Value = GetHelpTextList(Item.HelpTextList)
242 NewValue = Item.TokenSpaceGuidCName + '.' + Item.CName
243 if Item.DefaultValue != '':
244 NewValue = NewValue + '|' + Item.DefaultValue
245 Value.append(NewValue)
246 GenMetaDatSectionItem(Key, Value, InfList)
247
248 for Item in Module.Sources:
249 Key = 'Sources.' + GetStringOfList(Item.SupArchList)
250 Value = GetHelpTextList(Item.HelpTextList)
251 NewValue = Item.SourceFile
252 if Item.ToolChainFamily != '':
253 NewValue = NewValue + '|' + Item.ToolChainFamily
254 if Item.TagName != '':
255 NewValue = NewValue + '|' + Item.TagName
256 if Item.ToolCode != '':
257 NewValue = NewValue + '|' + Item.ToolCode
258 if Item.FeatureFlag != '':
259 NewValue = NewValue + '|' + Item.FeatureFlag
260 Value.append(NewValue)
261 if Item.HelpText != '':
262 SectionHeaderCommentDict[Key] = Item.HelpText
263 GenMetaDatSectionItem(Key, Value, InfList)
264
265 for Item in Module.Guids:
266 Key = 'Guids.' + GetStringOfList(Item.SupArchList)
267 Value = GetHelpTextList(Item.HelpTextList)
268 Value.append(Item.CName)
269 GenMetaDatSectionItem(Key, Value, InfList)
270
271 for Item in Module.Protocols:
272 Key = 'Protocols.' + GetStringOfList(Item.SupArchList)
273 Value = GetHelpTextList(Item.HelpTextList)
274 Value.append(Item.CName)
275 GenMetaDatSectionItem(Key, Value, InfList)
276
277 for Item in Module.Ppis:
278 Key = 'Ppis.' + GetStringOfList(Item.SupArchList)
279 Value = GetHelpTextList(Item.HelpTextList)
280 Value.append(Item.CName)
281 GenMetaDatSectionItem(Key, Value, InfList)
282
283 if Module.PeiDepex:
284 Key = 'Depex'
285 Value = Module.PeiDepex.Depex
286 GenMetaDatSectionItem(Key, Value, InfList)
287
288 if Module.DxeDepex:
289 Key = 'Depex'
290 Value = Module.DxeDepex.Depex
291 GenMetaDatSectionItem(Key, Value, InfList)
292
293 if Module.SmmDepex:
294 Key = 'Depex'
295 Value = Module.SmmDepex.Depex
296 GenMetaDatSectionItem(Key, Value, InfList)
297
298 for Item in Module.Binaries:
299 Key = 'Binaries.' + GetStringOfList(Item.SupArchList)
300 Value = GetHelpTextList(Item.HelpTextList)
301 NewValue = Item.FileType + '|' + Item.BinaryFile + '|' + Item.Target
302 if Item.FeatureFlag != '':
303 NewValue = NewValue + '|' + Item.FeatureFlag
304 Value.append(NewValue)
305 GenMetaDatSectionItem(Key, Value, InfList)
306
307 # Transfer Module to Inf
308 for Key in InfList:
309 if Key in SectionHeaderCommentDict:
310 List = SectionHeaderCommentDict[Key].split('\r')
311 for Item in List:
312 Inf = Inf + Item + '\n'
313 Inf = Inf + '[' + Key + ']' + '\n'
314 for Value in InfList[Key]:
315 if type(Value) == type([]):
316 for SubValue in Value:
317 Inf = Inf + ' ' + SubValue + '\n'
318 else:
319 Inf = Inf + ' ' + Value + '\n'
320 Inf = Inf + '\n'
321
322 return Inf
323
324
325 ## Transfer to Module Object
326 #
327 # Transfer all contents of an Inf file to a standard Module Object
328 #
329 def InfToModule(self):
330 # Init global information for the file
331 ContainerFile = self.Identification.FullPath
332
333 # Generate Module Header
334 self.GenModuleHeader(ContainerFile)
335
336 # Generate BuildOptions
337 self.GenBuildOptions(ContainerFile)
338
339 # Generate Includes
340 self.GenIncludes(ContainerFile)
341
342 # Generate LibraryClasses
343 self.GenLibraryClasses(ContainerFile)
344
345 # Generate Packages
346 self.GenPackages(ContainerFile)
347
348 # Generate Pcds
349 self.GenPcds(ContainerFile)
350
351 # Generate Sources
352 self.GenSources(ContainerFile)
353
354 # Generate Guids
355 self.GenGuidProtocolPpis(DataType.TAB_GUIDS, ContainerFile)
356
357 # Generate Protocols
358 self.GenGuidProtocolPpis(DataType.TAB_PROTOCOLS, ContainerFile)
359
360 # Generate Ppis
361 self.GenGuidProtocolPpis(DataType.TAB_PPIS, ContainerFile)
362
363 # Generate Depexes
364 self.GenDepexes(ContainerFile)
365
366 # Generate Binaries
367 self.GenBinaries(ContainerFile)
368
369 # Init MiscFiles
370 self.GenMiscFiles(ContainerFile)
371
372 ## GenMiscFiles
373 #
374 def GenMiscFiles(self, ContainerFile):
375 MiscFiles = MiscFileClass()
376 MiscFiles.Name = 'ModuleFiles'
377 for Item in GetFiles(os.path.dirname(ContainerFile), ['CVS', '.svn'], False):
378 File = CommonClass.FileClass()
379 File.Filename = Item
380 MiscFiles.Files.append(File)
381 self.Module.MiscFiles = MiscFiles
382
383 ## Load Inf file
384 #
385 # Load the file if it exists
386 #
387 # @param Filename: Input value for filename of Inf file
388 #
389 def LoadInfFile(self, Filename):
390 # Insert a record for file
391 Filename = NormPath(Filename)
392
393 self.Identification.FullPath = Filename
394 (self.Identification.RelaPath, self.Identification.FileName) = os.path.split(Filename)
395 if self.Identification.FullPath.find(self.WorkspaceDir) > -1:
396 self.Identification.ModulePath = os.path.dirname(self.Identification.FullPath[len(self.WorkspaceDir) + 1:])
397 if self.PackageDir:
398 self.Identification.PackagePath = self.PackageDir
399 if self.Identification.ModulePath.find(self.PackageDir) == 0:
400 self.Identification.ModulePath = self.Identification.ModulePath[len(self.PackageDir) + 1:]
401
402 # Init common datas
403 IfDefList, SectionItemList, CurrentSection, ArchList, ThirdList, IncludeFiles = \
404 [], [], TAB_UNKNOWN, [], [], []
405 LineNo = 0
406
407 # Parse file content
408 IsFindBlockComment = False
409 ReservedLine = ''
410 Comment = ''
411 for Line in open(Filename, 'r'):
412 LineNo = LineNo + 1
413 # Remove comment block
414 if Line.find(TAB_COMMENT_EDK_START) > -1:
415 ReservedLine = GetSplitList(Line, TAB_COMMENT_EDK_START, 1)[0]
416 if ReservedLine.strip().startswith(TAB_COMMENT_SPLIT):
417 Comment = Comment + Line.strip() + '\n'
418 ReservedLine = ''
419 else:
420 Comment = Comment + Line[len(ReservedLine):] + '\n'
421 IsFindBlockComment = True
422 if not ReservedLine:
423 continue
424 if Line.find(TAB_COMMENT_EDK_END) > -1:
425 Comment = Comment + Line[:Line.find(TAB_COMMENT_EDK_END) + len(TAB_COMMENT_EDK_END)] + '\n'
426 Line = ReservedLine + GetSplitList(Line, TAB_COMMENT_EDK_END, 1)[1]
427 ReservedLine = ''
428 IsFindBlockComment = False
429 if IsFindBlockComment:
430 Comment = Comment + Line.strip() + '\n'
431 continue
432
433 # Remove comments at tail and remove spaces again
434 if Line.strip().startswith(TAB_COMMENT_SPLIT) or Line.strip().startswith('--/'):
435 Comment = Comment + Line.strip() + '\n'
436 Line = CleanString(Line)
437 if Line == '':
438 continue
439
440 ## Find a new section tab
441 # First insert previous section items
442 # And then parse the content of the new section
443 if Line.startswith(TAB_SECTION_START) and Line.endswith(TAB_SECTION_END):
444 if Line[1:3] == "--":
445 continue
446 Model = Section[CurrentSection.upper()]
447 # Insert items data of previous section
448 InsertSectionItems(Model, CurrentSection, SectionItemList, ArchList, ThirdList, self.RecordSet)
449
450 # Parse the new section
451 SectionItemList = []
452 ArchList = []
453 ThirdList = []
454
455 CurrentSection = ''
456 LineList = GetSplitValueList(Line[len(TAB_SECTION_START):len(Line) - len(TAB_SECTION_END)], TAB_COMMA_SPLIT)
457 for Item in LineList:
458 ItemList = GetSplitValueList(Item, TAB_SPLIT)
459 if CurrentSection == '':
460 CurrentSection = ItemList[0]
461 else:
462 if CurrentSection != ItemList[0]:
463 EdkLogger.error("Parser", PARSER_ERROR, "Different section names '%s' and '%s' are found in one section definition, this is not allowed." % (CurrentSection, ItemList[0]), File=Filename, Line=LineNo, RaiseError=EdkLogger.IsRaiseError)
464 if CurrentSection.upper() not in self.KeyList:
465 RaiseParserError(Line, CurrentSection, Filename, '', LineNo)
466 ItemList.append('')
467 ItemList.append('')
468 if len(ItemList) > 5:
469 RaiseParserError(Line, CurrentSection, Filename, '', LineNo)
470 else:
471 if ItemList[1] != '' and ItemList[1].upper() not in ARCH_LIST_FULL:
472 EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo, RaiseError=EdkLogger.IsRaiseError)
473 ArchList.append(ItemList[1].upper())
474 ThirdList.append(ItemList[2])
475
476 if Comment:
477 if Comment.endswith('\n'):
478 Comment = Comment[:len(Comment) - len('\n')]
479 self.SectionHeaderCommentDict[Section[CurrentSection.upper()]] = Comment
480 Comment = ''
481 continue
482
483 # Not in any defined section
484 if CurrentSection == TAB_UNKNOWN:
485 ErrorMsg = "%s is not in any defined section" % Line
486 EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo, RaiseError=EdkLogger.IsRaiseError)
487
488 # Add a section item
489 SectionItemList.append([Line, LineNo, Comment])
490 Comment = ''
491 # End of parse
492 #End of For
493
494 # Insert items data of last section
495 Model = Section[CurrentSection.upper()]
496 InsertSectionItems(Model, CurrentSection, SectionItemList, ArchList, ThirdList, self.RecordSet)
497 if Comment != '':
498 self.SectionHeaderCommentDict[Model] = Comment
499 Comment = ''
500
501 ## Show detailed information of Module
502 #
503 # Print all members and their values of Module class
504 #
505 def ShowModule(self):
506 M = self.Module
507 print 'Filename =', M.ModuleHeader.FileName
508 print 'FullPath =', M.ModuleHeader.FullPath
509 print 'RelaPath =', M.ModuleHeader.RelaPath
510 print 'PackagePath =', M.ModuleHeader.PackagePath
511 print 'ModulePath =', M.ModuleHeader.ModulePath
512 print 'CombinePath =', M.ModuleHeader.CombinePath
513
514 print 'BaseName =', M.ModuleHeader.Name
515 print 'Guid =', M.ModuleHeader.Guid
516 print 'Version =', M.ModuleHeader.Version
517
518 print '\nIncludes ='
519 for Item in M.Includes:
520 print Item.FilePath, Item.SupArchList
521 print '\nLibraryClasses ='
522 for Item in M.LibraryClasses:
523 print Item.LibraryClass, Item.RecommendedInstance, Item.RecommendedInstanceGuid, Item.RecommendedInstanceVersion, Item.FeatureFlag, Item.SupModuleList, Item.SupArchList, Item.Define
524 print '\nPackageDependencies ='
525 for Item in M.PackageDependencies:
526 print Item.FilePath, Item.SupArchList, Item.FeatureFlag
527 print '\nPcds ='
528 for Item in M.PcdCodes:
529 print '\tCName=', Item.CName, 'TokenSpaceGuidCName=', Item.TokenSpaceGuidCName, 'DefaultValue=', Item.DefaultValue, 'ItemType=', Item.ItemType, Item.SupArchList
530 print '\nSources ='
531 for Source in M.Sources:
532 print Source.SourceFile, 'Fam=', Source.ToolChainFamily, 'Pcd=', Source.FeatureFlag, 'Tag=', Source.TagName, 'ToolCode=', Source.ToolCode, Source.SupArchList
533 print '\nGuids ='
534 for Item in M.Guids:
535 print Item.CName, Item.SupArchList, Item.FeatureFlag
536 print '\nProtocols ='
537 for Item in M.Protocols:
538 print Item.CName, Item.SupArchList, Item.FeatureFlag
539 print '\nPpis ='
540 for Item in M.Ppis:
541 print Item.CName, Item.SupArchList, Item.FeatureFlag
542 print '\nDepex ='
543 for Item in M.Depex:
544 print Item.Depex, Item.SupArchList, Item.Define
545 print '\nBinaries ='
546 for Binary in M.Binaries:
547 print 'Type=', Binary.FileType, 'Target=', Binary.Target, 'Name=', Binary.BinaryFile, 'FeatureFlag=', Binary.FeatureFlag, 'SupArchList=', Binary.SupArchList
548 print '\n*** FileList ***'
549 for Item in M.MiscFiles.Files:
550 print Item.Filename
551 print '****************\n'
552
553 ## Convert [Defines] section content to ModuleHeaderClass
554 #
555 # Convert [Defines] section content to ModuleHeaderClass
556 #
557 # @param Defines The content under [Defines] section
558 # @param ModuleHeader An object of ModuleHeaderClass
559 # @param Arch The supported ARCH
560 #
561 def GenModuleHeader(self, ContainerFile):
562 EdkLogger.debug(2, "Generate ModuleHeader ...")
563 # Update all defines item in database
564 RecordSet = self.RecordSet[MODEL_META_DATA_HEADER]
565
566 ModuleHeader = ModuleHeaderClass()
567 ModuleExtern = ModuleExternClass()
568 OtherDefines = []
569 for Record in RecordSet:
570 ValueList = GetSplitValueList(Record[0], TAB_EQUAL_SPLIT)
571 if len(ValueList) != 2:
572 OtherDefines.append(Record[0])
573 else:
574 Name = ValueList[0]
575 Value = ValueList[1]
576 if Name == TAB_INF_DEFINES_BASE_NAME:
577 ModuleHeader.Name = Value
578 ModuleHeader.BaseName = Value
579 elif Name == TAB_INF_DEFINES_FILE_GUID:
580 ModuleHeader.Guid = Value
581 elif Name == TAB_INF_DEFINES_VERSION_STRING:
582 ModuleHeader.Version = Value
583 elif Name == TAB_INF_DEFINES_PCD_IS_DRIVER:
584 ModuleHeader.PcdIsDriver = Value
585 elif Name == TAB_INF_DEFINES_MODULE_TYPE:
586 ModuleHeader.ModuleType = Value
587 elif Name in (TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION, TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION):
588 ModuleHeader.UefiSpecificationVersion = Value
589 elif Name == TAB_INF_DEFINES_PI_SPECIFICATION_VERSION:
590 ModuleHeader.PiSpecificationVersion = Value
591 elif Name == TAB_INF_DEFINES_ENTRY_POINT:
592 ModuleExtern.EntryPoint = Value
593 elif Name == TAB_INF_DEFINES_UNLOAD_IMAGE:
594 ModuleExtern.UnloadImage = Value
595 elif Name == TAB_INF_DEFINES_CONSTRUCTOR:
596 ModuleExtern.Constructor = Value
597 elif Name == TAB_INF_DEFINES_DESTRUCTOR:
598 ModuleExtern.Destructor = Value
599 else:
600 OtherDefines.append(Record[0])
601 ModuleHeader.FileName = self.Identification.FileName
602 ModuleHeader.FullPath = self.Identification.FullPath
603 ModuleHeader.RelaPath = self.Identification.RelaPath
604 ModuleHeader.PackagePath = self.Identification.PackagePath
605 ModuleHeader.ModulePath = self.Identification.ModulePath
606 ModuleHeader.CombinePath = os.path.normpath(os.path.join(ModuleHeader.PackagePath, ModuleHeader.ModulePath, ModuleHeader.FileName))
607
608 if MODEL_META_DATA_HEADER in self.SectionHeaderCommentDict:
609 ModuleHeader.Description = self.SectionHeaderCommentDict[MODEL_META_DATA_HEADER]
610 self.Module.ModuleHeader = ModuleHeader
611 self.Module.Externs.append(ModuleExtern)
612 UE = self.Module.UserExtensions
613 if UE == None:
614 UE = UserExtensionsClass()
615 UE.Defines = OtherDefines
616 self.Module.UserExtensions = UE
617
618 ## GenBuildOptions
619 #
620 # Gen BuildOptions of Inf
621 # [<Family>:]<ToolFlag>=Flag
622 #
623 # @param ContainerFile: The Inf file full path
624 #
625 def GenBuildOptions(self, ContainerFile):
626 EdkLogger.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS)
627 BuildOptions = {}
628 # Get all BuildOptions
629 RecordSet = self.RecordSet[MODEL_META_DATA_BUILD_OPTION]
630 UE = self.Module.UserExtensions
631 if UE == None:
632 UE = UserExtensionsClass()
633 for Record in RecordSet:
634 UE.BuildOptions.append(Record[0])
635 self.Module.UserExtensions = UE
636
637 ## GenIncludes
638 #
639 # Gen Includes of Inf
640 #
641 # @param ContainerFile: The Inf file full path
642 #
643 def GenIncludes(self, ContainerFile):
644 EdkLogger.debug(2, "Generate %s ..." % TAB_INCLUDES)
645 Includes = sdict()
646 # Get all Includes
647 RecordSet = self.RecordSet[MODEL_EFI_INCLUDE]
648 for Record in RecordSet:
649 Include = IncludeClass()
650 Include.FilePath = Record[0]
651 Include.SupArchList = Record[1]
652 if GenerateHelpText(Record[5], ''):
653 Include.HelpTextList.append(GenerateHelpText(Record[5], ''))
654 self.Module.Includes.append(Include)
655 #self.Module.FileList.extend(GetFiles(os.path.normpath(os.path.join(self.Identification.FileRelativePath, Include.FilePath)), ['CVS', '.svn']))
656
657 ## GenLibraryClasses
658 #
659 # Get LibraryClass of Inf
660 # <LibraryClassKeyWord>|<LibraryInstance>
661 #
662 # @param ContainerFile: The Inf file full path
663 #
664 def GenLibraryClasses(self, ContainerFile):
665 EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES)
666 LibraryClasses = {}
667 # Get all LibraryClasses
668 RecordSet = self.RecordSet[MODEL_EFI_LIBRARY_CLASS]
669 for Record in RecordSet:
670 (LibClassName, LibClassIns, Pcd, SupModelList) = GetLibraryClassOfInf([Record[0], Record[4]], ContainerFile, self.WorkspaceDir, Record[2])
671 LibraryClass = CommonClass.LibraryClassClass()
672 LibraryClass.LibraryClass = LibClassName
673 LibraryClass.RecommendedInstance = LibClassIns
674 LibraryClass.FeatureFlag = Pcd
675 LibraryClass.SupArchList = Record[1]
676 LibraryClass.SupModuleList = Record[4]
677 if GenerateHelpText(Record[5], ''):
678 LibraryClass.HelpTextList.append(GenerateHelpText(Record[5], ''))
679 self.Module.LibraryClasses.append(LibraryClass)
680
681 ## GenPackages
682 #
683 # Gen Packages of Inf
684 #
685 # @param ContainerFile: The Inf file full path
686 #
687 def GenPackages(self, ContainerFile):
688 EdkLogger.debug(2, "Generate %s ..." % TAB_PACKAGES)
689 Packages = {}
690 # Get all Packages
691 RecordSet = self.RecordSet[MODEL_META_DATA_PACKAGE]
692 for Record in RecordSet:
693 (PackagePath, Pcd) = GetPackage(Record[0], ContainerFile, self.WorkspaceDir, Record[2])
694 Package = ModulePackageDependencyClass()
695 Package.FilePath = NormPath(PackagePath)
696 Package.SupArchList = Record[1]
697 Package.FeatureFlag = Pcd
698 if GenerateHelpText(Record[5], ''):
699 Package.HelpTextList.append(GenerateHelpText(Record[5], ''))
700 self.Module.PackageDependencies.append(Package)
701
702 def AddPcd(self, CName, TokenSpaceGuidCName, DefaultValue, ItemType, Arch, HelpTextList):
703 Pcd = PcdClass()
704 Pcd.CName = CName
705 Pcd.TokenSpaceGuidCName = TokenSpaceGuidCName
706 Pcd.DefaultValue = DefaultValue
707 Pcd.ItemType = ItemType
708 Pcd.SupArchList = Arch
709 if GenerateHelpText(HelpTextList, ''):
710 Pcd.HelpTextList.append(GenerateHelpText(HelpTextList, ''))
711 self.Module.PcdCodes.append(Pcd)
712
713 ## GenPcds
714 #
715 # Gen Pcds of Inf
716 # <TokenSpaceGuidCName>.<PcdCName>[|<Value>]
717 #
718 # @param ContainerFile: The Dec file full path
719 #
720 def GenPcds(self, ContainerFile):
721 EdkLogger.debug(2, "Generate %s ..." % TAB_PCDS)
722 Pcds = {}
723 PcdToken = {}
724
725 # Get all Pcds
726 RecordSet1 = self.RecordSet[MODEL_PCD_FIXED_AT_BUILD]
727 RecordSet2 = self.RecordSet[MODEL_PCD_PATCHABLE_IN_MODULE]
728 RecordSet3 = self.RecordSet[MODEL_PCD_FEATURE_FLAG]
729 RecordSet4 = self.RecordSet[MODEL_PCD_DYNAMIC_EX]
730 RecordSet5 = self.RecordSet[MODEL_PCD_DYNAMIC]
731
732 # Go through each arch
733 for Record in RecordSet1:
734 (TokenSpaceGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], TAB_PCDS_FIXED_AT_BUILD, ContainerFile, Record[2])
735 self.AddPcd(TokenName, TokenSpaceGuidCName, Value, Type, Record[1], Record[5])
736 for Record in RecordSet2:
737 (TokenSpaceGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], TAB_PCDS_PATCHABLE_IN_MODULE, ContainerFile, Record[2])
738 self.AddPcd(TokenName, TokenSpaceGuidCName, Value, Type, Record[1], Record[5])
739 for Record in RecordSet3:
740 (TokenSpaceGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], TAB_PCDS_FEATURE_FLAG, ContainerFile, Record[2])
741 self.AddPcd(TokenName, TokenSpaceGuidCName, Value, Type, Record[1], Record[5])
742 for Record in RecordSet4:
743 (TokenSpaceGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], TAB_PCDS_DYNAMIC_EX, ContainerFile, Record[2])
744 self.AddPcd(TokenName, TokenSpaceGuidCName, Value, Type, Record[1], Record[5])
745 for Record in RecordSet5:
746 (TokenSpaceGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], '', ContainerFile, Record[2])
747 self.AddPcd(TokenName, TokenSpaceGuidCName, Value, Type, Record[1], Record[5])
748
749 ## GenSources
750 #
751 # Gen Sources of Inf
752 # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]
753 #
754 # @param ContainerFile: The Dec file full path
755 #
756 def GenSources(self, ContainerFile):
757 EdkLogger.debug(2, "Generate %s ..." % TAB_SOURCES)
758 Sources = {}
759
760 # Get all Sources
761 RecordSet = self.RecordSet[MODEL_EFI_SOURCE_FILE]
762 for Record in RecordSet:
763 (Filename, Family, TagName, ToolCode, Pcd) = GetSource(Record[0], ContainerFile, self.Identification.RelaPath, Record[2])
764 Source = ModuleSourceFileClass(Filename, TagName, ToolCode, Family, Pcd, Record[1])
765 if GenerateHelpText(Record[5], ''):
766 Source.HelpTextList.append(GenerateHelpText(Record[5], ''))
767 if MODEL_EFI_SOURCE_FILE in self.SectionHeaderCommentDict:
768 Source.HelpText = self.SectionHeaderCommentDict[MODEL_EFI_SOURCE_FILE]
769 self.Module.Sources.append(Source)
770 #self.Module.FileList.append(os.path.normpath(os.path.join(self.Identification.RelaPath, Filename)))
771
772 ## GenDepexes
773 #
774 # Gen Depex of Inf
775 #
776 # @param ContainerFile: The Inf file full path
777 #
778 def GenDepexes(self, ContainerFile):
779 EdkLogger.debug(2, "Generate %s ..." % TAB_DEPEX)
780 Depex = {}
781 # Get all Depexes
782 RecordSet = self.RecordSet[MODEL_EFI_DEPEX]
783 DepexString = ''
784 for Record in RecordSet:
785 DepexString = DepexString + Record[0] + '\n'
786 Dep = ModuleDepexClass()
787 if DepexString.endswith('\n'):
788 DepexString = DepexString[:len(DepexString) - len('\n')]
789 Dep.Depex = DepexString
790 if self.Module.ModuleHeader.ModuleType in ['DXE_SMM_DRIVER']:
791 self.Module.SmmDepex = Dep
792 elif self.Module.ModuleHeader.ModuleType in ['PEI_CORE', 'PEIM']:
793 self.Module.PeiDepex = Dep
794 else:
795 self.Module.DxeDepex = Dep
796 # for Record in RecordSet:
797 #
798 # Dep = ModuleDepexClass()
799 # Dep.Depex = Record[0]
800 # Dep.SupArchList = Record[1]
801 # if GenerateHelpText(Record[5], ''):
802 # Dep.HelpTextList.append(GenerateHelpText(Record[5], ''))
803 # DepexString = DepexString + Dep
804 # List.append(Dep)
805 # self.Module.Depex = List
806 # if self.Module.ModuleHeader.ModuleType in ['DXE_SMM_DRIVER']:
807 # self.Module.SmmDepex = List
808 # elif self.Module.ModuleHeader.ModuleType in ['PEI_CORE', 'PEIM']:
809 # self.Module.PeiDepex = List
810 # else:
811 # self.Module.DxeDepex = List
812
813 ## GenBinaries
814 #
815 # Gen Binary of Inf
816 # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]
817 #
818 # @param ContainerFile: The Dec file full path
819 #
820 def GenBinaries(self, ContainerFile):
821 EdkLogger.debug(2, "Generate %s ..." % TAB_BINARIES)
822 Binaries = {}
823
824 # Get all Guids
825 RecordSet = self.RecordSet[MODEL_EFI_BINARY_FILE]
826 for Record in RecordSet:
827 (FileType, Filename, Target, Pcd) = GetBinary(Record[0], ContainerFile, self.Identification.RelaPath, Record[2])
828 Binary = ModuleBinaryFileClass(Filename, FileType, Target, Pcd, Record[1])
829 if GenerateHelpText(Record[5], ''):
830 Binary.HelpTextList.append(GenerateHelpText(Record[5], ''))
831 self.Module.Binaries.append(Binary)
832 #self.Module.FileList.append(os.path.normpath(os.path.join(self.Identification.RelaPath, Filename)))
833
834 ## GenGuids
835 #
836 # Gen Guids of Inf
837 # <CName>=<GuidValue>
838 #
839 # @param ContainerFile: The Inf file full path
840 #
841 def GenGuidProtocolPpis(self, Type, ContainerFile):
842 EdkLogger.debug(2, "Generate %s ..." % Type)
843 Lists = {}
844 # Get all Items
845 if Type == TAB_GUIDS:
846 ListMember = self.Module.Guids
847 elif Type == TAB_PROTOCOLS:
848 ListMember = self.Module.Protocols
849 elif Type == TAB_PPIS:
850 ListMember = self.Module.Ppis
851
852 RecordSet = self.RecordSet[Section[Type.upper()]]
853 for Record in RecordSet:
854 (Name, Value) = GetGuidsProtocolsPpisOfInf(Record[0], Type, ContainerFile, Record[2])
855 ListClass = GuidProtocolPpiCommonClass()
856 ListClass.CName = Name
857 ListClass.SupArchList = Record[1]
858 ListClass.FeatureFlag = Value
859 if GenerateHelpText(Record[5], ''):
860 ListClass.HelpTextList.append(GenerateHelpText(Record[5], ''))
861 ListMember.append(ListClass)
862
863 ##
864 #
865 # This acts like the main() function for the script, unless it is 'import'ed into another
866 # script.
867 #
868 if __name__ == '__main__':
869 EdkLogger.Initialize()
870 EdkLogger.SetLevel(EdkLogger.QUIET)
871
872 W = os.getenv('WORKSPACE')
873 F = os.path.join(W, 'MdeModulePkg/Application/HelloWorld/HelloWorld.inf')
874
875 P = Inf(os.path.normpath(F), True, W, 'MdeModulePkg')
876 P.ShowModule()
877 print P.ModuleToInf(P.Module)