## @file
# This file is used to define each component of DEC file
#
# Copyright (c) 2007, 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
from String import *
from DataType import *
from Identification import *
from Dictionary import *
from CommonDataClass.PackageClass import *
from BuildToolError import *
import Database
from Parsing import *
import GlobalData
#
# Global variable
#
}
## DecObject
#
# This class defined basic Dec object which is used by inheriting
#
# @param object: Inherited from object class
#
## Dec
#
# This class defined the structure used in Dec object
#
# @param DecObject: Inherited from DecObject class
# @param Filename: Input value for Filename of Dec 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 IsToPackage: Input value for IsToPackage
# True is to transfer to PackageObject automatically
# False is not to transfer to PackageObject 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 Defines: To store value for Defines, it is a structure as DecDefines
# @var UserExtensions: To store value for UserExtensions
# @var Package: To store value for Package, it is a structure as PackageClass
# @var WorkspaceDir: To store value for WorkspaceDir
# @var Contents: To store value for Contents, it is a structure as DecContents
# @var KeyList: To store value for KeyList, a list for all Keys used in Dec
#
def __init__(self, Filename=None, IsToDatabase=False, IsToPackage=False, WorkspaceDir=None, Database=None, SupArchList=DataType.ARCH_LIST):
]
#
# Upper all KEYs to ignore case sensitive when parsing
#
#
# Init RecordSet
#
#
# Load Dec file if filename is not None
#
if Filename != None:
#
# Transfer to Package Object if IsToPackage is True
#
if IsToPackage:
## Load Dec file
#
# Load the file if it exists
#
# @param Filename: Input value for filename of Dec file
#
#
# Insert a record for file
#
#
# Init DecTable
#
#self.TblDec.Table = "Dec%s" % self.FileID
#self.TblDec.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
#
#
# Insert items data of previous section
#
InsertSectionItemsIntoDatabase(self.TblDec, 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)
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.TblDec, self.FileID, Filename, Model, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList, self.RecordSet)
#
# Replace all DEFINE macros with its actual values
#
## Transfer to Package Object
#
# Transfer all contents of a Dec file to a standard Package Object
#
#
# Init global information for the file
#
#
# Generate Package Header
#
#
# Generate Includes
#
#
# Generate Guids
#
#
# Generate Protocols
#
#
# Generate Ppis
#
#
# Generate LibraryClasses
#
#
# Generate Pcds
#
## Get Package Header
#
# Gen Package Header of Dec as <Key> = <Value>
#
# @param ContainerFile: The Dec file full path
#
#
# Update all defines item in database
#
SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'
where ID = %s""" % (self.TblDec.Table, ConvertToSqlString2(Value1), ConvertToSqlString2(Value2), ID)
#
# Get detailed information
#
PackageHeader.Name = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_NAME, Arch, self.FileID)[0]
PackageHeader.Guid = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_GUID, Arch, self.FileID)[0]
PackageHeader.Version = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_VERSION, Arch, self.FileID)[0]
PackageHeader.DecSpecification = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_DEC_SPECIFICATION, Arch, self.FileID)[0]
## GenIncludes
#
# Gen Includes of Dec
#
#
# @param ContainerFile: The Dec file full path
#
Includes = {}
#
# Get all Includes
#
#
# Go through each arch
#
Include = IncludeClass()
## GenPpis
#
# Gen Ppis of Dec
# <CName>=<GuidValue>
#
# @param ContainerFile: The Dec 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.TblDec.Table, ConvertToSqlString2(Name), ConvertToSqlString2(Value), Record[3])
ListMember = None
elif Type == TAB_PROTOCOLS:
## GenLibraryClasses
#
# Gen LibraryClasses of Dec
# <CName>=<GuidValue>
#
# @param ContainerFile: The Dec file full path
#
LibraryClasses = {}
#
# Get all Guids
#
#
# Go through each arch
#
RaiseParserError(Record[0], 'LibraryClasses', ContainerFile, '<LibraryClassName>|<LibraryClassInstanceFilename>', Record[2])
else:
CheckFileExist(self.Identification.FileRelativePath, List[1], ContainerFile, 'LibraryClasses', Record[0])
if self.IsToDatabase:
SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
where ID = %s""" % (self.TblDec.Table, ConvertToSqlString2(List[0]), ConvertToSqlString2(List[1]), SUP_MODULE_LIST_STRING, Record[3])
## GenPcds
#
# Gen Pcds of Dec
# <TokenSpcCName>.<TokenCName>|<Value>|<DatumType>|<Token>
#
# @param ContainerFile: The Dec file full path
#
Pcds = {}
PcdToken = {}
#
# Get all Guids
#
#
# Go through each arch
#
for Record in RecordSet1:
(TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_FIXED_AT_BUILD, ContainerFile, Record[2])
for Record in RecordSet2:
(TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_PATCHABLE_IN_MODULE, ContainerFile, Record[2])
for Record in RecordSet3:
(TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_FEATURE_FLAG, ContainerFile, Record[2])
for Record in RecordSet4:
(TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_DYNAMIC_EX, ContainerFile, Record[2])
for Record in RecordSet5:
(TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_DYNAMIC, ContainerFile, Record[2])
#
# Update to database
#
if self.IsToDatabase:
SqlCommand = """update %s set Value2 = '%s' where ID = %s""" % (self.TblDec.Table, ".".join((PcdToken[Key][0], PcdToken[Key][1])), Key)
## Show detailed information of Package
#
# Print all members and their values of Package class
#
print '\nArch =', Arch
print '\nIncludes =', M.Includes
print '\nGuids =', M.GuidDeclarations
for Item in M.GuidDeclarations:
print '\nProtocols =', M.ProtocolDeclarations
for Item in M.ProtocolDeclarations:
print '\nPpis =', M.PpiDeclarations
for Item in M.PpiDeclarations:
print '\nLibraryClasses =', M.LibraryClassDeclarations
for Item in M.LibraryClassDeclarations:
print '\nPcds =', M.PcdDeclarations
for Item in M.PcdDeclarations:
print 'CName=', Item.CName, 'TokenSpaceGuidCName=', Item.TokenSpaceGuidCName, 'DefaultValue=', Item.DefaultValue, 'ItemType=', Item.ItemType, 'Token=', Item.Token, 'DatumType=', Item.DatumType, Item.SupArchList
##
#
# This acts like the main() function for the script, unless it is 'import'ed into another
# script.
#
if __name__ == '__main__':
P.ShowPackage()