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