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.
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
: "UefiSpecificationVersion",
89 TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
: "UefiSpecificationVersion",
90 TAB_INF_DEFINES_EDK_RELEASE_VERSION
: "EdkReleaseVersion",
94 TAB_INF_DEFINES_INF_VERSION
: "InfVersion",
95 TAB_INF_DEFINES_BINARY_MODULE
: "BinaryModule",
96 TAB_INF_DEFINES_COMPONENT_TYPE
: "ComponentType",
97 TAB_INF_DEFINES_MAKEFILE_NAME
: "MakefileName",
98 TAB_INF_DEFINES_BUILD_NUMBER
: "BuildNumber",
99 TAB_INF_DEFINES_BUILD_TYPE
: "BuildType",
100 TAB_INF_DEFINES_FFS_EXT
: "FfsExt",
101 TAB_INF_DEFINES_FV_EXT
: "FvExt",
102 TAB_INF_DEFINES_SOURCE_FV
: "SourceFv",
103 TAB_INF_DEFINES_VERSION_NUMBER
: "VersionNumber",
104 TAB_INF_DEFINES_VERSION_STRING
: "VersionString",
105 TAB_INF_DEFINES_VERSION
: "Version",
106 TAB_INF_DEFINES_PCD_IS_DRIVER
: "PcdIsDriver",
107 TAB_INF_DEFINES_TIANO_EDK_FLASHMAP_H
: "TianoEdkFlashMap_h",
108 TAB_INF_DEFINES_SHADOW
: "Shadow",
109 # TAB_INF_DEFINES_LIBRARY_CLASS : "LibraryClass",
110 # TAB_INF_DEFINES_ENTRY_POINT : "ExternImages",
111 # TAB_INF_DEFINES_UNLOAD_IMAGE : "ExternImages",
112 # TAB_INF_DEFINES_CONSTRUCTOR : ,
113 # TAB_INF_DEFINES_DESTRUCTOR : ,
114 # TAB_INF_DEFINES_DEFINE : "Define",
115 # TAB_INF_DEFINES_SPEC : "Specification",
116 # TAB_INF_DEFINES_CUSTOM_MAKEFILE : "CustomMakefile",
117 # TAB_INF_DEFINES_MACRO :
121 ModuleHeaderClass
.__init
__(self
)
122 self
.VersionNumber
= ''
123 self
.VersionString
= ''
125 def __setitem__(self
, key
, value
):
126 self
.__dict
__[self
._Mapping
_[key
]] = value
127 def __getitem__(self
, key
):
128 return self
.__dict
__[self
._Mapping
_[key
]]
130 def __contains__(self
, key
):
131 return key
in self
._Mapping
_
135 # This class defined basic Inf object which is used by inheriting
137 # @param object: Inherited from object class
139 class InfObject(object):
145 # This class defined the structure used in Inf object
147 # @param InfObject: Inherited from InfObject class
148 # @param Ffilename: Input value for Ffilename of Inf file, default is None
149 # @param IsMergeAllArches: Input value for IsMergeAllArches
150 # True is to merge all arches
151 # Fales is not to merge all arches
153 # @param IsToModule: Input value for IsToModule
154 # True is to transfer to ModuleObject automatically
155 # False is not to transfer to ModuleObject automatically
157 # @param WorkspaceDir: Input value for current workspace directory, default is None
159 # @var Identification: To store value for Identification, it is a structure as Identification
160 # @var UserExtensions: To store value for UserExtensions
161 # @var Module: To store value for Module, it is a structure as ModuleClass
162 # @var WorkspaceDir: To store value for WorkspaceDir
163 # @var KeyList: To store value for KeyList, a list for all Keys used in Inf
165 class Inf(InfObject
):
166 def __init__(self
, Filename
= None, IsToDatabase
= False, IsToModule
= False, WorkspaceDir
= None, Database
= None, SupArchList
= DataType
.ARCH_LIST
):
167 self
.Identification
= Identification()
168 self
.Module
= ModuleClass()
169 self
.UserExtensions
= ''
170 self
.WorkspaceDir
= WorkspaceDir
171 self
.SupArchList
= SupArchList
172 self
.IsToDatabase
= IsToDatabase
174 self
.Cur
= Database
.Cur
175 self
.TblFile
= Database
.TblFile
176 self
.TblInf
= Database
.TblInf
178 #self.TblInf = TableInf(Database.Cur)
181 TAB_SOURCES
, TAB_BUILD_OPTIONS
, TAB_BINARIES
, TAB_INCLUDES
, TAB_GUIDS
,
182 TAB_PROTOCOLS
, TAB_PPIS
, TAB_LIBRARY_CLASSES
, TAB_PACKAGES
, TAB_LIBRARIES
,
183 TAB_INF_FIXED_PCD
, TAB_INF_PATCH_PCD
, TAB_INF_FEATURE_PCD
, TAB_INF_PCD
,
184 TAB_INF_PCD_EX
, TAB_DEPEX
, TAB_NMAKE
, TAB_INF_DEFINES
187 # Upper all KEYs to ignore case sensitive when parsing
189 self
.KeyList
= map(lambda c
: c
.upper(), self
.KeyList
)
195 for Key
in self
.KeyList
:
196 self
.RecordSet
[Section
[Key
]] = []
199 # Load Inf file if filename is not None
202 self
.LoadInfFile(Filename
)
205 # Transfer to Module Object if IsToModule is True
210 ## Transfer to Module Object
212 # Transfer all contents of an Inf file to a standard Module Object
214 def InfToModule(self
):
216 # Init global information for the file
218 ContainerFile
= self
.Identification
.FileFullPath
221 # Generate Package Header
223 self
.GenModuleHeader(ContainerFile
)
226 # Generate BuildOptions
228 self
.GenBuildOptions(ContainerFile
)
233 self
.GenIncludes(ContainerFile
)
238 self
.GenLibraries(ContainerFile
)
241 # Generate LibraryClasses
243 self
.GenLibraryClasses(ContainerFile
)
248 self
.GenPackages(ContainerFile
)
253 self
.GenNmakes(ContainerFile
)
258 self
.GenPcds(ContainerFile
)
263 self
.GenSources(ContainerFile
)
266 # Generate UserExtensions
268 self
.GenUserExtensions(ContainerFile
)
273 self
.GenGuidProtocolPpis(DataType
.TAB_GUIDS
, ContainerFile
)
278 self
.GenGuidProtocolPpis(DataType
.TAB_PROTOCOLS
, ContainerFile
)
283 self
.GenGuidProtocolPpis(DataType
.TAB_PPIS
, ContainerFile
)
288 self
.GenDepexes(ContainerFile
)
293 self
.GenBinaries(ContainerFile
)
295 ## Parse [Defines] section
297 # Parse [Defines] section into InfDefines object
299 # @param InfFile The path of the INF file
300 # @param Section The title of "Defines" section
301 # @param Lines The content of "Defines" section
303 def ParseDefines(self
, InfFile
, Section
, Lines
):
304 TokenList
= Section
.split(TAB_SPLIT
)
305 if len(TokenList
) == 3:
306 RaiseParserError(Section
, "Defines", InfFile
, "[xx.yy.%s] format (with platform) is not supported")
307 if len(TokenList
) == 2:
308 Arch
= TokenList
[1].upper()
310 Arch
= TAB_ARCH_COMMON
312 if Arch
not in self
.Defines
:
313 self
.Defines
[Arch
] = InfDefines()
314 GetSingleValueOfKeyFromLines(Lines
, self
.Defines
[Arch
].DefinesDictionary
,
315 TAB_COMMENT_SPLIT
, TAB_EQUAL_SPLIT
, False, None)
319 # Load the file if it exists
321 # @param Filename: Input value for filename of Inf file
323 def LoadInfFile(self
, Filename
):
325 # Insert a record for file
327 Filename
= NormPath(Filename
)
328 self
.Identification
.FileFullPath
= Filename
329 (self
.Identification
.FileRelativePath
, self
.Identification
.FileName
) = os
.path
.split(Filename
)
330 self
.FileID
= self
.TblFile
.InsertFile(Filename
, MODEL_FILE_INF
)
335 #self.TblInf.Table = "Inf%s" % self.FileID
336 #self.TblInf.Create()
341 IfDefList
, SectionItemList
, CurrentSection
, ArchList
, ThirdList
, IncludeFiles
= \
342 [], [], TAB_UNKNOWN
, [], [], []
348 IsFindBlockComment
= False
350 for Line
in open(Filename
, 'r'):
353 # Remove comment block
355 if Line
.find(TAB_COMMENT_EDK_START
) > -1:
356 ReservedLine
= GetSplitValueList(Line
, TAB_COMMENT_EDK_START
, 1)[0]
357 IsFindBlockComment
= True
358 if Line
.find(TAB_COMMENT_EDK_END
) > -1:
359 Line
= ReservedLine
+ GetSplitValueList(Line
, TAB_COMMENT_EDK_END
, 1)[1]
361 IsFindBlockComment
= False
362 if IsFindBlockComment
:
366 # Remove comments at tail and remove spaces again
368 Line
= CleanString(Line
)
373 # Find a new section tab
374 # First insert previous section items
375 # And then parse the content of the new section
377 if Line
.startswith(TAB_SECTION_START
) and Line
.endswith(TAB_SECTION_END
):
378 if Line
[1:3] == "--":
380 Model
= Section
[CurrentSection
.upper()]
382 # Insert items data of previous section
384 InsertSectionItemsIntoDatabase(self
.TblInf
, self
.FileID
, Filename
, Model
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
, self
.RecordSet
)
386 # Parse the new section
393 LineList
= GetSplitValueList(Line
[len(TAB_SECTION_START
):len(Line
) - len(TAB_SECTION_END
)], TAB_COMMA_SPLIT
)
394 for Item
in LineList
:
395 ItemList
= GetSplitValueList(Item
, TAB_SPLIT
)
396 if CurrentSection
== '':
397 CurrentSection
= ItemList
[0]
399 if CurrentSection
!= ItemList
[0]:
400 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
)
401 if CurrentSection
.upper() not in self
.KeyList
:
402 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
403 CurrentSection
= TAB_UNKNOWN
407 if len(ItemList
) > 5:
408 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
410 if ItemList
[1] != '' and ItemList
[1].upper() not in ARCH_LIST_FULL
:
411 EdkLogger
.error("Parser", PARSER_ERROR
, "Invalid Arch definition '%s' found" % ItemList
[1], File
=Filename
, Line
=LineNo
, RaiseError
= EdkLogger
.IsRaiseError
)
412 ArchList
.append(ItemList
[1].upper())
413 ThirdList
.append(ItemList
[2])
418 # Not in any defined section
420 if CurrentSection
== TAB_UNKNOWN
:
421 ErrorMsg
= "%s is not in any defined section" % Line
422 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
, File
=Filename
, Line
=LineNo
, RaiseError
= EdkLogger
.IsRaiseError
)
427 SectionItemList
.append([Line
, LineNo
])
432 # Insert items data of last section
434 Model
= Section
[CurrentSection
.upper()]
435 InsertSectionItemsIntoDatabase(self
.TblInf
, self
.FileID
, Filename
, Model
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
, self
.RecordSet
)
438 # Replace all DEFINE macros with its actual values
440 ParseDefineMacro2(self
.TblInf
, self
.RecordSet
, GlobalData
.gGlobalDefines
)
442 ## Show detailed information of Module
444 # Print all members and their values of Module class
446 def ShowModule(self
):
448 for Arch
in M
.Header
.keys():
449 print '\nArch =', Arch
450 print 'Filename =', M
.Header
[Arch
].FileName
451 print 'FullPath =', M
.Header
[Arch
].FullPath
452 print 'BaseName =', M
.Header
[Arch
].Name
453 print 'Guid =', M
.Header
[Arch
].Guid
454 print 'Version =', M
.Header
[Arch
].Version
455 print 'InfVersion =', M
.Header
[Arch
].InfVersion
456 print 'UefiSpecificationVersion =', M
.Header
[Arch
].UefiSpecificationVersion
457 print 'EdkReleaseVersion =', M
.Header
[Arch
].EdkReleaseVersion
458 print 'ModuleType =', M
.Header
[Arch
].ModuleType
459 print 'BinaryModule =', M
.Header
[Arch
].BinaryModule
460 print 'ComponentType =', M
.Header
[Arch
].ComponentType
461 print 'MakefileName =', M
.Header
[Arch
].MakefileName
462 print 'BuildNumber =', M
.Header
[Arch
].BuildNumber
463 print 'BuildType =', M
.Header
[Arch
].BuildType
464 print 'FfsExt =', M
.Header
[Arch
].FfsExt
465 print 'FvExt =', M
.Header
[Arch
].FvExt
466 print 'SourceFv =', M
.Header
[Arch
].SourceFv
467 print 'PcdIsDriver =', M
.Header
[Arch
].PcdIsDriver
468 print 'TianoEdkFlashMap_h =', M
.Header
[Arch
].TianoEdkFlashMap_h
469 print 'Shadow =', M
.Header
[Arch
].Shadow
470 print 'LibraryClass =', M
.Header
[Arch
].LibraryClass
471 for Item
in M
.Header
[Arch
].LibraryClass
:
472 print Item
.LibraryClass
, DataType
.TAB_VALUE_SPLIT
.join(Item
.SupModuleList
)
473 print 'CustomMakefile =', M
.Header
[Arch
].CustomMakefile
474 print 'Define =', M
.Header
[Arch
].Define
475 print 'Specification =', M
.Header
[Arch
].Specification
476 for Item
in self
.Module
.ExternImages
:
477 print '\nEntry_Point = %s, UnloadImage = %s' % (Item
.ModuleEntryPoint
, Item
.ModuleUnloadImage
)
478 for Item
in self
.Module
.ExternLibraries
:
479 print 'Constructor = %s, Destructor = %s' % (Item
.Constructor
, Item
.Destructor
)
480 print '\nBuildOptions =', M
.BuildOptions
481 for Item
in M
.BuildOptions
:
482 print Item
.ToolChainFamily
, Item
.ToolChain
, Item
.Option
, Item
.SupArchList
483 print '\nIncludes =', M
.Includes
484 for Item
in M
.Includes
:
485 print Item
.FilePath
, Item
.SupArchList
486 print '\nLibraries =', M
.Libraries
487 for Item
in M
.Libraries
:
488 print Item
.Library
, Item
.SupArchList
489 print '\nLibraryClasses =', M
.LibraryClasses
490 for Item
in M
.LibraryClasses
:
491 print Item
.LibraryClass
, Item
.RecommendedInstance
, Item
.FeatureFlag
, Item
.SupModuleList
, Item
.SupArchList
, Item
.Define
492 print '\nPackageDependencies =', M
.PackageDependencies
493 for Item
in M
.PackageDependencies
:
494 print Item
.FilePath
, Item
.SupArchList
, Item
.FeatureFlag
495 print '\nNmake =', M
.Nmake
497 print Item
.Name
, Item
.Value
, Item
.SupArchList
498 print '\nPcds =', M
.PcdCodes
499 for Item
in M
.PcdCodes
:
500 print '\tCName=',Item
.CName
, 'TokenSpaceGuidCName=', Item
.TokenSpaceGuidCName
, 'DefaultValue=', Item
.DefaultValue
, 'ItemType=', Item
.ItemType
, Item
.SupArchList
501 print '\nSources =', M
.Sources
502 for Source
in M
.Sources
:
503 print Source
.SourceFile
, 'Fam=', Source
.ToolChainFamily
, 'Pcd=', Source
.FeatureFlag
, 'Tag=', Source
.TagName
, 'ToolCode=', Source
.ToolCode
, Source
.SupArchList
504 print '\nUserExtensions =', M
.UserExtensions
505 for UserExtension
in M
.UserExtensions
:
506 print UserExtension
.UserID
, UserExtension
.Identifier
,UserExtension
.Content
507 print '\nGuids =', M
.Guids
509 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
510 print '\nProtocols =', M
.Protocols
511 for Item
in M
.Protocols
:
512 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
513 print '\nPpis =', M
.Ppis
515 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
516 print '\nDepex =', M
.Depex
518 print Item
.Depex
, Item
.SupArchList
, Item
.Define
519 print '\nBinaries =', M
.Binaries
520 for Binary
in M
.Binaries
:
521 print 'Type=', Binary
.FileType
, 'Target=', Binary
.Target
, 'Name=', Binary
.BinaryFile
, 'FeatureFlag=', Binary
.FeatureFlag
, 'SupArchList=', Binary
.SupArchList
523 ## Convert [Defines] section content to ModuleHeaderClass
525 # Convert [Defines] section content to ModuleHeaderClass
527 # @param Defines The content under [Defines] section
528 # @param ModuleHeader An object of ModuleHeaderClass
529 # @param Arch The supported ARCH
531 def GenModuleHeader(self
, ContainerFile
):
532 EdkLogger
.debug(2, "Generate ModuleHeader ...")
533 File
= self
.Identification
.FileFullPath
535 # Update all defines item in database
537 RecordSet
= self
.RecordSet
[MODEL_META_DATA_HEADER
]
538 for Record
in RecordSet
:
539 ValueList
= GetSplitValueList(Record
[0], TAB_EQUAL_SPLIT
)
540 if len(ValueList
) != 2:
541 RaiseParserError(Record
[0], 'Defines', ContainerFile
, '<Key> = <Value>', Record
[2])
542 ID
, Value1
, Value2
, Arch
, LineNo
= Record
[3], ValueList
[0], ValueList
[1], Record
[1], Record
[2]
543 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
544 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Value1
), ConvertToSqlString2(Value2
), ID
)
545 self
.TblInf
.Exec(SqlCommand
)
547 for Arch
in DataType
.ARCH_LIST
:
548 ModuleHeader
= InfHeader()
549 ModuleHeader
.FileName
= self
.Identification
.FileName
550 ModuleHeader
.FullPath
= self
.Identification
.FileFullPath
551 DefineList
= QueryDefinesItem2(self
.TblInf
, Arch
, self
.FileID
)
553 NotProcessedDefineList
= []
555 if D
[0] in ModuleHeader
:
556 ModuleHeader
[D
[0]] = GetSplitValueList(D
[1])[0]
558 NotProcessedDefineList
.append(D
)
560 if ModuleHeader
.ComponentType
== "LIBRARY":
561 Lib
= LibraryClassClass()
562 Lib
.LibraryClass
= ModuleHeader
.Name
563 Lib
.SupModuleList
= DataType
.SUP_MODULE_LIST
564 ModuleHeader
.LibraryClass
.append(Lib
)
566 # we need to make some key defines resolved first
567 for D
in NotProcessedDefineList
:
568 if D
[0] == TAB_INF_DEFINES_LIBRARY_CLASS
:
569 List
= GetSplitValueList(D
[1], DataType
.TAB_VALUE_SPLIT
, 1)
570 Lib
= LibraryClassClass()
571 Lib
.LibraryClass
= CleanString(List
[0])
573 Lib
.SupModuleList
= DataType
.SUP_MODULE_LIST
575 Lib
.SupModuleList
= GetSplitValueList(CleanString(List
[1]), ' ')
576 ModuleHeader
.LibraryClass
.append(Lib
)
577 elif D
[0] == TAB_INF_DEFINES_CUSTOM_MAKEFILE
:
578 List
= D
[1].split(DataType
.TAB_VALUE_SPLIT
)
580 ModuleHeader
.CustomMakefile
[CleanString(List
[0])] = CleanString(List
[1])
582 RaiseParserError(D
[1], 'CUSTOM_MAKEFILE of Defines', File
, 'CUSTOM_MAKEFILE=<Family>|<Filename>', D
[2])
583 elif D
[0] == TAB_INF_DEFINES_ENTRY_POINT
:
584 Image
= ModuleExternImageClass()
585 Image
.ModuleEntryPoint
= CleanString(D
[1])
586 self
.Module
.ExternImages
.append(Image
)
587 elif D
[0] == TAB_INF_DEFINES_UNLOAD_IMAGE
:
588 Image
= ModuleExternImageClass()
589 Image
.ModuleUnloadImage
= CleanString(D
[1])
590 self
.Module
.ExternImages
.append(Image
)
591 elif D
[0] == TAB_INF_DEFINES_CONSTRUCTOR
:
592 LibraryClass
= ModuleExternLibraryClass()
593 LibraryClass
.Constructor
= CleanString(D
[1])
594 self
.Module
.ExternLibraries
.append(LibraryClass
)
595 elif D
[0] == TAB_INF_DEFINES_DESTRUCTOR
:
596 LibraryClass
= ModuleExternLibraryClass()
597 LibraryClass
.Destructor
= CleanString(D
[1])
598 self
.Module
.ExternLibraries
.append(LibraryClass
)
599 elif D
[0] == TAB_INF_DEFINES_DEFINE
:
600 List
= D
[1].split(DataType
.TAB_EQUAL_SPLIT
)
602 RaiseParserError(Item
, 'DEFINE of Defines', File
, 'DEFINE <Word> = <Word>', D
[2])
604 ModuleHeader
.Define
[CleanString(List
[0])] = CleanString(List
[1])
605 elif D
[0] == TAB_INF_DEFINES_SPEC
:
606 List
= D
[1].split(DataType
.TAB_EQUAL_SPLIT
)
608 RaiseParserError(Item
, 'SPEC of Defines', File
, 'SPEC <Word> = <Version>', D
[2])
610 ModuleHeader
.Specification
[CleanString(List
[0])] = CleanString(List
[1])
615 if ModuleHeader
.InfVersion
!= "":
617 VersionNumber
= ModuleHeader
.VersionNumber
618 VersionString
= ModuleHeader
.VersionString
619 if len(VersionNumber
) > 0 and len(VersionString
) == 0:
620 EdkLogger
.warn(2000, 'VERSION_NUMBER depricated; INF file %s should be modified to use VERSION_STRING instead.' % self
.Identification
.FileFullPath
)
621 ModuleHeader
.Version
= VersionNumber
622 if len(VersionString
) > 0:
623 if len(VersionNumber
) > 0:
624 EdkLogger
.warn(2001, 'INF file %s defines both VERSION_NUMBER and VERSION_STRING, using VERSION_STRING' % self
.Identification
.FileFullPath
)
625 ModuleHeader
.Version
= VersionString
628 ModuleHeader
.InfVersion
= "0x00010000"
629 if ModuleHeader
.ComponentType
in gComponentType2ModuleType
:
630 ModuleHeader
.ModuleType
= gComponentType2ModuleType
[ModuleHeader
.ComponentType
]
631 elif ModuleHeader
.ComponentType
!= '':
632 EdkLogger
.error("Parser", PARSER_ERROR
, "Unsupported Edk component type [%s]" % ModuleHeader
.ComponentType
, ExtraData
=File
, RaiseError
= EdkLogger
.IsRaiseError
)
634 self
.Module
.Header
[Arch
] = ModuleHeader
639 # Gen BuildOptions of Inf
640 # [<Family>:]<ToolFlag>=Flag
642 # @param ContainerFile: The Inf file full path
644 def GenBuildOptions(self
, ContainerFile
):
645 EdkLogger
.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS
)
648 # Get all BuildOptions
650 RecordSet
= self
.RecordSet
[MODEL_META_DATA_BUILD_OPTION
]
653 # Go through each arch
655 for Arch
in self
.SupArchList
:
656 for Record
in RecordSet
:
657 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
658 (Family
, ToolChain
, Flag
) = GetBuildOption(Record
[0], ContainerFile
, Record
[2])
659 MergeArches(BuildOptions
, (Family
, ToolChain
, Flag
), Arch
)
663 if self
.IsToDatabase
:
664 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
665 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Family
), ConvertToSqlString2(ToolChain
), ConvertToSqlString2(Flag
), Record
[3])
666 self
.TblInf
.Exec(SqlCommand
)
668 for Key
in BuildOptions
.keys():
669 BuildOption
= BuildOptionClass(Key
[0], Key
[1], Key
[2])
670 BuildOption
.SupArchList
= BuildOptions
[Key
]
671 self
.Module
.BuildOptions
.append(BuildOption
)
675 # Gen Includes of Inf
678 # @param ContainerFile: The Inf file full path
680 def GenIncludes(self
, ContainerFile
):
681 EdkLogger
.debug(2, "Generate %s ..." % TAB_INCLUDES
)
686 RecordSet
= self
.RecordSet
[MODEL_EFI_INCLUDE
]
689 # Go through each arch
691 for Arch
in self
.SupArchList
:
692 for Record
in RecordSet
:
693 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
694 MergeArches(Includes
, Record
[0], Arch
)
696 for Key
in Includes
.keys():
697 Include
= IncludeClass()
698 Include
.FilePath
= NormPath(Key
)
699 Include
.SupArchList
= Includes
[Key
]
700 self
.Module
.Includes
.append(Include
)
704 # Gen Libraries of Inf
707 # @param ContainerFile: The Inf file full path
709 def GenLibraries(self
, ContainerFile
):
710 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARIES
)
715 RecordSet
= self
.RecordSet
[MODEL_EFI_LIBRARY_INSTANCE
]
718 # Go through each arch
720 for Arch
in self
.SupArchList
:
721 for Record
in RecordSet
:
722 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
723 MergeArches(Libraries
, Record
[0], Arch
)
725 for Key
in Libraries
.keys():
726 Library
= ModuleLibraryClass()
727 # replace macro and remove file extension
728 Library
.Library
= Key
.rsplit('.', 1)[0]
729 Library
.SupArchList
= Libraries
[Key
]
730 self
.Module
.Libraries
.append(Library
)
734 # Get LibraryClass of Inf
735 # <LibraryClassKeyWord>|<LibraryInstance>
737 # @param ContainerFile: The Inf file full path
739 def GenLibraryClasses(self
, ContainerFile
):
740 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES
)
743 # Get all LibraryClasses
745 RecordSet
= self
.RecordSet
[MODEL_EFI_LIBRARY_CLASS
]
748 # Go through each arch
750 for Arch
in self
.SupArchList
:
751 for Record
in RecordSet
:
752 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
753 (LibClassName
, LibClassIns
, Pcd
, SupModelList
) = GetLibraryClassOfInf([Record
[0], Record
[4]], ContainerFile
, self
.WorkspaceDir
, Record
[2])
754 MergeArches(LibraryClasses
, (LibClassName
, LibClassIns
, Pcd
, SupModelList
), Arch
)
758 if self
.IsToDatabase
:
759 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
760 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(LibClassName
), ConvertToSqlString2(LibClassIns
), ConvertToSqlString2(SupModelList
), Record
[3])
761 self
.TblInf
.Exec(SqlCommand
)
763 for Key
in LibraryClasses
.keys():
764 KeyList
= Key
[0].split(DataType
.TAB_VALUE_SPLIT
)
765 LibraryClass
= LibraryClassClass()
766 LibraryClass
.LibraryClass
= Key
[0]
767 LibraryClass
.RecommendedInstance
= NormPath(Key
[1])
768 LibraryClass
.FeatureFlag
= Key
[2]
769 LibraryClass
.SupArchList
= LibraryClasses
[Key
]
770 LibraryClass
.SupModuleList
= GetSplitValueList(Key
[3])
771 self
.Module
.LibraryClasses
.append(LibraryClass
)
775 # Gen Packages of Inf
778 # @param ContainerFile: The Inf file full path
780 def GenPackages(self
, ContainerFile
):
781 EdkLogger
.debug(2, "Generate %s ..." % TAB_PACKAGES
)
786 RecordSet
= self
.RecordSet
[MODEL_META_DATA_PACKAGE
]
789 # Go through each arch
791 for Arch
in self
.SupArchList
:
792 for Record
in RecordSet
:
793 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
794 (Package
, Pcd
) = GetPackage(Record
[0], ContainerFile
, self
.WorkspaceDir
, Record
[2])
795 MergeArches(Packages
, (Package
, Pcd
), Arch
)
796 if self
.IsToDatabase
:
797 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
798 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Package
), ConvertToSqlString2(Pcd
), Record
[3])
799 self
.TblInf
.Exec(SqlCommand
)
802 for Key
in Packages
.keys():
803 Package
= ModulePackageDependencyClass()
804 Package
.FilePath
= NormPath(Key
[0])
805 Package
.SupArchList
= Packages
[Key
]
806 Package
.FeatureFlag
= Key
[1]
807 self
.Module
.PackageDependencies
.append(Package
)
814 # @param ContainerFile: The Inf file full path
816 def GenNmakes(self
, ContainerFile
):
817 EdkLogger
.debug(2, "Generate %s ..." % TAB_NMAKE
)
822 RecordSet
= self
.RecordSet
[MODEL_META_DATA_NMAKE
]
826 # Go through each arch
828 for Arch
in self
.SupArchList
:
829 for Record
in RecordSet
:
830 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
831 MergeArches(Nmakes
, Record
[0], Arch
)
833 for Key
in Nmakes
.keys():
834 List
= GetSplitValueList(Key
, DataType
.TAB_EQUAL_SPLIT
, MaxSplit
=1)
836 RaiseParserError(Key
, 'Nmake', ContainerFile
, '<MacroName> = <Value>')
838 Nmake
= ModuleNmakeClass()
840 Nmake
.Value
= List
[1]
841 Nmake
.SupArchList
= Nmakes
[Key
]
842 self
.Module
.Nmake
.append(Nmake
)
844 # convert Edk format to EdkII format
845 if Nmake
.Name
== "IMAGE_ENTRY_POINT":
846 Image
= ModuleExternImageClass()
847 Image
.ModuleEntryPoint
= Nmake
.Value
848 self
.Module
.ExternImages
.append(Image
)
849 elif Nmake
.Name
== "DPX_SOURCE":
850 Source
= ModuleSourceFileClass(NormPath(Nmake
.Value
), "", "", "", "", Nmake
.SupArchList
)
851 self
.Module
.Sources
.append(Source
)
853 ToolList
= gNmakeFlagPattern
.findall(Nmake
.Name
)
854 if len(ToolList
) == 0 or len(ToolList
) != 1:
855 EdkLogger
.warn("\nParser", "Don't know how to do with MACRO: %s" % Nmake
.Name
,
856 ExtraData
=ContainerFile
)
858 if ToolList
[0] in gNmakeFlagName2ToolCode
:
859 Tool
= gNmakeFlagName2ToolCode
[ToolList
[0]]
862 BuildOption
= BuildOptionClass("MSFT", "*_*_*_%s_FLAGS" % Tool
, Nmake
.Value
)
863 BuildOption
.SupArchList
= Nmake
.SupArchList
864 self
.Module
.BuildOptions
.append(BuildOption
)
869 # <TokenSpaceGuidCName>.<PcdCName>[|<Value>]
871 # @param ContainerFile: The Dec file full path
873 def GenPcds(self
, ContainerFile
):
874 EdkLogger
.debug(2, "Generate %s ..." % TAB_PCDS
)
881 RecordSet1
= self
.RecordSet
[MODEL_PCD_FIXED_AT_BUILD
]
882 RecordSet2
= self
.RecordSet
[MODEL_PCD_PATCHABLE_IN_MODULE
]
883 RecordSet3
= self
.RecordSet
[MODEL_PCD_FEATURE_FLAG
]
884 RecordSet4
= self
.RecordSet
[MODEL_PCD_DYNAMIC_EX
]
885 RecordSet5
= self
.RecordSet
[MODEL_PCD_DYNAMIC
]
888 # Go through each arch
890 for Arch
in self
.SupArchList
:
891 for Record
in RecordSet1
:
892 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
893 if self
.Module
.Header
[Arch
].LibraryClass
!= {}:
895 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_FIXED_AT_BUILD
, ContainerFile
, Record
[2])
896 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
897 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
898 for Record
in RecordSet2
:
899 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
900 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_PATCHABLE_IN_MODULE
, ContainerFile
, Record
[2])
901 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
902 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
903 for Record
in RecordSet3
:
904 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
905 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_FEATURE_FLAG
, ContainerFile
, Record
[2])
906 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
907 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
908 for Record
in RecordSet4
:
909 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
910 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_DYNAMIC_EX
, ContainerFile
, Record
[2])
911 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
912 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
913 for Record
in RecordSet5
:
914 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
915 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], "", ContainerFile
, Record
[2])
916 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
917 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
921 if self
.IsToDatabase
:
922 for Key
in PcdToken
.keys():
923 SqlCommand
= """update %s set Value2 = '%s' where ID = %s""" % (self
.TblInf
.Table
, ".".join((PcdToken
[Key
][0], PcdToken
[Key
][1])), Key
)
924 self
.TblInf
.Exec(SqlCommand
)
926 for Key
in Pcds
.keys():
929 Pcd
.TokenSpaceGuidCName
= Key
[0]
930 Pcd
.DefaultValue
= Key
[2]
931 Pcd
.ItemType
= Key
[3]
932 Pcd
.SupArchList
= Pcds
[Key
]
933 self
.Module
.PcdCodes
.append(Pcd
)
938 # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]
940 # @param ContainerFile: The Dec file full path
942 def GenSources(self
, ContainerFile
):
943 EdkLogger
.debug(2, "Generate %s ..." % TAB_SOURCES
)
949 RecordSet
= self
.RecordSet
[MODEL_EFI_SOURCE_FILE
]
952 # Go through each arch
954 for Arch
in self
.SupArchList
:
955 for Record
in RecordSet
:
956 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
957 (Filename
, Family
, TagName
, ToolCode
, Pcd
) = GetSource(Record
[0], ContainerFile
, self
.Identification
.FileRelativePath
, Record
[2])
958 MergeArches(Sources
, (Filename
, Family
, TagName
, ToolCode
, Pcd
), Arch
)
959 if self
.IsToDatabase
:
960 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s', Value5 = '%s'
961 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Filename
), ConvertToSqlString2(Family
), ConvertToSqlString2(TagName
), ConvertToSqlString2(ToolCode
), ConvertToSqlString2(Pcd
), Record
[3])
962 self
.TblInf
.Exec(SqlCommand
)
964 for Key
in Sources
.keys():
965 Source
= ModuleSourceFileClass(Key
[0], Key
[2], Key
[3], Key
[1], Key
[4], Sources
[Key
])
966 self
.Module
.Sources
.append(Source
)
970 # Gen UserExtensions of Inf
972 def GenUserExtensions(self
, ContainerFile
):
976 # if self.UserExtensions != '':
977 # UserExtension = UserExtensionsClass()
978 # Lines = self.UserExtensions.splitlines()
979 # List = GetSplitValueList(Lines[0], DataType.TAB_SPLIT, 2)
981 # RaiseParserError(Lines[0], 'UserExtensions', File, "UserExtensions.UserId.'Identifier'")
983 # UserExtension.UserID = List[1]
984 # UserExtension.Identifier = List[2][0:-1].replace("'", '').replace('\"', '')
985 # for Line in Lines[1:]:
986 # UserExtension.Content = UserExtension.Content + CleanString(Line) + '\n'
987 # self.Module.UserExtensions.append(UserExtension)
994 # @param ContainerFile: The Inf file full path
996 def GenDepexes(self
, ContainerFile
):
997 EdkLogger
.debug(2, "Generate %s ..." % TAB_DEPEX
)
1002 RecordSet
= self
.RecordSet
[MODEL_EFI_DEPEX
]
1005 # Go through each arch
1007 for Arch
in self
.SupArchList
:
1009 for Record
in RecordSet
:
1010 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
1011 Line
= Line
+ Record
[0] + ' '
1013 MergeArches(Depex
, Line
, Arch
)
1015 for Key
in Depex
.keys():
1016 Dep
= ModuleDepexClass()
1018 Dep
.SupArchList
= Depex
[Key
]
1019 self
.Module
.Depex
.append(Dep
)
1024 # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]
1026 # @param ContainerFile: The Dec file full path
1028 def GenBinaries(self
, ContainerFile
):
1029 EdkLogger
.debug(2, "Generate %s ..." % TAB_BINARIES
)
1035 RecordSet
= self
.RecordSet
[MODEL_EFI_BINARY_FILE
]
1038 # Go through each arch
1040 for Arch
in self
.SupArchList
:
1041 for Record
in RecordSet
:
1042 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
1043 (FileType
, Filename
, Target
, Pcd
) = GetBinary(Record
[0], ContainerFile
, self
.Identification
.FileRelativePath
, Record
[2])
1044 MergeArches(Binaries
, (FileType
, Filename
, Target
, Pcd
), Arch
)
1045 if self
.IsToDatabase
:
1046 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s'
1047 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(FileType
), ConvertToSqlString2(Filename
), ConvertToSqlString2(Target
), ConvertToSqlString2(Pcd
), Record
[3])
1048 self
.TblInf
.Exec(SqlCommand
)
1050 for Key
in Binaries
.keys():
1051 Binary
= ModuleBinaryFileClass(NormPath(Key
[1]), Key
[0], Key
[2], Key
[3], Binaries
[Key
])
1052 self
.Module
.Binaries
.append(Binary
)
1057 # <CName>=<GuidValue>
1059 # @param ContainerFile: The Inf file full path
1061 def GenGuidProtocolPpis(self
, Type
, ContainerFile
):
1062 EdkLogger
.debug(2, "Generate %s ..." % Type
)
1067 RecordSet
= self
.RecordSet
[Section
[Type
.upper()]]
1070 # Go through each arch
1072 for Arch
in self
.SupArchList
:
1073 for Record
in RecordSet
:
1074 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
1075 (Name
, Value
) = GetGuidsProtocolsPpisOfInf(Record
[0], Type
, ContainerFile
, Record
[2])
1076 MergeArches(Lists
, (Name
, Value
), Arch
)
1077 if self
.IsToDatabase
:
1078 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
1079 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Name
), ConvertToSqlString2(Value
), Record
[3])
1080 self
.TblInf
.Exec(SqlCommand
)
1083 if Type
== TAB_GUIDS
:
1084 ListMember
= self
.Module
.Guids
1085 elif Type
== TAB_PROTOCOLS
:
1086 ListMember
= self
.Module
.Protocols
1087 elif Type
== TAB_PPIS
:
1088 ListMember
= self
.Module
.Ppis
1090 for Key
in Lists
.keys():
1091 ListClass
= GuidProtocolPpiCommonClass()
1092 ListClass
.CName
= Key
[0]
1093 ListClass
.SupArchList
= Lists
[Key
]
1094 ListClass
.FeatureFlag
= Key
[1]
1095 ListMember
.append(ListClass
)
1099 # This acts like the main() function for the script, unless it is 'import'ed into another
1102 if __name__
== '__main__':
1103 EdkLogger
.Initialize()
1104 EdkLogger
.SetLevel(EdkLogger
.DEBUG_0
)
1106 W
= os
.getenv('WORKSPACE')
1107 F
= os
.path
.join(W
, 'MdeModulePkg/Application/HelloWorld/HelloWorld.inf')
1109 Db
= Database
.Database('Inf.db')
1112 P
= Inf(os
.path
.normpath(F
), True, True, W
, Db
)