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.
20 from CommonDataClass
.CommonClass
import LibraryClassClass
21 from CommonDataClass
.ModuleClass
import *
23 from DataType
import *
24 from Identification
import *
25 from Dictionary
import *
26 from BuildToolError
import *
27 from Misc
import sdict
29 from Table
.TableInf
import TableInf
36 Section
= {TAB_UNKNOWN
.upper() : MODEL_UNKNOWN
,
37 TAB_INF_DEFINES
.upper() : MODEL_META_DATA_HEADER
,
38 TAB_BUILD_OPTIONS
.upper() : MODEL_META_DATA_BUILD_OPTION
,
39 TAB_INCLUDES
.upper() : MODEL_EFI_INCLUDE
,
40 TAB_LIBRARIES
.upper() : MODEL_EFI_LIBRARY_INSTANCE
,
41 TAB_LIBRARY_CLASSES
.upper() : MODEL_EFI_LIBRARY_CLASS
,
42 TAB_PACKAGES
.upper() : MODEL_META_DATA_PACKAGE
,
43 TAB_NMAKE
.upper() : MODEL_META_DATA_NMAKE
,
44 TAB_INF_FIXED_PCD
.upper() : MODEL_PCD_FIXED_AT_BUILD
,
45 TAB_INF_PATCH_PCD
.upper() : MODEL_PCD_PATCHABLE_IN_MODULE
,
46 TAB_INF_FEATURE_PCD
.upper() : MODEL_PCD_FEATURE_FLAG
,
47 TAB_INF_PCD_EX
.upper() : MODEL_PCD_DYNAMIC_EX
,
48 TAB_INF_PCD
.upper() : MODEL_PCD_DYNAMIC
,
49 TAB_SOURCES
.upper() : MODEL_EFI_SOURCE_FILE
,
50 TAB_GUIDS
.upper() : MODEL_EFI_GUID
,
51 TAB_PROTOCOLS
.upper() : MODEL_EFI_PROTOCOL
,
52 TAB_PPIS
.upper() : MODEL_EFI_PPI
,
53 TAB_DEPEX
.upper() : MODEL_EFI_DEPEX
,
54 TAB_BINARIES
.upper() : MODEL_EFI_BINARY_FILE
,
55 TAB_USER_EXTENSIONS
.upper() : MODEL_META_DATA_USER_EXTENSION
58 gComponentType2ModuleType
= {
60 "SECURITY_CORE" : "SEC",
61 "PEI_CORE" : "PEI_CORE",
62 "COMBINED_PEIM_DRIVER" : "PEIM",
64 "RELOCATABLE_PEIM" : "PEIM",
66 "BS_DRIVER" : "DXE_DRIVER",
67 "RT_DRIVER" : "DXE_RUNTIME_DRIVER",
68 "SAL_RT_DRIVER" : "DXE_SAL_DRIVER",
69 "APPLICATION" : "UEFI_APPLICATION",
73 gNmakeFlagPattern
= re
.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re
.UNICODE
)
74 gNmakeFlagName2ToolCode
= {
80 class InfHeader(ModuleHeaderClass
):
85 TAB_INF_DEFINES_BASE_NAME
: "Name",
86 TAB_INF_DEFINES_FILE_GUID
: "Guid",
87 TAB_INF_DEFINES_MODULE_TYPE
: "ModuleType",
88 TAB_INF_DEFINES_EFI_SPECIFICATION_VERSION
: "EfiSpecificationVersion",
89 TAB_INF_DEFINES_EDK_RELEASE_VERSION
: "EdkReleaseVersion",
93 TAB_INF_DEFINES_INF_VERSION
: "InfVersion",
94 TAB_INF_DEFINES_BINARY_MODULE
: "BinaryModule",
95 TAB_INF_DEFINES_COMPONENT_TYPE
: "ComponentType",
96 TAB_INF_DEFINES_MAKEFILE_NAME
: "MakefileName",
97 TAB_INF_DEFINES_BUILD_NUMBER
: "BuildNumber",
98 TAB_INF_DEFINES_BUILD_TYPE
: "BuildType",
99 TAB_INF_DEFINES_FFS_EXT
: "FfsExt",
100 TAB_INF_DEFINES_FV_EXT
: "FvExt",
101 TAB_INF_DEFINES_SOURCE_FV
: "SourceFv",
102 TAB_INF_DEFINES_VERSION_NUMBER
: "VersionNumber",
103 TAB_INF_DEFINES_VERSION_STRING
: "VersionString",
104 TAB_INF_DEFINES_VERSION
: "Version",
105 TAB_INF_DEFINES_PCD_IS_DRIVER
: "PcdIsDriver",
106 TAB_INF_DEFINES_TIANO_R8_FLASHMAP_H
: "TianoR8FlashMap_h",
107 TAB_INF_DEFINES_SHADOW
: "Shadow",
108 # TAB_INF_DEFINES_LIBRARY_CLASS : "LibraryClass",
109 # TAB_INF_DEFINES_ENTRY_POINT : "ExternImages",
110 # TAB_INF_DEFINES_UNLOAD_IMAGE : "ExternImages",
111 # TAB_INF_DEFINES_CONSTRUCTOR : ,
112 # TAB_INF_DEFINES_DESTRUCTOR : ,
113 # TAB_INF_DEFINES_DEFINE : "Define",
114 # TAB_INF_DEFINES_SPEC : "Specification",
115 # TAB_INF_DEFINES_CUSTOM_MAKEFILE : "CustomMakefile",
116 # TAB_INF_DEFINES_MACRO :
120 ModuleHeaderClass
.__init
__(self
)
121 self
.VersionNumber
= ''
122 self
.VersionString
= ''
124 def __setitem__(self
, key
, value
):
125 self
.__dict
__[self
._Mapping
_[key
]] = value
126 def __getitem__(self
, key
):
127 return self
.__dict
__[self
._Mapping
_[key
]]
129 def __contains__(self
, key
):
130 return key
in self
._Mapping
_
134 # This class defined basic Inf object which is used by inheriting
136 # @param object: Inherited from object class
138 class InfObject(object):
144 # This class defined the structure used in Inf object
146 # @param InfObject: Inherited from InfObject class
147 # @param Ffilename: Input value for Ffilename of Inf file, default is None
148 # @param IsMergeAllArches: Input value for IsMergeAllArches
149 # True is to merge all arches
150 # Fales is not to merge all arches
152 # @param IsToModule: Input value for IsToModule
153 # True is to transfer to ModuleObject automatically
154 # False is not to transfer to ModuleObject automatically
156 # @param WorkspaceDir: Input value for current workspace directory, default is None
158 # @var Identification: To store value for Identification, it is a structure as Identification
159 # @var UserExtensions: To store value for UserExtensions
160 # @var Module: To store value for Module, it is a structure as ModuleClass
161 # @var WorkspaceDir: To store value for WorkspaceDir
162 # @var KeyList: To store value for KeyList, a list for all Keys used in Inf
164 class Inf(InfObject
):
165 def __init__(self
, Filename
= None, IsToDatabase
= False, IsToModule
= False, WorkspaceDir
= None, Database
= None, SupArchList
= DataType
.ARCH_LIST
):
166 self
.Identification
= Identification()
167 self
.Module
= ModuleClass()
168 self
.UserExtensions
= ''
169 self
.WorkspaceDir
= WorkspaceDir
170 self
.SupArchList
= SupArchList
171 self
.IsToDatabase
= IsToDatabase
173 self
.Cur
= Database
.Cur
174 self
.TblFile
= Database
.TblFile
175 self
.TblInf
= Database
.TblInf
177 #self.TblInf = TableInf(Database.Cur)
180 TAB_SOURCES
, TAB_BUILD_OPTIONS
, TAB_BINARIES
, TAB_INCLUDES
, TAB_GUIDS
,
181 TAB_PROTOCOLS
, TAB_PPIS
, TAB_LIBRARY_CLASSES
, TAB_PACKAGES
, TAB_LIBRARIES
,
182 TAB_INF_FIXED_PCD
, TAB_INF_PATCH_PCD
, TAB_INF_FEATURE_PCD
, TAB_INF_PCD
,
183 TAB_INF_PCD_EX
, TAB_DEPEX
, TAB_NMAKE
, TAB_INF_DEFINES
186 # Upper all KEYs to ignore case sensitive when parsing
188 self
.KeyList
= map(lambda c
: c
.upper(), self
.KeyList
)
194 for Key
in self
.KeyList
:
195 self
.RecordSet
[Section
[Key
]] = []
198 # Load Inf file if filename is not None
201 self
.LoadInfFile(Filename
)
204 # Transfer to Module Object if IsToModule is True
209 ## Transfer to Module Object
211 # Transfer all contents of an Inf file to a standard Module Object
213 def InfToModule(self
):
215 # Init global information for the file
217 ContainerFile
= self
.Identification
.FileFullPath
220 # Generate Package Header
222 self
.GenModuleHeader(ContainerFile
)
225 # Generate BuildOptions
227 self
.GenBuildOptions(ContainerFile
)
232 self
.GenIncludes(ContainerFile
)
237 self
.GenLibraries(ContainerFile
)
240 # Generate LibraryClasses
242 self
.GenLibraryClasses(ContainerFile
)
247 self
.GenPackages(ContainerFile
)
252 self
.GenNmakes(ContainerFile
)
257 self
.GenPcds(ContainerFile
)
262 self
.GenSources(ContainerFile
)
265 # Generate UserExtensions
267 self
.GenUserExtensions(ContainerFile
)
272 self
.GenGuidProtocolPpis(DataType
.TAB_GUIDS
, ContainerFile
)
277 self
.GenGuidProtocolPpis(DataType
.TAB_PROTOCOLS
, ContainerFile
)
282 self
.GenGuidProtocolPpis(DataType
.TAB_PPIS
, ContainerFile
)
287 self
.GenDepexes(ContainerFile
)
292 self
.GenBinaries(ContainerFile
)
294 ## Parse [Defines] section
296 # Parse [Defines] section into InfDefines object
298 # @param InfFile The path of the INF file
299 # @param Section The title of "Defines" section
300 # @param Lines The content of "Defines" section
302 def ParseDefines(self
, InfFile
, Section
, Lines
):
303 TokenList
= Section
.split(TAB_SPLIT
)
304 if len(TokenList
) == 3:
305 RaiseParserError(Section
, "Defines", InfFile
, "[xx.yy.%s] format (with platform) is not supported")
306 if len(TokenList
) == 2:
307 Arch
= TokenList
[1].upper()
309 Arch
= TAB_ARCH_COMMON
311 if Arch
not in self
.Defines
:
312 self
.Defines
[Arch
] = InfDefines()
313 GetSingleValueOfKeyFromLines(Lines
, self
.Defines
[Arch
].DefinesDictionary
,
314 TAB_COMMENT_SPLIT
, TAB_EQUAL_SPLIT
, False, None)
318 # Load the file if it exists
320 # @param Filename: Input value for filename of Inf file
322 def LoadInfFile(self
, Filename
):
324 # Insert a record for file
326 Filename
= NormPath(Filename
)
327 self
.Identification
.FileFullPath
= Filename
328 (self
.Identification
.FileRelativePath
, self
.Identification
.FileName
) = os
.path
.split(Filename
)
329 self
.FileID
= self
.TblFile
.InsertFile(Filename
, MODEL_FILE_INF
)
334 #self.TblInf.Table = "Inf%s" % self.FileID
335 #self.TblInf.Create()
340 IfDefList
, SectionItemList
, CurrentSection
, ArchList
, ThirdList
, IncludeFiles
= \
341 [], [], TAB_UNKNOWN
, [], [], []
347 IsFindBlockComment
= False
349 for Line
in open(Filename
, 'r'):
352 # Remove comment block
354 if Line
.find(TAB_COMMENT_R8_START
) > -1:
355 ReservedLine
= GetSplitValueList(Line
, TAB_COMMENT_R8_START
, 1)[0]
356 IsFindBlockComment
= True
357 if Line
.find(TAB_COMMENT_R8_END
) > -1:
358 Line
= ReservedLine
+ GetSplitValueList(Line
, TAB_COMMENT_R8_END
, 1)[1]
360 IsFindBlockComment
= False
361 if IsFindBlockComment
:
365 # Remove comments at tail and remove spaces again
367 Line
= CleanString(Line
)
372 # Find a new section tab
373 # First insert previous section items
374 # And then parse the content of the new section
376 if Line
.startswith(TAB_SECTION_START
) and Line
.endswith(TAB_SECTION_END
):
377 if Line
[1:3] == "--":
379 Model
= Section
[CurrentSection
.upper()]
381 # Insert items data of previous section
383 InsertSectionItemsIntoDatabase(self
.TblInf
, self
.FileID
, Filename
, Model
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
, self
.RecordSet
)
385 # Parse the new section
392 LineList
= GetSplitValueList(Line
[len(TAB_SECTION_START
):len(Line
) - len(TAB_SECTION_END
)], TAB_COMMA_SPLIT
)
393 for Item
in LineList
:
394 ItemList
= GetSplitValueList(Item
, TAB_SPLIT
)
395 if CurrentSection
== '':
396 CurrentSection
= ItemList
[0]
398 if CurrentSection
!= ItemList
[0]:
399 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
)
400 if CurrentSection
.upper() not in self
.KeyList
:
401 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
402 CurrentSection
= TAB_UNKNOWN
406 if len(ItemList
) > 5:
407 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
409 if ItemList
[1] != '' and ItemList
[1].upper() not in ARCH_LIST_FULL
:
410 EdkLogger
.error("Parser", PARSER_ERROR
, "Invalid Arch definition '%s' found" % ItemList
[1], File
=Filename
, Line
=LineNo
, RaiseError
= EdkLogger
.IsRaiseError
)
411 ArchList
.append(ItemList
[1].upper())
412 ThirdList
.append(ItemList
[2])
417 # Not in any defined section
419 if CurrentSection
== TAB_UNKNOWN
:
420 ErrorMsg
= "%s is not in any defined section" % Line
421 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
, File
=Filename
, Line
=LineNo
, RaiseError
= EdkLogger
.IsRaiseError
)
426 SectionItemList
.append([Line
, LineNo
])
431 # Insert items data of last section
433 Model
= Section
[CurrentSection
.upper()]
434 InsertSectionItemsIntoDatabase(self
.TblInf
, self
.FileID
, Filename
, Model
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
, self
.RecordSet
)
437 # Replace all DEFINE macros with its actual values
439 ParseDefineMacro2(self
.TblInf
, self
.RecordSet
, GlobalData
.gGlobalDefines
)
441 ## Show detailed information of Module
443 # Print all members and their values of Module class
445 def ShowModule(self
):
447 for Arch
in M
.Header
.keys():
448 print '\nArch =', Arch
449 print 'Filename =', M
.Header
[Arch
].FileName
450 print 'FullPath =', M
.Header
[Arch
].FullPath
451 print 'BaseName =', M
.Header
[Arch
].Name
452 print 'Guid =', M
.Header
[Arch
].Guid
453 print 'Version =', M
.Header
[Arch
].Version
454 print 'InfVersion =', M
.Header
[Arch
].InfVersion
455 print 'EfiSpecificationVersion =', M
.Header
[Arch
].EfiSpecificationVersion
456 print 'EdkReleaseVersion =', M
.Header
[Arch
].EdkReleaseVersion
457 print 'ModuleType =', M
.Header
[Arch
].ModuleType
458 print 'BinaryModule =', M
.Header
[Arch
].BinaryModule
459 print 'ComponentType =', M
.Header
[Arch
].ComponentType
460 print 'MakefileName =', M
.Header
[Arch
].MakefileName
461 print 'BuildNumber =', M
.Header
[Arch
].BuildNumber
462 print 'BuildType =', M
.Header
[Arch
].BuildType
463 print 'FfsExt =', M
.Header
[Arch
].FfsExt
464 print 'FvExt =', M
.Header
[Arch
].FvExt
465 print 'SourceFv =', M
.Header
[Arch
].SourceFv
466 print 'PcdIsDriver =', M
.Header
[Arch
].PcdIsDriver
467 print 'TianoR8FlashMap_h =', M
.Header
[Arch
].TianoR8FlashMap_h
468 print 'Shadow =', M
.Header
[Arch
].Shadow
469 print 'LibraryClass =', M
.Header
[Arch
].LibraryClass
470 for Item
in M
.Header
[Arch
].LibraryClass
:
471 print Item
.LibraryClass
, DataType
.TAB_VALUE_SPLIT
.join(Item
.SupModuleList
)
472 print 'CustomMakefile =', M
.Header
[Arch
].CustomMakefile
473 print 'Define =', M
.Header
[Arch
].Define
474 print 'Specification =', M
.Header
[Arch
].Specification
475 for Item
in self
.Module
.ExternImages
:
476 print '\nEntry_Point = %s, UnloadImage = %s' % (Item
.ModuleEntryPoint
, Item
.ModuleUnloadImage
)
477 for Item
in self
.Module
.ExternLibraries
:
478 print 'Constructor = %s, Destructor = %s' % (Item
.Constructor
, Item
.Destructor
)
479 print '\nBuildOptions =', M
.BuildOptions
480 for Item
in M
.BuildOptions
:
481 print Item
.ToolChainFamily
, Item
.ToolChain
, Item
.Option
, Item
.SupArchList
482 print '\nIncludes =', M
.Includes
483 for Item
in M
.Includes
:
484 print Item
.FilePath
, Item
.SupArchList
485 print '\nLibraries =', M
.Libraries
486 for Item
in M
.Libraries
:
487 print Item
.Library
, Item
.SupArchList
488 print '\nLibraryClasses =', M
.LibraryClasses
489 for Item
in M
.LibraryClasses
:
490 print Item
.LibraryClass
, Item
.RecommendedInstance
, Item
.FeatureFlag
, Item
.SupModuleList
, Item
.SupArchList
, Item
.Define
491 print '\nPackageDependencies =', M
.PackageDependencies
492 for Item
in M
.PackageDependencies
:
493 print Item
.FilePath
, Item
.SupArchList
, Item
.FeatureFlag
494 print '\nNmake =', M
.Nmake
496 print Item
.Name
, Item
.Value
, Item
.SupArchList
497 print '\nPcds =', M
.PcdCodes
498 for Item
in M
.PcdCodes
:
499 print '\tCName=',Item
.CName
, 'TokenSpaceGuidCName=', Item
.TokenSpaceGuidCName
, 'DefaultValue=', Item
.DefaultValue
, 'ItemType=', Item
.ItemType
, Item
.SupArchList
500 print '\nSources =', M
.Sources
501 for Source
in M
.Sources
:
502 print Source
.SourceFile
, 'Fam=', Source
.ToolChainFamily
, 'Pcd=', Source
.FeatureFlag
, 'Tag=', Source
.TagName
, 'ToolCode=', Source
.ToolCode
, Source
.SupArchList
503 print '\nUserExtensions =', M
.UserExtensions
504 for UserExtension
in M
.UserExtensions
:
505 print UserExtension
.UserID
, UserExtension
.Identifier
,UserExtension
.Content
506 print '\nGuids =', M
.Guids
508 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
509 print '\nProtocols =', M
.Protocols
510 for Item
in M
.Protocols
:
511 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
512 print '\nPpis =', M
.Ppis
514 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
515 print '\nDepex =', M
.Depex
517 print Item
.Depex
, Item
.SupArchList
, Item
.Define
518 print '\nBinaries =', M
.Binaries
519 for Binary
in M
.Binaries
:
520 print 'Type=', Binary
.FileType
, 'Target=', Binary
.Target
, 'Name=', Binary
.BinaryFile
, 'FeatureFlag=', Binary
.FeatureFlag
, 'SupArchList=', Binary
.SupArchList
522 ## Convert [Defines] section content to ModuleHeaderClass
524 # Convert [Defines] section content to ModuleHeaderClass
526 # @param Defines The content under [Defines] section
527 # @param ModuleHeader An object of ModuleHeaderClass
528 # @param Arch The supported ARCH
530 def GenModuleHeader(self
, ContainerFile
):
531 EdkLogger
.debug(2, "Generate ModuleHeader ...")
532 File
= self
.Identification
.FileFullPath
534 # Update all defines item in database
536 RecordSet
= self
.RecordSet
[MODEL_META_DATA_HEADER
]
537 for Record
in RecordSet
:
538 ValueList
= GetSplitValueList(Record
[0], TAB_EQUAL_SPLIT
)
539 if len(ValueList
) != 2:
540 RaiseParserError(Record
[0], 'Defines', ContainerFile
, '<Key> = <Value>', Record
[2])
541 ID
, Value1
, Value2
, Arch
, LineNo
= Record
[3], ValueList
[0], ValueList
[1], Record
[1], Record
[2]
542 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
543 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Value1
), ConvertToSqlString2(Value2
), ID
)
544 self
.TblInf
.Exec(SqlCommand
)
546 for Arch
in DataType
.ARCH_LIST
:
547 ModuleHeader
= InfHeader()
548 ModuleHeader
.FileName
= self
.Identification
.FileName
549 ModuleHeader
.FullPath
= self
.Identification
.FileFullPath
550 DefineList
= QueryDefinesItem2(self
.TblInf
, Arch
, self
.FileID
)
552 NotProcessedDefineList
= []
554 if D
[0] in ModuleHeader
:
555 ModuleHeader
[D
[0]] = GetSplitValueList(D
[1])[0]
557 NotProcessedDefineList
.append(D
)
559 if ModuleHeader
.ComponentType
== "LIBRARY":
560 Lib
= LibraryClassClass()
561 Lib
.LibraryClass
= ModuleHeader
.Name
562 Lib
.SupModuleList
= DataType
.SUP_MODULE_LIST
563 ModuleHeader
.LibraryClass
.append(Lib
)
565 # we need to make some key defines resolved first
566 for D
in NotProcessedDefineList
:
567 if D
[0] == TAB_INF_DEFINES_LIBRARY_CLASS
:
568 List
= GetSplitValueList(D
[1], DataType
.TAB_VALUE_SPLIT
, 1)
569 Lib
= LibraryClassClass()
570 Lib
.LibraryClass
= CleanString(List
[0])
572 Lib
.SupModuleList
= DataType
.SUP_MODULE_LIST
574 Lib
.SupModuleList
= GetSplitValueList(CleanString(List
[1]), ' ')
575 ModuleHeader
.LibraryClass
.append(Lib
)
576 elif D
[0] == TAB_INF_DEFINES_CUSTOM_MAKEFILE
:
577 List
= D
[1].split(DataType
.TAB_VALUE_SPLIT
)
579 ModuleHeader
.CustomMakefile
[CleanString(List
[0])] = CleanString(List
[1])
581 RaiseParserError(D
[1], 'CUSTOM_MAKEFILE of Defines', File
, 'CUSTOM_MAKEFILE=<Family>|<Filename>', D
[2])
582 elif D
[0] == TAB_INF_DEFINES_ENTRY_POINT
:
583 Image
= ModuleExternImageClass()
584 Image
.ModuleEntryPoint
= CleanString(D
[1])
585 self
.Module
.ExternImages
.append(Image
)
586 elif D
[0] == TAB_INF_DEFINES_UNLOAD_IMAGE
:
587 Image
= ModuleExternImageClass()
588 Image
.ModuleUnloadImage
= CleanString(D
[1])
589 self
.Module
.ExternImages
.append(Image
)
590 elif D
[0] == TAB_INF_DEFINES_CONSTRUCTOR
:
591 LibraryClass
= ModuleExternLibraryClass()
592 LibraryClass
.Constructor
= CleanString(D
[1])
593 self
.Module
.ExternLibraries
.append(LibraryClass
)
594 elif D
[0] == TAB_INF_DEFINES_DESTRUCTOR
:
595 LibraryClass
= ModuleExternLibraryClass()
596 LibraryClass
.Destructor
= CleanString(D
[1])
597 self
.Module
.ExternLibraries
.append(LibraryClass
)
598 elif D
[0] == TAB_INF_DEFINES_DEFINE
:
599 List
= D
[1].split(DataType
.TAB_EQUAL_SPLIT
)
601 RaiseParserError(Item
, 'DEFINE of Defines', File
, 'DEFINE <Word> = <Word>', D
[2])
603 ModuleHeader
.Define
[CleanString(List
[0])] = CleanString(List
[1])
604 elif D
[0] == TAB_INF_DEFINES_SPEC
:
605 List
= D
[1].split(DataType
.TAB_EQUAL_SPLIT
)
607 RaiseParserError(Item
, 'SPEC of Defines', File
, 'SPEC <Word> = <Version>', D
[2])
609 ModuleHeader
.Specification
[CleanString(List
[0])] = CleanString(List
[1])
614 if ModuleHeader
.InfVersion
!= "":
616 VersionNumber
= ModuleHeader
.VersionNumber
617 VersionString
= ModuleHeader
.VersionString
618 if len(VersionNumber
) > 0 and len(VersionString
) == 0:
619 EdkLogger
.warn(2000, 'VERSION_NUMBER depricated; INF file %s should be modified to use VERSION_STRING instead.' % self
.Identification
.FileFullPath
)
620 ModuleHeader
.Version
= VersionNumber
621 if len(VersionString
) > 0:
622 if len(VersionNumber
) > 0:
623 EdkLogger
.warn(2001, 'INF file %s defines both VERSION_NUMBER and VERSION_STRING, using VERSION_STRING' % self
.Identification
.FileFullPath
)
624 ModuleHeader
.Version
= VersionString
627 ModuleHeader
.InfVersion
= "0x00010000"
628 if ModuleHeader
.ComponentType
in gComponentType2ModuleType
:
629 ModuleHeader
.ModuleType
= gComponentType2ModuleType
[ModuleHeader
.ComponentType
]
630 elif ModuleHeader
.ComponentType
!= '':
631 EdkLogger
.error("Parser", PARSER_ERROR
, "Unsupported R8 component type [%s]" % ModuleHeader
.ComponentType
, ExtraData
=File
, RaiseError
= EdkLogger
.IsRaiseError
)
633 self
.Module
.Header
[Arch
] = ModuleHeader
638 # Gen BuildOptions of Inf
639 # [<Family>:]<ToolFlag>=Flag
641 # @param ContainerFile: The Inf file full path
643 def GenBuildOptions(self
, ContainerFile
):
644 EdkLogger
.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS
)
647 # Get all BuildOptions
649 RecordSet
= self
.RecordSet
[MODEL_META_DATA_BUILD_OPTION
]
652 # Go through each arch
654 for Arch
in self
.SupArchList
:
655 for Record
in RecordSet
:
656 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
657 (Family
, ToolChain
, Flag
) = GetBuildOption(Record
[0], ContainerFile
, Record
[2])
658 MergeArches(BuildOptions
, (Family
, ToolChain
, Flag
), Arch
)
662 if self
.IsToDatabase
:
663 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
664 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Family
), ConvertToSqlString2(ToolChain
), ConvertToSqlString2(Flag
), Record
[3])
665 self
.TblInf
.Exec(SqlCommand
)
667 for Key
in BuildOptions
.keys():
668 BuildOption
= BuildOptionClass(Key
[0], Key
[1], Key
[2])
669 BuildOption
.SupArchList
= BuildOptions
[Key
]
670 self
.Module
.BuildOptions
.append(BuildOption
)
674 # Gen Includes of Inf
677 # @param ContainerFile: The Inf file full path
679 def GenIncludes(self
, ContainerFile
):
680 EdkLogger
.debug(2, "Generate %s ..." % TAB_INCLUDES
)
685 RecordSet
= self
.RecordSet
[MODEL_EFI_INCLUDE
]
688 # Go through each arch
690 for Arch
in self
.SupArchList
:
691 for Record
in RecordSet
:
692 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
693 MergeArches(Includes
, Record
[0], Arch
)
695 for Key
in Includes
.keys():
696 Include
= IncludeClass()
697 Include
.FilePath
= NormPath(Key
)
698 Include
.SupArchList
= Includes
[Key
]
699 self
.Module
.Includes
.append(Include
)
703 # Gen Libraries of Inf
706 # @param ContainerFile: The Inf file full path
708 def GenLibraries(self
, ContainerFile
):
709 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARIES
)
714 RecordSet
= self
.RecordSet
[MODEL_EFI_LIBRARY_INSTANCE
]
717 # Go through each arch
719 for Arch
in self
.SupArchList
:
720 for Record
in RecordSet
:
721 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
722 MergeArches(Libraries
, Record
[0], Arch
)
724 for Key
in Libraries
.keys():
725 Library
= ModuleLibraryClass()
726 # replace macro and remove file extension
727 Library
.Library
= Key
.rsplit('.', 1)[0]
728 Library
.SupArchList
= Libraries
[Key
]
729 self
.Module
.Libraries
.append(Library
)
733 # Get LibraryClass of Inf
734 # <LibraryClassKeyWord>|<LibraryInstance>
736 # @param ContainerFile: The Inf file full path
738 def GenLibraryClasses(self
, ContainerFile
):
739 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES
)
742 # Get all LibraryClasses
744 RecordSet
= self
.RecordSet
[MODEL_EFI_LIBRARY_CLASS
]
747 # Go through each arch
749 for Arch
in self
.SupArchList
:
750 for Record
in RecordSet
:
751 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
752 (LibClassName
, LibClassIns
, Pcd
, SupModelList
) = GetLibraryClassOfInf([Record
[0], Record
[4]], ContainerFile
, self
.WorkspaceDir
, Record
[2])
753 MergeArches(LibraryClasses
, (LibClassName
, LibClassIns
, Pcd
, SupModelList
), Arch
)
757 if self
.IsToDatabase
:
758 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
759 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(LibClassName
), ConvertToSqlString2(LibClassIns
), ConvertToSqlString2(SupModelList
), Record
[3])
760 self
.TblInf
.Exec(SqlCommand
)
762 for Key
in LibraryClasses
.keys():
763 KeyList
= Key
[0].split(DataType
.TAB_VALUE_SPLIT
)
764 LibraryClass
= LibraryClassClass()
765 LibraryClass
.LibraryClass
= Key
[0]
766 LibraryClass
.RecommendedInstance
= NormPath(Key
[1])
767 LibraryClass
.FeatureFlag
= Key
[2]
768 LibraryClass
.SupArchList
= LibraryClasses
[Key
]
769 LibraryClass
.SupModuleList
= GetSplitValueList(Key
[3])
770 self
.Module
.LibraryClasses
.append(LibraryClass
)
774 # Gen Packages of Inf
777 # @param ContainerFile: The Inf file full path
779 def GenPackages(self
, ContainerFile
):
780 EdkLogger
.debug(2, "Generate %s ..." % TAB_PACKAGES
)
785 RecordSet
= self
.RecordSet
[MODEL_META_DATA_PACKAGE
]
788 # Go through each arch
790 for Arch
in self
.SupArchList
:
791 for Record
in RecordSet
:
792 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
793 (Package
, Pcd
) = GetPackage(Record
[0], ContainerFile
, self
.WorkspaceDir
, Record
[2])
794 MergeArches(Packages
, (Package
, Pcd
), Arch
)
795 if self
.IsToDatabase
:
796 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
797 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Package
), ConvertToSqlString2(Pcd
), Record
[3])
798 self
.TblInf
.Exec(SqlCommand
)
801 for Key
in Packages
.keys():
802 Package
= ModulePackageDependencyClass()
803 Package
.FilePath
= NormPath(Key
[0])
804 Package
.SupArchList
= Packages
[Key
]
805 Package
.FeatureFlag
= Key
[1]
806 self
.Module
.PackageDependencies
.append(Package
)
813 # @param ContainerFile: The Inf file full path
815 def GenNmakes(self
, ContainerFile
):
816 EdkLogger
.debug(2, "Generate %s ..." % TAB_NMAKE
)
821 RecordSet
= self
.RecordSet
[MODEL_META_DATA_NMAKE
]
825 # Go through each arch
827 for Arch
in self
.SupArchList
:
828 for Record
in RecordSet
:
829 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
830 MergeArches(Nmakes
, Record
[0], Arch
)
832 for Key
in Nmakes
.keys():
833 List
= GetSplitValueList(Key
, DataType
.TAB_EQUAL_SPLIT
, MaxSplit
=1)
835 RaiseParserError(Key
, 'Nmake', ContainerFile
, '<MacroName> = <Value>')
837 Nmake
= ModuleNmakeClass()
839 Nmake
.Value
= List
[1]
840 Nmake
.SupArchList
= Nmakes
[Key
]
841 self
.Module
.Nmake
.append(Nmake
)
843 # convert R8 format to R9 format
844 if Nmake
.Name
== "IMAGE_ENTRY_POINT":
845 Image
= ModuleExternImageClass()
846 Image
.ModuleEntryPoint
= Nmake
.Value
847 self
.Module
.ExternImages
.append(Image
)
848 elif Nmake
.Name
== "DPX_SOURCE":
849 Source
= ModuleSourceFileClass(NormPath(Nmake
.Value
), "", "", "", "", Nmake
.SupArchList
)
850 self
.Module
.Sources
.append(Source
)
852 ToolList
= gNmakeFlagPattern
.findall(Nmake
.Name
)
853 if len(ToolList
) == 0 or len(ToolList
) != 1:
854 EdkLogger
.warn("\nParser", "Don't know how to do with MACRO: %s" % Nmake
.Name
,
855 ExtraData
=ContainerFile
)
857 if ToolList
[0] in gNmakeFlagName2ToolCode
:
858 Tool
= gNmakeFlagName2ToolCode
[ToolList
[0]]
861 BuildOption
= BuildOptionClass("MSFT", "*_*_*_%s_FLAGS" % Tool
, Nmake
.Value
)
862 BuildOption
.SupArchList
= Nmake
.SupArchList
863 self
.Module
.BuildOptions
.append(BuildOption
)
868 # <TokenSpaceGuidCName>.<PcdCName>[|<Value>]
870 # @param ContainerFile: The Dec file full path
872 def GenPcds(self
, ContainerFile
):
873 EdkLogger
.debug(2, "Generate %s ..." % TAB_PCDS
)
880 RecordSet1
= self
.RecordSet
[MODEL_PCD_FIXED_AT_BUILD
]
881 RecordSet2
= self
.RecordSet
[MODEL_PCD_PATCHABLE_IN_MODULE
]
882 RecordSet3
= self
.RecordSet
[MODEL_PCD_FEATURE_FLAG
]
883 RecordSet4
= self
.RecordSet
[MODEL_PCD_DYNAMIC_EX
]
884 RecordSet5
= self
.RecordSet
[MODEL_PCD_DYNAMIC
]
887 # Go through each arch
889 for Arch
in self
.SupArchList
:
890 for Record
in RecordSet1
:
891 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
892 if self
.Module
.Header
[Arch
].LibraryClass
!= {}:
894 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_FIXED_AT_BUILD
, ContainerFile
, Record
[2])
895 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
896 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
897 for Record
in RecordSet2
:
898 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
899 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_PATCHABLE_IN_MODULE
, ContainerFile
, Record
[2])
900 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
901 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
902 for Record
in RecordSet3
:
903 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
904 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_FEATURE_FLAG
, ContainerFile
, Record
[2])
905 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
906 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
907 for Record
in RecordSet4
:
908 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
909 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_DYNAMIC_EX
, ContainerFile
, Record
[2])
910 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
911 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
912 for Record
in RecordSet5
:
913 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
914 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], "", ContainerFile
, Record
[2])
915 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
916 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
920 if self
.IsToDatabase
:
921 for Key
in PcdToken
.keys():
922 SqlCommand
= """update %s set Value2 = '%s' where ID = %s""" % (self
.TblInf
.Table
, ".".join((PcdToken
[Key
][0], PcdToken
[Key
][1])), Key
)
923 self
.TblInf
.Exec(SqlCommand
)
925 for Key
in Pcds
.keys():
928 Pcd
.TokenSpaceGuidCName
= Key
[0]
929 Pcd
.DefaultValue
= Key
[2]
930 Pcd
.ItemType
= Key
[3]
931 Pcd
.SupArchList
= Pcds
[Key
]
932 self
.Module
.PcdCodes
.append(Pcd
)
937 # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]
939 # @param ContainerFile: The Dec file full path
941 def GenSources(self
, ContainerFile
):
942 EdkLogger
.debug(2, "Generate %s ..." % TAB_SOURCES
)
948 RecordSet
= self
.RecordSet
[MODEL_EFI_SOURCE_FILE
]
951 # Go through each arch
953 for Arch
in self
.SupArchList
:
954 for Record
in RecordSet
:
955 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
956 (Filename
, Family
, TagName
, ToolCode
, Pcd
) = GetSource(Record
[0], ContainerFile
, self
.Identification
.FileRelativePath
, Record
[2])
957 MergeArches(Sources
, (Filename
, Family
, TagName
, ToolCode
, Pcd
), Arch
)
958 if self
.IsToDatabase
:
959 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s', Value5 = '%s'
960 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Filename
), ConvertToSqlString2(Family
), ConvertToSqlString2(TagName
), ConvertToSqlString2(ToolCode
), ConvertToSqlString2(Pcd
), Record
[3])
961 self
.TblInf
.Exec(SqlCommand
)
963 for Key
in Sources
.keys():
964 Source
= ModuleSourceFileClass(Key
[0], Key
[2], Key
[3], Key
[1], Key
[4], Sources
[Key
])
965 self
.Module
.Sources
.append(Source
)
969 # Gen UserExtensions of Inf
971 def GenUserExtensions(self
, ContainerFile
):
975 # if self.UserExtensions != '':
976 # UserExtension = UserExtensionsClass()
977 # Lines = self.UserExtensions.splitlines()
978 # List = GetSplitValueList(Lines[0], DataType.TAB_SPLIT, 2)
980 # RaiseParserError(Lines[0], 'UserExtensions', File, "UserExtensions.UserId.'Identifier'")
982 # UserExtension.UserID = List[1]
983 # UserExtension.Identifier = List[2][0:-1].replace("'", '').replace('\"', '')
984 # for Line in Lines[1:]:
985 # UserExtension.Content = UserExtension.Content + CleanString(Line) + '\n'
986 # self.Module.UserExtensions.append(UserExtension)
993 # @param ContainerFile: The Inf file full path
995 def GenDepexes(self
, ContainerFile
):
996 EdkLogger
.debug(2, "Generate %s ..." % TAB_DEPEX
)
1001 RecordSet
= self
.RecordSet
[MODEL_EFI_DEPEX
]
1004 # Go through each arch
1006 for Arch
in self
.SupArchList
:
1008 for Record
in RecordSet
:
1009 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
1010 Line
= Line
+ Record
[0] + ' '
1012 MergeArches(Depex
, Line
, Arch
)
1014 for Key
in Depex
.keys():
1015 Dep
= ModuleDepexClass()
1017 Dep
.SupArchList
= Depex
[Key
]
1018 self
.Module
.Depex
.append(Dep
)
1023 # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]
1025 # @param ContainerFile: The Dec file full path
1027 def GenBinaries(self
, ContainerFile
):
1028 EdkLogger
.debug(2, "Generate %s ..." % TAB_BINARIES
)
1034 RecordSet
= self
.RecordSet
[MODEL_EFI_BINARY_FILE
]
1037 # Go through each arch
1039 for Arch
in self
.SupArchList
:
1040 for Record
in RecordSet
:
1041 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
1042 (FileType
, Filename
, Target
, Pcd
) = GetBinary(Record
[0], ContainerFile
, self
.Identification
.FileRelativePath
, Record
[2])
1043 MergeArches(Binaries
, (FileType
, Filename
, Target
, Pcd
), Arch
)
1044 if self
.IsToDatabase
:
1045 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s'
1046 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(FileType
), ConvertToSqlString2(Filename
), ConvertToSqlString2(Target
), ConvertToSqlString2(Pcd
), Record
[3])
1047 self
.TblInf
.Exec(SqlCommand
)
1049 for Key
in Binaries
.keys():
1050 Binary
= ModuleBinaryFileClass(NormPath(Key
[1]), Key
[0], Key
[2], Key
[3], Binaries
[Key
])
1051 self
.Module
.Binaries
.append(Binary
)
1056 # <CName>=<GuidValue>
1058 # @param ContainerFile: The Inf file full path
1060 def GenGuidProtocolPpis(self
, Type
, ContainerFile
):
1061 EdkLogger
.debug(2, "Generate %s ..." % Type
)
1066 RecordSet
= self
.RecordSet
[Section
[Type
.upper()]]
1069 # Go through each arch
1071 for Arch
in self
.SupArchList
:
1072 for Record
in RecordSet
:
1073 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
1074 (Name
, Value
) = GetGuidsProtocolsPpisOfInf(Record
[0], Type
, ContainerFile
, Record
[2])
1075 MergeArches(Lists
, (Name
, Value
), Arch
)
1076 if self
.IsToDatabase
:
1077 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
1078 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Name
), ConvertToSqlString2(Value
), Record
[3])
1079 self
.TblInf
.Exec(SqlCommand
)
1082 if Type
== TAB_GUIDS
:
1083 ListMember
= self
.Module
.Guids
1084 elif Type
== TAB_PROTOCOLS
:
1085 ListMember
= self
.Module
.Protocols
1086 elif Type
== TAB_PPIS
:
1087 ListMember
= self
.Module
.Ppis
1089 for Key
in Lists
.keys():
1090 ListClass
= GuidProtocolPpiCommonClass()
1091 ListClass
.CName
= Key
[0]
1092 ListClass
.SupArchList
= Lists
[Key
]
1093 ListClass
.FeatureFlag
= Key
[1]
1094 ListMember
.append(ListClass
)
1098 # This acts like the main() function for the script, unless it is 'import'ed into another
1101 if __name__
== '__main__':
1102 EdkLogger
.Initialize()
1103 EdkLogger
.SetLevel(EdkLogger
.DEBUG_0
)
1105 W
= os
.getenv('WORKSPACE')
1106 F
= os
.path
.join(W
, 'MdeModulePkg/Application/HelloWorld/HelloWorld.inf')
1108 Db
= Database
.Database('Inf.db')
1111 P
= Inf(os
.path
.normpath(F
), True, True, W
, Db
)