2 # This file is used to define each component of INF file
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
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
: "EfiSpecificationVersion",
75 TAB_INF_DEFINES_EDK_RELEASE_VERSION
: "EdkReleaseVersion",
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",
96 ModuleHeaderClass
.__init
__(self
)
97 self
.VersionNumber
= ''
98 self
.VersionString
= ''
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
]]
105 def __contains__(self
, key
):
106 return key
in self
._Mapping
_
110 # This class defined basic Inf object which is used by inheriting
112 # @param object: Inherited from object class
114 class InfObject(object):
120 # This class defined the structure used in Inf object
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
128 # @param IsToModule: Input value for IsToModule
129 # True is to transfer to ModuleObject automatically
130 # False is not to transfer to ModuleObject automatically
132 # @param WorkspaceDir: Input value for current workspace directory, default is None
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
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
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
154 # Upper all KEYs to ignore case sensitive when parsing
155 self
.KeyList
= map(lambda c
: c
.upper(), self
.KeyList
)
159 for Key
in self
.KeyList
:
160 self
.RecordSet
[Section
[Key
]] = []
163 self
.SectionHeaderCommentDict
= {}
165 # Load Inf file if filename is not None
167 self
.LoadInfFile(Filename
)
169 # Transfer to Module Object if IsToModule is True
173 ## Module Object to INF file
174 def ModuleToInf(self
, Module
):
177 SectionHeaderCommentDict
= {}
181 ModuleHeader
= Module
.ModuleHeader
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
)
195 for Item
in Module
.Externs
:
197 TmpList
.append(TAB_INF_DEFINES_ENTRY_POINT
+ ' = ' + Item
.EntryPoint
)
199 TmpList
.append(TAB_INF_DEFINES_UNLOAD_IMAGE
+ ' = ' + Item
.UnloadImage
)
201 TmpList
.append(TAB_INF_DEFINES_CONSTRUCTOR
+ ' = ' + Item
.Constructor
)
203 TmpList
.append(TAB_INF_DEFINES_DESTRUCTOR
+ ' = ' + Item
.Destructor
)
205 if Module
.UserExtensions
!= None:
206 for Item
in Module
.UserExtensions
.Defines
:
208 InfList
['Defines'] = TmpList
209 if ModuleHeader
.Description
!= '':
210 SectionHeaderCommentDict
['Defines'] = ModuleHeader
.Description
212 if Module
.UserExtensions
!= None:
213 InfList
['BuildOptions'] = Module
.UserExtensions
.BuildOptions
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
)
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
228 NewValue
= NewValue
+ '|' + Item
.FeatureFlag
229 Value
.append(NewValue
)
230 GenMetaDatSectionItem(Key
, Value
, InfList
)
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
)
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
)
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
)
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
)
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
)
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
)
284 Value
= Module
.PeiDepex
.Depex
285 GenMetaDatSectionItem(Key
, Value
, InfList
)
289 Value
= Module
.DxeDepex
.Depex
290 GenMetaDatSectionItem(Key
, Value
, InfList
)
294 Value
= Module
.SmmDepex
.Depex
295 GenMetaDatSectionItem(Key
, Value
, InfList
)
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
)
306 # Transfer Module to Inf
308 if Key
in SectionHeaderCommentDict
:
309 List
= SectionHeaderCommentDict
[Key
].split('\r')
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'
318 Inf
= Inf
+ ' ' + Value
+ '\n'
324 ## Transfer to Module Object
326 # Transfer all contents of an Inf file to a standard Module Object
328 def InfToModule(self
):
329 # Init global information for the file
330 ContainerFile
= self
.Identification
.FullPath
332 # Generate Module Header
333 self
.GenModuleHeader(ContainerFile
)
335 # Generate BuildOptions
336 self
.GenBuildOptions(ContainerFile
)
339 self
.GenIncludes(ContainerFile
)
341 # Generate LibraryClasses
342 self
.GenLibraryClasses(ContainerFile
)
345 self
.GenPackages(ContainerFile
)
348 self
.GenPcds(ContainerFile
)
351 self
.GenSources(ContainerFile
)
354 self
.GenGuidProtocolPpis(DataType
.TAB_GUIDS
, ContainerFile
)
357 self
.GenGuidProtocolPpis(DataType
.TAB_PROTOCOLS
, ContainerFile
)
360 self
.GenGuidProtocolPpis(DataType
.TAB_PPIS
, ContainerFile
)
363 self
.GenDepexes(ContainerFile
)
366 self
.GenBinaries(ContainerFile
)
369 self
.GenMiscFiles(ContainerFile
)
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()
379 MiscFiles
.Files
.append(File
)
380 self
.Module
.MiscFiles
= MiscFiles
384 # Load the file if it exists
386 # @param Filename: Input value for filename of Inf file
388 def LoadInfFile(self
, Filename
):
389 # Insert a record for file
390 Filename
= NormPath(Filename
)
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:])
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:]
402 IfDefList
, SectionItemList
, CurrentSection
, ArchList
, ThirdList
, IncludeFiles
= \
403 [], [], TAB_UNKNOWN
, [], [], []
407 IsFindBlockComment
= False
410 for Line
in open(Filename
, 'r'):
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'
419 Comment
= Comment
+ Line
[len(ReservedLine
):] + '\n'
420 IsFindBlockComment
= True
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]
427 IsFindBlockComment
= False
428 if IsFindBlockComment
:
429 Comment
= Comment
+ Line
.strip() + '\n'
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
)
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] == "--":
445 Model
= Section
[CurrentSection
.upper()]
446 # Insert items data of previous section
447 InsertSectionItems(Model
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, self
.RecordSet
)
449 # Parse the new section
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]
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
)
467 if len(ItemList
) > 5:
468 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
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])
476 if Comment
.endswith('\n'):
477 Comment
= Comment
[:len(Comment
) - len('\n')]
478 self
.SectionHeaderCommentDict
[Section
[CurrentSection
.upper()]] = Comment
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
)
488 SectionItemList
.append([Line
, LineNo
, Comment
])
493 # Insert items data of last section
494 Model
= Section
[CurrentSection
.upper()]
495 InsertSectionItems(Model
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, self
.RecordSet
)
497 self
.SectionHeaderCommentDict
[Model
] = Comment
500 ## Show detailed information of Module
502 # Print all members and their values of Module class
504 def ShowModule(self
):
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
513 print 'BaseName =', M
.ModuleHeader
.Name
514 print 'Guid =', M
.ModuleHeader
.Guid
515 print 'Version =', M
.ModuleHeader
.Version
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
527 for Item
in M
.PcdCodes
:
528 print '\tCName=',Item
.CName
, 'TokenSpaceGuidCName=', Item
.TokenSpaceGuidCName
, 'DefaultValue=', Item
.DefaultValue
, 'ItemType=', Item
.ItemType
, Item
.SupArchList
530 for Source
in M
.Sources
:
531 print Source
.SourceFile
, 'Fam=', Source
.ToolChainFamily
, 'Pcd=', Source
.FeatureFlag
, 'Tag=', Source
.TagName
, 'ToolCode=', Source
.ToolCode
, Source
.SupArchList
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
540 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
543 print Item
.Depex
, Item
.SupArchList
, Item
.Define
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
:
550 print '****************\n'
552 ## Convert [Defines] section content to ModuleHeaderClass
554 # Convert [Defines] section content to ModuleHeaderClass
556 # @param Defines The content under [Defines] section
557 # @param ModuleHeader An object of ModuleHeaderClass
558 # @param Arch The supported ARCH
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
]
565 ModuleHeader
= ModuleHeaderClass()
566 ModuleExtern
= ModuleExternClass()
568 for Record
in RecordSet
:
569 ValueList
= GetSplitValueList(Record
[0], TAB_EQUAL_SPLIT
)
570 if len(ValueList
) != 2:
571 OtherDefines
.append(Record
[0])
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
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
))
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
613 UE
= UserExtensionsClass()
614 UE
.Defines
= OtherDefines
615 self
.Module
.UserExtensions
= UE
619 # Gen BuildOptions of Inf
620 # [<Family>:]<ToolFlag>=Flag
622 # @param ContainerFile: The Inf file full path
624 def GenBuildOptions(self
, ContainerFile
):
625 EdkLogger
.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS
)
627 # Get all BuildOptions
628 RecordSet
= self
.RecordSet
[MODEL_META_DATA_BUILD_OPTION
]
629 UE
= self
.Module
.UserExtensions
631 UE
= UserExtensionsClass()
632 for Record
in RecordSet
:
633 UE
.BuildOptions
.append(Record
[0])
634 self
.Module
.UserExtensions
= UE
638 # Gen Includes of Inf
640 # @param ContainerFile: The Inf file full path
642 def GenIncludes(self
, ContainerFile
):
643 EdkLogger
.debug(2, "Generate %s ..." % TAB_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']))
658 # Get LibraryClass of Inf
659 # <LibraryClassKeyWord>|<LibraryInstance>
661 # @param ContainerFile: The Inf file full path
663 def GenLibraryClasses(self
, ContainerFile
):
664 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES
)
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
)
682 # Gen Packages of Inf
684 # @param ContainerFile: The Inf file full path
686 def GenPackages(self
, ContainerFile
):
687 EdkLogger
.debug(2, "Generate %s ..." % TAB_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
)
701 def AddPcd(self
, CName
, TokenSpaceGuidCName
, DefaultValue
, ItemType
, Arch
, HelpTextList
):
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
)
715 # <TokenSpaceGuidCName>.<PcdCName>[|<Value>]
717 # @param ContainerFile: The Dec file full path
719 def GenPcds(self
, ContainerFile
):
720 EdkLogger
.debug(2, "Generate %s ..." % TAB_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
]
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])
751 # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]
753 # @param ContainerFile: The Dec file full path
755 def GenSources(self
, ContainerFile
):
756 EdkLogger
.debug(2, "Generate %s ..." % TAB_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)))
775 # @param ContainerFile: The Inf file full path
777 def GenDepexes(self
, ContainerFile
):
778 EdkLogger
.debug(2, "Generate %s ..." % TAB_DEPEX
)
781 RecordSet
= self
.RecordSet
[MODEL_EFI_DEPEX
]
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
794 self
.Module
.DxeDepex
= Dep
795 # for Record in RecordSet:
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
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
810 # self.Module.DxeDepex = List
815 # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]
817 # @param ContainerFile: The Dec file full path
819 def GenBinaries(self
, ContainerFile
):
820 EdkLogger
.debug(2, "Generate %s ..." % TAB_BINARIES
)
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)))
836 # <CName>=<GuidValue>
838 # @param ContainerFile: The Inf file full path
840 def GenGuidProtocolPpis(self
, Type
, ContainerFile
):
841 EdkLogger
.debug(2, "Generate %s ..." % Type
)
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
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
)
864 # This acts like the main() function for the script, unless it is 'import'ed into another
867 if __name__
== '__main__':
868 EdkLogger
.Initialize()
869 EdkLogger
.SetLevel(EdkLogger
.QUIET
)
871 W
= os
.getenv('WORKSPACE')
872 F
= os
.path
.join(W
, 'MdeModulePkg/Application/HelloWorld/HelloWorld.inf')
874 P
= Inf(os
.path
.normpath(F
), True, W
, 'MdeModulePkg')
876 print P
.ModuleToInf(P
.Module
)