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 the structure used in Inf object
138 # @param Ffilename: Input value for Ffilename of Inf file, default is None
139 # @param IsMergeAllArches: Input value for IsMergeAllArches
140 # True is to merge all arches
141 # Fales is not to merge all arches
143 # @param IsToModule: Input value for IsToModule
144 # True is to transfer to ModuleObject automatically
145 # False is not to transfer to ModuleObject automatically
147 # @param WorkspaceDir: Input value for current workspace directory, default is None
149 # @var Identification: To store value for Identification, it is a structure as Identification
150 # @var UserExtensions: To store value for UserExtensions
151 # @var Module: To store value for Module, it is a structure as ModuleClass
152 # @var WorkspaceDir: To store value for WorkspaceDir
153 # @var KeyList: To store value for KeyList, a list for all Keys used in Inf
156 def __init__(self
, Filename
=None, IsToDatabase
=False, IsToModule
=False, WorkspaceDir
=None, Database
=None, SupArchList
=DataType
.ARCH_LIST
):
157 self
.Identification
= Identification()
158 self
.Module
= ModuleClass()
159 self
.UserExtensions
= ''
160 self
.WorkspaceDir
= WorkspaceDir
161 self
.SupArchList
= SupArchList
162 self
.IsToDatabase
= IsToDatabase
164 self
.Cur
= Database
.Cur
165 self
.TblFile
= Database
.TblFile
166 self
.TblInf
= Database
.TblInf
168 #self.TblInf = TableInf(Database.Cur)
171 TAB_SOURCES
, TAB_BUILD_OPTIONS
, TAB_BINARIES
, TAB_INCLUDES
, TAB_GUIDS
,
172 TAB_PROTOCOLS
, TAB_PPIS
, TAB_LIBRARY_CLASSES
, TAB_PACKAGES
, TAB_LIBRARIES
,
173 TAB_INF_FIXED_PCD
, TAB_INF_PATCH_PCD
, TAB_INF_FEATURE_PCD
, TAB_INF_PCD
,
174 TAB_INF_PCD_EX
, TAB_DEPEX
, TAB_NMAKE
, TAB_INF_DEFINES
177 # Upper all KEYs to ignore case sensitive when parsing
179 self
.KeyList
= map(lambda c
: c
.upper(), self
.KeyList
)
185 for Key
in self
.KeyList
:
186 self
.RecordSet
[Section
[Key
]] = []
189 # Load Inf file if filename is not None
191 if Filename
is not None:
192 self
.LoadInfFile(Filename
)
195 # Transfer to Module Object if IsToModule is True
200 ## Transfer to Module Object
202 # Transfer all contents of an Inf file to a standard Module Object
204 def InfToModule(self
):
206 # Init global information for the file
208 ContainerFile
= self
.Identification
.FileFullPath
211 # Generate Package Header
213 self
.GenModuleHeader(ContainerFile
)
216 # Generate BuildOptions
218 self
.GenBuildOptions(ContainerFile
)
223 self
.GenIncludes(ContainerFile
)
228 self
.GenLibraries(ContainerFile
)
231 # Generate LibraryClasses
233 self
.GenLibraryClasses(ContainerFile
)
238 self
.GenPackages(ContainerFile
)
243 self
.GenNmakes(ContainerFile
)
248 self
.GenPcds(ContainerFile
)
253 self
.GenSources(ContainerFile
)
256 # Generate UserExtensions
258 self
.GenUserExtensions(ContainerFile
)
263 self
.GenGuidProtocolPpis(DataType
.TAB_GUIDS
, ContainerFile
)
268 self
.GenGuidProtocolPpis(DataType
.TAB_PROTOCOLS
, ContainerFile
)
273 self
.GenGuidProtocolPpis(DataType
.TAB_PPIS
, ContainerFile
)
278 self
.GenDepexes(ContainerFile
)
283 self
.GenBinaries(ContainerFile
)
285 ## Parse [Defines] section
287 # Parse [Defines] section into InfDefines object
289 # @param InfFile The path of the INF file
290 # @param Section The title of "Defines" section
291 # @param Lines The content of "Defines" section
293 def ParseDefines(self
, InfFile
, Section
, Lines
):
294 TokenList
= Section
.split(TAB_SPLIT
)
295 if len(TokenList
) == 3:
296 RaiseParserError(Section
, "Defines", InfFile
, "[xx.yy.%s] format (with platform) is not supported")
297 if len(TokenList
) == 2:
298 Arch
= TokenList
[1].upper()
300 Arch
= TAB_ARCH_COMMON
302 if Arch
not in self
.Defines
:
303 self
.Defines
[Arch
] = InfDefines()
304 GetSingleValueOfKeyFromLines(Lines
, self
.Defines
[Arch
].DefinesDictionary
,
305 TAB_COMMENT_SPLIT
, TAB_EQUAL_SPLIT
, False, None)
309 # Load the file if it exists
311 # @param Filename: Input value for filename of Inf file
313 def LoadInfFile(self
, Filename
):
315 # Insert a record for file
317 Filename
= NormPath(Filename
)
318 self
.Identification
.FileFullPath
= Filename
319 (self
.Identification
.FileRelativePath
, self
.Identification
.FileName
) = os
.path
.split(Filename
)
320 self
.FileID
= self
.TblFile
.InsertFile(Filename
, MODEL_FILE_INF
)
325 #self.TblInf.Table = "Inf%s" % self.FileID
326 #self.TblInf.Create()
331 IfDefList
, SectionItemList
, CurrentSection
, ArchList
, ThirdList
, IncludeFiles
= \
332 [], [], TAB_UNKNOWN
, [], [], []
338 IsFindBlockComment
= False
340 for Line
in open(Filename
, 'r'):
343 # Remove comment block
345 if Line
.find(TAB_COMMENT_EDK_START
) > -1:
346 ReservedLine
= GetSplitList(Line
, TAB_COMMENT_EDK_START
, 1)[0]
347 IsFindBlockComment
= True
348 if Line
.find(TAB_COMMENT_EDK_END
) > -1:
349 Line
= ReservedLine
+ GetSplitList(Line
, TAB_COMMENT_EDK_END
, 1)[1]
351 IsFindBlockComment
= False
352 if IsFindBlockComment
:
356 # Remove comments at tail and remove spaces again
358 Line
= CleanString(Line
)
363 # Find a new section tab
364 # First insert previous section items
365 # And then parse the content of the new section
367 if Line
.startswith(TAB_SECTION_START
) and Line
.endswith(TAB_SECTION_END
):
368 if Line
[1:3] == "--":
370 Model
= Section
[CurrentSection
.upper()]
372 # Insert items data of previous section
374 InsertSectionItemsIntoDatabase(self
.TblInf
, self
.FileID
, Filename
, Model
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
, self
.RecordSet
)
376 # Parse the new section
383 LineList
= GetSplitValueList(Line
[len(TAB_SECTION_START
):len(Line
) - len(TAB_SECTION_END
)], TAB_COMMA_SPLIT
)
384 for Item
in LineList
:
385 ItemList
= GetSplitValueList(Item
, TAB_SPLIT
)
386 if CurrentSection
== '':
387 CurrentSection
= ItemList
[0]
389 if CurrentSection
!= ItemList
[0]:
390 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
)
391 if CurrentSection
.upper() not in self
.KeyList
:
392 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
393 CurrentSection
= TAB_UNKNOWN
397 if len(ItemList
) > 5:
398 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
400 if ItemList
[1] != '' and ItemList
[1].upper() not in ARCH_LIST_FULL
:
401 EdkLogger
.error("Parser", PARSER_ERROR
, "Invalid Arch definition '%s' found" % ItemList
[1], File
=Filename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
402 ArchList
.append(ItemList
[1].upper())
403 ThirdList
.append(ItemList
[2])
408 # Not in any defined section
410 if CurrentSection
== TAB_UNKNOWN
:
411 ErrorMsg
= "%s is not in any defined section" % Line
412 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
, File
=Filename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
417 SectionItemList
.append([Line
, LineNo
])
422 # Insert items data of last section
424 Model
= Section
[CurrentSection
.upper()]
425 InsertSectionItemsIntoDatabase(self
.TblInf
, self
.FileID
, Filename
, Model
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
, self
.RecordSet
)
428 # Replace all DEFINE macros with its actual values
430 ParseDefineMacro2(self
.TblInf
, self
.RecordSet
, GlobalData
.gGlobalDefines
)
432 ## Show detailed information of Module
434 # Print all members and their values of Module class
436 def ShowModule(self
):
438 for Arch
in M
.Header
.keys():
439 print '\nArch =', Arch
440 print 'Filename =', M
.Header
[Arch
].FileName
441 print 'FullPath =', M
.Header
[Arch
].FullPath
442 print 'BaseName =', M
.Header
[Arch
].Name
443 print 'Guid =', M
.Header
[Arch
].Guid
444 print 'Version =', M
.Header
[Arch
].Version
445 print 'InfVersion =', M
.Header
[Arch
].InfVersion
446 print 'UefiSpecificationVersion =', M
.Header
[Arch
].UefiSpecificationVersion
447 print 'EdkReleaseVersion =', M
.Header
[Arch
].EdkReleaseVersion
448 print 'ModuleType =', M
.Header
[Arch
].ModuleType
449 print 'BinaryModule =', M
.Header
[Arch
].BinaryModule
450 print 'ComponentType =', M
.Header
[Arch
].ComponentType
451 print 'MakefileName =', M
.Header
[Arch
].MakefileName
452 print 'BuildNumber =', M
.Header
[Arch
].BuildNumber
453 print 'BuildType =', M
.Header
[Arch
].BuildType
454 print 'FfsExt =', M
.Header
[Arch
].FfsExt
455 print 'FvExt =', M
.Header
[Arch
].FvExt
456 print 'SourceFv =', M
.Header
[Arch
].SourceFv
457 print 'PcdIsDriver =', M
.Header
[Arch
].PcdIsDriver
458 print 'TianoEdkFlashMap_h =', M
.Header
[Arch
].TianoEdkFlashMap_h
459 print 'Shadow =', M
.Header
[Arch
].Shadow
460 print 'LibraryClass =', M
.Header
[Arch
].LibraryClass
461 for Item
in M
.Header
[Arch
].LibraryClass
:
462 print Item
.LibraryClass
, DataType
.TAB_VALUE_SPLIT
.join(Item
.SupModuleList
)
463 print 'CustomMakefile =', M
.Header
[Arch
].CustomMakefile
464 print 'Define =', M
.Header
[Arch
].Define
465 print 'Specification =', M
.Header
[Arch
].Specification
466 for Item
in self
.Module
.ExternImages
:
467 print '\nEntry_Point = %s, UnloadImage = %s' % (Item
.ModuleEntryPoint
, Item
.ModuleUnloadImage
)
468 for Item
in self
.Module
.ExternLibraries
:
469 print 'Constructor = %s, Destructor = %s' % (Item
.Constructor
, Item
.Destructor
)
470 print '\nBuildOptions =', M
.BuildOptions
471 for Item
in M
.BuildOptions
:
472 print Item
.ToolChainFamily
, Item
.ToolChain
, Item
.Option
, Item
.SupArchList
473 print '\nIncludes =', M
.Includes
474 for Item
in M
.Includes
:
475 print Item
.FilePath
, Item
.SupArchList
476 print '\nLibraries =', M
.Libraries
477 for Item
in M
.Libraries
:
478 print Item
.Library
, Item
.SupArchList
479 print '\nLibraryClasses =', M
.LibraryClasses
480 for Item
in M
.LibraryClasses
:
481 print Item
.LibraryClass
, Item
.RecommendedInstance
, Item
.FeatureFlag
, Item
.SupModuleList
, Item
.SupArchList
, Item
.Define
482 print '\nPackageDependencies =', M
.PackageDependencies
483 for Item
in M
.PackageDependencies
:
484 print Item
.FilePath
, Item
.SupArchList
, Item
.FeatureFlag
485 print '\nNmake =', M
.Nmake
487 print Item
.Name
, Item
.Value
, Item
.SupArchList
488 print '\nPcds =', M
.PcdCodes
489 for Item
in M
.PcdCodes
:
490 print '\tCName=', Item
.CName
, 'TokenSpaceGuidCName=', Item
.TokenSpaceGuidCName
, 'DefaultValue=', Item
.DefaultValue
, 'ItemType=', Item
.ItemType
, Item
.SupArchList
491 print '\nSources =', M
.Sources
492 for Source
in M
.Sources
:
493 print Source
.SourceFile
, 'Fam=', Source
.ToolChainFamily
, 'Pcd=', Source
.FeatureFlag
, 'Tag=', Source
.TagName
, 'ToolCode=', Source
.ToolCode
, Source
.SupArchList
494 print '\nUserExtensions =', M
.UserExtensions
495 for UserExtension
in M
.UserExtensions
:
496 print UserExtension
.UserID
, UserExtension
.Identifier
, UserExtension
.Content
497 print '\nGuids =', M
.Guids
499 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
500 print '\nProtocols =', M
.Protocols
501 for Item
in M
.Protocols
:
502 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
503 print '\nPpis =', M
.Ppis
505 print Item
.CName
, Item
.SupArchList
, Item
.FeatureFlag
506 print '\nDepex =', M
.Depex
508 print Item
.Depex
, Item
.SupArchList
, Item
.Define
509 print '\nBinaries =', M
.Binaries
510 for Binary
in M
.Binaries
:
511 print 'Type=', Binary
.FileType
, 'Target=', Binary
.Target
, 'Name=', Binary
.BinaryFile
, 'FeatureFlag=', Binary
.FeatureFlag
, 'SupArchList=', Binary
.SupArchList
513 ## Convert [Defines] section content to ModuleHeaderClass
515 # Convert [Defines] section content to ModuleHeaderClass
517 # @param Defines The content under [Defines] section
518 # @param ModuleHeader An object of ModuleHeaderClass
519 # @param Arch The supported ARCH
521 def GenModuleHeader(self
, ContainerFile
):
522 EdkLogger
.debug(2, "Generate ModuleHeader ...")
523 File
= self
.Identification
.FileFullPath
525 # Update all defines item in database
527 RecordSet
= self
.RecordSet
[MODEL_META_DATA_HEADER
]
528 for Record
in RecordSet
:
529 ValueList
= GetSplitValueList(Record
[0], TAB_EQUAL_SPLIT
)
530 if len(ValueList
) != 2:
531 RaiseParserError(Record
[0], 'Defines', ContainerFile
, '<Key> = <Value>', Record
[2])
532 ID
, Value1
, Value2
, Arch
, LineNo
= Record
[3], ValueList
[0], ValueList
[1], Record
[1], Record
[2]
533 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
534 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Value1
), ConvertToSqlString2(Value2
), ID
)
535 self
.TblInf
.Exec(SqlCommand
)
537 for Arch
in DataType
.ARCH_LIST
:
538 ModuleHeader
= InfHeader()
539 ModuleHeader
.FileName
= self
.Identification
.FileName
540 ModuleHeader
.FullPath
= self
.Identification
.FileFullPath
541 DefineList
= QueryDefinesItem2(self
.TblInf
, Arch
, self
.FileID
)
543 NotProcessedDefineList
= []
545 if D
[0] in ModuleHeader
:
546 ModuleHeader
[D
[0]] = GetSplitValueList(D
[1])[0]
548 NotProcessedDefineList
.append(D
)
550 if ModuleHeader
.ComponentType
== "LIBRARY":
551 Lib
= LibraryClassClass()
552 Lib
.LibraryClass
= ModuleHeader
.Name
553 Lib
.SupModuleList
= DataType
.SUP_MODULE_LIST
554 ModuleHeader
.LibraryClass
.append(Lib
)
556 # we need to make some key defines resolved first
557 for D
in NotProcessedDefineList
:
558 if D
[0] == TAB_INF_DEFINES_LIBRARY_CLASS
:
559 List
= GetSplitValueList(D
[1], DataType
.TAB_VALUE_SPLIT
, 1)
560 Lib
= LibraryClassClass()
561 Lib
.LibraryClass
= CleanString(List
[0])
563 Lib
.SupModuleList
= DataType
.SUP_MODULE_LIST
565 Lib
.SupModuleList
= GetSplitValueList(CleanString(List
[1]), ' ')
566 ModuleHeader
.LibraryClass
.append(Lib
)
567 elif D
[0] == TAB_INF_DEFINES_CUSTOM_MAKEFILE
:
568 List
= D
[1].split(DataType
.TAB_VALUE_SPLIT
)
570 ModuleHeader
.CustomMakefile
[CleanString(List
[0])] = CleanString(List
[1])
572 RaiseParserError(D
[1], 'CUSTOM_MAKEFILE of Defines', File
, 'CUSTOM_MAKEFILE=<Family>|<Filename>', D
[2])
573 elif D
[0] == TAB_INF_DEFINES_ENTRY_POINT
:
574 Image
= ModuleExternImageClass()
575 Image
.ModuleEntryPoint
= CleanString(D
[1])
576 self
.Module
.ExternImages
.append(Image
)
577 elif D
[0] == TAB_INF_DEFINES_UNLOAD_IMAGE
:
578 Image
= ModuleExternImageClass()
579 Image
.ModuleUnloadImage
= CleanString(D
[1])
580 self
.Module
.ExternImages
.append(Image
)
581 elif D
[0] == TAB_INF_DEFINES_CONSTRUCTOR
:
582 LibraryClass
= ModuleExternLibraryClass()
583 LibraryClass
.Constructor
= CleanString(D
[1])
584 self
.Module
.ExternLibraries
.append(LibraryClass
)
585 elif D
[0] == TAB_INF_DEFINES_DESTRUCTOR
:
586 LibraryClass
= ModuleExternLibraryClass()
587 LibraryClass
.Destructor
= CleanString(D
[1])
588 self
.Module
.ExternLibraries
.append(LibraryClass
)
589 elif D
[0] == TAB_INF_DEFINES_DEFINE
:
590 List
= D
[1].split(DataType
.TAB_EQUAL_SPLIT
)
592 RaiseParserError(Item
, 'DEFINE of Defines', File
, 'DEFINE <Word> = <Word>', D
[2])
594 ModuleHeader
.Define
[CleanString(List
[0])] = CleanString(List
[1])
595 elif D
[0] == TAB_INF_DEFINES_SPEC
:
596 List
= D
[1].split(DataType
.TAB_EQUAL_SPLIT
)
598 RaiseParserError(Item
, 'SPEC of Defines', File
, 'SPEC <Word> = <Version>', D
[2])
600 ModuleHeader
.Specification
[CleanString(List
[0])] = CleanString(List
[1])
605 if ModuleHeader
.InfVersion
!= "":
607 VersionNumber
= ModuleHeader
.VersionNumber
608 VersionString
= ModuleHeader
.VersionString
609 if len(VersionNumber
) > 0 and len(VersionString
) == 0:
610 EdkLogger
.warn(2000, 'VERSION_NUMBER depricated; INF file %s should be modified to use VERSION_STRING instead.' % self
.Identification
.FileFullPath
)
611 ModuleHeader
.Version
= VersionNumber
612 if len(VersionString
) > 0:
613 if len(VersionNumber
) > 0:
614 EdkLogger
.warn(2001, 'INF file %s defines both VERSION_NUMBER and VERSION_STRING, using VERSION_STRING' % self
.Identification
.FileFullPath
)
615 ModuleHeader
.Version
= VersionString
618 ModuleHeader
.InfVersion
= "0x00010000"
619 if ModuleHeader
.ComponentType
in gComponentType2ModuleType
:
620 ModuleHeader
.ModuleType
= gComponentType2ModuleType
[ModuleHeader
.ComponentType
]
621 elif ModuleHeader
.ComponentType
!= '':
622 EdkLogger
.error("Parser", PARSER_ERROR
, "Unsupported Edk component type [%s]" % ModuleHeader
.ComponentType
, ExtraData
=File
, RaiseError
=EdkLogger
.IsRaiseError
)
624 self
.Module
.Header
[Arch
] = ModuleHeader
629 # Gen BuildOptions of Inf
630 # [<Family>:]<ToolFlag>=Flag
632 # @param ContainerFile: The Inf file full path
634 def GenBuildOptions(self
, ContainerFile
):
635 EdkLogger
.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS
)
638 # Get all BuildOptions
640 RecordSet
= self
.RecordSet
[MODEL_META_DATA_BUILD_OPTION
]
643 # Go through each arch
645 for Arch
in self
.SupArchList
:
646 for Record
in RecordSet
:
647 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
648 (Family
, ToolChain
, Flag
) = GetBuildOption(Record
[0], ContainerFile
, Record
[2])
649 MergeArches(BuildOptions
, (Family
, ToolChain
, Flag
), Arch
)
653 if self
.IsToDatabase
:
654 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
655 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Family
), ConvertToSqlString2(ToolChain
), ConvertToSqlString2(Flag
), Record
[3])
656 self
.TblInf
.Exec(SqlCommand
)
658 for Key
in BuildOptions
.keys():
659 BuildOption
= BuildOptionClass(Key
[0], Key
[1], Key
[2])
660 BuildOption
.SupArchList
= BuildOptions
[Key
]
661 self
.Module
.BuildOptions
.append(BuildOption
)
665 # Gen Includes of Inf
668 # @param ContainerFile: The Inf file full path
670 def GenIncludes(self
, ContainerFile
):
671 EdkLogger
.debug(2, "Generate %s ..." % TAB_INCLUDES
)
676 RecordSet
= self
.RecordSet
[MODEL_EFI_INCLUDE
]
679 # Go through each arch
681 for Arch
in self
.SupArchList
:
682 for Record
in RecordSet
:
683 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
684 MergeArches(Includes
, Record
[0], Arch
)
686 for Key
in Includes
.keys():
687 Include
= IncludeClass()
688 Include
.FilePath
= NormPath(Key
)
689 Include
.SupArchList
= Includes
[Key
]
690 self
.Module
.Includes
.append(Include
)
694 # Gen Libraries of Inf
697 # @param ContainerFile: The Inf file full path
699 def GenLibraries(self
, ContainerFile
):
700 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARIES
)
705 RecordSet
= self
.RecordSet
[MODEL_EFI_LIBRARY_INSTANCE
]
708 # Go through each arch
710 for Arch
in self
.SupArchList
:
711 for Record
in RecordSet
:
712 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
713 MergeArches(Libraries
, Record
[0], Arch
)
715 for Key
in Libraries
.keys():
716 Library
= ModuleLibraryClass()
717 # replace macro and remove file extension
718 Library
.Library
= Key
.rsplit('.', 1)[0]
719 Library
.SupArchList
= Libraries
[Key
]
720 self
.Module
.Libraries
.append(Library
)
724 # Get LibraryClass of Inf
725 # <LibraryClassKeyWord>|<LibraryInstance>
727 # @param ContainerFile: The Inf file full path
729 def GenLibraryClasses(self
, ContainerFile
):
730 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES
)
733 # Get all LibraryClasses
735 RecordSet
= self
.RecordSet
[MODEL_EFI_LIBRARY_CLASS
]
738 # Go through each arch
740 for Arch
in self
.SupArchList
:
741 for Record
in RecordSet
:
742 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
743 (LibClassName
, LibClassIns
, Pcd
, SupModelList
) = GetLibraryClassOfInf([Record
[0], Record
[4]], ContainerFile
, self
.WorkspaceDir
, Record
[2])
744 MergeArches(LibraryClasses
, (LibClassName
, LibClassIns
, Pcd
, SupModelList
), Arch
)
748 if self
.IsToDatabase
:
749 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
750 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(LibClassName
), ConvertToSqlString2(LibClassIns
), ConvertToSqlString2(SupModelList
), Record
[3])
751 self
.TblInf
.Exec(SqlCommand
)
753 for Key
in LibraryClasses
.keys():
754 KeyList
= Key
[0].split(DataType
.TAB_VALUE_SPLIT
)
755 LibraryClass
= LibraryClassClass()
756 LibraryClass
.LibraryClass
= Key
[0]
757 LibraryClass
.RecommendedInstance
= NormPath(Key
[1])
758 LibraryClass
.FeatureFlag
= Key
[2]
759 LibraryClass
.SupArchList
= LibraryClasses
[Key
]
760 LibraryClass
.SupModuleList
= GetSplitValueList(Key
[3])
761 self
.Module
.LibraryClasses
.append(LibraryClass
)
765 # Gen Packages of Inf
768 # @param ContainerFile: The Inf file full path
770 def GenPackages(self
, ContainerFile
):
771 EdkLogger
.debug(2, "Generate %s ..." % TAB_PACKAGES
)
776 RecordSet
= self
.RecordSet
[MODEL_META_DATA_PACKAGE
]
779 # Go through each arch
781 for Arch
in self
.SupArchList
:
782 for Record
in RecordSet
:
783 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
784 (Package
, Pcd
) = GetPackage(Record
[0], ContainerFile
, self
.WorkspaceDir
, Record
[2])
785 MergeArches(Packages
, (Package
, Pcd
), Arch
)
786 if self
.IsToDatabase
:
787 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
788 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Package
), ConvertToSqlString2(Pcd
), Record
[3])
789 self
.TblInf
.Exec(SqlCommand
)
792 for Key
in Packages
.keys():
793 Package
= ModulePackageDependencyClass()
794 Package
.FilePath
= NormPath(Key
[0])
795 Package
.SupArchList
= Packages
[Key
]
796 Package
.FeatureFlag
= Key
[1]
797 self
.Module
.PackageDependencies
.append(Package
)
804 # @param ContainerFile: The Inf file full path
806 def GenNmakes(self
, ContainerFile
):
807 EdkLogger
.debug(2, "Generate %s ..." % TAB_NMAKE
)
812 RecordSet
= self
.RecordSet
[MODEL_META_DATA_NMAKE
]
816 # Go through each arch
818 for Arch
in self
.SupArchList
:
819 for Record
in RecordSet
:
820 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
821 MergeArches(Nmakes
, Record
[0], Arch
)
823 for Key
in Nmakes
.keys():
824 List
= GetSplitValueList(Key
, DataType
.TAB_EQUAL_SPLIT
, MaxSplit
=1)
826 RaiseParserError(Key
, 'Nmake', ContainerFile
, '<MacroName> = <Value>')
828 Nmake
= ModuleNmakeClass()
830 Nmake
.Value
= List
[1]
831 Nmake
.SupArchList
= Nmakes
[Key
]
832 self
.Module
.Nmake
.append(Nmake
)
834 # convert Edk format to EdkII format
835 if Nmake
.Name
== "IMAGE_ENTRY_POINT":
836 Image
= ModuleExternImageClass()
837 Image
.ModuleEntryPoint
= Nmake
.Value
838 self
.Module
.ExternImages
.append(Image
)
839 elif Nmake
.Name
== "DPX_SOURCE":
840 Source
= ModuleSourceFileClass(NormPath(Nmake
.Value
), "", "", "", "", Nmake
.SupArchList
)
841 self
.Module
.Sources
.append(Source
)
843 ToolList
= gNmakeFlagPattern
.findall(Nmake
.Name
)
844 if len(ToolList
) == 0 or len(ToolList
) != 1:
845 EdkLogger
.warn("\nParser", "Don't know how to do with MACRO: %s" % Nmake
.Name
,
846 ExtraData
=ContainerFile
)
848 if ToolList
[0] in gNmakeFlagName2ToolCode
:
849 Tool
= gNmakeFlagName2ToolCode
[ToolList
[0]]
852 BuildOption
= BuildOptionClass("MSFT", "*_*_*_%s_FLAGS" % Tool
, Nmake
.Value
)
853 BuildOption
.SupArchList
= Nmake
.SupArchList
854 self
.Module
.BuildOptions
.append(BuildOption
)
859 # <TokenSpaceGuidCName>.<PcdCName>[|<Value>]
861 # @param ContainerFile: The Dec file full path
863 def GenPcds(self
, ContainerFile
):
864 EdkLogger
.debug(2, "Generate %s ..." % TAB_PCDS
)
871 RecordSet1
= self
.RecordSet
[MODEL_PCD_FIXED_AT_BUILD
]
872 RecordSet2
= self
.RecordSet
[MODEL_PCD_PATCHABLE_IN_MODULE
]
873 RecordSet3
= self
.RecordSet
[MODEL_PCD_FEATURE_FLAG
]
874 RecordSet4
= self
.RecordSet
[MODEL_PCD_DYNAMIC_EX
]
875 RecordSet5
= self
.RecordSet
[MODEL_PCD_DYNAMIC
]
878 # Go through each arch
880 for Arch
in self
.SupArchList
:
881 for Record
in RecordSet1
:
882 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
883 if self
.Module
.Header
[Arch
].LibraryClass
!= {}:
885 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_FIXED_AT_BUILD
, ContainerFile
, Record
[2])
886 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
887 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
888 for Record
in RecordSet2
:
889 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
890 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_PATCHABLE_IN_MODULE
, ContainerFile
, Record
[2])
891 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
892 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
893 for Record
in RecordSet3
:
894 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
895 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_FEATURE_FLAG
, ContainerFile
, Record
[2])
896 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
897 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
898 for Record
in RecordSet4
:
899 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
900 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], TAB_PCDS_DYNAMIC_EX
, ContainerFile
, Record
[2])
901 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
902 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
903 for Record
in RecordSet5
:
904 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
905 (TokenGuidCName
, TokenName
, Value
, Type
) = GetPcdOfInf(Record
[0], "", ContainerFile
, Record
[2])
906 MergeArches(Pcds
, (TokenGuidCName
, TokenName
, Value
, Type
), Arch
)
907 PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
911 if self
.IsToDatabase
:
912 for Key
in PcdToken
.keys():
913 SqlCommand
= """update %s set Value2 = '%s' where ID = %s""" % (self
.TblInf
.Table
, ".".join((PcdToken
[Key
][0], PcdToken
[Key
][1])), Key
)
914 self
.TblInf
.Exec(SqlCommand
)
916 for Key
in Pcds
.keys():
919 Pcd
.TokenSpaceGuidCName
= Key
[0]
920 Pcd
.DefaultValue
= Key
[2]
921 Pcd
.ItemType
= Key
[3]
922 Pcd
.SupArchList
= Pcds
[Key
]
923 self
.Module
.PcdCodes
.append(Pcd
)
928 # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]
930 # @param ContainerFile: The Dec file full path
932 def GenSources(self
, ContainerFile
):
933 EdkLogger
.debug(2, "Generate %s ..." % TAB_SOURCES
)
939 RecordSet
= self
.RecordSet
[MODEL_EFI_SOURCE_FILE
]
942 # Go through each arch
944 for Arch
in self
.SupArchList
:
945 for Record
in RecordSet
:
946 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
947 (Filename
, Family
, TagName
, ToolCode
, Pcd
) = GetSource(Record
[0], ContainerFile
, self
.Identification
.FileRelativePath
, Record
[2])
948 MergeArches(Sources
, (Filename
, Family
, TagName
, ToolCode
, Pcd
), Arch
)
949 if self
.IsToDatabase
:
950 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s', Value5 = '%s'
951 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Filename
), ConvertToSqlString2(Family
), ConvertToSqlString2(TagName
), ConvertToSqlString2(ToolCode
), ConvertToSqlString2(Pcd
), Record
[3])
952 self
.TblInf
.Exec(SqlCommand
)
954 for Key
in Sources
.keys():
955 Source
= ModuleSourceFileClass(Key
[0], Key
[2], Key
[3], Key
[1], Key
[4], Sources
[Key
])
956 self
.Module
.Sources
.append(Source
)
960 # Gen UserExtensions of Inf
962 def GenUserExtensions(self
, ContainerFile
):
966 # if self.UserExtensions != '':
967 # UserExtension = UserExtensionsClass()
968 # Lines = self.UserExtensions.splitlines()
969 # List = GetSplitValueList(Lines[0], DataType.TAB_SPLIT, 2)
971 # RaiseParserError(Lines[0], 'UserExtensions', File, "UserExtensions.UserId.'Identifier'")
973 # UserExtension.UserID = List[1]
974 # UserExtension.Identifier = List[2][0:-1].replace("'", '').replace('\"', '')
975 # for Line in Lines[1:]:
976 # UserExtension.Content = UserExtension.Content + CleanString(Line) + '\n'
977 # self.Module.UserExtensions.append(UserExtension)
984 # @param ContainerFile: The Inf file full path
986 def GenDepexes(self
, ContainerFile
):
987 EdkLogger
.debug(2, "Generate %s ..." % TAB_DEPEX
)
992 RecordSet
= self
.RecordSet
[MODEL_EFI_DEPEX
]
995 # Go through each arch
997 for Arch
in self
.SupArchList
:
999 for Record
in RecordSet
:
1000 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
1001 Line
= Line
+ Record
[0] + ' '
1003 MergeArches(Depex
, Line
, Arch
)
1005 for Key
in Depex
.keys():
1006 Dep
= ModuleDepexClass()
1008 Dep
.SupArchList
= Depex
[Key
]
1009 self
.Module
.Depex
.append(Dep
)
1014 # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]
1016 # @param ContainerFile: The Dec file full path
1018 def GenBinaries(self
, ContainerFile
):
1019 EdkLogger
.debug(2, "Generate %s ..." % TAB_BINARIES
)
1025 RecordSet
= self
.RecordSet
[MODEL_EFI_BINARY_FILE
]
1028 # Go through each arch
1030 for Arch
in self
.SupArchList
:
1031 for Record
in RecordSet
:
1032 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
1033 (FileType
, Filename
, Target
, Pcd
) = GetBinary(Record
[0], ContainerFile
, self
.Identification
.FileRelativePath
, Record
[2])
1034 MergeArches(Binaries
, (FileType
, Filename
, Target
, Pcd
), Arch
)
1035 if self
.IsToDatabase
:
1036 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s'
1037 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(FileType
), ConvertToSqlString2(Filename
), ConvertToSqlString2(Target
), ConvertToSqlString2(Pcd
), Record
[3])
1038 self
.TblInf
.Exec(SqlCommand
)
1040 for Key
in Binaries
.keys():
1041 Binary
= ModuleBinaryFileClass(NormPath(Key
[1]), Key
[0], Key
[2], Key
[3], Binaries
[Key
])
1042 self
.Module
.Binaries
.append(Binary
)
1047 # <CName>=<GuidValue>
1049 # @param ContainerFile: The Inf file full path
1051 def GenGuidProtocolPpis(self
, Type
, ContainerFile
):
1052 EdkLogger
.debug(2, "Generate %s ..." % Type
)
1057 RecordSet
= self
.RecordSet
[Section
[Type
.upper()]]
1060 # Go through each arch
1062 for Arch
in self
.SupArchList
:
1063 for Record
in RecordSet
:
1064 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
:
1065 (Name
, Value
) = GetGuidsProtocolsPpisOfInf(Record
[0], Type
, ContainerFile
, Record
[2])
1066 MergeArches(Lists
, (Name
, Value
), Arch
)
1067 if self
.IsToDatabase
:
1068 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
1069 where ID = %s""" % (self
.TblInf
.Table
, ConvertToSqlString2(Name
), ConvertToSqlString2(Value
), Record
[3])
1070 self
.TblInf
.Exec(SqlCommand
)
1073 if Type
== TAB_GUIDS
:
1074 ListMember
= self
.Module
.Guids
1075 elif Type
== TAB_PROTOCOLS
:
1076 ListMember
= self
.Module
.Protocols
1077 elif Type
== TAB_PPIS
:
1078 ListMember
= self
.Module
.Ppis
1080 for Key
in Lists
.keys():
1081 ListClass
= GuidProtocolPpiCommonClass()
1082 ListClass
.CName
= Key
[0]
1083 ListClass
.SupArchList
= Lists
[Key
]
1084 ListClass
.FeatureFlag
= Key
[1]
1085 ListMember
.append(ListClass
)
1089 # This acts like the main() function for the script, unless it is 'import'ed into another
1092 if __name__
== '__main__':
1093 EdkLogger
.Initialize()
1094 EdkLogger
.SetLevel(EdkLogger
.DEBUG_0
)
1096 W
= os
.getenv('WORKSPACE')
1097 F
= os
.path
.join(W
, 'MdeModulePkg/Application/HelloWorld/HelloWorld.inf')
1099 Db
= Database
.Database('Inf.db')
1102 P
= Inf(os
.path
.normpath(F
), True, True, W
, Db
)