## @file
# This file is used to define each component of INF file
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
# Import Modules
#
import os
import re
import EdkLogger
from CommonDataClass.ModuleClass import *
from String import *
from DataType import *
from Identification import *
from Dictionary import *
from BuildToolError import *
import GlobalData
import Database
from Parsing import *
#
# Global variable
#
}
"LIBRARY" : "BASE",
"SECURITY_CORE" : "SEC",
"PEI_CORE" : "PEI_CORE",
"COMBINED_PEIM_DRIVER" : "PEIM",
"PIC_PEIM" : "PEIM",
"RELOCATABLE_PEIM" : "PEIM",
"PE32_PEIM" : "PEIM",
"BS_DRIVER" : "DXE_DRIVER",
"RT_DRIVER" : "DXE_RUNTIME_DRIVER",
"SAL_RT_DRIVER" : "DXE_SAL_DRIVER",
"APPLICATION" : "UEFI_APPLICATION",
"LOGO" : "BASE",
}
gNmakeFlagPattern = re.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re.UNICODE)
"C" : "CC",
"LIB" : "SLINK",
"LINK" : "DLINK",
}
_Mapping_ = {
#
# Required Fields
#
TAB_INF_DEFINES_BASE_NAME : "Name",
TAB_INF_DEFINES_FILE_GUID : "Guid",
TAB_INF_DEFINES_MODULE_TYPE : "ModuleType",
TAB_INF_DEFINES_EFI_SPECIFICATION_VERSION : "UefiSpecificationVersion",
TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION : "UefiSpecificationVersion",
TAB_INF_DEFINES_EDK_RELEASE_VERSION : "EdkReleaseVersion",
#
# Optional Fields
#
TAB_INF_DEFINES_INF_VERSION : "InfVersion",
TAB_INF_DEFINES_BINARY_MODULE : "BinaryModule",
TAB_INF_DEFINES_COMPONENT_TYPE : "ComponentType",
TAB_INF_DEFINES_MAKEFILE_NAME : "MakefileName",
TAB_INF_DEFINES_BUILD_NUMBER : "BuildNumber",
TAB_INF_DEFINES_BUILD_TYPE : "BuildType",
TAB_INF_DEFINES_FFS_EXT : "FfsExt",
TAB_INF_DEFINES_FV_EXT : "FvExt",
TAB_INF_DEFINES_SOURCE_FV : "SourceFv",
TAB_INF_DEFINES_VERSION_NUMBER : "VersionNumber",
TAB_INF_DEFINES_VERSION_STRING : "VersionString",
TAB_INF_DEFINES_VERSION : "Version",
TAB_INF_DEFINES_PCD_IS_DRIVER : "PcdIsDriver",
TAB_INF_DEFINES_TIANO_EDK_FLASHMAP_H : "TianoEdkFlashMap_h",
TAB_INF_DEFINES_SHADOW : "Shadow",
# TAB_INF_DEFINES_LIBRARY_CLASS : "LibraryClass",
# TAB_INF_DEFINES_ENTRY_POINT : "ExternImages",
# TAB_INF_DEFINES_UNLOAD_IMAGE : "ExternImages",
# TAB_INF_DEFINES_CONSTRUCTOR : ,
# TAB_INF_DEFINES_DESTRUCTOR : ,
# TAB_INF_DEFINES_DEFINE : "Define",
# TAB_INF_DEFINES_SPEC : "Specification",
# TAB_INF_DEFINES_CUSTOM_MAKEFILE : "CustomMakefile",
# TAB_INF_DEFINES_MACRO :
}
#print self.__dict__
## "in" test support
## InfObject
#
# This class defined basic Inf object which is used by inheriting
#
# @param object: Inherited from object class
#
## Inf
#
# This class defined the structure used in Inf object
#
# @param InfObject: Inherited from InfObject class
# @param Ffilename: Input value for Ffilename of Inf file, default is None
# @param IsMergeAllArches: Input value for IsMergeAllArches
# True is to merge all arches
# Fales is not to merge all arches
# default is False
# @param IsToModule: Input value for IsToModule
# True is to transfer to ModuleObject automatically
# False is not to transfer to ModuleObject automatically
# default is False
# @param WorkspaceDir: Input value for current workspace directory, default is None
#
# @var Identification: To store value for Identification, it is a structure as Identification
# @var UserExtensions: To store value for UserExtensions
# @var Module: To store value for Module, it is a structure as ModuleClass
# @var WorkspaceDir: To store value for WorkspaceDir
# @var KeyList: To store value for KeyList, a list for all Keys used in Inf
#
def __init__(self, Filename=None, IsToDatabase=False, IsToModule=False, WorkspaceDir=None, Database=None, SupArchList=DataType.ARCH_LIST):
#self.TblInf = TableInf(Database.Cur)
]
#
# Upper all KEYs to ignore case sensitive when parsing
#
#
# Init RecordSet
#
#
# Load Inf file if filename is not None
#
if Filename != None:
#
# Transfer to Module Object if IsToModule is True
#
if IsToModule:
## Transfer to Module Object
#
# Transfer all contents of an Inf file to a standard Module Object
#
#
# Init global information for the file
#
#
# Generate Package Header
#
#
# Generate BuildOptions
#
#
# Generate Includes
#
#
# Generate Libraries
#
#
# Generate LibraryClasses
#
#
# Generate Packages
#
#
# Generate Nmakes
#
#
# Generate Pcds
#
#
# Generate Sources
#
#
# Generate UserExtensions
#
#
# Generate Guids
#
#
# Generate Protocols
#
#
# Generate Ppis
#
#
# Generate Depexes
#
#
# Generate Binaries
#
## Parse [Defines] section
#
# Parse [Defines] section into InfDefines object
#
# @param InfFile The path of the INF file
# @param Section The title of "Defines" section
# @param Lines The content of "Defines" section
#
else:
## Load Inf file
#
# Load the file if it exists
#
# @param Filename: Input value for filename of Inf file
#
#
# Insert a record for file
#
#
# Init InfTable
#
#self.TblInf.Table = "Inf%s" % self.FileID
#self.TblInf.Create()
#
# Init common datas
#
[], [], TAB_UNKNOWN, [], [], []
LineNo = 0
#
# Parse file content
#
ReservedLine = ''
#
# Remove comment block
#
ReservedLine = ''
continue
#
# Remove comments at tail and remove spaces again
#
if Line == '':
continue
#
# Find a new section tab
# First insert previous section items
# And then parse the content of the new section
#
continue
#
# Insert items data of previous section
#
InsertSectionItemsIntoDatabase(self.TblInf, self.FileID, Filename, Model, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList, self.RecordSet)
#
# Parse the new section
#
SectionItemList = []
ArchList = []
ThirdList = []
CurrentSection = ''
LineList = GetSplitValueList(Line[len(TAB_SECTION_START):len(Line) - len(TAB_SECTION_END)], TAB_COMMA_SPLIT)
if CurrentSection == '':
else:
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)
continue
else:
EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo, RaiseError=EdkLogger.IsRaiseError)
continue
#
# Not in any defined section
#
if CurrentSection == TAB_UNKNOWN:
EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo, RaiseError=EdkLogger.IsRaiseError)
#
# Add a section item
#
# End of parse
#End of For
#
# Insert items data of last section
#
InsertSectionItemsIntoDatabase(self.TblInf, self.FileID, Filename, Model, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList, self.RecordSet)
#
# Replace all DEFINE macros with its actual values
#
## Show detailed information of Module
#
# Print all members and their values of Module class
#
print '\nArch =', Arch
print '\nBuildOptions =', M.BuildOptions
for Item in M.BuildOptions:
print '\nIncludes =', M.Includes
print '\nLibraries =', M.Libraries
print '\nLibraryClasses =', M.LibraryClasses
for Item in M.LibraryClasses:
print Item.LibraryClass, Item.RecommendedInstance, Item.FeatureFlag, Item.SupModuleList, Item.SupArchList, Item.Define
print '\nPackageDependencies =', M.PackageDependencies
for Item in M.PackageDependencies:
print '\nNmake =', M.Nmake
print '\nPcds =', M.PcdCodes
print '\tCName=', Item.CName, 'TokenSpaceGuidCName=', Item.TokenSpaceGuidCName, 'DefaultValue=', Item.DefaultValue, 'ItemType=', Item.ItemType, Item.SupArchList
print '\nSources =', M.Sources
print Source.SourceFile, 'Fam=', Source.ToolChainFamily, 'Pcd=', Source.FeatureFlag, 'Tag=', Source.TagName, 'ToolCode=', Source.ToolCode, Source.SupArchList
print '\nUserExtensions =', M.UserExtensions
for UserExtension in M.UserExtensions:
print '\nGuids =', M.Guids
print '\nProtocols =', M.Protocols
print '\nPpis =', M.Ppis
print '\nDepex =', M.Depex
print '\nBinaries =', M.Binaries
print 'Type=', Binary.FileType, 'Target=', Binary.Target, 'Name=', Binary.BinaryFile, 'FeatureFlag=', Binary.FeatureFlag, 'SupArchList=', Binary.SupArchList
## Convert [Defines] section content to ModuleHeaderClass
#
# Convert [Defines] section content to ModuleHeaderClass
#
# @param Defines The content under [Defines] section
# @param ModuleHeader An object of ModuleHeaderClass
# @param Arch The supported ARCH
#
#
# Update all defines item in database
#
SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'
where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Value1), ConvertToSqlString2(Value2), ID)
for D in DefineList:
if D[0] in ModuleHeader:
else:
Lib = LibraryClassClass()
# we need to make some key defines resolved first
for D in NotProcessedDefineList:
if D[0] == TAB_INF_DEFINES_LIBRARY_CLASS:
Lib = LibraryClassClass()
elif D[0] == TAB_INF_DEFINES_CUSTOM_MAKEFILE:
else:
RaiseParserError(D[1], 'CUSTOM_MAKEFILE of Defines', File, 'CUSTOM_MAKEFILE=<Family>|<Filename>', D[2])
elif D[0] == TAB_INF_DEFINES_ENTRY_POINT:
elif D[0] == TAB_INF_DEFINES_UNLOAD_IMAGE:
elif D[0] == TAB_INF_DEFINES_CONSTRUCTOR:
elif D[0] == TAB_INF_DEFINES_DESTRUCTOR:
elif D[0] == TAB_INF_DEFINES_DEFINE:
else:
elif D[0] == TAB_INF_DEFINES_SPEC:
else:
#
# Get version of INF
#
# EdkII inf
EdkLogger.warn(2000, 'VERSION_NUMBER depricated; INF file %s should be modified to use VERSION_STRING instead.' % self.Identification.FileFullPath)
EdkLogger.warn(2001, 'INF file %s defines both VERSION_NUMBER and VERSION_STRING, using VERSION_STRING' % self.Identification.FileFullPath)
else:
# Edk inf
EdkLogger.error("Parser", PARSER_ERROR, "Unsupported Edk component type [%s]" % ModuleHeader.ComponentType, ExtraData=File, RaiseError=EdkLogger.IsRaiseError)
## GenBuildOptions
#
# Gen BuildOptions of Inf
# [<Family>:]<ToolFlag>=Flag
#
# @param ContainerFile: The Inf file full path
#
BuildOptions = {}
#
# Get all BuildOptions
#
#
# Go through each arch
#
#
# Update to Database
#
if self.IsToDatabase:
SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Family), ConvertToSqlString2(ToolChain), ConvertToSqlString2(Flag), Record[3])
## GenIncludes
#
# Gen Includes of Inf
#
#
# @param ContainerFile: The Inf file full path
#
#
# Get all Includes
#
#
# Go through each arch
#
Include = IncludeClass()
## GenLibraries
#
# Gen Libraries of Inf
#
#
# @param ContainerFile: The Inf file full path
#
#
# Get all Includes
#
#
# Go through each arch
#
# replace macro and remove file extension
## GenLibraryClasses
#
# Get LibraryClass of Inf
# <LibraryClassKeyWord>|<LibraryInstance>
#
# @param ContainerFile: The Inf file full path
#
LibraryClasses = {}
#
# Get all LibraryClasses
#
#
# Go through each arch
#
(LibClassName, LibClassIns, Pcd, SupModelList) = GetLibraryClassOfInf([Record[0], Record[4]], ContainerFile, self.WorkspaceDir, Record[2])
#
# Update to Database
#
if self.IsToDatabase:
SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(LibClassName), ConvertToSqlString2(LibClassIns), ConvertToSqlString2(SupModelList), Record[3])
## GenPackages
#
# Gen Packages of Inf
#
#
# @param ContainerFile: The Inf file full path
#
Packages = {}
#
# Get all Packages
#
#
# Go through each arch
#
if self.IsToDatabase:
SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'
where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Package), ConvertToSqlString2(Pcd), Record[3])
## GenNmakes
#
# Gen Nmakes of Inf
#
#
# @param ContainerFile: The Inf file full path
#
#
# Get all Nmakes
#
#
# Go through each arch
#
continue
# convert Edk format to EdkII format
else:
else:
else:
## GenPcds
#
# Gen Pcds of Inf
# <TokenSpaceGuidCName>.<PcdCName>[|<Value>]
#
# @param ContainerFile: The Dec file full path
#
Pcds = {}
PcdToken = {}
#
# Get all Guids
#
#
# Go through each arch
#
for Record in RecordSet1:
pass
(TokenGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], TAB_PCDS_FIXED_AT_BUILD, ContainerFile, Record[2])
for Record in RecordSet2:
(TokenGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], TAB_PCDS_PATCHABLE_IN_MODULE, ContainerFile, Record[2])
for Record in RecordSet3:
(TokenGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], TAB_PCDS_FEATURE_FLAG, ContainerFile, Record[2])
for Record in RecordSet4:
(TokenGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], TAB_PCDS_DYNAMIC_EX, ContainerFile, Record[2])
for Record in RecordSet5:
#
# Update to database
#
if self.IsToDatabase:
SqlCommand = """update %s set Value2 = '%s' where ID = %s""" % (self.TblInf.Table, ".".join((PcdToken[Key][0], PcdToken[Key][1])), Key)
## GenSources
#
# Gen Sources of Inf
# <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]
#
# @param ContainerFile: The Dec file full path
#
Sources = {}
#
# Get all Nmakes
#
#
# Go through each arch
#
(Filename, Family, TagName, ToolCode, Pcd) = GetSource(Record[0], ContainerFile, self.Identification.FileRelativePath, Record[2])
if self.IsToDatabase:
SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s', Value5 = '%s'
where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Filename), ConvertToSqlString2(Family), ConvertToSqlString2(TagName), ConvertToSqlString2(ToolCode), ConvertToSqlString2(Pcd), Record[3])
## GenUserExtensions
#
# Gen UserExtensions of Inf
#
# #
# # UserExtensions
# #
# if self.UserExtensions != '':
# UserExtension = UserExtensionsClass()
# Lines = self.UserExtensions.splitlines()
# List = GetSplitValueList(Lines[0], DataType.TAB_SPLIT, 2)
# if len(List) != 3:
# RaiseParserError(Lines[0], 'UserExtensions', File, "UserExtensions.UserId.'Identifier'")
# else:
# UserExtension.UserID = List[1]
# UserExtension.Identifier = List[2][0:-1].replace("'", '').replace('\"', '')
# for Line in Lines[1:]:
# UserExtension.Content = UserExtension.Content + CleanString(Line) + '\n'
# self.Module.UserExtensions.append(UserExtension)
pass
## GenDepexes
#
# Gen Depex of Inf
#
# @param ContainerFile: The Inf file full path
#
Depex = {}
#
# Get all Depexes
#
#
# Go through each arch
#
Line = ''
if Line != '':
Dep = ModuleDepexClass()
## GenBinaries
#
# Gen Binary of Inf
# <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]
#
# @param ContainerFile: The Dec file full path
#
Binaries = {}
#
# Get all Guids
#
#
# Go through each arch
#
(FileType, Filename, Target, Pcd) = GetBinary(Record[0], ContainerFile, self.Identification.FileRelativePath, Record[2])
if self.IsToDatabase:
SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s'
where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(FileType), ConvertToSqlString2(Filename), ConvertToSqlString2(Target), ConvertToSqlString2(Pcd), Record[3])
## GenGuids
#
# Gen Guids of Inf
# <CName>=<GuidValue>
#
# @param ContainerFile: The Inf file full path
#
Lists = {}
#
# Get all Items
#
#
# Go through each arch
#
if self.IsToDatabase:
SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'
where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Name), ConvertToSqlString2(Value), Record[3])
ListMember = None
elif Type == TAB_PROTOCOLS:
##
#
# This acts like the main() function for the script, unless it is 'import'ed into another
# script.
#
if __name__ == '__main__':
P.ShowModule()