2 # This file is used to define each component of INF file
4 # Copyright (c) 2007 - 2014, 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.
17 import Common
.LongFilePathOs
as os
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
32 from Common
.LongFilePathSupport
import OpenLongFilePath
as open
37 Section
= {TAB_UNKNOWN
.upper() : MODEL_UNKNOWN
,
38 TAB_INF_DEFINES
.upper() : MODEL_META_DATA_HEADER
,
39 TAB_BUILD_OPTIONS
.upper() : MODEL_META_DATA_BUILD_OPTION
,
40 TAB_INCLUDES
.upper() : MODEL_EFI_INCLUDE
,
41 TAB_LIBRARIES
.upper() : MODEL_EFI_LIBRARY_INSTANCE
,
42 TAB_LIBRARY_CLASSES
.upper() : MODEL_EFI_LIBRARY_CLASS
,
43 TAB_PACKAGES
.upper() : MODEL_META_DATA_PACKAGE
,
44 TAB_NMAKE
.upper() : MODEL_META_DATA_NMAKE
,
45 TAB_INF_FIXED_PCD
.upper() : MODEL_PCD_FIXED_AT_BUILD
,
46 TAB_INF_PATCH_PCD
.upper() : MODEL_PCD_PATCHABLE_IN_MODULE
,
47 TAB_INF_FEATURE_PCD
.upper() : MODEL_PCD_FEATURE_FLAG
,
48 TAB_INF_PCD_EX
.upper() : MODEL_PCD_DYNAMIC_EX
,
49 TAB_INF_PCD
.upper() : MODEL_PCD_DYNAMIC
,
50 TAB_SOURCES
.upper() : MODEL_EFI_SOURCE_FILE
,
51 TAB_GUIDS
.upper() : MODEL_EFI_GUID
,
52 TAB_PROTOCOLS
.upper() : MODEL_EFI_PROTOCOL
,
53 TAB_PPIS
.upper() : MODEL_EFI_PPI
,
54 TAB_DEPEX
.upper() : MODEL_EFI_DEPEX
,
55 TAB_BINARIES
.upper() : MODEL_EFI_BINARY_FILE
,
56 TAB_USER_EXTENSIONS
.upper() : MODEL_META_DATA_USER_EXTENSION
59 gComponentType2ModuleType
= {
61 "SECURITY_CORE" : "SEC",
62 "PEI_CORE" : "PEI_CORE",
63 "COMBINED_PEIM_DRIVER" : "PEIM",
65 "RELOCATABLE_PEIM" : "PEIM",
67 "BS_DRIVER" : "DXE_DRIVER",
68 "RT_DRIVER" : "DXE_RUNTIME_DRIVER",
69 "SAL_RT_DRIVER" : "DXE_SAL_DRIVER",
70 "APPLICATION" : "UEFI_APPLICATION",
74 gNmakeFlagPattern
= re
.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re
.UNICODE
)
75 gNmakeFlagName2ToolCode
= {
81 class InfHeader(ModuleHeaderClass
):
86 TAB_INF_DEFINES_BASE_NAME
: "Name",
87 TAB_INF_DEFINES_FILE_GUID
: "Guid",
88 TAB_INF_DEFINES_MODULE_TYPE
: "ModuleType",
89 TAB_INF_DEFINES_EFI_SPECIFICATION_VERSION
: "UefiSpecificationVersion",
90 TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
: "UefiSpecificationVersion",
91 TAB_INF_DEFINES_EDK_RELEASE_VERSION
: "EdkReleaseVersion",
95 TAB_INF_DEFINES_INF_VERSION
: "InfVersion",
96 TAB_INF_DEFINES_BINARY_MODULE
: "BinaryModule",
97 TAB_INF_DEFINES_COMPONENT_TYPE
: "ComponentType",
98 TAB_INF_DEFINES_MAKEFILE_NAME
: "MakefileName",
99 TAB_INF_DEFINES_BUILD_NUMBER
: "BuildNumber",
100 TAB_INF_DEFINES_BUILD_TYPE
: "BuildType",
101 TAB_INF_DEFINES_FFS_EXT
: "FfsExt",
102 TAB_INF_DEFINES_FV_EXT
: "FvExt",
103 TAB_INF_DEFINES_SOURCE_FV
: "SourceFv",
104 TAB_INF_DEFINES_VERSION_NUMBER
: "VersionNumber",
105 TAB_INF_DEFINES_VERSION_STRING
: "VersionString",
106 TAB_INF_DEFINES_VERSION
: "Version",
107 TAB_INF_DEFINES_PCD_IS_DRIVER
: "PcdIsDriver",
108 TAB_INF_DEFINES_TIANO_EDK_FLASHMAP_H
: "TianoEdkFlashMap_h",
109 TAB_INF_DEFINES_SHADOW
: "Shadow",
110 # TAB_INF_DEFINES_LIBRARY_CLASS : "LibraryClass",
111 # TAB_INF_DEFINES_ENTRY_POINT : "ExternImages",
112 # TAB_INF_DEFINES_UNLOAD_IMAGE : "ExternImages",
113 # TAB_INF_DEFINES_CONSTRUCTOR : ,
114 # TAB_INF_DEFINES_DESTRUCTOR : ,
115 # TAB_INF_DEFINES_DEFINE : "Define",
116 # TAB_INF_DEFINES_SPEC : "Specification",
117 # TAB_INF_DEFINES_CUSTOM_MAKEFILE : "CustomMakefile",
118 # TAB_INF_DEFINES_MACRO :
122 ModuleHeaderClass
.__init
__(self
)
123 self
.VersionNumber
= ''
124 self
.VersionString
= ''
126 def __setitem__(self
, key
, value
):
127 self
.__dict
__[self
._Mapping
_[key
]] = value
128 def __getitem__(self
, key
):
129 return self
.__dict
__[self
._Mapping
_[key
]]
131 def __contains__(self
, key
):
132 return key
in self
._Mapping
_
136 # This class defined basic Inf object which is used by inheriting
138 # @param object: Inherited from object class
140 class InfObject(object):
146 # This class defined the structure used in Inf object
148 # @param InfObject: Inherited from InfObject class
149 # @param Ffilename: Input value for Ffilename of Inf file, default is None
150 # @param IsMergeAllArches: Input value for IsMergeAllArches
151 # True is to merge all arches
152 # Fales is not to merge all arches
154 # @param IsToModule: Input value for IsToModule
155 # True is to transfer to ModuleObject automatically
156 # False is not to transfer to ModuleObject automatically
158 # @param WorkspaceDir: Input value for current workspace directory, default is None
160 # @var Identification: To store value for Identification, it is a structure as Identification
161 # @var UserExtensions: To store value for UserExtensions
162 # @var Module: To store value for Module, it is a structure as ModuleClass
163 # @var WorkspaceDir: To store value for WorkspaceDir
164 # @var KeyList: To store value for KeyList, a list for all Keys used in Inf
166 class Inf(InfObject
):
167 def __init__(self
, Filename
=None, IsToDatabase
=False, IsToModule
=False, WorkspaceDir
=None, Database
=None, SupArchList
=DataType
.ARCH_LIST
):
168 self
.Identification
= Identification()
169 self
.Module
= ModuleClass()
170 self
.UserExtensions
= ''
171 self
.WorkspaceDir
= WorkspaceDir
172 self
.SupArchList
= SupArchList
173 self
.IsToDatabase
= IsToDatabase
175 self
.Cur
= Database
.Cur
176 self
.TblFile
= Database
.TblFile
177 self
.TblInf
= Database
.TblInf
179 #self.TblInf = TableInf(Database.Cur)
182 TAB_SOURCES
, TAB_BUILD_OPTIONS
, TAB_BINARIES
, TAB_INCLUDES
, TAB_GUIDS
,
183 TAB_PROTOCOLS
, TAB_PPIS
, TAB_LIBRARY_CLASSES
, TAB_PACKAGES
, TAB_LIBRARIES
,
184 TAB_INF_FIXED_PCD
, TAB_INF_PATCH_PCD
, TAB_INF_FEATURE_PCD
, TAB_INF_PCD
,
185 TAB_INF_PCD_EX
, TAB_DEPEX
, TAB_NMAKE
, TAB_INF_DEFINES
188 # Upper all KEYs to ignore case sensitive when parsing
190 self
.KeyList
= map(lambda c
: c
.upper(), self
.KeyList
)
196 for Key
in self
.KeyList
:
197 self
.RecordSet
[Section
[Key
]] = []
200 # Load Inf file if filename is not None
203 self
.LoadInfFile(Filename
)
206 # Transfer to Module Object if IsToModule is True
211 ## Transfer to Module Object
213 # Transfer all contents of an Inf file to a standard Module Object
215 def InfToModule(self
):
217 # Init global information for the file
219 ContainerFile
= self
.Identification
.FileFullPath
222 # Generate Package Header
224 self
.GenModuleHeader(ContainerFile
)
227 # Generate BuildOptions
229 self
.GenBuildOptions(ContainerFile
)
234 self
.GenIncludes(ContainerFile
)
239 self
.GenLibraries(ContainerFile
)
242 # Generate LibraryClasses
244 self
.GenLibraryClasses(ContainerFile
)
249 self
.GenPackages(ContainerFile
)
254 self
.GenNmakes(ContainerFile
)
259 self
.GenPcds(ContainerFile
)
264 self
.GenSources(ContainerFile
)
267 # Generate UserExtensions
269 self
.GenUserExtensions(ContainerFile
)
274 self
.GenGuidProtocolPpis(DataType
.TAB_GUIDS
, ContainerFile
)
279 self
.GenGuidProtocolPpis(DataType
.TAB_PROTOCOLS
, ContainerFile
)
284 self
.GenGuidProtocolPpis(DataType
.TAB_PPIS
, ContainerFile
)
289 self
.GenDepexes(ContainerFile
)
294 self
.GenBinaries(ContainerFile
)
296 ## Parse [Defines] section
298 # Parse [Defines] section into InfDefines object
300 # @param InfFile The path of the INF file
301 # @param Section The title of "Defines" section
302 # @param Lines The content of "Defines" section
304 def ParseDefines(self
, InfFile
, Section
, Lines
):
305 TokenList
= Section
.split(TAB_SPLIT
)
306 if len(TokenList
) == 3:
307 RaiseParserError(Section
, "Defines", InfFile
, "[xx.yy.%s] format (with platform) is not supported")
308 if len(TokenList
) == 2:
309 Arch
= TokenList
[1].upper()
311 Arch
= TAB_ARCH_COMMON
313 if Arch
not in self
.Defines
:
314 self
.Defines
[Arch
] = InfDefines()
315 GetSingleValueOfKeyFromLines(Lines
, self
.Defines
[Arch
].DefinesDictionary
,
316 TAB_COMMENT_SPLIT
, TAB_EQUAL_SPLIT
, False, None)
320 # Load the file if it exists
322 # @param Filename: Input value for filename of Inf file
324 def LoadInfFile(self
, Filename
):
326 # Insert a record for file
328 Filename
= NormPath(Filename
)
329 self
.Identification
.FileFullPath
= Filename
330 (self
.Identification
.FileRelativePath
, self
.Identification
.FileName
) = os
.path
.split(Filename
)
331 self
.FileID
= self
.TblFile
.InsertFile(Filename
, MODEL_FILE_INF
)
336 #self.TblInf.Table = "Inf%s" % self.FileID
337 #self.TblInf.Create()
342 IfDefList
, SectionItemList
, CurrentSection
, ArchList
, ThirdList
, IncludeFiles
= \
343 [], [], TAB_UNKNOWN
, [], [], []
349 IsFindBlockComment
= False
351 for Line
in open(Filename
, 'r'):
354 # Remove comment block
356 if Line
.find(TAB_COMMENT_EDK_START
) > -1:
357 ReservedLine
= GetSplitList(Line
, TAB_COMMENT_EDK_START
, 1)[0]
358 IsFindBlockComment
= True
359 if Line
.find(TAB_COMMENT_EDK_END
) > -1:
360 Line
= ReservedLine
+ GetSplitList(Line
, TAB_COMMENT_EDK_END
, 1)[1]
362 IsFindBlockComment
= False
363 if IsFindBlockComment
:
367 # Remove comments at tail and remove spaces again
369 Line
= CleanString(Line
)
374 # Find a new section tab
375 # First insert previous section items
376 # And then parse the content of the new section
378 if Line
.startswith(TAB_SECTION_START
) and Line
.endswith(TAB_SECTION_END
):
379 if Line
[1:3] == "--":
381 Model
= Section
[CurrentSection
.upper()]
383 # Insert items data of previous section
385 InsertSectionItemsIntoDatabase(self
.TblInf
, self
.FileID
, Filename
, Model
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
, self
.RecordSet
)
387 # Parse the new section
394 LineList
= GetSplitValueList(Line
[len(TAB_SECTION_START
):len(Line
) - len(TAB_SECTION_END
)], TAB_COMMA_SPLIT
)
395 for Item
in LineList
:
396 ItemList
= GetSplitValueList(Item
, TAB_SPLIT
)
397 if CurrentSection
== '':
398 CurrentSection
= ItemList
[0]
400 if CurrentSection
!= ItemList
[0]:
401 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
)
402 if CurrentSection
.upper() not in self
.KeyList
:
403 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
404 CurrentSection
= TAB_UNKNOWN
408 if len(ItemList
) > 5:
409 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
411 if ItemList
[1] != '' and ItemList
[1].upper() not in ARCH_LIST_FULL
:
412 EdkLogger
.error("Parser", PARSER_ERROR
, "Invalid Arch definition '%s' found" % ItemList
[1], File
=Filename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
413 ArchList
.append(ItemList
[1].upper())
414 ThirdList
.append(ItemList
[2])
419 # Not in any defined section
421 if CurrentSection
== TAB_UNKNOWN
:
422 ErrorMsg
= "%s is not in any defined section" % Line
423 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
, File
=Filename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
428 SectionItemList
.append([Line
, LineNo
])
433 # Insert items data of last section
435 Model
= Section
[CurrentSection
.upper()]
436 InsertSectionItemsIntoDatabase(self
.TblInf
, self
.FileID
, Filename
, Model
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
, self
.RecordSet
)
439 # Replace all DEFINE macros with its actual values
441 ParseDefineMacro2(self
.TblInf
, self
.RecordSet
, GlobalData
.gGlobalDefines
)
443 ## Show detailed information of Module
445 # Print all members and their values of Module class
447 def ShowModule(self
):
449 for Arch
in M
.Header
.keys():
450 print '\nArch =', Arch
451 print 'Filename =', M
.Header
[Arch
].FileName
452 print 'FullPath =', M
.Header
[Arch
].FullPath
453 print 'BaseName =', M
.Header
[Arch
].Name
454 print 'Guid =', M
.Header
[Arch
].Guid
455 print 'Version =', M
.Header
[Arch
].Version
456 print 'InfVersion =', M
.Header
[Arch
].InfVersion
457 print 'UefiSpecificationVersion =', M
.Header
[Arch
].UefiSpecificationVersion
458 print 'EdkReleaseVersion =', M
.Header
[Arch
].EdkReleaseVersion
459 print 'ModuleType =', M
.Header
[Arch
].ModuleType
460 print 'BinaryModule =', M
.Header
[Arch
].BinaryModule
461 print 'ComponentType =', M
.Header
[Arch
].ComponentType
462 print 'MakefileName =', M
.Header
[Arch
].MakefileName
463 print 'BuildNumber =', M
.Header
[Arch
].BuildNumber
464 print 'BuildType =', M
.Header
[Arch
].BuildType
465 print 'FfsExt =', M
.Header
[Arch
].FfsExt
466 print 'FvExt =', M
.Header
[Arch
].FvExt
467 print 'SourceFv =', M
.Header
[Arch
].SourceFv
468 print 'PcdIsDriver =', M
.Header
[Arch
].PcdIsDriver
469 print 'TianoEdkFlashMap_h =', M
.Header
[Arch
].TianoEdkFlashMap_h
470 print 'Shadow =', M
.Header
[Arch
].Shadow
471 print 'LibraryClass =', M
.Header
[Arch
].LibraryClass
472 for Item
in M
.Header
[Arch
].LibraryClass
:
473 print Item
.LibraryClass
, DataType
.TAB_VALUE_SPLIT
.join(Item
.SupModuleList
)
474 print 'CustomMakefile =', M
.Header
[Arch
].CustomMakefile
475 print 'Define =', M
.Header
[Arch
].Define
476 print 'Specification =', M
.Header
[Arch
].Specification
477 for Item
in self
.Module
.ExternImages
:
478 print '\nEntry_Point = %s, UnloadImage = %s' % (Item
.ModuleEntryPoint
, Item
.ModuleUnloadImage
)
479 for Item
in self
.Module
.ExternLibraries
:
480 print 'Constructor = %s, Destructor = %s' % (Item
.Constructor
, Item
.Destructor
)
481 print '\nBuildOptions =', M
.BuildOptions
482 for Item
in M
.BuildOptions
:
483 print Item
.ToolChainFamily
, Item
.ToolChain
, Item
.Option
, Item
.SupArchList
484 print '\nIncludes =', M
.Includes
485 for Item
in M
.Includes
:
486 print Item
.FilePath
, Item
.SupArchList
487 print '\nLibraries =', M
.Libraries
488 for Item
in M
.Libraries
:
489 print Item
.Library
, Item
.SupArchList
490 print '\nLibraryClasses =', M
.LibraryClasses
491 for Item
in M
.LibraryClasses
:
492 print Item
.LibraryClass
, Item
.RecommendedInstance
, Item
.FeatureFlag
, Item
.SupModuleList
, Item
.SupArchList
, Item
.Define
493 print '\nPackageDependencies =', M
.PackageDependencies
494 for Item
in M
.PackageDependencies
:
495 print Item
.FilePath
, Item
.SupArchList
, Item
.FeatureFlag
496 print '\nNmake =', M
.Nmake
498 print Item
.Name
, Item
.Value
, Item
.SupArchList
499 print '\nPcds =', M
.PcdCodes
500 for Item
in M
.PcdCodes
:
501 print '\tCName=', Item
.CName
, 'TokenSpaceGuidCName=', Item
.TokenSpaceGuidCName
, 'DefaultValue=', Item
.DefaultValue
, 'ItemType=', Item
.ItemType
, Item
.SupArchList
502 print '\nSources =', M
.Sources
503 for Source
in M
.Sources
:
504 print Source
.SourceFile
, 'Fam=', Source
.ToolChainFamily
, 'Pcd=', Source
.FeatureFlag
, 'Tag=', Source
.TagName
, 'ToolCode=', Source
.ToolCode
, Source
.SupArchList
505 print '\nUserExtensions =', M
.UserExtensions
506 for UserExtension
in M
.UserExtensions
:
507 print UserExtension
.UserID
, UserExtension
.Identifier
, UserExtension
.Content
508 print '\nGuids =', M
.Guids
510 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
511 print '\nProtocols =', M
.Protocols
512 for Item
in M
.Protocols
:
513 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
514 print '\nPpis =', M
.Ppis
516 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
517 print '\nDepex =', M
.Depex
519 print Item
.Depex
, Item
.SupArchList
, Item
.Define
520 print '\nBinaries =', M
.Binaries
521 for Binary
in M
.Binaries
:
522 print 'Type=', Binary
.FileType
, 'Target=', Binary
.Target
, 'Name=', Binary
.BinaryFile
, 'FeatureFlag=', Binary
.FeatureFlag
, 'SupArchList=', Binary
.SupArchList
524 ## Convert [Defines] section content to ModuleHeaderClass
526 # Convert [Defines] section content to ModuleHeaderClass
528 # @param Defines The content under [Defines] section
529 # @param ModuleHeader An object of ModuleHeaderClass
530 # @param Arch The supported ARCH
532 def GenModuleHeader(self
, ContainerFile
):
533 EdkLogger
.debug(2, "Generate ModuleHeader ...")
534 File
= self
.Identification
.FileFullPath
536 # Update all defines item in database
538 RecordSet
= self
.RecordSet
[MODEL_META_DATA_HEADER
]
539 for Record
in RecordSet
:
540 ValueList
= GetSplitValueList(Record
[0], TAB_EQUAL_SPLIT
)
541 if len(ValueList
) != 2:
542 RaiseParserError(Record
[0], 'Defines', ContainerFile
, '<Key> = <Value>', Record
[2])
543 ID
, Value1
, Value2
, Arch
, LineNo
= Record
[3], ValueList
[0], ValueList
[1], Record
[1], Record
[2]
544 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
545 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Value1
), ConvertToSqlString2(Value2
), ID
)
546 self
.TblInf
.Exec(SqlCommand
)
548 for Arch
in DataType
.ARCH_LIST
:
549 ModuleHeader
= InfHeader()
550 ModuleHeader
.FileName
= self
.Identification
.FileName
551 ModuleHeader
.FullPath
= self
.Identification
.FileFullPath
552 DefineList
= QueryDefinesItem2(self
.TblInf
, Arch
, self
.FileID
)
554 NotProcessedDefineList
= []
556 if D
[0] in ModuleHeader
:
557 ModuleHeader
[D
[0]] = GetSplitValueList(D
[1])[0]
559 NotProcessedDefineList
.append(D
)
561 if ModuleHeader
.ComponentType
== "LIBRARY":
562 Lib
= LibraryClassClass()
563 Lib
.LibraryClass
= ModuleHeader
.Name
564 Lib
.SupModuleList
= DataType
.SUP_MODULE_LIST
565 ModuleHeader
.LibraryClass
.append(Lib
)
567 # we need to make some key defines resolved first
568 for D
in NotProcessedDefineList
:
569 if D
[0] == TAB_INF_DEFINES_LIBRARY_CLASS
:
570 List
= GetSplitValueList(D
[1], DataType
.TAB_VALUE_SPLIT
, 1)
571 Lib
= LibraryClassClass()
572 Lib
.LibraryClass
= CleanString(List
[0])
574 Lib
.SupModuleList
= DataType
.SUP_MODULE_LIST
576 Lib
.SupModuleList
= GetSplitValueList(CleanString(List
[1]), ' ')
577 ModuleHeader
.LibraryClass
.append(Lib
)
578 elif D
[0] == TAB_INF_DEFINES_CUSTOM_MAKEFILE
:
579 List
= D
[1].split(DataType
.TAB_VALUE_SPLIT
)
581 ModuleHeader
.CustomMakefile
[CleanString(List
[0])] = CleanString(List
[1])
583 RaiseParserError(D
[1], 'CUSTOM_MAKEFILE of Defines', File
, 'CUSTOM_MAKEFILE=<Family>|<Filename>', D
[2])
584 elif D
[0] == TAB_INF_DEFINES_ENTRY_POINT
:
585 Image
= ModuleExternImageClass()
586 Image
.ModuleEntryPoint
= CleanString(D
[1])
587 self
.Module
.ExternImages
.append(Image
)
588 elif D
[0] == TAB_INF_DEFINES_UNLOAD_IMAGE
:
589 Image
= ModuleExternImageClass()
590 Image
.ModuleUnloadImage
= CleanString(D
[1])
591 self
.Module
.ExternImages
.append(Image
)
592 elif D
[0] == TAB_INF_DEFINES_CONSTRUCTOR
:
593 LibraryClass
= ModuleExternLibraryClass()
594 LibraryClass
.Constructor
= CleanString(D
[1])
595 self
.Module
.ExternLibraries
.append(LibraryClass
)
596 elif D
[0] == TAB_INF_DEFINES_DESTRUCTOR
:
597 LibraryClass
= ModuleExternLibraryClass()
598 LibraryClass
.Destructor
= CleanString(D
[1])
599 self
.Module
.ExternLibraries
.append(LibraryClass
)
600 elif D
[0] == TAB_INF_DEFINES_DEFINE
:
601 List
= D
[1].split(DataType
.TAB_EQUAL_SPLIT
)
603 RaiseParserError(Item
, 'DEFINE of Defines', File
, 'DEFINE <Word> = <Word>', D
[2])
605 ModuleHeader
.Define
[CleanString(List
[0])] = CleanString(List
[1])
606 elif D
[0] == TAB_INF_DEFINES_SPEC
:
607 List
= D
[1].split(DataType
.TAB_EQUAL_SPLIT
)
609 RaiseParserError(Item
, 'SPEC of Defines', File
, 'SPEC <Word> = <Version>', D
[2])
611 ModuleHeader
.Specification
[CleanString(List
[0])] = CleanString(List
[1])
616 if ModuleHeader
.InfVersion
!= "":
618 VersionNumber
= ModuleHeader
.VersionNumber
619 VersionString
= ModuleHeader
.VersionString
620 if len(VersionNumber
) > 0 and len(VersionString
) == 0:
621 EdkLogger
.warn(2000, 'VERSION_NUMBER depricated; INF file %s should be modified to use VERSION_STRING instead.' % self
.Identification
.FileFullPath
)
622 ModuleHeader
.Version
= VersionNumber
623 if len(VersionString
) > 0:
624 if len(VersionNumber
) > 0:
625 EdkLogger
.warn(2001, 'INF file %s defines both VERSION_NUMBER and VERSION_STRING, using VERSION_STRING' % self
.Identification
.FileFullPath
)
626 ModuleHeader
.Version
= VersionString
629 ModuleHeader
.InfVersion
= "0x00010000"
630 if ModuleHeader
.ComponentType
in gComponentType2ModuleType
:
631 ModuleHeader
.ModuleType
= gComponentType2ModuleType
[ModuleHeader
.ComponentType
]
632 elif ModuleHeader
.ComponentType
!= '':
633 EdkLogger
.error("Parser", PARSER_ERROR
, "Unsupported Edk component type [%s]" % ModuleHeader
.ComponentType
, ExtraData
=File
, RaiseError
=EdkLogger
.IsRaiseError
)
635 self
.Module
.Header
[Arch
] = ModuleHeader
640 # Gen BuildOptions of Inf
641 # [<Family>:]<ToolFlag>=Flag
643 # @param ContainerFile: The Inf file full path
645 def GenBuildOptions(self
, ContainerFile
):
646 EdkLogger
.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS
)
649 # Get all BuildOptions
651 RecordSet
= self
.RecordSet
[MODEL_META_DATA_BUILD_OPTION
]
654 # Go through each arch
656 for Arch
in self
.SupArchList
:
657 for Record
in RecordSet
:
658 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
659 (Family
, ToolChain
, Flag
) = GetBuildOption(Record
[0], ContainerFile
, Record
[2])
660 MergeArches(BuildOptions
, (Family
, ToolChain
, Flag
), Arch
)
664 if self
.IsToDatabase
:
665 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
666 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Family
), ConvertToSqlString2(ToolChain
), ConvertToSqlString2(Flag
), Record
[3])
667 self
.TblInf
.Exec(SqlCommand
)
669 for Key
in BuildOptions
.keys():
670 BuildOption
= BuildOptionClass(Key
[0], Key
[1], Key
[2])
671 BuildOption
.SupArchList
= BuildOptions
[Key
]
672 self
.Module
.BuildOptions
.append(BuildOption
)
676 # Gen Includes of Inf
679 # @param ContainerFile: The Inf file full path
681 def GenIncludes(self
, ContainerFile
):
682 EdkLogger
.debug(2, "Generate %s ..." % TAB_INCLUDES
)
687 RecordSet
= self
.RecordSet
[MODEL_EFI_INCLUDE
]
690 # Go through each arch
692 for Arch
in self
.SupArchList
:
693 for Record
in RecordSet
:
694 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
695 MergeArches(Includes
, Record
[0], Arch
)
697 for Key
in Includes
.keys():
698 Include
= IncludeClass()
699 Include
.FilePath
= NormPath(Key
)
700 Include
.SupArchList
= Includes
[Key
]
701 self
.Module
.Includes
.append(Include
)
705 # Gen Libraries of Inf
708 # @param ContainerFile: The Inf file full path
710 def GenLibraries(self
, ContainerFile
):
711 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARIES
)
716 RecordSet
= self
.RecordSet
[MODEL_EFI_LIBRARY_INSTANCE
]
719 # Go through each arch
721 for Arch
in self
.SupArchList
:
722 for Record
in RecordSet
:
723 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
724 MergeArches(Libraries
, Record
[0], Arch
)
726 for Key
in Libraries
.keys():
727 Library
= ModuleLibraryClass()
728 # replace macro and remove file extension
729 Library
.Library
= Key
.rsplit('.', 1)[0]
730 Library
.SupArchList
= Libraries
[Key
]
731 self
.Module
.Libraries
.append(Library
)
735 # Get LibraryClass of Inf
736 # <LibraryClassKeyWord>|<LibraryInstance>
738 # @param ContainerFile: The Inf file full path
740 def GenLibraryClasses(self
, ContainerFile
):
741 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES
)
744 # Get all LibraryClasses
746 RecordSet
= self
.RecordSet
[MODEL_EFI_LIBRARY_CLASS
]
749 # Go through each arch
751 for Arch
in self
.SupArchList
:
752 for Record
in RecordSet
:
753 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
754 (LibClassName
, LibClassIns
, Pcd
, SupModelList
) = GetLibraryClassOfInf([Record
[0], Record
[4]], ContainerFile
, self
.WorkspaceDir
, Record
[2])
755 MergeArches(LibraryClasses
, (LibClassName
, LibClassIns
, Pcd
, SupModelList
), Arch
)
759 if self
.IsToDatabase
:
760 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
761 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(LibClassName
), ConvertToSqlString2(LibClassIns
), ConvertToSqlString2(SupModelList
), Record
[3])
762 self
.TblInf
.Exec(SqlCommand
)
764 for Key
in LibraryClasses
.keys():
765 KeyList
= Key
[0].split(DataType
.TAB_VALUE_SPLIT
)
766 LibraryClass
= LibraryClassClass()
767 LibraryClass
.LibraryClass
= Key
[0]
768 LibraryClass
.RecommendedInstance
= NormPath(Key
[1])
769 LibraryClass
.FeatureFlag
= Key
[2]
770 LibraryClass
.SupArchList
= LibraryClasses
[Key
]
771 LibraryClass
.SupModuleList
= GetSplitValueList(Key
[3])
772 self
.Module
.LibraryClasses
.append(LibraryClass
)
776 # Gen Packages of Inf
779 # @param ContainerFile: The Inf file full path
781 def GenPackages(self
, ContainerFile
):
782 EdkLogger
.debug(2, "Generate %s ..." % TAB_PACKAGES
)
787 RecordSet
= self
.RecordSet
[MODEL_META_DATA_PACKAGE
]
790 # Go through each arch
792 for Arch
in self
.SupArchList
:
793 for Record
in RecordSet
:
794 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
795 (Package
, Pcd
) = GetPackage(Record
[0], ContainerFile
, self
.WorkspaceDir
, Record
[2])
796 MergeArches(Packages
, (Package
, Pcd
), Arch
)
797 if self
.IsToDatabase
:
798 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
799 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Package
), ConvertToSqlString2(Pcd
), Record
[3])
800 self
.TblInf
.Exec(SqlCommand
)
803 for Key
in Packages
.keys():
804 Package
= ModulePackageDependencyClass()
805 Package
.FilePath
= NormPath(Key
[0])
806 Package
.SupArchList
= Packages
[Key
]
807 Package
.FeatureFlag
= Key
[1]
808 self
.Module
.PackageDependencies
.append(Package
)
815 # @param ContainerFile: The Inf file full path
817 def GenNmakes(self
, ContainerFile
):
818 EdkLogger
.debug(2, "Generate %s ..." % TAB_NMAKE
)
823 RecordSet
= self
.RecordSet
[MODEL_META_DATA_NMAKE
]
827 # Go through each arch
829 for Arch
in self
.SupArchList
:
830 for Record
in RecordSet
:
831 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
832 MergeArches(Nmakes
, Record
[0], Arch
)
834 for Key
in Nmakes
.keys():
835 List
= GetSplitValueList(Key
, DataType
.TAB_EQUAL_SPLIT
, MaxSplit
=1)
837 RaiseParserError(Key
, 'Nmake', ContainerFile
, '<MacroName> = <Value>')
839 Nmake
= ModuleNmakeClass()
841 Nmake
.Value
= List
[1]
842 Nmake
.SupArchList
= Nmakes
[Key
]
843 self
.Module
.Nmake
.append(Nmake
)
845 # convert Edk format to EdkII format
846 if Nmake
.Name
== "IMAGE_ENTRY_POINT":
847 Image
= ModuleExternImageClass()
848 Image
.ModuleEntryPoint
= Nmake
.Value
849 self
.Module
.ExternImages
.append(Image
)
850 elif Nmake
.Name
== "DPX_SOURCE":
851 Source
= ModuleSourceFileClass(NormPath(Nmake
.Value
), "", "", "", "", Nmake
.SupArchList
)
852 self
.Module
.Sources
.append(Source
)
854 ToolList
= gNmakeFlagPattern
.findall(Nmake
.Name
)
855 if len(ToolList
) == 0 or len(ToolList
) != 1:
856 EdkLogger
.warn("\nParser", "Don't know how to do with MACRO: %s" % Nmake
.Name
,
857 ExtraData
=ContainerFile
)
859 if ToolList
[0] in gNmakeFlagName2ToolCode
:
860 Tool
= gNmakeFlagName2ToolCode
[ToolList
[0]]
863 BuildOption
= BuildOptionClass("MSFT", "*_*_*_%s_FLAGS" % Tool
, Nmake
.Value
)
864 BuildOption
.SupArchList
= Nmake
.SupArchList
865 self
.Module
.BuildOptions
.append(BuildOption
)
870 # <TokenSpaceGuidCName>.<PcdCName>[|<Value>]
872 # @param ContainerFile: The Dec file full path
874 def GenPcds(self
, ContainerFile
):
875 EdkLogger
.debug(2, "Generate %s ..." % TAB_PCDS
)
882 RecordSet1
= self
.RecordSet
[MODEL_PCD_FIXED_AT_BUILD
]
883 RecordSet2
= self
.RecordSet
[MODEL_PCD_PATCHABLE_IN_MODULE
]
884 RecordSet3
= self
.RecordSet
[MODEL_PCD_FEATURE_FLAG
]
885 RecordSet4
= self
.RecordSet
[MODEL_PCD_DYNAMIC_EX
]
886 RecordSet5
= self
.RecordSet
[MODEL_PCD_DYNAMIC
]
889 # Go through each arch
891 for Arch
in self
.SupArchList
:
892 for Record
in RecordSet1
:
893 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
894 if self
.Module
.Header
[Arch
].LibraryClass
!= {}:
896 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_FIXED_AT_BUILD
, ContainerFile
, Record
[2])
897 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
898 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
899 for Record
in RecordSet2
:
900 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
901 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_PATCHABLE_IN_MODULE
, ContainerFile
, Record
[2])
902 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
903 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
904 for Record
in RecordSet3
:
905 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
906 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_FEATURE_FLAG
, ContainerFile
, Record
[2])
907 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
908 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
909 for Record
in RecordSet4
:
910 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
911 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_DYNAMIC_EX
, ContainerFile
, Record
[2])
912 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
913 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
914 for Record
in RecordSet5
:
915 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
916 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], "", ContainerFile
, Record
[2])
917 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
918 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
922 if self
.IsToDatabase
:
923 for Key
in PcdToken
.keys():
924 SqlCommand
= """update %s set Value2 = '%s' where ID = %s""" % (self
.TblInf
.Table
, ".".join((PcdToken
[Key
][0], PcdToken
[Key
][1])), Key
)
925 self
.TblInf
.Exec(SqlCommand
)
927 for Key
in Pcds
.keys():
930 Pcd
.TokenSpaceGuidCName
= Key
[0]
931 Pcd
.DefaultValue
= Key
[2]
932 Pcd
.ItemType
= Key
[3]
933 Pcd
.SupArchList
= Pcds
[Key
]
934 self
.Module
.PcdCodes
.append(Pcd
)
939 # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]
941 # @param ContainerFile: The Dec file full path
943 def GenSources(self
, ContainerFile
):
944 EdkLogger
.debug(2, "Generate %s ..." % TAB_SOURCES
)
950 RecordSet
= self
.RecordSet
[MODEL_EFI_SOURCE_FILE
]
953 # Go through each arch
955 for Arch
in self
.SupArchList
:
956 for Record
in RecordSet
:
957 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
958 (Filename
, Family
, TagName
, ToolCode
, Pcd
) = GetSource(Record
[0], ContainerFile
, self
.Identification
.FileRelativePath
, Record
[2])
959 MergeArches(Sources
, (Filename
, Family
, TagName
, ToolCode
, Pcd
), Arch
)
960 if self
.IsToDatabase
:
961 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s', Value5 = '%s'
962 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Filename
), ConvertToSqlString2(Family
), ConvertToSqlString2(TagName
), ConvertToSqlString2(ToolCode
), ConvertToSqlString2(Pcd
), Record
[3])
963 self
.TblInf
.Exec(SqlCommand
)
965 for Key
in Sources
.keys():
966 Source
= ModuleSourceFileClass(Key
[0], Key
[2], Key
[3], Key
[1], Key
[4], Sources
[Key
])
967 self
.Module
.Sources
.append(Source
)
971 # Gen UserExtensions of Inf
973 def GenUserExtensions(self
, ContainerFile
):
977 # if self.UserExtensions != '':
978 # UserExtension = UserExtensionsClass()
979 # Lines = self.UserExtensions.splitlines()
980 # List = GetSplitValueList(Lines[0], DataType.TAB_SPLIT, 2)
982 # RaiseParserError(Lines[0], 'UserExtensions', File, "UserExtensions.UserId.'Identifier'")
984 # UserExtension.UserID = List[1]
985 # UserExtension.Identifier = List[2][0:-1].replace("'", '').replace('\"', '')
986 # for Line in Lines[1:]:
987 # UserExtension.Content = UserExtension.Content + CleanString(Line) + '\n'
988 # self.Module.UserExtensions.append(UserExtension)
995 # @param ContainerFile: The Inf file full path
997 def GenDepexes(self
, ContainerFile
):
998 EdkLogger
.debug(2, "Generate %s ..." % TAB_DEPEX
)
1003 RecordSet
= self
.RecordSet
[MODEL_EFI_DEPEX
]
1006 # Go through each arch
1008 for Arch
in self
.SupArchList
:
1010 for Record
in RecordSet
:
1011 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
1012 Line
= Line
+ Record
[0] + ' '
1014 MergeArches(Depex
, Line
, Arch
)
1016 for Key
in Depex
.keys():
1017 Dep
= ModuleDepexClass()
1019 Dep
.SupArchList
= Depex
[Key
]
1020 self
.Module
.Depex
.append(Dep
)
1025 # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]
1027 # @param ContainerFile: The Dec file full path
1029 def GenBinaries(self
, ContainerFile
):
1030 EdkLogger
.debug(2, "Generate %s ..." % TAB_BINARIES
)
1036 RecordSet
= self
.RecordSet
[MODEL_EFI_BINARY_FILE
]
1039 # Go through each arch
1041 for Arch
in self
.SupArchList
:
1042 for Record
in RecordSet
:
1043 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
1044 (FileType
, Filename
, Target
, Pcd
) = GetBinary(Record
[0], ContainerFile
, self
.Identification
.FileRelativePath
, Record
[2])
1045 MergeArches(Binaries
, (FileType
, Filename
, Target
, Pcd
), Arch
)
1046 if self
.IsToDatabase
:
1047 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s'
1048 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(FileType
), ConvertToSqlString2(Filename
), ConvertToSqlString2(Target
), ConvertToSqlString2(Pcd
), Record
[3])
1049 self
.TblInf
.Exec(SqlCommand
)
1051 for Key
in Binaries
.keys():
1052 Binary
= ModuleBinaryFileClass(NormPath(Key
[1]), Key
[0], Key
[2], Key
[3], Binaries
[Key
])
1053 self
.Module
.Binaries
.append(Binary
)
1058 # <CName>=<GuidValue>
1060 # @param ContainerFile: The Inf file full path
1062 def GenGuidProtocolPpis(self
, Type
, ContainerFile
):
1063 EdkLogger
.debug(2, "Generate %s ..." % Type
)
1068 RecordSet
= self
.RecordSet
[Section
[Type
.upper()]]
1071 # Go through each arch
1073 for Arch
in self
.SupArchList
:
1074 for Record
in RecordSet
:
1075 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
1076 (Name
, Value
) = GetGuidsProtocolsPpisOfInf(Record
[0], Type
, ContainerFile
, Record
[2])
1077 MergeArches(Lists
, (Name
, Value
), Arch
)
1078 if self
.IsToDatabase
:
1079 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
1080 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Name
), ConvertToSqlString2(Value
), Record
[3])
1081 self
.TblInf
.Exec(SqlCommand
)
1084 if Type
== TAB_GUIDS
:
1085 ListMember
= self
.Module
.Guids
1086 elif Type
== TAB_PROTOCOLS
:
1087 ListMember
= self
.Module
.Protocols
1088 elif Type
== TAB_PPIS
:
1089 ListMember
= self
.Module
.Ppis
1091 for Key
in Lists
.keys():
1092 ListClass
= GuidProtocolPpiCommonClass()
1093 ListClass
.CName
= Key
[0]
1094 ListClass
.SupArchList
= Lists
[Key
]
1095 ListClass
.FeatureFlag
= Key
[1]
1096 ListMember
.append(ListClass
)
1100 # This acts like the main() function for the script, unless it is 'import'ed into another
1103 if __name__
== '__main__':
1104 EdkLogger
.Initialize()
1105 EdkLogger
.SetLevel(EdkLogger
.DEBUG_0
)
1107 W
= os
.getenv('WORKSPACE')
1108 F
= os
.path
.join(W
, 'MdeModulePkg/Application/HelloWorld/HelloWorld.inf')
1110 Db
= Database
.Database('Inf.db')
1113 P
= Inf(os
.path
.normpath(F
), True, True, W
, Db
)