2 # This file is used to define each component of INF file
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
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.
21 from CommonDataClass
.ModuleClass
import *
22 from CommonDataClass
import CommonClass
24 from DataType
import *
25 from BuildToolError
import *
26 from Misc
import sdict
27 from Misc
import GetFiles
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
53 gComponentType2ModuleType
= {
55 "SECURITY_CORE" : "SEC",
56 "PEI_CORE" : "PEI_CORE",
57 "COMBINED_PEIM_DRIVER" : "PEIM",
59 "RELOCATABLE_PEIM" : "PEIM",
61 "BS_DRIVER" : "DXE_DRIVER",
62 "RT_DRIVER" : "DXE_RUNTIME_DRIVER",
63 "SAL_RT_DRIVER" : "DXE_SAL_DRIVER",
64 "APPLICATION" : "UEFI_APPLICATION",
68 class InfHeader(ModuleHeaderClass
):
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",
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",
97 ModuleHeaderClass
.__init
__(self
)
98 self
.VersionNumber
= ''
99 self
.VersionString
= ''
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
]]
106 def __contains__(self
, key
):
107 return key
in self
._Mapping
_
111 # This class defined basic Inf object which is used by inheriting
113 # @param object: Inherited from object class
115 class InfObject(object):
121 # This class defined the structure used in Inf object
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
129 # @param IsToModule: Input value for IsToModule
130 # True is to transfer to ModuleObject automatically
131 # False is not to transfer to ModuleObject automatically
133 # @param WorkspaceDir: Input value for current workspace directory, default is None
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
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
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
155 # Upper all KEYs to ignore case sensitive when parsing
156 self
.KeyList
= map(lambda c
: c
.upper(), self
.KeyList
)
160 for Key
in self
.KeyList
:
161 self
.RecordSet
[Section
[Key
]] = []
164 self
.SectionHeaderCommentDict
= {}
166 # Load Inf file if filename is not None
168 self
.LoadInfFile(Filename
)
170 # Transfer to Module Object if IsToModule is True
174 ## Module Object to INF file
175 def ModuleToInf(self
, Module
):
178 SectionHeaderCommentDict
= {}
182 ModuleHeader
= Module
.ModuleHeader
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
)
196 for Item
in Module
.Externs
:
198 TmpList
.append(TAB_INF_DEFINES_ENTRY_POINT
+ ' = ' + Item
.EntryPoint
)
200 TmpList
.append(TAB_INF_DEFINES_UNLOAD_IMAGE
+ ' = ' + Item
.UnloadImage
)
202 TmpList
.append(TAB_INF_DEFINES_CONSTRUCTOR
+ ' = ' + Item
.Constructor
)
204 TmpList
.append(TAB_INF_DEFINES_DESTRUCTOR
+ ' = ' + Item
.Destructor
)
206 if Module
.UserExtensions
!= None:
207 for Item
in Module
.UserExtensions
.Defines
:
209 InfList
['Defines'] = TmpList
210 if ModuleHeader
.Description
!= '':
211 SectionHeaderCommentDict
['Defines'] = ModuleHeader
.Description
213 if Module
.UserExtensions
!= None:
214 InfList
['BuildOptions'] = Module
.UserExtensions
.BuildOptions
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
)
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
229 NewValue
= NewValue
+ '|' + Item
.FeatureFlag
230 Value
.append(NewValue
)
231 GenMetaDatSectionItem(Key
, Value
, InfList
)
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
)
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
)
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
)
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
)
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
)
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
)
285 Value
= Module
.PeiDepex
.Depex
286 GenMetaDatSectionItem(Key
, Value
, InfList
)
290 Value
= Module
.DxeDepex
.Depex
291 GenMetaDatSectionItem(Key
, Value
, InfList
)
295 Value
= Module
.SmmDepex
.Depex
296 GenMetaDatSectionItem(Key
, Value
, InfList
)
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
)
307 # Transfer Module to Inf
309 if Key
in SectionHeaderCommentDict
:
310 List
= SectionHeaderCommentDict
[Key
].split('\r')
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'
319 Inf
= Inf
+ ' ' + Value
+ '\n'
325 ## Transfer to Module Object
327 # Transfer all contents of an Inf file to a standard Module Object
329 def InfToModule(self
):
330 # Init global information for the file
331 ContainerFile
= self
.Identification
.FullPath
333 # Generate Module Header
334 self
.GenModuleHeader(ContainerFile
)
336 # Generate BuildOptions
337 self
.GenBuildOptions(ContainerFile
)
340 self
.GenIncludes(ContainerFile
)
342 # Generate LibraryClasses
343 self
.GenLibraryClasses(ContainerFile
)
346 self
.GenPackages(ContainerFile
)
349 self
.GenPcds(ContainerFile
)
352 self
.GenSources(ContainerFile
)
355 self
.GenGuidProtocolPpis(DataType
.TAB_GUIDS
, ContainerFile
)
358 self
.GenGuidProtocolPpis(DataType
.TAB_PROTOCOLS
, ContainerFile
)
361 self
.GenGuidProtocolPpis(DataType
.TAB_PPIS
, ContainerFile
)
364 self
.GenDepexes(ContainerFile
)
367 self
.GenBinaries(ContainerFile
)
370 self
.GenMiscFiles(ContainerFile
)
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()
380 MiscFiles
.Files
.append(File
)
381 self
.Module
.MiscFiles
= MiscFiles
385 # Load the file if it exists
387 # @param Filename: Input value for filename of Inf file
389 def LoadInfFile(self
, Filename
):
390 # Insert a record for file
391 Filename
= NormPath(Filename
)
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:])
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:]
403 IfDefList
, SectionItemList
, CurrentSection
, ArchList
, ThirdList
, IncludeFiles
= \
404 [], [], TAB_UNKNOWN
, [], [], []
408 IsFindBlockComment
= False
411 for Line
in open(Filename
, 'r'):
413 # Remove comment block
414 if Line
.find(TAB_COMMENT_EDK_START
) > -1:
415 ReservedLine
= GetSplitValueList(Line
, TAB_COMMENT_EDK_START
, 1)[0]
416 if ReservedLine
.strip().startswith(TAB_COMMENT_SPLIT
):
417 Comment
= Comment
+ Line
.strip() + '\n'
420 Comment
= Comment
+ Line
[len(ReservedLine
):] + '\n'
421 IsFindBlockComment
= True
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
+ GetSplitValueList(Line
, TAB_COMMENT_EDK_END
, 1)[1]
428 IsFindBlockComment
= False
429 if IsFindBlockComment
:
430 Comment
= Comment
+ Line
.strip() + '\n'
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
)
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] == "--":
446 Model
= Section
[CurrentSection
.upper()]
447 # Insert items data of previous section
448 InsertSectionItems(Model
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, self
.RecordSet
)
450 # Parse the new section
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]
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
)
468 if len(ItemList
) > 5:
469 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
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])
477 if Comment
.endswith('\n'):
478 Comment
= Comment
[:len(Comment
) - len('\n')]
479 self
.SectionHeaderCommentDict
[Section
[CurrentSection
.upper()]] = Comment
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
)
489 SectionItemList
.append([Line
, LineNo
, Comment
])
494 # Insert items data of last section
495 Model
= Section
[CurrentSection
.upper()]
496 InsertSectionItems(Model
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, self
.RecordSet
)
498 self
.SectionHeaderCommentDict
[Model
] = Comment
501 ## Show detailed information of Module
503 # Print all members and their values of Module class
505 def ShowModule(self
):
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
514 print 'BaseName =', M
.ModuleHeader
.Name
515 print 'Guid =', M
.ModuleHeader
.Guid
516 print 'Version =', M
.ModuleHeader
.Version
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
528 for Item
in M
.PcdCodes
:
529 print '\tCName=',Item
.CName
, 'TokenSpaceGuidCName=', Item
.TokenSpaceGuidCName
, 'DefaultValue=', Item
.DefaultValue
, 'ItemType=', Item
.ItemType
, Item
.SupArchList
531 for Source
in M
.Sources
:
532 print Source
.SourceFile
, 'Fam=', Source
.ToolChainFamily
, 'Pcd=', Source
.FeatureFlag
, 'Tag=', Source
.TagName
, 'ToolCode=', Source
.ToolCode
, Source
.SupArchList
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
541 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
544 print Item
.Depex
, Item
.SupArchList
, Item
.Define
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
:
551 print '****************\n'
553 ## Convert [Defines] section content to ModuleHeaderClass
555 # Convert [Defines] section content to ModuleHeaderClass
557 # @param Defines The content under [Defines] section
558 # @param ModuleHeader An object of ModuleHeaderClass
559 # @param Arch The supported ARCH
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
]
566 ModuleHeader
= ModuleHeaderClass()
567 ModuleExtern
= ModuleExternClass()
569 for Record
in RecordSet
:
570 ValueList
= GetSplitValueList(Record
[0], TAB_EQUAL_SPLIT
)
571 if len(ValueList
) != 2:
572 OtherDefines
.append(Record
[0])
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
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
))
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
614 UE
= UserExtensionsClass()
615 UE
.Defines
= OtherDefines
616 self
.Module
.UserExtensions
= UE
620 # Gen BuildOptions of Inf
621 # [<Family>:]<ToolFlag>=Flag
623 # @param ContainerFile: The Inf file full path
625 def GenBuildOptions(self
, ContainerFile
):
626 EdkLogger
.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS
)
628 # Get all BuildOptions
629 RecordSet
= self
.RecordSet
[MODEL_META_DATA_BUILD_OPTION
]
630 UE
= self
.Module
.UserExtensions
632 UE
= UserExtensionsClass()
633 for Record
in RecordSet
:
634 UE
.BuildOptions
.append(Record
[0])
635 self
.Module
.UserExtensions
= UE
639 # Gen Includes of Inf
641 # @param ContainerFile: The Inf file full path
643 def GenIncludes(self
, ContainerFile
):
644 EdkLogger
.debug(2, "Generate %s ..." % TAB_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']))
659 # Get LibraryClass of Inf
660 # <LibraryClassKeyWord>|<LibraryInstance>
662 # @param ContainerFile: The Inf file full path
664 def GenLibraryClasses(self
, ContainerFile
):
665 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES
)
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
)
683 # Gen Packages of Inf
685 # @param ContainerFile: The Inf file full path
687 def GenPackages(self
, ContainerFile
):
688 EdkLogger
.debug(2, "Generate %s ..." % TAB_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
)
702 def AddPcd(self
, CName
, TokenSpaceGuidCName
, DefaultValue
, ItemType
, Arch
, HelpTextList
):
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
)
716 # <TokenSpaceGuidCName>.<PcdCName>[|<Value>]
718 # @param ContainerFile: The Dec file full path
720 def GenPcds(self
, ContainerFile
):
721 EdkLogger
.debug(2, "Generate %s ..." % TAB_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
]
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])
752 # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]
754 # @param ContainerFile: The Dec file full path
756 def GenSources(self
, ContainerFile
):
757 EdkLogger
.debug(2, "Generate %s ..." % TAB_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)))
776 # @param ContainerFile: The Inf file full path
778 def GenDepexes(self
, ContainerFile
):
779 EdkLogger
.debug(2, "Generate %s ..." % TAB_DEPEX
)
782 RecordSet
= self
.RecordSet
[MODEL_EFI_DEPEX
]
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
795 self
.Module
.DxeDepex
= Dep
796 # for Record in RecordSet:
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
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
811 # self.Module.DxeDepex = List
816 # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]
818 # @param ContainerFile: The Dec file full path
820 def GenBinaries(self
, ContainerFile
):
821 EdkLogger
.debug(2, "Generate %s ..." % TAB_BINARIES
)
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)))
837 # <CName>=<GuidValue>
839 # @param ContainerFile: The Inf file full path
841 def GenGuidProtocolPpis(self
, Type
, ContainerFile
):
842 EdkLogger
.debug(2, "Generate %s ..." % Type
)
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
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
)
865 # This acts like the main() function for the script, unless it is 'import'ed into another
868 if __name__
== '__main__':
869 EdkLogger
.Initialize()
870 EdkLogger
.SetLevel(EdkLogger
.QUIET
)
872 W
= os
.getenv('WORKSPACE')
873 F
= os
.path
.join(W
, 'MdeModulePkg/Application/HelloWorld/HelloWorld.inf')
875 P
= Inf(os
.path
.normpath(F
), True, W
, 'MdeModulePkg')
877 print P
.ModuleToInf(P
.Module
)