Sync BaseTools Branch (version r2271) to EDKII main trunk.
BaseTool Branch: https://edk2-buildtools.svn.sourceforge.net/svnroot/edk2-buildtools/branches/Releases/BaseTools_r2100 Signed-off-by: lgao4 Reviewed-by: hchen30 git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12214 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
879
BaseTools/Source/Python/UPT/Xml/CommonXml.py
Normal file
879
BaseTools/Source/Python/UPT/Xml/CommonXml.py
Normal file
@@ -0,0 +1,879 @@
|
||||
## @file
|
||||
# This file is used to parse a PCD file of .PKG file
|
||||
#
|
||||
# Copyright (c) 2011, 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
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
'''
|
||||
CommonXml
|
||||
'''
|
||||
|
||||
##
|
||||
# Import Modules
|
||||
#
|
||||
|
||||
from Core.DistributionPackageClass import DistributionPackageHeaderObject
|
||||
from Library.String import ConvertNEToNOTEQ
|
||||
from Library.String import ConvertNOTEQToNE
|
||||
from Library.String import GetSplitValueList
|
||||
from Library.String import GetStringOfList
|
||||
from Library.Xml.XmlRoutines import XmlElement
|
||||
from Library.Xml.XmlRoutines import XmlElement2
|
||||
from Library.Xml.XmlRoutines import XmlAttribute
|
||||
from Library.Xml.XmlRoutines import XmlNode
|
||||
from Library.Xml.XmlRoutines import XmlList
|
||||
from Library.Xml.XmlRoutines import CreateXmlElement
|
||||
from Object.POM.CommonObject import FileObject
|
||||
from Object.POM.CommonObject import MiscFileObject
|
||||
from Object.POM.CommonObject import UserExtensionObject
|
||||
from Object.POM.CommonObject import ClonedRecordObject
|
||||
from Object.POM.CommonObject import LibraryClassObject
|
||||
from Object.POM.CommonObject import FileNameObject
|
||||
from Object.POM.ModuleObject import ModuleObject
|
||||
from Xml.XmlParserMisc import IsRequiredItemListNull
|
||||
from Xml.XmlParserMisc import GetHelpTextList
|
||||
|
||||
import Library.DataType as DataType
|
||||
|
||||
##
|
||||
# ClonedFromXml
|
||||
#
|
||||
class ClonedFromXml(object):
|
||||
def __init__(self):
|
||||
self.GUID = ''
|
||||
self.Version = ''
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.GUID = XmlElement(Item, '%s/GUID' % Key)
|
||||
self.Version = XmlAttribute(XmlNode(Item, '%s/GUID' % Key), 'Version')
|
||||
|
||||
if self.GUID == '' and self.Version == '':
|
||||
return None
|
||||
|
||||
ClonedFrom = ClonedRecordObject()
|
||||
ClonedFrom.SetPackageGuid(self.GUID)
|
||||
ClonedFrom.SetPackageVersion(self.Version)
|
||||
|
||||
return ClonedFrom
|
||||
|
||||
def ToXml(self, ClonedFrom, Key):
|
||||
if self.GUID:
|
||||
pass
|
||||
Element1 = CreateXmlElement('GUID', ClonedFrom.GetPackageGuid(), [],
|
||||
[['Version', ClonedFrom.GetPackageVersion()]])
|
||||
AttributeList = []
|
||||
NodeList = [Element1]
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
return "GUID = %s Version = %s" % (self.GUID, self.Version)
|
||||
|
||||
|
||||
##
|
||||
# CommonDefinesXml
|
||||
#
|
||||
class CommonDefinesXml(object):
|
||||
def __init__(self):
|
||||
self.Usage = ''
|
||||
self.SupArchList = []
|
||||
self.SupModList = []
|
||||
self.FeatureFlag = ''
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
if Key:
|
||||
pass
|
||||
self.Usage = XmlAttribute(Item, 'Usage')
|
||||
self.SupArchList = \
|
||||
[Arch for Arch in GetSplitValueList(XmlAttribute(Item, 'SupArchList'), DataType.TAB_SPACE_SPLIT) if Arch]
|
||||
self.SupModList = \
|
||||
[Mod for Mod in GetSplitValueList(XmlAttribute(Item, 'SupModList'), DataType.TAB_SPACE_SPLIT) if Mod]
|
||||
self.FeatureFlag = ConvertNOTEQToNE(XmlAttribute(Item, 'FeatureFlag'))
|
||||
|
||||
|
||||
def ToXml(self):
|
||||
pass
|
||||
|
||||
def __str__(self):
|
||||
return "Usage = %s SupArchList = %s SupModList = %s FeatureFlag = %s" \
|
||||
% (self.Usage, self.SupArchList, self.SupModList, self.FeatureFlag)
|
||||
|
||||
|
||||
##
|
||||
# HelpTextXml
|
||||
#
|
||||
class HelpTextXml(object):
|
||||
def __init__(self):
|
||||
self.HelpText = ''
|
||||
self.Lang = ''
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
if Key:
|
||||
pass
|
||||
self.HelpText = XmlElement2(Item, 'HelpText')
|
||||
self.Lang = XmlAttribute(Item, 'Lang')
|
||||
|
||||
def ToXml(self, HelpText, Key='HelpText'):
|
||||
if self.HelpText:
|
||||
pass
|
||||
return CreateXmlElement('%s' % Key, HelpText.GetString(), [], [['Lang', HelpText.GetLang()]])
|
||||
def __str__(self):
|
||||
return "HelpText = %s Lang = %s" % (self.HelpText, self.Lang)
|
||||
|
||||
##
|
||||
# HeaderXml
|
||||
#
|
||||
class HeaderXml(object):
|
||||
def __init__(self):
|
||||
self.Name = ''
|
||||
self.BaseName = ''
|
||||
self.GUID = ''
|
||||
self.Version = ''
|
||||
self.Copyright = ''
|
||||
self.License = ''
|
||||
self.Abstract = ''
|
||||
self.Description = ''
|
||||
|
||||
def FromXml(self, Item, Key, IsRequiredCheck=False, IsStandAlongModule=False):
|
||||
if not Item and IsRequiredCheck:
|
||||
XmlTreeLevel = []
|
||||
if IsStandAlongModule:
|
||||
XmlTreeLevel = ['DistributionPackage', 'ModuleSurfaceArea']
|
||||
else:
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'ModuleSurfaceArea']
|
||||
CheckDict = {'Header':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
self.Name = XmlElement(Item, '%s/Name' % Key)
|
||||
self.BaseName = XmlAttribute(XmlNode(Item, '%s/Name' % Key), 'BaseName')
|
||||
self.GUID = XmlElement(Item, '%s/GUID' % Key)
|
||||
self.Version = XmlAttribute(XmlNode(Item, '%s/GUID' % Key), 'Version')
|
||||
self.Copyright = XmlElement(Item, '%s/Copyright' % Key)
|
||||
self.License = XmlElement(Item, '%s/License' % Key)
|
||||
self.Abstract = XmlElement(Item, '%s/Abstract' % Key)
|
||||
self.Description = XmlElement(Item, '%s/Description' % Key)
|
||||
|
||||
ModuleHeader = ModuleObject()
|
||||
ModuleHeader.SetName(self.Name)
|
||||
ModuleHeader.SetBaseName(self.BaseName)
|
||||
ModuleHeader.SetGuid(self.GUID)
|
||||
ModuleHeader.SetVersion(self.Version)
|
||||
ModuleHeader.SetCopyright(self.Copyright)
|
||||
ModuleHeader.SetLicense(self.License)
|
||||
ModuleHeader.SetAbstract(self.Abstract)
|
||||
ModuleHeader.SetDescription(self.Description)
|
||||
|
||||
return ModuleHeader
|
||||
|
||||
def ToXml(self, Header, Key):
|
||||
if self.GUID:
|
||||
pass
|
||||
Element1 = CreateXmlElement('Name', Header.GetName(), [], [['BaseName', Header.GetBaseName()]])
|
||||
Element2 = CreateXmlElement('GUID', Header.GetGuid(), [], [['Version', Header.GetVersion()]])
|
||||
AttributeList = []
|
||||
NodeList = [Element1,
|
||||
Element2,
|
||||
['Copyright', Header.GetCopyright()],
|
||||
['License', Header.GetLicense()],
|
||||
['Abstract', Header.GetAbstract()],
|
||||
['Description', Header.GetDescription()],
|
||||
]
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
return "Name = %s BaseName = %s GUID = %s Version = %s Copyright = %s \
|
||||
License = %s Abstract = %s Description = %s" % \
|
||||
(self.Name, self.BaseName, self.GUID, self.Version, self.Copyright, \
|
||||
self.License, self.Abstract, self.Description)
|
||||
##
|
||||
# DistributionPackageHeaderXml
|
||||
#
|
||||
class DistributionPackageHeaderXml(object):
|
||||
def __init__(self):
|
||||
self.Header = HeaderXml()
|
||||
self.ReadOnly = ''
|
||||
self.RePackage = ''
|
||||
self.Vendor = ''
|
||||
self.Date = ''
|
||||
self.Signature = ''
|
||||
self.XmlSpecification = ''
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
if not Item:
|
||||
return None
|
||||
self.ReadOnly = XmlAttribute(XmlNode(Item, '%s' % Key), 'ReadOnly')
|
||||
self.RePackage = XmlAttribute(XmlNode(Item, '%s' % Key), 'RePackage')
|
||||
self.Vendor = XmlElement(Item, '%s/Vendor' % Key)
|
||||
self.Date = XmlElement(Item, '%s/Date' % Key)
|
||||
self.Signature = XmlElement(Item, '%s/Signature' % Key)
|
||||
self.XmlSpecification = XmlElement(Item, '%s/XmlSpecification' % Key)
|
||||
self.Header.FromXml(Item, Key)
|
||||
|
||||
DistributionPackageHeader = DistributionPackageHeaderObject()
|
||||
if self.ReadOnly.upper() == 'TRUE':
|
||||
DistributionPackageHeader.ReadOnly = True
|
||||
elif self.ReadOnly.upper() == 'FALSE':
|
||||
DistributionPackageHeader.ReadOnly = False
|
||||
|
||||
if self.RePackage.upper() == 'TRUE':
|
||||
DistributionPackageHeader.RePackage = True
|
||||
elif self.RePackage.upper() == 'FALSE':
|
||||
DistributionPackageHeader.RePackage = False
|
||||
DistributionPackageHeader.Vendor = self.Vendor
|
||||
DistributionPackageHeader.Date = self.Date
|
||||
DistributionPackageHeader.Signature = self.Signature
|
||||
DistributionPackageHeader.XmlSpecification = self.XmlSpecification
|
||||
|
||||
DistributionPackageHeader.SetName(self.Header.Name)
|
||||
DistributionPackageHeader.SetBaseName(self.Header.BaseName)
|
||||
DistributionPackageHeader.SetGuid(self.Header.GUID)
|
||||
DistributionPackageHeader.SetVersion(self.Header.Version)
|
||||
DistributionPackageHeader.SetCopyright(self.Header.Copyright)
|
||||
DistributionPackageHeader.SetLicense(self.Header.License)
|
||||
DistributionPackageHeader.SetAbstract(self.Header.Abstract)
|
||||
DistributionPackageHeader.SetDescription(self.Header.Description)
|
||||
|
||||
return DistributionPackageHeader
|
||||
|
||||
def ToXml(self, DistributionPackageHeader, Key):
|
||||
if self.Header:
|
||||
pass
|
||||
Element1 = CreateXmlElement('Name', \
|
||||
DistributionPackageHeader.GetName(), [], \
|
||||
[['BaseName', \
|
||||
DistributionPackageHeader.GetBaseName()]])
|
||||
Element2 = CreateXmlElement('GUID', \
|
||||
DistributionPackageHeader.GetGuid(), [], \
|
||||
[['Version', \
|
||||
DistributionPackageHeader.GetVersion()]])
|
||||
AttributeList = []
|
||||
if DistributionPackageHeader.ReadOnly != '':
|
||||
AttributeList.append(['ReadOnly', str(DistributionPackageHeader.ReadOnly).lower()])
|
||||
if DistributionPackageHeader.RePackage != '':
|
||||
AttributeList.append(['RePackage', str(DistributionPackageHeader.RePackage).lower()])
|
||||
|
||||
NodeList = [Element1,
|
||||
Element2,
|
||||
['Vendor', DistributionPackageHeader.Vendor],
|
||||
['Date', DistributionPackageHeader.Date],
|
||||
['Copyright', DistributionPackageHeader.GetCopyright()],
|
||||
['License', DistributionPackageHeader.GetLicense()],
|
||||
['Abstract', DistributionPackageHeader.GetAbstract()],
|
||||
['Description', \
|
||||
DistributionPackageHeader.GetDescription()],
|
||||
['Signature', DistributionPackageHeader.Signature],
|
||||
['XmlSpecification', \
|
||||
DistributionPackageHeader.XmlSpecification],
|
||||
]
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
return "ReadOnly = %s RePackage = %s Vendor = %s Date = %s \
|
||||
Signature = %s XmlSpecification = %s %s" % \
|
||||
(self.ReadOnly, self.RePackage, self.Vendor, self.Date, \
|
||||
self.Signature, self.XmlSpecification, self.Header)
|
||||
##
|
||||
# PackageHeaderXml
|
||||
#
|
||||
class PackageHeaderXml(object):
|
||||
def __init__(self):
|
||||
self.Header = HeaderXml()
|
||||
self.PackagePath = ''
|
||||
|
||||
def FromXml(self, Item, Key, PackageObject2):
|
||||
if not Item:
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea']
|
||||
CheckDict = {'PackageHeader':None, }
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
self.PackagePath = XmlElement(Item, '%s/PackagePath' % Key)
|
||||
self.Header.FromXml(Item, Key)
|
||||
|
||||
PackageObject2.SetName(self.Header.Name)
|
||||
PackageObject2.SetBaseName(self.Header.BaseName)
|
||||
PackageObject2.SetGuid(self.Header.GUID)
|
||||
PackageObject2.SetVersion(self.Header.Version)
|
||||
PackageObject2.SetCopyright(self.Header.Copyright)
|
||||
PackageObject2.SetLicense(self.Header.License)
|
||||
PackageObject2.SetAbstract(self.Header.Abstract)
|
||||
PackageObject2.SetDescription(self.Header.Description)
|
||||
PackageObject2.SetPackagePath(self.PackagePath)
|
||||
|
||||
def ToXml(self, PackageObject2, Key):
|
||||
if self.PackagePath:
|
||||
pass
|
||||
Element1 = \
|
||||
CreateXmlElement('Name', PackageObject2.GetName(), [], \
|
||||
[['BaseName', PackageObject2.GetBaseName()]])
|
||||
Element2 = CreateXmlElement('GUID', PackageObject2.GetGuid(), [], \
|
||||
[['Version', PackageObject2.GetVersion()]])
|
||||
AttributeList = []
|
||||
NodeList = [Element1,
|
||||
Element2,
|
||||
['Copyright', PackageObject2.GetCopyright()],
|
||||
['License', PackageObject2.GetLicense()],
|
||||
['Abstract', PackageObject2.GetAbstract()],
|
||||
['Description', PackageObject2.GetDescription()],
|
||||
['PackagePath', PackageObject2.GetPackagePath()],
|
||||
]
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
return "PackagePath = %s %s" \
|
||||
% (self.PackagePath, self.Header)
|
||||
|
||||
##
|
||||
# MiscellaneousFileXml
|
||||
#
|
||||
class MiscellaneousFileXml(object):
|
||||
def __init__(self):
|
||||
self.Header = HeaderXml()
|
||||
self.Files = []
|
||||
##
|
||||
# This API is used for Package or Module's MiscellaneousFile section
|
||||
#
|
||||
def FromXml(self, Item, Key):
|
||||
if not Item:
|
||||
return None
|
||||
self.Header.FromXml(Item, Key)
|
||||
NewItem = XmlNode(Item, '%s/Header' % Key)
|
||||
self.Header.FromXml(NewItem, 'Header')
|
||||
|
||||
for SubItem in XmlList(Item, '%s/Filename' % Key):
|
||||
Filename = XmlElement(SubItem, '%s/Filename' % Key)
|
||||
Executable = XmlAttribute(XmlNode(SubItem, '%s/Filename' % Key), 'Executable')
|
||||
if Executable.upper() == "TRUE":
|
||||
Executable = True
|
||||
else:
|
||||
Executable = False
|
||||
self.Files.append([Filename, Executable])
|
||||
|
||||
MiscFile = MiscFileObject()
|
||||
MiscFile.SetCopyright(self.Header.Copyright)
|
||||
MiscFile.SetLicense(self.Header.License)
|
||||
MiscFile.SetAbstract(self.Header.Abstract)
|
||||
MiscFile.SetDescription(self.Header.Description)
|
||||
MiscFileList = []
|
||||
for File in self.Files:
|
||||
FileObj = FileObject()
|
||||
FileObj.SetURI(File[0])
|
||||
FileObj.SetExecutable(File[1])
|
||||
MiscFileList.append(FileObj)
|
||||
MiscFile.SetFileList(MiscFileList)
|
||||
|
||||
return MiscFile
|
||||
##
|
||||
# This API is used for DistP's tool section
|
||||
#
|
||||
def FromXml2(self, Item, Key):
|
||||
if Item is None:
|
||||
return None
|
||||
|
||||
NewItem = XmlNode(Item, '%s/Header' % Key)
|
||||
self.Header.FromXml(NewItem, 'Header')
|
||||
|
||||
for SubItem in XmlList(Item, '%s/Filename' % Key):
|
||||
Filename = XmlElement(SubItem, '%s/Filename' % Key)
|
||||
Executable = \
|
||||
XmlAttribute(XmlNode(SubItem, '%s/Filename' % Key), 'Executable')
|
||||
OsType = XmlAttribute(XmlNode(SubItem, '%s/Filename' % Key), 'OS')
|
||||
if Executable.upper() == "TRUE":
|
||||
Executable = True
|
||||
else:
|
||||
Executable = False
|
||||
self.Files.append([Filename, Executable, OsType])
|
||||
|
||||
MiscFile = MiscFileObject()
|
||||
MiscFile.SetName(self.Header.Name)
|
||||
MiscFile.SetCopyright(self.Header.Copyright)
|
||||
MiscFile.SetLicense(self.Header.License)
|
||||
MiscFile.SetAbstract(self.Header.Abstract)
|
||||
MiscFile.SetDescription(self.Header.Description)
|
||||
MiscFileList = []
|
||||
for File in self.Files:
|
||||
FileObj = FileObject()
|
||||
FileObj.SetURI(File[0])
|
||||
FileObj.SetExecutable(File[1])
|
||||
FileObj.SetOS(File[2])
|
||||
MiscFileList.append(FileObj)
|
||||
MiscFile.SetFileList(MiscFileList)
|
||||
|
||||
return MiscFile
|
||||
|
||||
##
|
||||
# This API is used for Package or Module's MiscellaneousFile section
|
||||
#
|
||||
def ToXml(self, MiscFile, Key):
|
||||
if self.Header:
|
||||
pass
|
||||
if MiscFile:
|
||||
NodeList = [['Copyright', MiscFile.GetCopyright()],
|
||||
['License', MiscFile.GetLicense()],
|
||||
['Abstract', MiscFile.GetAbstract()],
|
||||
['Description', MiscFile.GetDescription()],
|
||||
]
|
||||
|
||||
for File in MiscFile.GetFileList():
|
||||
NodeList.append\
|
||||
(CreateXmlElement\
|
||||
('Filename', File.GetURI(), [], \
|
||||
[['Executable', str(File.GetExecutable()).lower()]]))
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, [])
|
||||
|
||||
return Root
|
||||
##
|
||||
# This API is used for DistP's tool section
|
||||
#
|
||||
def ToXml2(self, MiscFile, Key):
|
||||
if self.Header:
|
||||
pass
|
||||
if MiscFile:
|
||||
NodeList = [['Name', MiscFile.GetName()],
|
||||
['Copyright', MiscFile.GetCopyright()],
|
||||
['License', MiscFile.GetLicense()],
|
||||
['Abstract', MiscFile.GetAbstract()],
|
||||
['Description', MiscFile.GetDescription()],
|
||||
]
|
||||
HeaderNode = CreateXmlElement('Header', '', NodeList, [])
|
||||
NodeList = [HeaderNode]
|
||||
|
||||
for File in MiscFile.GetFileList():
|
||||
NodeList.append\
|
||||
(CreateXmlElement\
|
||||
('Filename', File.GetURI(), [], \
|
||||
[['Executable', str(File.GetExecutable()).lower()], \
|
||||
['OS', File.GetOS()]]))
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, [])
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = str(self.Header)
|
||||
for Item in self.Files:
|
||||
Str = Str + '\n\tFilename:' + str(Item)
|
||||
return Str
|
||||
##
|
||||
# UserExtensionsXml
|
||||
#
|
||||
class UserExtensionsXml(object):
|
||||
def __init__(self):
|
||||
self.UserId = ''
|
||||
self.Identifier = ''
|
||||
self.DefineDict = {}
|
||||
self.BuildOptionDict = {}
|
||||
self.IncludesDict = {}
|
||||
self.SourcesDict = {}
|
||||
self.BinariesDict = {}
|
||||
self.SupArchList = []
|
||||
self.Statement = ''
|
||||
self.Defines = ''
|
||||
self.BuildOptions = ''
|
||||
|
||||
def FromXml2(self, Item, Key):
|
||||
self.UserId = XmlAttribute(XmlNode(Item, '%s' % Key), 'UserId')
|
||||
self.Identifier = XmlAttribute(XmlNode(Item, '%s' % Key), 'Identifier')
|
||||
|
||||
UserExtension = UserExtensionObject()
|
||||
UserExtension.SetUserID(self.UserId)
|
||||
UserExtension.SetIdentifier(self.Identifier)
|
||||
|
||||
return UserExtension
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.UserId = XmlAttribute(XmlNode(Item, '%s' % Key), 'UserId')
|
||||
self.Identifier = XmlAttribute(XmlNode(Item, '%s' % Key), 'Identifier')
|
||||
|
||||
DefineItem = XmlNode(Item, '%s/Define' % Key)
|
||||
for SubItem in XmlList(DefineItem, 'Define/Statement'):
|
||||
Statement = XmlElement(SubItem, '%s/Statement' % Key)
|
||||
self.DefineDict[Statement] = ""
|
||||
|
||||
BuildOptionItem = XmlNode(Item, '%s/BuildOption' % Key)
|
||||
for SubItem in XmlList(BuildOptionItem, 'BuildOption/Statement'):
|
||||
Statement = XmlElement(SubItem, '%s/Statement' % Key)
|
||||
Arch = XmlAttribute(XmlNode(SubItem, '%s/Statement' % Key), 'SupArchList')
|
||||
self.BuildOptionDict[Arch] = Statement
|
||||
|
||||
IncludesItem = XmlNode(Item, '%s/Includes' % Key)
|
||||
for SubItem in XmlList(IncludesItem, 'Includes/Statement'):
|
||||
Statement = XmlElement(SubItem, '%s/Statement' % Key)
|
||||
Arch = XmlAttribute(XmlNode(SubItem, '%s/Statement' % Key), 'SupArchList')
|
||||
self.IncludesDict[Statement] = Arch
|
||||
|
||||
SourcesItem = XmlNode(Item, '%s/Sources' % Key)
|
||||
Tmp = UserExtensionSourceXml()
|
||||
SourceDict = Tmp.FromXml(SourcesItem, 'Sources')
|
||||
self.SourcesDict = SourceDict
|
||||
|
||||
BinariesItem = XmlNode(Item, '%s/Binaries' % Key)
|
||||
Tmp = UserExtensionBinaryXml()
|
||||
BinariesDict = Tmp.FromXml(BinariesItem, 'Binaries')
|
||||
self.BinariesDict = BinariesDict
|
||||
|
||||
self.Statement = XmlElement(Item, 'UserExtensions')
|
||||
SupArch = XmlAttribute(XmlNode(Item, '%s' % Key), 'SupArchList')
|
||||
self.SupArchList = [Arch for Arch in GetSplitValueList(SupArch, DataType.TAB_SPACE_SPLIT) if Arch]
|
||||
|
||||
UserExtension = UserExtensionObject()
|
||||
UserExtension.SetUserID(self.UserId)
|
||||
UserExtension.SetIdentifier(self.Identifier)
|
||||
UserExtension.SetStatement(self.Statement)
|
||||
UserExtension.SetSupArchList(self.SupArchList)
|
||||
UserExtension.SetDefinesDict(self.DefineDict)
|
||||
UserExtension.SetBuildOptionDict(self.BuildOptionDict)
|
||||
UserExtension.SetIncludesDict(self.IncludesDict)
|
||||
UserExtension.SetSourcesDict(self.SourcesDict)
|
||||
UserExtension.SetBinariesDict(self.BinariesDict)
|
||||
|
||||
return UserExtension
|
||||
|
||||
def ToXml(self, UserExtension, Key):
|
||||
if self.UserId:
|
||||
pass
|
||||
|
||||
AttributeList = [['UserId', str(UserExtension.GetUserID())],
|
||||
['Identifier', str(UserExtension.GetIdentifier())],
|
||||
['SupArchList', \
|
||||
GetStringOfList(UserExtension.GetSupArchList())],
|
||||
]
|
||||
|
||||
Root = CreateXmlElement('%s' % Key, UserExtension.GetStatement(), [], \
|
||||
AttributeList)
|
||||
|
||||
NodeList = []
|
||||
DefineDict = UserExtension.GetDefinesDict()
|
||||
if DefineDict:
|
||||
for Item in DefineDict.keys():
|
||||
NodeList.append(CreateXmlElement\
|
||||
('Statement', Item, [], []))
|
||||
DefineElement = CreateXmlElement('Define', '', NodeList, [])
|
||||
Root.appendChild(DefineElement)
|
||||
|
||||
NodeList = []
|
||||
BuildOptionDict = UserExtension.GetBuildOptionDict()
|
||||
if BuildOptionDict:
|
||||
for Item in BuildOptionDict.keys():
|
||||
NodeList.append(CreateXmlElement\
|
||||
('Statement', BuildOptionDict[Item], [], \
|
||||
[['SupArchList', Item]]))
|
||||
BuildOptionElement = \
|
||||
CreateXmlElement('BuildOption', '', NodeList, [])
|
||||
Root.appendChild(BuildOptionElement)
|
||||
|
||||
NodeList = []
|
||||
IncludesDict = UserExtension.GetIncludesDict()
|
||||
if IncludesDict:
|
||||
for Item in IncludesDict.keys():
|
||||
NodeList.append(CreateXmlElement\
|
||||
('Statement', Item, [], \
|
||||
[['SupArchList', IncludesDict[Item]]]))
|
||||
IncludesElement = CreateXmlElement('Includes', '', NodeList, [])
|
||||
Root.appendChild(IncludesElement)
|
||||
|
||||
NodeList = []
|
||||
SourcesDict = UserExtension.GetSourcesDict()
|
||||
if SourcesDict:
|
||||
Tmp = UserExtensionSourceXml()
|
||||
Root.appendChild(Tmp.ToXml(SourcesDict, 'Sources'))
|
||||
|
||||
NodeList = []
|
||||
BinariesDict = UserExtension.GetBinariesDict()
|
||||
if BinariesDict:
|
||||
Tmp = UserExtensionBinaryXml()
|
||||
Root.appendChild(Tmp.ToXml(BinariesDict, 'Binaries'))
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = "UserId = %s Identifier = %s" % (self.UserId, self.Identifier)
|
||||
Str = Str + '\n\tDefines:' + str(self.Defines)
|
||||
Str = Str + '\n\tBuildOptions:' + str(self.BuildOptions)
|
||||
return Str
|
||||
|
||||
##
|
||||
# UserExtensionSourceXml
|
||||
#
|
||||
class UserExtensionSourceXml(object):
|
||||
def __init__(self):
|
||||
self.UserExtensionSource = ''
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
if Key:
|
||||
pass
|
||||
if self.UserExtensionSource:
|
||||
pass
|
||||
Dict = {}
|
||||
|
||||
#SourcesItem = XmlNode(Item, '%s/Sources' % Key)
|
||||
for SubItem in XmlList(Item, 'Sources/SourceFile'):
|
||||
FileName = XmlElement(SubItem, 'SourceFile/FileName')
|
||||
Family = XmlElement(SubItem, 'SourceFile/Family')
|
||||
FeatureFlag = XmlElement(SubItem, 'SourceFile/FeatureFlag')
|
||||
SupArchStr = XmlElement(SubItem, 'SourceFile/SupArchList')
|
||||
DictKey = (FileName, Family, FeatureFlag, SupArchStr)
|
||||
|
||||
ValueList = []
|
||||
for ValueNodeItem in XmlList(SubItem, \
|
||||
'SourceFile/SourceFileOtherAttr'):
|
||||
TagName = XmlElement(ValueNodeItem, \
|
||||
'SourceFileOtherAttr/TagName')
|
||||
ToolCode = XmlElement(ValueNodeItem, \
|
||||
'SourceFileOtherAttr/ToolCode')
|
||||
Comment = XmlElement(ValueNodeItem, \
|
||||
'SourceFileOtherAttr/Comment')
|
||||
if (TagName == ' ') and (ToolCode == ' ') and (Comment == ' '):
|
||||
TagName = ''
|
||||
ToolCode = ''
|
||||
Comment = ''
|
||||
ValueList.append((TagName, ToolCode, Comment))
|
||||
|
||||
Dict[DictKey] = ValueList
|
||||
|
||||
return Dict
|
||||
|
||||
def ToXml(self, Dict, Key):
|
||||
if self.UserExtensionSource:
|
||||
pass
|
||||
SourcesNodeList = []
|
||||
for Item in Dict:
|
||||
ValueList = Dict[Item]
|
||||
(FileName, Family, FeatureFlag, SupArchStr) = Item
|
||||
SourceFileNodeList = []
|
||||
SourceFileNodeList.append(["FileName", FileName])
|
||||
SourceFileNodeList.append(["Family", Family])
|
||||
SourceFileNodeList.append(["FeatureFlag", FeatureFlag])
|
||||
SourceFileNodeList.append(["SupArchList", SupArchStr])
|
||||
for (TagName, ToolCode, Comment) in ValueList:
|
||||
ValueNodeList = []
|
||||
if not (TagName or ToolCode or Comment):
|
||||
TagName = ' '
|
||||
ToolCode = ' '
|
||||
Comment = ' '
|
||||
ValueNodeList.append(["TagName", TagName])
|
||||
ValueNodeList.append(["ToolCode", ToolCode])
|
||||
ValueNodeList.append(["Comment", Comment])
|
||||
ValueNodeXml = CreateXmlElement('SourceFileOtherAttr', '', \
|
||||
ValueNodeList, [])
|
||||
SourceFileNodeList.append(ValueNodeXml)
|
||||
SourceFileNodeXml = CreateXmlElement('SourceFile', '', \
|
||||
SourceFileNodeList, [])
|
||||
SourcesNodeList.append(SourceFileNodeXml)
|
||||
Root = CreateXmlElement('%s' % Key, '', SourcesNodeList, [])
|
||||
return Root
|
||||
|
||||
##
|
||||
# UserExtensionBinaryXml
|
||||
#
|
||||
class UserExtensionBinaryXml(object):
|
||||
def __init__(self):
|
||||
self.UserExtensionBinary = ''
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
if Key:
|
||||
pass
|
||||
if self.UserExtensionBinary:
|
||||
pass
|
||||
|
||||
Dict = {}
|
||||
|
||||
for SubItem in XmlList(Item, 'Binaries/Binary'):
|
||||
FileName = XmlElement(SubItem, 'Binary/FileName')
|
||||
FileType = XmlElement(SubItem, 'Binary/FileType')
|
||||
FFE = XmlElement(SubItem, 'Binary/FeatureFlag')
|
||||
SupArch = XmlElement(SubItem, 'Binary/SupArchList')
|
||||
DictKey = (FileName, FileType, ConvertNOTEQToNE(FFE), SupArch)
|
||||
|
||||
ValueList = []
|
||||
for ValueNodeItem in XmlList(SubItem, \
|
||||
'Binary/BinaryFileOtherAttr'):
|
||||
Target = XmlElement(ValueNodeItem, \
|
||||
'BinaryFileOtherAttr/Target')
|
||||
Family = XmlElement(ValueNodeItem, \
|
||||
'BinaryFileOtherAttr/Family')
|
||||
TagName = XmlElement(ValueNodeItem, \
|
||||
'BinaryFileOtherAttr/TagName')
|
||||
Comment = XmlElement(ValueNodeItem, \
|
||||
'BinaryFileOtherAttr/Comment')
|
||||
if (Target == ' ') and (Family == ' ') and \
|
||||
(TagName == ' ') and (Comment == ' '):
|
||||
Target = ''
|
||||
Family = ''
|
||||
TagName = ''
|
||||
Comment = ''
|
||||
|
||||
ValueList.append((Target, Family, TagName, Comment))
|
||||
|
||||
Dict[DictKey] = ValueList
|
||||
|
||||
return Dict
|
||||
|
||||
def ToXml(self, Dict, Key):
|
||||
if self.UserExtensionBinary:
|
||||
pass
|
||||
BinariesNodeList = []
|
||||
for Item in Dict:
|
||||
ValueList = Dict[Item]
|
||||
(FileName, FileType, FeatureFlag, SupArch) = Item
|
||||
FileNodeList = []
|
||||
FileNodeList.append(["FileName", FileName])
|
||||
FileNodeList.append(["FileType", FileType])
|
||||
FileNodeList.append(["FeatureFlag", ConvertNEToNOTEQ(FeatureFlag)])
|
||||
FileNodeList.append(["SupArchList", SupArch])
|
||||
for (Target, Family, TagName, Comment) in ValueList:
|
||||
ValueNodeList = []
|
||||
if not (Target or Family or TagName or Comment):
|
||||
Target = ' '
|
||||
Family = ' '
|
||||
TagName = ' '
|
||||
Comment = ' '
|
||||
ValueNodeList.append(["Target", Target])
|
||||
ValueNodeList.append(["Family", Family])
|
||||
ValueNodeList.append(["TagName", TagName])
|
||||
ValueNodeList.append(["Comment", Comment])
|
||||
ValueNodeXml = CreateXmlElement('BinaryFileOtherAttr', '', \
|
||||
ValueNodeList, [])
|
||||
FileNodeList.append(ValueNodeXml)
|
||||
FileNodeXml = CreateXmlElement('Binary', '', FileNodeList, [])
|
||||
BinariesNodeList.append(FileNodeXml)
|
||||
Root = CreateXmlElement('%s' % Key, '', BinariesNodeList, [])
|
||||
return Root
|
||||
|
||||
##
|
||||
# LibraryClassXml
|
||||
#
|
||||
class LibraryClassXml(object):
|
||||
def __init__(self):
|
||||
self.Keyword = ''
|
||||
self.HeaderFile = ''
|
||||
self.RecommendedInstanceGuid = ''
|
||||
self.RecommendedInstanceVersion = ''
|
||||
self.CommonDefines = CommonDefinesXml()
|
||||
self.HelpText = []
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.Keyword = XmlAttribute(XmlNode(Item, '%s' % Key), 'Keyword')
|
||||
if self.Keyword == '':
|
||||
self.Keyword = XmlElement(Item, '%s/Keyword' % Key)
|
||||
self.HeaderFile = XmlElement(Item, '%s/HeaderFile' % Key)
|
||||
self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)
|
||||
for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
|
||||
HelpTextObj = HelpTextXml()
|
||||
HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
|
||||
self.HelpText.append(HelpTextObj)
|
||||
|
||||
LibraryClass = LibraryClassObject()
|
||||
LibraryClass.SetLibraryClass(self.Keyword)
|
||||
LibraryClass.SetIncludeHeader(self.HeaderFile)
|
||||
if self.CommonDefines.Usage:
|
||||
LibraryClass.SetUsage(self.CommonDefines.Usage)
|
||||
LibraryClass.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
LibraryClass.SetSupModuleList(self.CommonDefines.SupModList)
|
||||
LibraryClass.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))
|
||||
LibraryClass.SetHelpTextList(GetHelpTextList(self.HelpText))
|
||||
|
||||
return LibraryClass
|
||||
|
||||
def ToXml(self, LibraryClass, Key):
|
||||
if self.HeaderFile:
|
||||
pass
|
||||
AttributeList = \
|
||||
[['Keyword', LibraryClass.GetLibraryClass()],
|
||||
['SupArchList', GetStringOfList(LibraryClass.GetSupArchList())],
|
||||
['SupModList', GetStringOfList(LibraryClass.GetSupModuleList())]
|
||||
]
|
||||
NodeList = [['HeaderFile', LibraryClass.GetIncludeHeader()]]
|
||||
for Item in LibraryClass.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item))
|
||||
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def ToXml2(self, LibraryClass, Key):
|
||||
if self.HeaderFile:
|
||||
pass
|
||||
|
||||
FeatureFlag = ConvertNEToNOTEQ(LibraryClass.GetFeatureFlag())
|
||||
|
||||
AttributeList = \
|
||||
[['Usage', LibraryClass.GetUsage()], \
|
||||
['SupArchList', GetStringOfList(LibraryClass.GetSupArchList())], \
|
||||
['SupModList', GetStringOfList(LibraryClass.GetSupModuleList())], \
|
||||
['FeatureFlag', FeatureFlag]
|
||||
]
|
||||
NodeList = [['Keyword', LibraryClass.GetLibraryClass()], ]
|
||||
for Item in LibraryClass.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item))
|
||||
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = "Keyword = %s HeaderFile = %s RecommendedInstanceGuid = %s RecommendedInstanceVersion = %s %s" % \
|
||||
(self.Keyword, self.HeaderFile, self.RecommendedInstanceGuid, self.RecommendedInstanceVersion, \
|
||||
self.CommonDefines)
|
||||
for Item in self.HelpText:
|
||||
Str = Str + "\n\t" + str(Item)
|
||||
return Str
|
||||
|
||||
##
|
||||
# FilenameXml
|
||||
#
|
||||
class FilenameXml(object):
|
||||
def __init__(self):
|
||||
self.FileType = ''
|
||||
self.Filename = ''
|
||||
self.CommonDefines = CommonDefinesXml()
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.FileType = XmlAttribute(Item, 'FileType')
|
||||
self.Filename = XmlElement(Item, 'Filename')
|
||||
self.CommonDefines.FromXml(Item, Key)
|
||||
|
||||
FeatureFlag = ConvertNOTEQToNE(self.CommonDefines.FeatureFlag)
|
||||
|
||||
Filename = FileNameObject()
|
||||
#
|
||||
# Convert File Type
|
||||
#
|
||||
if self.FileType == 'UEFI_IMAGE':
|
||||
self.FileType = 'PE32'
|
||||
|
||||
Filename.SetFileType(self.FileType)
|
||||
Filename.SetFilename(self.Filename)
|
||||
Filename.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
Filename.SetFeatureFlag(FeatureFlag)
|
||||
|
||||
return Filename
|
||||
|
||||
def ToXml(self, Filename, Key):
|
||||
if self.Filename:
|
||||
pass
|
||||
AttributeList = [['SupArchList', \
|
||||
GetStringOfList(Filename.GetSupArchList())],
|
||||
['FileType', Filename.GetFileType()],
|
||||
['FeatureFlag', ConvertNEToNOTEQ(Filename.GetFeatureFlag())],
|
||||
]
|
||||
Root = CreateXmlElement('%s' % Key, Filename.GetFilename(), [], AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
return "FileType = %s Filename = %s %s" \
|
||||
% (self.FileType, self.Filename, self.CommonDefines)
|
284
BaseTools/Source/Python/UPT/Xml/GuidProtocolPpiXml.py
Normal file
284
BaseTools/Source/Python/UPT/Xml/GuidProtocolPpiXml.py
Normal file
@@ -0,0 +1,284 @@
|
||||
## @file
|
||||
# This file is used to parse a xml file of .PKG file
|
||||
#
|
||||
# Copyright (c) 2011, 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
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
'''
|
||||
GuidProtocolPpiXml
|
||||
'''
|
||||
from Library.String import ConvertNEToNOTEQ
|
||||
from Library.String import ConvertNOTEQToNE
|
||||
from Library.String import GetStringOfList
|
||||
from Library.Xml.XmlRoutines import XmlElement
|
||||
from Library.Xml.XmlRoutines import XmlAttribute
|
||||
from Library.Xml.XmlRoutines import XmlNode
|
||||
from Library.Xml.XmlRoutines import XmlList
|
||||
from Library.Xml.XmlRoutines import CreateXmlElement
|
||||
|
||||
from Object.POM.CommonObject import GuidObject
|
||||
from Object.POM.CommonObject import ProtocolObject
|
||||
from Object.POM.CommonObject import PpiObject
|
||||
|
||||
from Xml.CommonXml import CommonDefinesXml
|
||||
from Xml.CommonXml import HelpTextXml
|
||||
|
||||
from Xml.XmlParserMisc import GetHelpTextList
|
||||
|
||||
##
|
||||
#GUID/Protocol/Ppi Common
|
||||
#
|
||||
class GuidProtocolPpiXml(object):
|
||||
def __init__(self, Mode):
|
||||
self.UiName = ''
|
||||
self.GuidTypes = ''
|
||||
self.Notify = ''
|
||||
self.CName = ''
|
||||
self.GuidValue = ''
|
||||
self.CommonDefines = CommonDefinesXml()
|
||||
self.HelpText = []
|
||||
#
|
||||
# Guid/Ppi/Library, internal used for indicate return object for
|
||||
# FromXml
|
||||
#
|
||||
self.Type = ''
|
||||
#
|
||||
# there are slightly different field between package and module
|
||||
#
|
||||
self.Mode = Mode
|
||||
self.GuidType = ''
|
||||
self.VariableName = ''
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.UiName = XmlAttribute(XmlNode(Item, '%s' % Key), 'UiName')
|
||||
self.GuidType = XmlAttribute(XmlNode(Item, '%s' % Key), 'GuidType')
|
||||
self.Notify = XmlAttribute(XmlNode(Item, '%s' % Key), 'Notify')
|
||||
self.CName = XmlElement(Item, '%s/CName' % Key)
|
||||
self.GuidValue = XmlElement(Item, '%s/GuidValue' % Key)
|
||||
self.VariableName = XmlElement(Item, '%s/VariableName' % Key)
|
||||
self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)
|
||||
for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
|
||||
HelpTextObj = HelpTextXml()
|
||||
HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
|
||||
self.HelpText.append(HelpTextObj)
|
||||
|
||||
if self.Type == 'Guid':
|
||||
GuidProtocolPpi = GuidObject()
|
||||
elif self.Type == 'Protocol':
|
||||
GuidProtocolPpi = ProtocolObject()
|
||||
else:
|
||||
GuidProtocolPpi = PpiObject()
|
||||
GuidProtocolPpi.SetHelpTextList(GetHelpTextList(self.HelpText))
|
||||
|
||||
return GuidProtocolPpi
|
||||
|
||||
def ToXml(self, GuidProtocolPpi, Key):
|
||||
if self.GuidValue:
|
||||
pass
|
||||
AttributeList = \
|
||||
[['Usage', GetStringOfList(GuidProtocolPpi.GetUsage())], \
|
||||
['UiName', GuidProtocolPpi.GetName()], \
|
||||
['GuidType', GetStringOfList(GuidProtocolPpi.GetGuidTypeList())], \
|
||||
['Notify', str(GuidProtocolPpi.GetNotify()).lower()], \
|
||||
['SupArchList', GetStringOfList(GuidProtocolPpi.GetSupArchList())], \
|
||||
['SupModList', GetStringOfList(GuidProtocolPpi.GetSupModuleList())], \
|
||||
['FeatureFlag', ConvertNEToNOTEQ(GuidProtocolPpi.GetFeatureFlag())]
|
||||
]
|
||||
NodeList = [['CName', GuidProtocolPpi.GetCName()],
|
||||
['GuidValue', GuidProtocolPpi.GetGuid()],
|
||||
['VariableName', GuidProtocolPpi.VariableName]
|
||||
]
|
||||
for Item in GuidProtocolPpi.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item))
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = \
|
||||
"UiName = %s Notify = %s GuidTypes = %s CName = %s GuidValue = %s %s" \
|
||||
% (self.UiName, self.Notify, self.GuidTypes, self.CName, \
|
||||
self.GuidValue, self.CommonDefines)
|
||||
for Item in self.HelpText:
|
||||
Str = Str + "\n\t" + str(Item)
|
||||
return Str
|
||||
##
|
||||
#GUID Xml
|
||||
#
|
||||
class GuidXml(GuidProtocolPpiXml):
|
||||
def __init__(self, Mode):
|
||||
GuidProtocolPpiXml.__init__(self, Mode)
|
||||
self.Type = 'Guid'
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
GuidProtocolPpi = GuidProtocolPpiXml.FromXml(self, Item, Key)
|
||||
|
||||
if self.Mode == 'Package':
|
||||
|
||||
GuidProtocolPpi.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
GuidProtocolPpi.SetSupModuleList(self.CommonDefines.SupModList)
|
||||
GuidProtocolPpi.SetCName(self.CName)
|
||||
GuidProtocolPpi.SetGuid(self.GuidValue)
|
||||
else:
|
||||
GuidProtocolPpi.SetUsage(self.CommonDefines.Usage)
|
||||
if self.GuidType:
|
||||
GuidProtocolPpi.SetGuidTypeList([self.GuidType])
|
||||
GuidProtocolPpi.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
GuidProtocolPpi.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))
|
||||
GuidProtocolPpi.SetCName(self.CName)
|
||||
GuidProtocolPpi.SetVariableName(self.VariableName)
|
||||
return GuidProtocolPpi
|
||||
|
||||
def ToXml(self, GuidProtocolPpi, Key):
|
||||
if self.Mode == 'Package':
|
||||
AttributeList = \
|
||||
[['GuidType', \
|
||||
GetStringOfList(GuidProtocolPpi.GetGuidTypeList())], \
|
||||
['SupArchList', \
|
||||
GetStringOfList(GuidProtocolPpi.GetSupArchList())], \
|
||||
['SupModList', \
|
||||
GetStringOfList(GuidProtocolPpi.GetSupModuleList())],
|
||||
]
|
||||
NodeList = [['CName', GuidProtocolPpi.GetCName()],
|
||||
['GuidValue', GuidProtocolPpi.GetGuid()],
|
||||
]
|
||||
else:
|
||||
AttributeList = \
|
||||
[['Usage', GetStringOfList(GuidProtocolPpi.GetUsage())], \
|
||||
['GuidType', GetStringOfList(GuidProtocolPpi.GetGuidTypeList())],\
|
||||
['SupArchList', \
|
||||
GetStringOfList(GuidProtocolPpi.GetSupArchList())], \
|
||||
['FeatureFlag', ConvertNEToNOTEQ(GuidProtocolPpi.GetFeatureFlag())]
|
||||
]
|
||||
NodeList = [['CName', GuidProtocolPpi.GetCName()],
|
||||
['VariableName', GuidProtocolPpi.GetVariableName()]
|
||||
]
|
||||
|
||||
for Item in GuidProtocolPpi.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item))
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
##
|
||||
#Protocol Xml
|
||||
#
|
||||
class ProtocolXml(GuidProtocolPpiXml):
|
||||
def __init__(self, Mode):
|
||||
GuidProtocolPpiXml.__init__(self, Mode)
|
||||
self.Type = 'Protocol'
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
GuidProtocolPpi = GuidProtocolPpiXml.FromXml(self, Item, Key)
|
||||
if self.Mode == 'Package':
|
||||
GuidProtocolPpi.SetFeatureFlag(self.CommonDefines.FeatureFlag)
|
||||
GuidProtocolPpi.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
GuidProtocolPpi.SetSupModuleList(self.CommonDefines.SupModList)
|
||||
GuidProtocolPpi.SetCName(self.CName)
|
||||
GuidProtocolPpi.SetGuid(self.GuidValue)
|
||||
else:
|
||||
GuidProtocolPpi.SetUsage(self.CommonDefines.Usage)
|
||||
if self.Notify.upper() == "TRUE":
|
||||
GuidProtocolPpi.SetNotify(True)
|
||||
elif self.Notify.upper() == "FALSE":
|
||||
GuidProtocolPpi.SetNotify(False)
|
||||
else:
|
||||
GuidProtocolPpi.SetNotify('')
|
||||
GuidProtocolPpi.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
GuidProtocolPpi.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))
|
||||
GuidProtocolPpi.SetCName(self.CName)
|
||||
|
||||
return GuidProtocolPpi
|
||||
|
||||
def ToXml(self, GuidProtocolPpi, Key):
|
||||
if self.Mode == 'Package':
|
||||
AttributeList = \
|
||||
[['SupArchList', \
|
||||
GetStringOfList(GuidProtocolPpi.GetSupArchList())], \
|
||||
['SupModList', \
|
||||
GetStringOfList(GuidProtocolPpi.GetSupModuleList())], \
|
||||
['FeatureFlag', GuidProtocolPpi.GetFeatureFlag()]
|
||||
]
|
||||
NodeList = [['CName', GuidProtocolPpi.GetCName()],
|
||||
['GuidValue', GuidProtocolPpi.GetGuid()],
|
||||
]
|
||||
else:
|
||||
AttributeList = \
|
||||
[['Usage', GetStringOfList(GuidProtocolPpi.GetUsage())], \
|
||||
['Notify', str(GuidProtocolPpi.GetNotify()).lower()], \
|
||||
['SupArchList', \
|
||||
GetStringOfList(GuidProtocolPpi.GetSupArchList())], \
|
||||
['FeatureFlag', ConvertNEToNOTEQ(GuidProtocolPpi.GetFeatureFlag())]
|
||||
]
|
||||
NodeList = [['CName', GuidProtocolPpi.GetCName()],
|
||||
]
|
||||
|
||||
for Item in GuidProtocolPpi.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item))
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
##
|
||||
#Ppi Xml
|
||||
#
|
||||
class PpiXml(GuidProtocolPpiXml):
|
||||
def __init__(self, Mode):
|
||||
GuidProtocolPpiXml.__init__(self, Mode)
|
||||
self.Type = 'Ppi'
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
GuidProtocolPpi = GuidProtocolPpiXml.FromXml(self, Item, Key)
|
||||
if self.Mode == 'Package':
|
||||
GuidProtocolPpi.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
GuidProtocolPpi.SetSupModuleList(self.CommonDefines.SupModList)
|
||||
GuidProtocolPpi.SetCName(self.CName)
|
||||
GuidProtocolPpi.SetGuid(self.GuidValue)
|
||||
else:
|
||||
GuidProtocolPpi.SetUsage(self.CommonDefines.Usage)
|
||||
if self.Notify.upper() == "TRUE":
|
||||
GuidProtocolPpi.SetNotify(True)
|
||||
elif self.Notify.upper() == "FALSE":
|
||||
GuidProtocolPpi.SetNotify(False)
|
||||
else:
|
||||
GuidProtocolPpi.SetNotify('')
|
||||
GuidProtocolPpi.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
GuidProtocolPpi.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))
|
||||
GuidProtocolPpi.SetCName(self.CName)
|
||||
|
||||
return GuidProtocolPpi
|
||||
|
||||
def ToXml(self, GuidProtocolPpi, Key):
|
||||
if self.Mode == 'Package':
|
||||
AttributeList = \
|
||||
[['SupArchList', \
|
||||
GetStringOfList(GuidProtocolPpi.GetSupArchList())],
|
||||
]
|
||||
NodeList = [['CName', GuidProtocolPpi.GetCName()],
|
||||
['GuidValue', GuidProtocolPpi.GetGuid()],
|
||||
]
|
||||
else:
|
||||
AttributeList = \
|
||||
[['Usage', GetStringOfList(GuidProtocolPpi.GetUsage())], \
|
||||
['Notify', str(GuidProtocolPpi.GetNotify()).lower()], \
|
||||
['SupArchList', \
|
||||
GetStringOfList(GuidProtocolPpi.GetSupArchList())], \
|
||||
['FeatureFlag', ConvertNEToNOTEQ(GuidProtocolPpi.GetFeatureFlag())]
|
||||
]
|
||||
NodeList = [['CName', GuidProtocolPpi.GetCName()],
|
||||
]
|
||||
|
||||
for Item in GuidProtocolPpi.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item))
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
return Root
|
503
BaseTools/Source/Python/UPT/Xml/IniToXml.py
Normal file
503
BaseTools/Source/Python/UPT/Xml/IniToXml.py
Normal file
@@ -0,0 +1,503 @@
|
||||
## @file
|
||||
# This file is for converting package information data file to xml file.
|
||||
#
|
||||
# Copyright (c) 2011, 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
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
'''
|
||||
IniToXml
|
||||
'''
|
||||
|
||||
import os.path
|
||||
import re
|
||||
from time import strftime
|
||||
from time import localtime
|
||||
|
||||
import Logger.Log as Logger
|
||||
from Logger.ToolError import UPT_INI_PARSE_ERROR
|
||||
from Logger.ToolError import FILE_NOT_FOUND
|
||||
from Library.Xml.XmlRoutines import CreateXmlElement
|
||||
from Library.DataType import TAB_VALUE_SPLIT
|
||||
from Library.DataType import TAB_EQUAL_SPLIT
|
||||
from Library.DataType import TAB_SECTION_START
|
||||
from Library.DataType import TAB_SECTION_END
|
||||
from Logger import StringTable as ST
|
||||
from Library.String import ConvertSpecialChar
|
||||
from Library.ParserValidate import IsValidPath
|
||||
|
||||
## log error:
|
||||
#
|
||||
# @param error: error
|
||||
# @param File: File
|
||||
# @param Line: Line
|
||||
#
|
||||
def IniParseError(Error, File, Line):
|
||||
Logger.Error("UPT", UPT_INI_PARSE_ERROR, File=File,
|
||||
Line=Line, ExtraData=Error)
|
||||
|
||||
## __ValidatePath
|
||||
#
|
||||
# @param Path: Path to be checked
|
||||
#
|
||||
def __ValidatePath(Path, Root):
|
||||
Path = Path.strip()
|
||||
if os.path.isabs(Path) or not IsValidPath(Path, Root):
|
||||
return False, ST.ERR_FILELIST_LOCATION % (Root, Path)
|
||||
return True, ''
|
||||
|
||||
## ValidateMiscFile
|
||||
#
|
||||
# @param Filename: File to be checked
|
||||
#
|
||||
def ValidateMiscFile(Filename):
|
||||
Root = ''
|
||||
if 'WORKSPACE' in os.environ:
|
||||
Root = os.environ['WORKSPACE']
|
||||
return __ValidatePath(Filename, Root)
|
||||
|
||||
## ValidateToolsFile
|
||||
#
|
||||
# @param Filename: File to be checked
|
||||
#
|
||||
def ValidateToolsFile(Filename):
|
||||
Valid, Cause = False, ''
|
||||
if not Valid and 'EDK_TOOLS_PATH' in os.environ:
|
||||
Valid, Cause = __ValidatePath(Filename, os.environ['EDK_TOOLS_PATH'])
|
||||
if not Valid and 'WORKSPACE' in os.environ:
|
||||
Valid, Cause = __ValidatePath(Filename, os.environ['WORKSPACE'])
|
||||
return Valid, Cause
|
||||
|
||||
## ParseFileList
|
||||
#
|
||||
# @param Line: Line
|
||||
# @param Map: Map
|
||||
# @param CurrentKey: CurrentKey
|
||||
# @param PathFunc: Path validate function
|
||||
#
|
||||
def ParseFileList(Line, Map, CurrentKey, PathFunc):
|
||||
FileList = ["", {}]
|
||||
TokenList = Line.split(TAB_VALUE_SPLIT)
|
||||
if len(TokenList) > 0:
|
||||
Path = TokenList[0].strip().replace('\\', '/')
|
||||
if not Path:
|
||||
return False, ST.ERR_WRONG_FILELIST_FORMAT
|
||||
Valid, Cause = PathFunc(Path)
|
||||
if not Valid:
|
||||
return Valid, Cause
|
||||
FileList[0] = TokenList[0].strip()
|
||||
for Token in TokenList[1:]:
|
||||
Attr = Token.split(TAB_EQUAL_SPLIT)
|
||||
if len(Attr) != 2 or not Attr[0].strip() or not Attr[1].strip():
|
||||
return False, ST.ERR_WRONG_FILELIST_FORMAT
|
||||
|
||||
Key = Attr[0].strip()
|
||||
Val = Attr[1].strip()
|
||||
if Key not in ['OS', 'Executable']:
|
||||
return False, ST.ERR_UNKNOWN_FILELIST_ATTR % Key
|
||||
|
||||
if Key == 'OS' and Val not in ["Win32", "Win64", "Linux32",
|
||||
"Linux64", "OS/X32", "OS/X64",
|
||||
"GenericWin", "GenericNix"]:
|
||||
return False, ST.ERR_FILELIST_ATTR % 'OS'
|
||||
elif Key == 'Executable' and Val not in ['true', 'false']:
|
||||
return False, ST.ERR_FILELIST_ATTR % 'Executable'
|
||||
FileList[1][Key] = Val
|
||||
|
||||
Map[CurrentKey].append(FileList)
|
||||
return True, ''
|
||||
|
||||
## Create header XML file
|
||||
#
|
||||
# @param DistMap: DistMap
|
||||
# @param Root: Root
|
||||
#
|
||||
def CreateHeaderXml(DistMap, Root):
|
||||
Element1 = CreateXmlElement('Name', DistMap['Name'],
|
||||
[], [['BaseName', DistMap['BaseName']]])
|
||||
Element2 = CreateXmlElement('GUID', DistMap['GUID'],
|
||||
[], [['Version', DistMap['Version']]])
|
||||
AttributeList = [['ReadOnly', DistMap['ReadOnly']],
|
||||
['RePackage', DistMap['RePackage']]]
|
||||
NodeList = [Element1,
|
||||
Element2,
|
||||
['Vendor', DistMap['Vendor']],
|
||||
['Date', DistMap['Date']],
|
||||
['Copyright', DistMap['Copyright']],
|
||||
['License', DistMap['License']],
|
||||
['Abstract', DistMap['Abstract']],
|
||||
['Description', DistMap['Description']],
|
||||
['Signature', DistMap['Signature']],
|
||||
['XmlSpecification', DistMap['XmlSpecification']],
|
||||
]
|
||||
Root.appendChild(CreateXmlElement('DistributionHeader', '',
|
||||
NodeList, AttributeList))
|
||||
|
||||
## Create tools XML file
|
||||
#
|
||||
# @param Map: Map
|
||||
# @param Root: Root
|
||||
# @param Tag: Tag
|
||||
#
|
||||
def CreateToolsXml(Map, Root, Tag):
|
||||
#
|
||||
# Check if all elements in this section are empty
|
||||
#
|
||||
for Key in Map:
|
||||
if len(Map[Key]) > 0:
|
||||
break
|
||||
else:
|
||||
return
|
||||
|
||||
NodeList = [['Name', Map['Name']],
|
||||
['Copyright', Map['Copyright']],
|
||||
['License', Map['License']],
|
||||
['Abstract', Map['Abstract']],
|
||||
['Description', Map['Description']],
|
||||
]
|
||||
HeaderNode = CreateXmlElement('Header', '', NodeList, [])
|
||||
NodeList = [HeaderNode]
|
||||
|
||||
for File in Map['FileList']:
|
||||
AttrList = []
|
||||
for Key in File[1]:
|
||||
AttrList.append([Key, File[1][Key]])
|
||||
NodeList.append(CreateXmlElement('Filename', File[0], [], AttrList))
|
||||
Root.appendChild(CreateXmlElement(Tag, '', NodeList, []))
|
||||
|
||||
## ValidateValues
|
||||
#
|
||||
# @param Key: Key
|
||||
# @param Value: Value
|
||||
# @param SectionName: SectionName
|
||||
#
|
||||
def ValidateValues(Key, Value, SectionName):
|
||||
if SectionName == 'DistributionHeader':
|
||||
Valid, Cause = ValidateRegValues(Key, Value)
|
||||
if not Valid:
|
||||
return Valid, Cause
|
||||
Valid = __ValidateDistHeader(Key, Value)
|
||||
if not Valid:
|
||||
return Valid, ST.ERR_VALUE_INVALID % (Key, SectionName)
|
||||
else:
|
||||
Valid = __ValidateOtherHeader(Key, Value)
|
||||
if not Valid:
|
||||
return Valid, ST.ERR_VALUE_INVALID % (Key, SectionName)
|
||||
return True, ''
|
||||
|
||||
## ValidateRegValues
|
||||
#
|
||||
# @param Key: Key
|
||||
# @param Value: Value
|
||||
#
|
||||
def ValidateRegValues(Key, Value):
|
||||
ValidateMap = {
|
||||
'ReadOnly' :
|
||||
('true|false', ST.ERR_BOOLEAN_VALUE % (Key, Value)),
|
||||
'RePackage' :
|
||||
('true|false', ST.ERR_BOOLEAN_VALUE % (Key, Value)),
|
||||
'GUID' :
|
||||
('[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}'
|
||||
'-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}',
|
||||
ST.ERR_GUID_VALUE % Value),
|
||||
'Version' : ('[0-9]+(\.[0-9]+)?', ST.ERR_VERSION_VALUE % \
|
||||
(Key, Value)),
|
||||
'XmlSpecification' : ('1\.1', ST.ERR_VERSION_XMLSPEC % Value)
|
||||
}
|
||||
if Key not in ValidateMap:
|
||||
return True, ''
|
||||
Elem = ValidateMap[Key]
|
||||
Match = re.compile(Elem[0]).match(Value)
|
||||
if Match and Match.start() == 0 and Match.end() == len(Value):
|
||||
return True, ''
|
||||
return False, Elem[1]
|
||||
|
||||
## __ValidateDistHeaderName
|
||||
#
|
||||
# @param Name: Name
|
||||
#
|
||||
def __ValidateDistHeaderName(Name):
|
||||
if len(Name) < 1:
|
||||
return False
|
||||
|
||||
for Char in Name:
|
||||
if ord(Char) < 0x20 or ord(Char) >= 0x7f:
|
||||
return False
|
||||
return True
|
||||
|
||||
## __ValidateDistHeaderBaseName
|
||||
#
|
||||
# @param BaseName: BaseName
|
||||
#
|
||||
def __ValidateDistHeaderBaseName(BaseName):
|
||||
if not BaseName:
|
||||
return False
|
||||
# if CheckLen and len(BaseName) < 2:
|
||||
# return False
|
||||
if not BaseName[0].isalnum() and BaseName[0] != '_':
|
||||
return False
|
||||
for Char in BaseName[1:]:
|
||||
if not Char.isalnum() and Char not in '-_':
|
||||
return False
|
||||
return True
|
||||
|
||||
## __ValidateDistHeaderAbstract
|
||||
#
|
||||
# @param Abstract: Abstract
|
||||
#
|
||||
def __ValidateDistHeaderAbstract(Abstract):
|
||||
return '\t' not in Abstract and len(Abstract.splitlines()) == 1
|
||||
|
||||
## __ValidateOtherHeaderAbstract
|
||||
#
|
||||
# @param Abstract: Abstract
|
||||
#
|
||||
def __ValidateOtherHeaderAbstract(Abstract):
|
||||
return __ValidateDistHeaderAbstract(Abstract)
|
||||
|
||||
## __ValidateDistHeader
|
||||
#
|
||||
# @param Key: Key
|
||||
# @param Value: Value
|
||||
#
|
||||
def __ValidateDistHeader(Key, Value):
|
||||
ValidateMap = {
|
||||
'Name' : __ValidateDistHeaderName,
|
||||
'BaseName' : __ValidateDistHeaderBaseName,
|
||||
'Abstract' : __ValidateDistHeaderAbstract,
|
||||
'Vendor' : __ValidateDistHeaderAbstract
|
||||
}
|
||||
return not (Value and Key in ValidateMap and not ValidateMap[Key](Value))
|
||||
|
||||
## __ValidateOtherHeader
|
||||
#
|
||||
# @param Key: Key
|
||||
# @param Value: Value
|
||||
#
|
||||
def __ValidateOtherHeader(Key, Value):
|
||||
ValidateMap = {
|
||||
'Name' : __ValidateDistHeaderName,
|
||||
'Abstract' : __ValidateOtherHeaderAbstract
|
||||
}
|
||||
return not (Value and Key in ValidateMap and not ValidateMap[Key](Value))
|
||||
|
||||
## Convert ini file to xml file
|
||||
#
|
||||
# @param IniFile
|
||||
#
|
||||
def IniToXml(IniFile):
|
||||
if not os.path.exists(IniFile):
|
||||
Logger.Error("UPT", FILE_NOT_FOUND, ST.ERR_TEMPLATE_NOTFOUND % IniFile)
|
||||
|
||||
DistMap = {'ReadOnly' : '', 'RePackage' : '', 'Name' : '',
|
||||
'BaseName' : '', 'GUID' : '', 'Version' : '', 'Vendor' : '',
|
||||
'Date' : '', 'Copyright' : '', 'License' : '', 'Abstract' : '',
|
||||
'Description' : '', 'Signature' : '', 'XmlSpecification' : ''
|
||||
}
|
||||
|
||||
ToolsMap = {'Name' : '', 'Copyright' : '', 'License' : '',
|
||||
'Abstract' : '', 'Description' : '', 'FileList' : []}
|
||||
#
|
||||
# Only FileList is a list: [['file1', {}], ['file2', {}], ...]
|
||||
#
|
||||
MiscMap = {'Name' : '', 'Copyright' : '', 'License' : '',
|
||||
'Abstract' : '', 'Description' : '', 'FileList' : []}
|
||||
|
||||
SectionMap = {
|
||||
'DistributionHeader' : DistMap,
|
||||
'ToolsHeader' : ToolsMap,
|
||||
'MiscellaneousFilesHeader' : MiscMap
|
||||
}
|
||||
|
||||
PathValidator = {
|
||||
'ToolsHeader' : ValidateToolsFile,
|
||||
'MiscellaneousFilesHeader' : ValidateMiscFile
|
||||
}
|
||||
|
||||
ParsedSection = []
|
||||
|
||||
SectionName = ''
|
||||
CurrentKey = ''
|
||||
PreMap = None
|
||||
Map = None
|
||||
FileContent = ConvertSpecialChar(open(IniFile, 'rb').readlines())
|
||||
LastIndex = 0
|
||||
for Index in range(0, len(FileContent)):
|
||||
LastIndex = Index
|
||||
Line = FileContent[Index].strip()
|
||||
if Line == '':
|
||||
continue
|
||||
if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:
|
||||
CurrentKey = ''
|
||||
SectionName = Line[1:-1].strip()
|
||||
if SectionName not in SectionMap:
|
||||
IniParseError(ST.ERR_SECTION_NAME_INVALID % SectionName,
|
||||
IniFile, Index+1)
|
||||
|
||||
if SectionName in ParsedSection:
|
||||
IniParseError(ST.ERR_SECTION_REDEFINE % SectionName,
|
||||
IniFile, Index+1)
|
||||
else:
|
||||
ParsedSection.append(SectionName)
|
||||
|
||||
Map = SectionMap[SectionName]
|
||||
continue
|
||||
if not Map:
|
||||
IniParseError(ST.ERR_SECTION_NAME_NONE, IniFile, Index+1)
|
||||
TokenList = Line.split(TAB_EQUAL_SPLIT, 1)
|
||||
TempKey = TokenList[0].strip()
|
||||
#
|
||||
# Value spanned multiple or same keyword appears more than one time
|
||||
#
|
||||
if len(TokenList) < 2 or TempKey not in Map:
|
||||
if CurrentKey == '':
|
||||
IniParseError(ST.ERR_KEYWORD_INVALID % TempKey,
|
||||
IniFile, Index+1)
|
||||
elif CurrentKey == 'FileList':
|
||||
#
|
||||
# Special for FileList
|
||||
#
|
||||
Valid, Cause = ParseFileList(Line, Map, CurrentKey,
|
||||
PathValidator[SectionName])
|
||||
if not Valid:
|
||||
IniParseError(Cause, IniFile, Index+1)
|
||||
|
||||
else:
|
||||
#
|
||||
# Multiple lines for one key such as license
|
||||
# Or if string on the left side of '=' is not a keyword
|
||||
#
|
||||
Map[CurrentKey] = ''.join([Map[CurrentKey], '\n', Line])
|
||||
Valid, Cause = ValidateValues(CurrentKey,
|
||||
Map[CurrentKey], SectionName)
|
||||
if not Valid:
|
||||
IniParseError(Cause, IniFile, Index+1)
|
||||
continue
|
||||
|
||||
if (TokenList[1].strip() == ''):
|
||||
IniParseError(ST.ERR_EMPTY_VALUE, IniFile, Index+1)
|
||||
|
||||
#
|
||||
# A keyword found
|
||||
#
|
||||
CurrentKey = TempKey
|
||||
if Map[CurrentKey]:
|
||||
IniParseError(ST.ERR_KEYWORD_REDEFINE % CurrentKey,
|
||||
IniFile, Index+1)
|
||||
|
||||
if id(Map) != id(PreMap) and Map['Copyright']:
|
||||
PreMap = Map
|
||||
Copyright = Map['Copyright'].lower()
|
||||
Pos = Copyright.find('copyright')
|
||||
if Pos == -1:
|
||||
IniParseError(ST.ERR_COPYRIGHT_CONTENT, IniFile, Index)
|
||||
if not Copyright[Pos + len('copyright'):].lstrip(' ').startswith('('):
|
||||
IniParseError(ST.ERR_COPYRIGHT_CONTENT, IniFile, Index)
|
||||
|
||||
if CurrentKey == 'FileList':
|
||||
Valid, Cause = ParseFileList(TokenList[1], Map, CurrentKey,
|
||||
PathValidator[SectionName])
|
||||
if not Valid:
|
||||
IniParseError(Cause, IniFile, Index+1)
|
||||
else:
|
||||
Map[CurrentKey] = TokenList[1].strip()
|
||||
Valid, Cause = ValidateValues(CurrentKey,
|
||||
Map[CurrentKey], SectionName)
|
||||
if not Valid:
|
||||
IniParseError(Cause, IniFile, Index+1)
|
||||
|
||||
if id(Map) != id(PreMap) and Map['Copyright'] and 'copyright' not in Map['Copyright'].lower():
|
||||
IniParseError(ST.ERR_COPYRIGHT_CONTENT, IniFile, LastIndex)
|
||||
|
||||
#
|
||||
# Check mandatory keys
|
||||
#
|
||||
CheckMdtKeys(DistMap, IniFile, LastIndex,
|
||||
(('ToolsHeader', ToolsMap), ('MiscellaneousFilesHeader', MiscMap))
|
||||
)
|
||||
|
||||
return CreateXml(DistMap, ToolsMap, MiscMap, IniFile)
|
||||
|
||||
|
||||
## CheckMdtKeys
|
||||
#
|
||||
# @param MdtDistKeys: All mandatory keys
|
||||
# @param DistMap: Dist content
|
||||
# @param IniFile: Ini file
|
||||
# @param LastIndex: Last index of Ini file
|
||||
# @param Maps: Tools and Misc section name and map. (('section_name', map),*)
|
||||
#
|
||||
def CheckMdtKeys(DistMap, IniFile, LastIndex, Maps):
|
||||
MdtDistKeys = ['Name', 'GUID', 'Version', 'Vendor', 'Copyright', 'License', 'Abstract', 'XmlSpecification']
|
||||
for Key in MdtDistKeys:
|
||||
if Key not in DistMap or DistMap[Key] == '':
|
||||
IniParseError(ST.ERR_KEYWORD_MANDATORY % Key, IniFile, LastIndex+1)
|
||||
|
||||
if '.' not in DistMap['Version']:
|
||||
DistMap['Version'] = DistMap['Version'] + '.0'
|
||||
|
||||
DistMap['Date'] = str(strftime("%Y-%m-%dT%H:%M:%S", localtime()))
|
||||
|
||||
#
|
||||
# Check Tools Surface Area according to UPT Spec
|
||||
# <Tools> {0,}
|
||||
# <Header> ... </Header> {0,1}
|
||||
# <Filename> ... </Filename> {1,}
|
||||
# </Tools>
|
||||
# <Header>
|
||||
# <Name> xs:normalizedString </Name> {1}
|
||||
# <Copyright> xs:string </Copyright> {0,1}
|
||||
# <License> xs:string </License> {0,1}
|
||||
# <Abstract> xs:normalizedString </Abstract> {0,1}
|
||||
# <Description> xs:string </Description> {0,1}
|
||||
# </Header>
|
||||
#
|
||||
for Item in Maps:
|
||||
Map = Item[1]
|
||||
NonEmptyKey = 0
|
||||
for Key in Map:
|
||||
if Map[Key]:
|
||||
NonEmptyKey += 1
|
||||
|
||||
if NonEmptyKey > 0 and not Map['FileList']:
|
||||
IniParseError(ST.ERR_KEYWORD_MANDATORY % (Item[0] + '.FileList'), IniFile, LastIndex+1)
|
||||
|
||||
if NonEmptyKey > 0 and not Map['Name']:
|
||||
IniParseError(ST.ERR_KEYWORD_MANDATORY % (Item[0] + '.Name'), IniFile, LastIndex+1)
|
||||
|
||||
## CreateXml
|
||||
#
|
||||
# @param DistMap: Dist Content
|
||||
# @param ToolsMap: Tools Content
|
||||
# @param MiscMap: Misc Content
|
||||
# @param IniFile: Ini File
|
||||
#
|
||||
def CreateXml(DistMap, ToolsMap, MiscMap, IniFile):
|
||||
Attrs = [['xmlns', 'http://www.uefi.org/2011/1.1'],
|
||||
['xmlns:xsi', 'http:/www.w3.org/2001/XMLSchema-instance'],
|
||||
]
|
||||
Root = CreateXmlElement('DistributionPackage', '', [], Attrs)
|
||||
CreateHeaderXml(DistMap, Root)
|
||||
CreateToolsXml(ToolsMap, Root, 'Tools')
|
||||
CreateToolsXml(MiscMap, Root, 'MiscellaneousFiles')
|
||||
|
||||
FileAndExt = IniFile.rsplit('.', 1)
|
||||
if len(FileAndExt) > 1:
|
||||
FileName = FileAndExt[0] + '.xml'
|
||||
else:
|
||||
FileName = IniFile + '.xml'
|
||||
File = open(FileName, 'w')
|
||||
|
||||
try:
|
||||
File.write(Root.toprettyxml(indent = ' '))
|
||||
finally:
|
||||
File.close()
|
||||
return FileName
|
||||
|
997
BaseTools/Source/Python/UPT/Xml/ModuleSurfaceAreaXml.py
Normal file
997
BaseTools/Source/Python/UPT/Xml/ModuleSurfaceAreaXml.py
Normal file
@@ -0,0 +1,997 @@
|
||||
## @file
|
||||
# This file is used to parse a Module file of .PKG file
|
||||
#
|
||||
# Copyright (c) 2011, 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
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
'''
|
||||
ModuleSurfaceAreaXml
|
||||
'''
|
||||
from xml.dom import minidom
|
||||
|
||||
from Library.String import ConvertNEToNOTEQ
|
||||
from Library.String import ConvertNOTEQToNE
|
||||
from Library.String import GetStringOfList
|
||||
from Library.Xml.XmlRoutines import XmlElement
|
||||
from Library.Xml.XmlRoutines import XmlAttribute
|
||||
from Library.Xml.XmlRoutines import XmlNode
|
||||
from Library.Xml.XmlRoutines import XmlList
|
||||
from Library.Xml.XmlRoutines import CreateXmlElement
|
||||
from Object.POM.CommonObject import GuidVersionObject
|
||||
from Object.POM.ModuleObject import BootModeObject
|
||||
from Object.POM.ModuleObject import DepexObject
|
||||
from Object.POM.ModuleObject import ModuleObject
|
||||
from Object.POM.ModuleObject import EventObject
|
||||
from Object.POM.ModuleObject import HobObject
|
||||
from Object.POM.ModuleObject import SourceFileObject
|
||||
from Object.POM.ModuleObject import PackageDependencyObject
|
||||
from Object.POM.ModuleObject import ExternObject
|
||||
from Object.POM.ModuleObject import BinaryFileObject
|
||||
from Object.POM.ModuleObject import AsBuiltObject
|
||||
from Object.POM.ModuleObject import BinaryBuildFlagObject
|
||||
from Xml.CommonXml import ClonedFromXml
|
||||
from Xml.CommonXml import HeaderXml
|
||||
from Xml.CommonXml import HelpTextXml
|
||||
from Xml.CommonXml import CommonDefinesXml
|
||||
from Xml.CommonXml import LibraryClassXml
|
||||
from Xml.CommonXml import UserExtensionsXml
|
||||
from Xml.CommonXml import MiscellaneousFileXml
|
||||
from Xml.CommonXml import FilenameXml
|
||||
from Xml.GuidProtocolPpiXml import GuidXml
|
||||
from Xml.GuidProtocolPpiXml import ProtocolXml
|
||||
from Xml.GuidProtocolPpiXml import PpiXml
|
||||
from Xml.PcdXml import PcdEntryXml
|
||||
from Xml.XmlParserMisc import GetHelpTextList
|
||||
from Library import GlobalData
|
||||
from Library.Misc import GetSplitValueList
|
||||
|
||||
## BinaryFileXml
|
||||
#
|
||||
# represent the following XML item
|
||||
#
|
||||
# <BinaryFile>
|
||||
# <Filename
|
||||
# FileType=" FileType " {1}
|
||||
# SupArchList=" ArchListType " {0,1}
|
||||
# FeatureFlag=" FeatureFlagExpression " {0,1} >
|
||||
# xs:anyURI
|
||||
# </Filename> {1,}
|
||||
# <AsBuilt> ... </AsBuilt> {0,}
|
||||
# </BinaryFile> {1,}
|
||||
#
|
||||
class BinaryFileXml(object):
|
||||
def __init__(self):
|
||||
self.FileNames = []
|
||||
self.AsBuiltList = []
|
||||
self.PatchPcdValues = ''
|
||||
self.PcdExValues = ''
|
||||
self.LibraryInstances = ''
|
||||
self.BuildFlags = ''
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
if self.FileNames:
|
||||
pass
|
||||
BinaryFile = BinaryFileObject()
|
||||
FilenameList = []
|
||||
for SubItem in XmlList(Item, '%s/Filename' % Key):
|
||||
Axml = FilenameXml()
|
||||
Bxml = Axml.FromXml(SubItem, 'Filename')
|
||||
FilenameList.append(Bxml)
|
||||
BinaryFile.SetFileNameList(FilenameList)
|
||||
if GlobalData.gIS_BINARY_INF:
|
||||
AsBuiltList = []
|
||||
for AsBuiltItem in XmlList(Item, '%s/AsBuilt' % Key):
|
||||
AsBuilt = AsBuiltObject()
|
||||
|
||||
PatchPcdValueList = []
|
||||
for SubItem in XmlList(AsBuiltItem, 'AsBuilt/PatchPcdValue'):
|
||||
Axml = PcdEntryXml()
|
||||
Bxml = Axml.FromXml(SubItem, 'PatchPcdValue')
|
||||
PatchPcdValueList.append(Bxml)
|
||||
AsBuilt.SetPatchPcdList(PatchPcdValueList)
|
||||
PcdExValueList = []
|
||||
for SubItem in XmlList(AsBuiltItem, 'AsBuilt/PcdExValue'):
|
||||
Axml = PcdEntryXml()
|
||||
Bxml = Axml.FromXml(SubItem, 'PcdExValue')
|
||||
PcdExValueList.append(Bxml)
|
||||
AsBuilt.SetPcdExList(PcdExValueList)
|
||||
LibraryList = []
|
||||
for SubItem in XmlList(Item, '%s/AsBuilt/LibraryInstances/GUID' % Key):
|
||||
GuidVerObj = GuidVersionObject()
|
||||
GUID = XmlElement(SubItem, 'GUID')
|
||||
Version = XmlAttribute(XmlNode(SubItem, 'GUID'), 'Version')
|
||||
GuidVerObj.SetGuid(GUID)
|
||||
GuidVerObj.SetVersion(Version)
|
||||
LibraryList.append(GuidVerObj)
|
||||
if XmlList(Item, '%s/AsBuilt/LibraryInstances' % Key) and not LibraryList:
|
||||
LibraryList = [None]
|
||||
AsBuilt.SetLibraryInstancesList(LibraryList)
|
||||
BuildFlagList = []
|
||||
for SubItem in XmlList(Item, '%s/AsBuilt/BuildFlags' % Key):
|
||||
BuildFlag = BuildFlagXml()
|
||||
BuildFlagList.append(BuildFlag.FromXml2(SubItem, 'BuildFlags'))
|
||||
AsBuilt.SetBuildFlagsList(BuildFlagList)
|
||||
AsBuiltList.append(AsBuilt)
|
||||
BinaryFile.SetAsBuiltList(AsBuiltList)
|
||||
return BinaryFile
|
||||
|
||||
def ToXml(self, BinaryFile, Key):
|
||||
if self.FileNames:
|
||||
pass
|
||||
NodeList = []
|
||||
FilenameList = BinaryFile.GetFileNameList()
|
||||
for Filename in FilenameList:
|
||||
Tmp = FilenameXml()
|
||||
NodeList.append(Tmp.ToXml(Filename, 'Filename'))
|
||||
|
||||
if GlobalData.gIS_BINARY_INF:
|
||||
AsBuildList = BinaryFile.GetAsBuiltList()
|
||||
PatchPcdValueList = AsBuildList.GetPatchPcdList()
|
||||
PcdExList = AsBuildList.GetPcdExList()
|
||||
LibGuidVerList = AsBuildList.GetLibraryInstancesList()
|
||||
BuildFlagList = AsBuildList.GetBuildFlagsList()
|
||||
|
||||
AsBuiltNodeList = []
|
||||
|
||||
for Pcd in PatchPcdValueList:
|
||||
Tmp = PcdEntryXml()
|
||||
AsBuiltNodeList.append(Tmp.ToXml4(Pcd, 'PatchPcdValue'))
|
||||
|
||||
for Pcd in PcdExList:
|
||||
Tmp = PcdEntryXml()
|
||||
AsBuiltNodeList.append(Tmp.ToXml4(Pcd, 'PcdExValue'))
|
||||
|
||||
GuiVerElemList = []
|
||||
for LibGuidVer in LibGuidVerList:
|
||||
GuiVerElem = \
|
||||
CreateXmlElement('GUID', LibGuidVer.GetLibGuid(), [], [['Version', LibGuidVer.GetLibVersion()]])
|
||||
GuiVerElemList.append(GuiVerElem)
|
||||
if len(GuiVerElemList) > 0:
|
||||
LibGuidVerElem = CreateXmlElement('LibraryInstances', '', GuiVerElemList, [])
|
||||
AsBuiltNodeList.append(LibGuidVerElem)
|
||||
|
||||
for BuildFlag in BuildFlagList:
|
||||
Tmp = BuildFlagXml()
|
||||
Elem = CreateXmlElement('BuildFlags', ''.join(BuildFlag), [], [])
|
||||
AsBuiltNodeList.append(Elem)
|
||||
|
||||
if len(AsBuiltNodeList) > 0:
|
||||
Element = CreateXmlElement('AsBuilt', '', AsBuiltNodeList, [])
|
||||
NodeList.append(Element)
|
||||
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, [])
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = "BinaryFiles:"
|
||||
for Item in self.FileNames:
|
||||
Str = Str + '\n\t' + str(Item)
|
||||
for Item in self.PatchPcdValues:
|
||||
Str = Str + '\n\t' + str(Item)
|
||||
for Item in self.PcdExValues:
|
||||
Str = Str + '\n\t' + str(Item)
|
||||
for Item in self.LibraryInstances:
|
||||
Str = Str + '\n\t' + str(Item)
|
||||
for Item in self.BuildFlags:
|
||||
Str = Str + '\n\t' + str(Item)
|
||||
return Str
|
||||
|
||||
##
|
||||
# PackageXml
|
||||
#
|
||||
class PackageXml(object):
|
||||
def __init__(self):
|
||||
self.Description = ''
|
||||
self.Guid = ''
|
||||
self.Version = ''
|
||||
self.CommonDefines = CommonDefinesXml()
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.Description = XmlElement(Item, '%s/Description' % Key)
|
||||
self.Guid = XmlElement(Item, '%s/GUID' % Key)
|
||||
self.Version = XmlAttribute(XmlNode(Item, '%s/GUID' % Key), 'Version')
|
||||
self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)
|
||||
|
||||
PackageDependency = PackageDependencyObject()
|
||||
PackageDependency.SetPackage(self.Description)
|
||||
PackageDependency.SetGuid(self.Guid)
|
||||
PackageDependency.SetVersion(self.Version)
|
||||
PackageDependency.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))
|
||||
PackageDependency.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
|
||||
return PackageDependency
|
||||
|
||||
def ToXml(self, PackageDependency, Key):
|
||||
if self.Guid:
|
||||
pass
|
||||
AttributeList = [['SupArchList', GetStringOfList(PackageDependency.GetSupArchList())],
|
||||
['FeatureFlag', ConvertNEToNOTEQ(PackageDependency.GetFeatureFlag())], ]
|
||||
Element1 = CreateXmlElement('GUID', PackageDependency.GetGuid(), [],
|
||||
[['Version', PackageDependency.GetVersion()]])
|
||||
NodeList = [['Description', PackageDependency.GetPackage()], Element1, ]
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = "Description = %s Guid = %s Version = %s %s" \
|
||||
% (self.Description, self.Guid, self.Version, self.CommonDefines)
|
||||
return Str
|
||||
##
|
||||
# ExternXml
|
||||
#
|
||||
class ExternXml(object):
|
||||
def __init__(self):
|
||||
self.CommonDefines = CommonDefinesXml()
|
||||
self.EntryPoint = ''
|
||||
self.UnloadImage = ''
|
||||
self.Constructor = ''
|
||||
self.Destructor = ''
|
||||
self.SupModList = ''
|
||||
self.SupArchList = ''
|
||||
self.HelpText = []
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.CommonDefines.FromXml(Item, Key)
|
||||
self.EntryPoint = XmlElement(Item, '%s/EntryPoint' % Key)
|
||||
self.UnloadImage = XmlElement(Item, '%s/UnloadImage' % Key)
|
||||
self.Constructor = XmlElement(Item, '%s/Constructor' % Key)
|
||||
self.Destructor = XmlElement(Item, '%s/Destructor' % Key)
|
||||
|
||||
Extern = ExternObject()
|
||||
Extern.SetEntryPoint(self.EntryPoint)
|
||||
Extern.SetUnloadImage(self.UnloadImage)
|
||||
Extern.SetConstructor(self.Constructor)
|
||||
Extern.SetDestructor(self.Destructor)
|
||||
if self.CommonDefines.SupModList:
|
||||
Extern.SetSupModList(self.CommonDefines.SupModList)
|
||||
if self.CommonDefines.SupArchList:
|
||||
Extern.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
return Extern
|
||||
|
||||
def ToXml(self, Extern, Key):
|
||||
if self.HelpText:
|
||||
pass
|
||||
|
||||
NodeList = []
|
||||
if Extern.GetEntryPoint():
|
||||
NodeList.append(['EntryPoint', Extern.GetEntryPoint()])
|
||||
if Extern.GetUnloadImage():
|
||||
NodeList.append(['UnloadImage', Extern.GetUnloadImage()])
|
||||
if Extern.GetConstructor():
|
||||
NodeList.append(['Constructor', Extern.GetConstructor()])
|
||||
if Extern.GetDestructor():
|
||||
NodeList.append(['Destructor', Extern.GetDestructor()])
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, [])
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = "EntryPoint = %s UnloadImage = %s Constructor = %s Destructor = %s %s" \
|
||||
% (self.EntryPoint, self.UnloadImage, self.Constructor, self.Destructor, self.CommonDefines)
|
||||
for Item in self.HelpText:
|
||||
Str = Str + '\n\t' + str(Item)
|
||||
return Str
|
||||
##
|
||||
# DepexXml
|
||||
#
|
||||
class DepexXml(object):
|
||||
def __init__(self):
|
||||
self.CommonDefines = CommonDefinesXml()
|
||||
self.Expression = None
|
||||
self.HelpText = []
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
if not Item:
|
||||
return None
|
||||
self.CommonDefines.FromXml(Item, Key)
|
||||
self.Expression = XmlElement(Item, '%s/Expression' % Key)
|
||||
for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
|
||||
HelpTextObj = HelpTextXml()
|
||||
HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
|
||||
self.HelpText.append(HelpTextObj)
|
||||
|
||||
Depex = DepexObject()
|
||||
Depex.SetDepex(self.Expression)
|
||||
Depex.SetModuleType(self.CommonDefines.SupModList)
|
||||
Depex.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
Depex.SetFeatureFlag(self.CommonDefines.FeatureFlag)
|
||||
Depex.SetHelpTextList(GetHelpTextList(self.HelpText))
|
||||
|
||||
return Depex
|
||||
|
||||
def ToXml(self, Depex, Key):
|
||||
if self.HelpText:
|
||||
pass
|
||||
AttributeList = [['SupArchList', GetStringOfList(Depex.GetSupArchList())],
|
||||
['SupModList', Depex.GetModuleType()]]
|
||||
NodeList = [['Expression', Depex.GetDepex()]]
|
||||
if Depex.GetHelpText():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Depex.GetHelpText(), 'HelpText'))
|
||||
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = "Expression = %s" % (self.Expression)
|
||||
for Item in self.HelpText:
|
||||
Str = Str + '\n\t' + str(Item)
|
||||
return Str
|
||||
|
||||
##
|
||||
# BootModeXml
|
||||
#
|
||||
class BootModeXml(object):
|
||||
def __init__(self):
|
||||
self.SupportedBootModes = ''
|
||||
self.CommonDefines = CommonDefinesXml()
|
||||
self.HelpText = []
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.SupportedBootModes = \
|
||||
XmlElement(Item, '%s/SupportedBootModes' % Key)
|
||||
self.CommonDefines.FromXml(Item, Key)
|
||||
for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
|
||||
HelpTextObj = HelpTextXml()
|
||||
HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
|
||||
self.HelpText.append(HelpTextObj)
|
||||
|
||||
BootMode = BootModeObject()
|
||||
BootMode.SetSupportedBootModes(self.SupportedBootModes)
|
||||
BootMode.SetUsage(self.CommonDefines.Usage)
|
||||
BootMode.SetHelpTextList(GetHelpTextList(self.HelpText))
|
||||
|
||||
return BootMode
|
||||
|
||||
def ToXml(self, BootMode, Key):
|
||||
if self.HelpText:
|
||||
pass
|
||||
AttributeList = [['Usage', BootMode.GetUsage()], ]
|
||||
NodeList = [['SupportedBootModes', BootMode.GetSupportedBootModes()]]
|
||||
for Item in BootMode.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item, 'HelpText'))
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = "SupportedBootModes = %s %s" % (self.SupportedBootModes, self.CommonDefines)
|
||||
for Item in self.HelpText:
|
||||
Str = Str + '\n\t' + str(Item)
|
||||
return Str
|
||||
##
|
||||
# EventXml
|
||||
#
|
||||
class EventXml(object):
|
||||
def __init__(self):
|
||||
self.EventType = ''
|
||||
self.Name = ''
|
||||
self.CommonDefines = CommonDefinesXml()
|
||||
self.HelpText = []
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.EventType = XmlAttribute(XmlNode(Item, '%s' % Key), 'EventType')
|
||||
self.Name = XmlElement(Item, '%s' % Key)
|
||||
self.CommonDefines.FromXml(Item, Key)
|
||||
for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
|
||||
HelpTextObj = HelpTextXml()
|
||||
HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
|
||||
self.HelpText.append(HelpTextObj)
|
||||
|
||||
Event = EventObject()
|
||||
Event.SetEventType(self.EventType)
|
||||
Event.SetUsage(self.CommonDefines.Usage)
|
||||
Event.SetHelpTextList(GetHelpTextList(self.HelpText))
|
||||
|
||||
return Event
|
||||
|
||||
def ToXml(self, Event, Key):
|
||||
if self.HelpText:
|
||||
pass
|
||||
AttributeList = [['EventType', Event.GetEventType()],
|
||||
['Usage', Event.GetUsage()],
|
||||
]
|
||||
NodeList = []
|
||||
for Item in Event.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item, 'HelpText'))
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = "EventType = %s %s" % (self.EventType, self.CommonDefines)
|
||||
for Item in self.HelpText:
|
||||
Str = Str + '\n\t' + str(Item)
|
||||
return Str
|
||||
##
|
||||
# HobXml
|
||||
#
|
||||
class HobXml(object):
|
||||
def __init__(self):
|
||||
self.HobType = ''
|
||||
self.Name = ''
|
||||
self.CommonDefines = CommonDefinesXml()
|
||||
self.HelpText = []
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.HobType = XmlAttribute(XmlNode(Item, '%s' % Key), 'HobType')
|
||||
self.Name = XmlElement(Item, '%s' % Key)
|
||||
self.CommonDefines.FromXml(Item, Key)
|
||||
for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
|
||||
HelpTextObj = HelpTextXml()
|
||||
HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
|
||||
self.HelpText.append(HelpTextObj)
|
||||
|
||||
Hob = HobObject()
|
||||
Hob.SetHobType(self.HobType)
|
||||
Hob.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
Hob.SetUsage(self.CommonDefines.Usage)
|
||||
Hob.SetHelpTextList(GetHelpTextList(self.HelpText))
|
||||
|
||||
return Hob
|
||||
|
||||
def ToXml(self, Hob, Key):
|
||||
if self.Name:
|
||||
pass
|
||||
AttributeList = [['HobType', Hob.GetHobType()],
|
||||
['Usage', Hob.GetUsage()],
|
||||
['SupArchList', GetStringOfList(Hob.GetSupArchList())], ]
|
||||
NodeList = []
|
||||
for Item in Hob.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item, 'HelpText'))
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = "HobType = %s %s" % (self.HobType, self.CommonDefines)
|
||||
for Item in self.HelpText:
|
||||
Str = Str + '\n\t' + str(Item)
|
||||
return Str
|
||||
|
||||
##
|
||||
# SourceFileXml
|
||||
#
|
||||
class SourceFileXml(object):
|
||||
def __init__(self):
|
||||
self.SourceFile = ''
|
||||
self.ToolChainFamily = ''
|
||||
self.FileType = ''
|
||||
self.CommonDefines = CommonDefinesXml()
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.ToolChainFamily = XmlAttribute(Item, 'Family')
|
||||
self.SourceFile = XmlElement(Item, 'Filename')
|
||||
self.CommonDefines.FromXml(Item, Key)
|
||||
|
||||
self.CommonDefines.FeatureFlag = ConvertNOTEQToNE(self.CommonDefines.FeatureFlag)
|
||||
|
||||
SourceFile = SourceFileObject()
|
||||
SourceFile.SetSourceFile(self.SourceFile)
|
||||
SourceFile.SetFamily(self.ToolChainFamily)
|
||||
SourceFile.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
SourceFile.SetFeatureFlag(self.CommonDefines.FeatureFlag)
|
||||
|
||||
return SourceFile
|
||||
|
||||
def ToXml(self, SourceFile, Key):
|
||||
if self.SourceFile:
|
||||
pass
|
||||
FeatureFlag = ConvertNEToNOTEQ(SourceFile.GetFeatureFlag())
|
||||
AttributeList = [['SupArchList', GetStringOfList(SourceFile.GetSupArchList())],
|
||||
['Family', SourceFile.GetFamily()],
|
||||
['FeatureFlag', FeatureFlag], ]
|
||||
Root = CreateXmlElement('%s' % Key, SourceFile.GetSourceFile(), [], AttributeList)
|
||||
return Root
|
||||
|
||||
##
|
||||
# ModulePropertyXml
|
||||
#
|
||||
class ModulePropertyXml(object):
|
||||
def __init__(self):
|
||||
self.CommonDefines = CommonDefinesXml()
|
||||
self.ModuleType = ''
|
||||
self.Path = ''
|
||||
self.PcdIsDriver = ''
|
||||
self.UefiSpecificationVersion = ''
|
||||
self.PiSpecificationVersion = ''
|
||||
self.SpecificationList = []
|
||||
self.SpecificationVersion = ''
|
||||
self.BootModes = []
|
||||
self.Events = []
|
||||
self.HOBs = []
|
||||
|
||||
def FromXml(self, Item, Key, Header=None):
|
||||
self.CommonDefines.FromXml(Item, Key)
|
||||
self.ModuleType = XmlElement(Item, '%s/ModuleType' % Key)
|
||||
self.Path = XmlElement(Item, '%s/Path' % Key)
|
||||
self.PcdIsDriver = XmlElement(Item, '%s/PcdIsDriver' % Key)
|
||||
self.UefiSpecificationVersion = XmlElement(Item, '%s/UefiSpecificationVersion' % Key)
|
||||
self.PiSpecificationVersion = XmlElement(Item, '%s/PiSpecificationVersion' % Key)
|
||||
for SubItem in XmlList(Item, '%s/Specification' % Key):
|
||||
Specification = XmlElement(SubItem, '/Specification')
|
||||
Version = XmlAttribute(XmlNode(SubItem, '/Specification'), 'Version')
|
||||
self.SpecificationList.append((Specification, Version))
|
||||
for SubItem in XmlList(Item, '%s/BootMode' % Key):
|
||||
Axml = BootModeXml()
|
||||
BootMode = Axml.FromXml(SubItem, 'BootMode')
|
||||
self.BootModes.append(BootMode)
|
||||
for SubItem in XmlList(Item, '%s/Event' % Key):
|
||||
Axml = EventXml()
|
||||
Event = Axml.FromXml(SubItem, 'Event')
|
||||
self.Events.append(Event)
|
||||
for SubItem in XmlList(Item, '%s/HOB' % Key):
|
||||
Axml = HobXml()
|
||||
Hob = Axml.FromXml(SubItem, 'HOB')
|
||||
self.HOBs.append(Hob)
|
||||
|
||||
if Header == None:
|
||||
Header = ModuleObject()
|
||||
|
||||
Header.SetModuleType(self.ModuleType)
|
||||
Header.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
Header.SetModulePath(self.Path)
|
||||
|
||||
Header.SetPcdIsDriver(self.PcdIsDriver)
|
||||
Header.SetUefiSpecificationVersion(self.UefiSpecificationVersion)
|
||||
Header.SetPiSpecificationVersion(self.PiSpecificationVersion)
|
||||
Header.SetSpecList(self.SpecificationList)
|
||||
|
||||
return Header, self.BootModes, self.Events, self.HOBs
|
||||
|
||||
|
||||
def ToXml(self, Header, BootModes, Events, Hobs, Key):
|
||||
if self.ModuleType:
|
||||
pass
|
||||
AttributeList = [['SupArchList', GetStringOfList(Header.GetSupArchList())], ]
|
||||
|
||||
NodeList = [['ModuleType', Header.GetModuleType()],
|
||||
['Path', Header.GetModulePath()],
|
||||
['PcdIsDriver', Header.GetPcdIsDriver()],
|
||||
['UefiSpecificationVersion', Header.GetUefiSpecificationVersion()],
|
||||
['PiSpecificationVersion', Header.GetPiSpecificationVersion()],
|
||||
]
|
||||
for Item in Header.GetSpecList():
|
||||
Spec, Version = Item
|
||||
SpecElem = CreateXmlElement('Specification', Spec, [], [['Version', Version]])
|
||||
NodeList.append(SpecElem)
|
||||
|
||||
for Item in BootModes:
|
||||
Tmp = BootModeXml()
|
||||
NodeList.append(Tmp.ToXml(Item, 'BootMode'))
|
||||
for Item in Events:
|
||||
Tmp = EventXml()
|
||||
NodeList.append(Tmp.ToXml(Item, 'Event'))
|
||||
for Item in Hobs:
|
||||
Tmp = HobXml()
|
||||
NodeList.append(Tmp.ToXml(Item, 'HOB'))
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = "ModuleType = %s Path = %s PcdIsDriver = %s UefiSpecificationVersion = %s PiSpecificationVersion = %s \
|
||||
Specification = %s SpecificationVersion = %s %s" % \
|
||||
(self.ModuleType, self.Path, self.PcdIsDriver, \
|
||||
self.UefiSpecificationVersion, self.PiSpecificationVersion, \
|
||||
self.SpecificationList, self.SpecificationVersion, self.CommonDefines)
|
||||
for Item in self.BootModes:
|
||||
Str = Str + '\n\t' + str(Item)
|
||||
for Item in self.Events:
|
||||
Str = Str + '\n\t' + str(Item)
|
||||
for Item in self.HOBs:
|
||||
Str = Str + '\n\t' + str(Item)
|
||||
return Str
|
||||
|
||||
##
|
||||
# ModuleXml
|
||||
#
|
||||
class ModuleSurfaceAreaXml(object):
|
||||
def __init__(self, Package=''):
|
||||
self.Module = None
|
||||
#
|
||||
# indicate the package that this module resides in
|
||||
#
|
||||
self.Package = Package
|
||||
|
||||
def FromXml2(self, Item, Module):
|
||||
if self.Module:
|
||||
pass
|
||||
#
|
||||
# PeiDepex
|
||||
#
|
||||
PeiDepexList = []
|
||||
for SubItem in XmlList(Item, '/ModuleSurfaceArea/PeiDepex'):
|
||||
Tmp = DepexXml()
|
||||
Depex = Tmp.FromXml(XmlNode(SubItem, 'PeiDepex'), 'PeiDepex')
|
||||
PeiDepexList.append(Depex)
|
||||
Module.SetPeiDepex(PeiDepexList)
|
||||
|
||||
#
|
||||
# DxeDepex
|
||||
#
|
||||
DxeDepexList = []
|
||||
for SubItem in XmlList(Item, '/ModuleSurfaceArea/DxeDepex'):
|
||||
Tmp = DepexXml()
|
||||
Depex = Tmp.FromXml(XmlNode(SubItem, 'DxeDepex'), 'DxeDepex')
|
||||
DxeDepexList.append(Depex)
|
||||
Module.SetDxeDepex(DxeDepexList)
|
||||
|
||||
#
|
||||
# SmmDepex
|
||||
#
|
||||
SmmDepexList = []
|
||||
for SubItem in XmlList(Item, '/ModuleSurfaceArea/SmmDepex'):
|
||||
Tmp = DepexXml()
|
||||
Depex = Tmp.FromXml(XmlNode(SubItem, 'SmmDepex'), 'SmmDepex')
|
||||
SmmDepexList.append(Depex)
|
||||
Module.SetSmmDepex(SmmDepexList)
|
||||
|
||||
#
|
||||
# MiscellaneousFile
|
||||
Tmp = MiscellaneousFileXml()
|
||||
MiscFileList = Tmp.FromXml(XmlNode(Item, '/ModuleSurfaceArea/MiscellaneousFiles'), 'MiscellaneousFiles')
|
||||
if MiscFileList:
|
||||
Module.SetMiscFileList([MiscFileList])
|
||||
else:
|
||||
Module.SetMiscFileList([])
|
||||
|
||||
#
|
||||
# UserExtensions
|
||||
#
|
||||
for Item in XmlList(Item, '/ModuleSurfaceArea/UserExtensions'):
|
||||
Tmp = UserExtensionsXml()
|
||||
UserExtension = Tmp.FromXml(Item, 'UserExtensions')
|
||||
Module.SetUserExtensionList(Module.GetUserExtensionList() + [UserExtension])
|
||||
|
||||
return Module
|
||||
|
||||
def FromXml(self, Item, Key, IsStandAlongModule=False):
|
||||
IsBinaryModule = XmlAttribute(Item, 'BinaryModule')
|
||||
#
|
||||
# Header
|
||||
#
|
||||
Tmp = HeaderXml()
|
||||
Module = Tmp.FromXml(XmlNode(Item, '/%s/Header' % Key), 'Header', True, IsStandAlongModule)
|
||||
Module.SetBinaryModule(IsBinaryModule)
|
||||
|
||||
if IsBinaryModule:
|
||||
GlobalData.gIS_BINARY_INF = True
|
||||
|
||||
#
|
||||
# ModuleProperties
|
||||
#
|
||||
Tmp = ModulePropertyXml()
|
||||
(Module, BootModes, Events, HOBs) = \
|
||||
Tmp.FromXml(XmlNode(Item, '/ModuleSurfaceArea/ModuleProperties'), 'ModuleProperties', Module)
|
||||
Module.SetBootModeList(BootModes)
|
||||
Module.SetEventList(Events)
|
||||
Module.SetHobList(HOBs)
|
||||
#
|
||||
# ClonedFrom
|
||||
#
|
||||
Tmp = ClonedFromXml()
|
||||
ClonedFrom = Tmp.FromXml(XmlNode(Item, '/ModuleSurfaceArea/ClonedFrom'), 'ClonedFrom')
|
||||
if ClonedFrom:
|
||||
Module.SetClonedFrom(ClonedFrom)
|
||||
|
||||
#
|
||||
# LibraryClass
|
||||
#
|
||||
for SubItem in XmlList(Item, '/ModuleSurfaceArea/LibraryClassDefinitions/LibraryClass'):
|
||||
Tmp = LibraryClassXml()
|
||||
LibraryClass = Tmp.FromXml(SubItem, 'LibraryClass')
|
||||
Module.SetLibraryClassList(Module.GetLibraryClassList() + [LibraryClass])
|
||||
|
||||
if XmlList(Item, '/ModuleSurfaceArea/LibraryClassDefinitions') and \
|
||||
not XmlList(Item, '/ModuleSurfaceArea/LibraryClassDefinitions/LibraryClass'):
|
||||
Module.SetLibraryClassList([None])
|
||||
|
||||
#
|
||||
# SourceFiles
|
||||
#
|
||||
for SubItem in XmlList(Item, '/ModuleSurfaceArea/SourceFiles/Filename'):
|
||||
Tmp = SourceFileXml()
|
||||
SourceFile = Tmp.FromXml(SubItem, 'Filename')
|
||||
Module.SetSourceFileList(Module.GetSourceFileList() + [SourceFile])
|
||||
|
||||
if XmlList(Item, '/ModuleSurfaceArea/SourceFiles') and \
|
||||
not XmlList(Item, '/ModuleSurfaceArea/SourceFiles/Filename') :
|
||||
Module.SetSourceFileList([None])
|
||||
|
||||
#
|
||||
# BinaryFile
|
||||
#
|
||||
for SubItem in XmlList(Item, '/ModuleSurfaceArea/BinaryFiles/BinaryFile'):
|
||||
Tmp = BinaryFileXml()
|
||||
BinaryFile = Tmp.FromXml(SubItem, 'BinaryFile')
|
||||
Module.SetBinaryFileList(Module.GetBinaryFileList() + [BinaryFile])
|
||||
|
||||
if XmlList(Item, '/ModuleSurfaceArea/BinaryFiles') and \
|
||||
not XmlList(Item, '/ModuleSurfaceArea/BinaryFiles/BinaryFile') :
|
||||
Module.SetBinaryFileList([None])
|
||||
#
|
||||
# PackageDependencies
|
||||
#
|
||||
for SubItem in XmlList(Item, '/ModuleSurfaceArea/PackageDependencies/Package'):
|
||||
Tmp = PackageXml()
|
||||
PackageDependency = Tmp.FromXml(SubItem, 'Package')
|
||||
Module.SetPackageDependencyList(Module.GetPackageDependencyList() + [PackageDependency])
|
||||
|
||||
if XmlList(Item, '/ModuleSurfaceArea/PackageDependencies') and \
|
||||
not XmlList(Item, '/ModuleSurfaceArea/PackageDependencies/Package'):
|
||||
Module.SetPackageDependencyList([None])
|
||||
|
||||
#
|
||||
# Guid
|
||||
#
|
||||
for SubItem in XmlList(Item, '/ModuleSurfaceArea/Guids/GuidCName'):
|
||||
Tmp = GuidXml('Module')
|
||||
GuidProtocolPpi = Tmp.FromXml(SubItem, 'GuidCName')
|
||||
Module.SetGuidList(Module.GetGuidList() + [GuidProtocolPpi])
|
||||
|
||||
if XmlList(Item, '/ModuleSurfaceArea/Guids') and not XmlList(Item, '/ModuleSurfaceArea/Guids/GuidCName'):
|
||||
Module.SetGuidList([None])
|
||||
|
||||
#
|
||||
# Protocol
|
||||
#
|
||||
for SubItem in XmlList(Item, '/ModuleSurfaceArea/Protocols/Protocol'):
|
||||
Tmp = ProtocolXml('Module')
|
||||
GuidProtocolPpi = Tmp.FromXml(SubItem, 'Protocol')
|
||||
Module.SetProtocolList(Module.GetProtocolList() + [GuidProtocolPpi])
|
||||
|
||||
if XmlList(Item, '/ModuleSurfaceArea/Protocols') and not XmlList(Item, '/ModuleSurfaceArea/Protocols/Protocol'):
|
||||
Module.SetProtocolList([None])
|
||||
|
||||
#
|
||||
# Ppi
|
||||
#
|
||||
for SubItem in XmlList(Item, '/ModuleSurfaceArea/PPIs/Ppi'):
|
||||
Tmp = PpiXml('Module')
|
||||
GuidProtocolPpi = Tmp.FromXml(SubItem, 'Ppi')
|
||||
Module.SetPpiList(Module.GetPpiList() + [GuidProtocolPpi])
|
||||
|
||||
if XmlList(Item, '/ModuleSurfaceArea/PPIs') and not XmlList(Item, '/ModuleSurfaceArea/PPIs/Ppi'):
|
||||
Module.SetPpiList([None])
|
||||
|
||||
#
|
||||
# Extern
|
||||
#
|
||||
for SubItem in XmlList(Item, '/ModuleSurfaceArea/Externs/Extern'):
|
||||
Tmp = ExternXml()
|
||||
Extern = Tmp.FromXml(SubItem, 'Extern')
|
||||
Module.SetExternList(Module.GetExternList() + [Extern])
|
||||
|
||||
if XmlList(Item, '/ModuleSurfaceArea/Externs') and not XmlList(Item, '/ModuleSurfaceArea/Externs/Extern'):
|
||||
Module.SetExternList([None])
|
||||
|
||||
if not Module.GetBinaryModule():
|
||||
#
|
||||
# PcdCoded
|
||||
#
|
||||
for SubItem in XmlList(Item, '/ModuleSurfaceArea/PcdCoded/PcdEntry'):
|
||||
Tmp = PcdEntryXml()
|
||||
PcdEntry = Tmp.FromXml3(SubItem, 'PcdEntry')
|
||||
Module.SetPcdList(Module.GetPcdList() + [PcdEntry])
|
||||
|
||||
if XmlList(Item, '/ModuleSurfaceArea/PcdCoded') and \
|
||||
not XmlList(Item, '/ModuleSurfaceArea/PcdCoded/PcdEntry'):
|
||||
Module.SetPcdList([None])
|
||||
|
||||
Module = self.FromXml2(Item, Module)
|
||||
#
|
||||
# return the module object
|
||||
#
|
||||
self.Module = Module
|
||||
return self.Module
|
||||
|
||||
def ToXml(self, Module):
|
||||
if self.Package:
|
||||
pass
|
||||
#
|
||||
# Create root node of module surface area
|
||||
#
|
||||
DomModule = minidom.Document().createElement('ModuleSurfaceArea')
|
||||
if Module.GetBinaryModule():
|
||||
DomModule.setAttribute('BinaryModule', 'true')
|
||||
|
||||
#
|
||||
# Header
|
||||
#
|
||||
Tmp = HeaderXml()
|
||||
DomModule.appendChild(Tmp.ToXml(Module, 'Header'))
|
||||
#
|
||||
# ModuleProperties
|
||||
#
|
||||
Tmp = ModulePropertyXml()
|
||||
DomModule.appendChild(Tmp.ToXml(Module, Module.GetBootModeList(), Module.GetEventList(), Module.GetHobList(), \
|
||||
'ModuleProperties'))
|
||||
#
|
||||
# ClonedFrom
|
||||
#
|
||||
Tmp = ClonedFromXml()
|
||||
if Module.GetClonedFrom():
|
||||
DomModule.appendChild(Tmp.ToXml(Module.GetClonedFrom(), 'ClonedFrom'))
|
||||
#
|
||||
# LibraryClass
|
||||
#
|
||||
LibraryClassNode = CreateXmlElement('LibraryClassDefinitions', '', [], [])
|
||||
for LibraryClass in Module.GetLibraryClassList():
|
||||
Tmp = LibraryClassXml()
|
||||
LibraryClassNode.appendChild(Tmp.ToXml2(LibraryClass, 'LibraryClass'))
|
||||
DomModule.appendChild(LibraryClassNode)
|
||||
#
|
||||
# SourceFile
|
||||
#
|
||||
SourceFileNode = CreateXmlElement('SourceFiles', '', [], [])
|
||||
for SourceFile in Module.GetSourceFileList():
|
||||
Tmp = SourceFileXml()
|
||||
SourceFileNode.appendChild(Tmp.ToXml(SourceFile, 'Filename'))
|
||||
DomModule.appendChild(SourceFileNode)
|
||||
#
|
||||
# BinaryFile
|
||||
#
|
||||
BinaryFileNode = CreateXmlElement('BinaryFiles', '', [], [])
|
||||
for BinaryFile in Module.GetBinaryFileList():
|
||||
Tmp = BinaryFileXml()
|
||||
BinaryFileNode.appendChild(Tmp.ToXml(BinaryFile, 'BinaryFile'))
|
||||
DomModule.appendChild(BinaryFileNode)
|
||||
#
|
||||
# PackageDependencies
|
||||
#
|
||||
PackageDependencyNode = CreateXmlElement('PackageDependencies', '', [], [])
|
||||
for PackageDependency in Module.GetPackageDependencyList():
|
||||
Tmp = PackageXml()
|
||||
PackageDependencyNode.appendChild(Tmp.ToXml(PackageDependency, 'Package'))
|
||||
DomModule.appendChild(PackageDependencyNode)
|
||||
|
||||
#
|
||||
# Guid
|
||||
#
|
||||
GuidProtocolPpiNode = CreateXmlElement('Guids', '', [], [])
|
||||
for GuidProtocolPpi in Module.GetGuidList():
|
||||
Tmp = GuidXml('Module')
|
||||
GuidProtocolPpiNode.appendChild(Tmp.ToXml(GuidProtocolPpi, 'GuidCName'))
|
||||
DomModule.appendChild(GuidProtocolPpiNode)
|
||||
|
||||
#
|
||||
# Protocol
|
||||
#
|
||||
GuidProtocolPpiNode = CreateXmlElement('Protocols', '', [], [])
|
||||
for GuidProtocolPpi in Module.GetProtocolList():
|
||||
Tmp = ProtocolXml('Module')
|
||||
GuidProtocolPpiNode.appendChild(Tmp.ToXml(GuidProtocolPpi, 'Protocol'))
|
||||
DomModule.appendChild(GuidProtocolPpiNode)
|
||||
|
||||
#
|
||||
# Ppi
|
||||
#
|
||||
GuidProtocolPpiNode = CreateXmlElement('PPIs', '', [], [])
|
||||
for GuidProtocolPpi in Module.GetPpiList():
|
||||
Tmp = PpiXml('Module')
|
||||
GuidProtocolPpiNode.appendChild(Tmp.ToXml(GuidProtocolPpi, 'Ppi'))
|
||||
DomModule.appendChild(GuidProtocolPpiNode)
|
||||
#
|
||||
# Extern
|
||||
#
|
||||
ExternNode = CreateXmlElement('Externs', '', [], [])
|
||||
for Extern in Module.GetExternList():
|
||||
Tmp = ExternXml()
|
||||
ExternNode.appendChild(Tmp.ToXml(Extern, 'Extern'))
|
||||
DomModule.appendChild(ExternNode)
|
||||
#
|
||||
# PcdCoded
|
||||
#
|
||||
PcdEntryNode = CreateXmlElement('PcdCoded', '', [], [])
|
||||
for PcdEntry in Module.GetPcdList():
|
||||
Tmp = PcdEntryXml()
|
||||
PcdEntryNode.appendChild(Tmp.ToXml3(PcdEntry, 'PcdEntry'))
|
||||
DomModule.appendChild(PcdEntryNode)
|
||||
|
||||
#
|
||||
# PeiDepex
|
||||
#
|
||||
if Module.GetPeiDepex():
|
||||
for Item in Module.GetPeiDepex():
|
||||
Tmp = DepexXml()
|
||||
DomModule.appendChild(Tmp.ToXml(Item, 'PeiDepex'))
|
||||
|
||||
#
|
||||
# DxeDepex
|
||||
#
|
||||
if Module.GetDxeDepex():
|
||||
for Item in Module.GetDxeDepex():
|
||||
Tmp = DepexXml()
|
||||
DomModule.appendChild(Tmp.ToXml(Item, 'DxeDepex'))
|
||||
|
||||
#
|
||||
# SmmDepex
|
||||
#
|
||||
if Module.GetSmmDepex():
|
||||
for Item in Module.GetSmmDepex():
|
||||
Tmp = DepexXml()
|
||||
DomModule.appendChild(Tmp.ToXml(Item, 'SmmDepex'))
|
||||
|
||||
#
|
||||
# MiscellaneousFile
|
||||
#
|
||||
if Module.GetMiscFileList():
|
||||
Tmp = MiscellaneousFileXml()
|
||||
DomModule.appendChild(Tmp.ToXml(Module.GetMiscFileList()[0], 'MiscellaneousFiles'))
|
||||
#
|
||||
# UserExtensions
|
||||
#
|
||||
if Module.GetUserExtensionList():
|
||||
for UserExtension in Module.GetUserExtensionList():
|
||||
Tmp = UserExtensionsXml()
|
||||
DomModule.appendChild(Tmp.ToXml(UserExtension, 'UserExtensions'))
|
||||
|
||||
return DomModule
|
||||
|
||||
##
|
||||
# BuildFlagXml used to generate BuildFlag for <AsBuilt>
|
||||
#
|
||||
class BuildFlagXml(object):
|
||||
def __init__(self):
|
||||
self.Target = ''
|
||||
self.TagName = ''
|
||||
self.Family = ''
|
||||
self.AsBuiltFlags = ''
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.Target = XmlElement(Item, '%s/Target' % Key)
|
||||
self.TagName = XmlElement(Item, '%s/TagName' % Key)
|
||||
self.Family = XmlElement(Item, '%s/Family' % Key)
|
||||
|
||||
BuildFlag = BinaryBuildFlagObject()
|
||||
|
||||
BuildFlag.SetTarget(self.Target)
|
||||
BuildFlag.SetTagName(self.TagName)
|
||||
BuildFlag.SetFamily(self.Family)
|
||||
|
||||
return BuildFlag
|
||||
|
||||
#
|
||||
# For AsBuild INF usage
|
||||
#
|
||||
def FromXml2(self, Item, Key):
|
||||
self.AsBuiltFlags = XmlElement(Item, '%s' % Key)
|
||||
|
||||
LineList = GetSplitValueList(self.AsBuiltFlags, '\n')
|
||||
ReturnLine = ''
|
||||
Count = 0
|
||||
for Line in LineList:
|
||||
if Count == 0:
|
||||
ReturnLine = "# " + Line
|
||||
else:
|
||||
ReturnLine = ReturnLine + '\n' + '# ' + Line
|
||||
Count += 1
|
||||
|
||||
BuildFlag = BinaryBuildFlagObject()
|
||||
BuildFlag.SetAsBuiltOptionFlags(ReturnLine)
|
||||
|
||||
return BuildFlag
|
||||
|
||||
def ToXml(self, BuildFlag, Key):
|
||||
if self.Target:
|
||||
pass
|
||||
AttributeList = []
|
||||
NodeList = []
|
||||
NodeList.append(['BuildFlags', BuildFlag])
|
||||
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
return Root
|
397
BaseTools/Source/Python/UPT/Xml/PackageSurfaceAreaXml.py
Normal file
397
BaseTools/Source/Python/UPT/Xml/PackageSurfaceAreaXml.py
Normal file
@@ -0,0 +1,397 @@
|
||||
## @file
|
||||
# This file is used to parse a Package file of .PKG file
|
||||
#
|
||||
# Copyright (c) 2011, 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
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
'''
|
||||
PackageSurfaceAreaXml
|
||||
'''
|
||||
from xml.dom import minidom
|
||||
|
||||
from Library.String import GetStringOfList
|
||||
from Library.Xml.XmlRoutines import XmlElement
|
||||
from Library.Xml.XmlRoutines import XmlNode
|
||||
from Library.Xml.XmlRoutines import XmlList
|
||||
from Library.Xml.XmlRoutines import CreateXmlElement
|
||||
from Object.POM.CommonObject import IncludeObject
|
||||
from Object.POM.CommonObject import TextObject
|
||||
from Object.POM.PackageObject import PackageObject
|
||||
from Xml.CommonXml import ClonedFromXml
|
||||
from Xml.CommonXml import PackageHeaderXml
|
||||
from Xml.CommonXml import HelpTextXml
|
||||
from Xml.CommonXml import CommonDefinesXml
|
||||
from Xml.CommonXml import LibraryClassXml
|
||||
from Xml.CommonXml import UserExtensionsXml
|
||||
from Xml.CommonXml import MiscellaneousFileXml
|
||||
from Xml.GuidProtocolPpiXml import GuidXml
|
||||
from Xml.GuidProtocolPpiXml import ProtocolXml
|
||||
from Xml.GuidProtocolPpiXml import PpiXml
|
||||
from Xml.ModuleSurfaceAreaXml import ModuleSurfaceAreaXml
|
||||
from Xml.PcdXml import PcdEntryXml
|
||||
|
||||
##
|
||||
# IndustryStandardHeaderXml
|
||||
#
|
||||
class IndustryStandardHeaderXml(object):
|
||||
def __init__(self):
|
||||
self.HeaderFile = ''
|
||||
self.HelpText = []
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.HeaderFile = XmlElement(Item, '%s/HeaderFile' % Key)
|
||||
for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
|
||||
HelpTextObj = HelpTextXml()
|
||||
HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
|
||||
self.HelpText.append(HelpTextObj)
|
||||
|
||||
Include = IncludeObject()
|
||||
Include.SetFilePath(self.HeaderFile)
|
||||
HelpTxt = TextObject()
|
||||
HelpTxt.SetString(self.HelpText)
|
||||
Include.SetHelpText(HelpTxt)
|
||||
|
||||
return Include
|
||||
|
||||
def ToXml(self, IndustryStandardHeader, Key):
|
||||
if self.HeaderFile:
|
||||
pass
|
||||
AttributeList = []
|
||||
NodeList = [['HeaderFile', IndustryStandardHeader.GetFilePath()]]
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = "HeaderFile = %s" % (self.HeaderFile)
|
||||
for Item in self.HelpText:
|
||||
Str = Str + "\n\t" + str(Item)
|
||||
return Str
|
||||
##
|
||||
# PackageIncludeHeaderXml
|
||||
#
|
||||
class PackageIncludeHeaderXml(object):
|
||||
def __init__(self):
|
||||
self.HeaderFile = ''
|
||||
self.CommonDefines = CommonDefinesXml()
|
||||
self.HelpText = []
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.HeaderFile = XmlElement(Item, '%s/HeaderFile' % Key)
|
||||
self.CommonDefines.FromXml(XmlNode(Item, '%s/HeaderFile' % Key), 'HeaderFile')
|
||||
for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
|
||||
HelpTextObj = HelpTextXml()
|
||||
HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
|
||||
self.HelpText.append(HelpTextObj)
|
||||
|
||||
Include = IncludeObject()
|
||||
Include.SetFilePath(self.HeaderFile)
|
||||
Include.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
HelpTxt = TextObject()
|
||||
HelpTxt.SetString(self.HelpText)
|
||||
Include.SetHelpText(HelpTxt)
|
||||
|
||||
return Include
|
||||
|
||||
def ToXml(self, PackageIncludeHeader, Key):
|
||||
if self.HeaderFile:
|
||||
pass
|
||||
AttributeList = [['SupArchList', GetStringOfList(PackageIncludeHeader.GetSupArchList())], \
|
||||
['SupModList', GetStringOfList(PackageIncludeHeader.GetSupModuleList())], ]
|
||||
|
||||
HeaderFileNode = CreateXmlElement('HeaderFile', PackageIncludeHeader.FilePath, [], AttributeList)
|
||||
|
||||
NodeList = [HeaderFileNode]
|
||||
for Item in PackageIncludeHeader.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item))
|
||||
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, [])
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
Str = "HeaderFile = %s\n\t%s" % (self.HeaderFile, self.CommonDefines)
|
||||
for Item in self.HelpText:
|
||||
Str = Str + "\n\t" + str(Item)
|
||||
return Str
|
||||
|
||||
##
|
||||
# PcdCheckXml
|
||||
#
|
||||
class PcdCheckXml(object):
|
||||
def __init__(self):
|
||||
self.PcdCheck = ''
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
if Key:
|
||||
pass
|
||||
self.PcdCheck = XmlElement(Item, 'PcdCheck')
|
||||
|
||||
return self.PcdCheck
|
||||
|
||||
def ToXml(self, PcdCheck, Key):
|
||||
if self.PcdCheck:
|
||||
pass
|
||||
Root = CreateXmlElement('%s' % Key, PcdCheck, [], [])
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
return "PcdCheck = %s" % (self.PcdCheck)
|
||||
|
||||
##
|
||||
# PackageSurfaceAreaXml
|
||||
#
|
||||
class PackageSurfaceAreaXml(object):
|
||||
def __init__(self):
|
||||
self.Package = None
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
if Key:
|
||||
pass
|
||||
#
|
||||
# Create a package object
|
||||
#
|
||||
Package = PackageObject()
|
||||
#
|
||||
# Header
|
||||
#
|
||||
Tmp = PackageHeaderXml()
|
||||
Tmp.FromXml(XmlNode(Item, '/PackageSurfaceArea/Header'), 'Header', Package)
|
||||
#
|
||||
# ClonedFrom
|
||||
#
|
||||
Tmp = ClonedFromXml()
|
||||
if XmlNode(Item, '/PackageSurfaceArea/ClonedFrom'):
|
||||
ClonedFrom = Tmp.FromXml(XmlNode(Item, '/PackageSurfaceArea/ClonedFrom'), 'ClonedFrom')
|
||||
Package.SetClonedFromList([ClonedFrom])
|
||||
#
|
||||
# LibraryClass
|
||||
#
|
||||
|
||||
for SubItem in XmlList(Item, '/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass'):
|
||||
Tmp = LibraryClassXml()
|
||||
LibraryClass = Tmp.FromXml(SubItem, 'LibraryClass')
|
||||
Package.SetLibraryClassList(Package.GetLibraryClassList() + [LibraryClass])
|
||||
|
||||
if XmlList(Item, '/PackageSurfaceArea/LibraryClassDeclarations') and \
|
||||
not XmlList(Item, '/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass'):
|
||||
Package.SetLibraryClassList([None])
|
||||
|
||||
#
|
||||
# IndustryStandardHeader
|
||||
#
|
||||
for SubItem in XmlList(Item, '/PackageSurfaceArea/IndustryStandardIncludes/IndustryStandardHeader'):
|
||||
Tmp = IndustryStandardHeaderXml()
|
||||
Include = Tmp.FromXml(SubItem, 'IndustryStandardHeader')
|
||||
Package.SetStandardIncludeFileList(Package.GetStandardIncludeFileList() + [Include])
|
||||
|
||||
if XmlList(Item, '/PackageSurfaceArea/IndustryStandardIncludes') and \
|
||||
not XmlList(Item, '/PackageSurfaceArea/IndustryStandardIncludes/IndustryStandardHeader'):
|
||||
Package.SetStandardIncludeFileList([None])
|
||||
|
||||
|
||||
#
|
||||
# PackageHeader
|
||||
#
|
||||
for SubItem in XmlList(Item, '/PackageSurfaceArea/PackageIncludes/PackageHeader'):
|
||||
Tmp = PackageIncludeHeaderXml()
|
||||
Include = Tmp.FromXml(SubItem, 'PackageHeader')
|
||||
Package.SetPackageIncludeFileList(Package.GetPackageIncludeFileList() + [Include])
|
||||
|
||||
if XmlList(Item, '/PackageSurfaceArea/PackageIncludes') and not \
|
||||
XmlList(Item, '/PackageSurfaceArea/PackageIncludes/PackageHeader'):
|
||||
Package.SetPackageIncludeFileList([None])
|
||||
|
||||
#
|
||||
# Guid
|
||||
#
|
||||
for SubItem in XmlList(Item, '/PackageSurfaceArea/GuidDeclarations/Entry'):
|
||||
Tmp = GuidXml('Package')
|
||||
GuidProtocolPpi = Tmp.FromXml(SubItem, 'Entry')
|
||||
Package.SetGuidList(Package.GetGuidList() + [GuidProtocolPpi])
|
||||
|
||||
if XmlList(Item, '/PackageSurfaceArea/GuidDeclarations') and not \
|
||||
XmlList(Item, '/PackageSurfaceArea/GuidDeclarations/Entry'):
|
||||
Package.SetGuidList([None])
|
||||
|
||||
#
|
||||
# Protocol
|
||||
#
|
||||
for SubItem in XmlList(Item, '/PackageSurfaceArea/ProtocolDeclarations/Entry'):
|
||||
Tmp = ProtocolXml('Package')
|
||||
GuidProtocolPpi = Tmp.FromXml(SubItem, 'Entry')
|
||||
Package.SetProtocolList(Package.GetProtocolList() + [GuidProtocolPpi])
|
||||
|
||||
if XmlList(Item, '/PackageSurfaceArea/ProtocolDeclarations') and not \
|
||||
XmlList(Item, '/PackageSurfaceArea/ProtocolDeclarations/Entry'):
|
||||
Package.SetProtocolList([None])
|
||||
|
||||
#
|
||||
# Ppi
|
||||
#
|
||||
for SubItem in XmlList(Item, '/PackageSurfaceArea/PpiDeclarations/Entry'):
|
||||
Tmp = PpiXml('Package')
|
||||
GuidProtocolPpi = Tmp.FromXml(SubItem, 'Entry')
|
||||
Package.SetPpiList(Package.GetPpiList() + [GuidProtocolPpi])
|
||||
|
||||
if XmlList(Item, '/PackageSurfaceArea/PpiDeclarations') and not \
|
||||
XmlList(Item, '/PackageSurfaceArea/PpiDeclarations/Entry'):
|
||||
Package.SetPpiList([None])
|
||||
|
||||
#
|
||||
# PcdEntry
|
||||
#
|
||||
for SubItem in XmlList(Item, '/PackageSurfaceArea/PcdDeclarations/PcdEntry'):
|
||||
Tmp = PcdEntryXml()
|
||||
PcdEntry = Tmp.FromXml2(SubItem, 'PcdEntry')
|
||||
Package.SetPcdList(Package.GetPcdList() + [PcdEntry])
|
||||
|
||||
if XmlList(Item, '/PackageSurfaceArea/PcdDeclarations') and not \
|
||||
XmlList(Item, '/PackageSurfaceArea/PcdDeclarations/PcdEntry'):
|
||||
Package.SetPcdList([None])
|
||||
|
||||
#
|
||||
# PcdCheck
|
||||
#
|
||||
for SubItem in XmlList(Item, '/PackageSurfaceArea/PcdRelationshipChecks/PcdCheck'):
|
||||
Tmp = PcdCheckXml()
|
||||
PcdCheck = Tmp.FromXml(SubItem, 'PcdCheck')
|
||||
Package.PcdChecks.append(PcdCheck)
|
||||
|
||||
#
|
||||
# Modules
|
||||
#
|
||||
for SubItem in XmlList(Item, '/PackageSurfaceArea/Modules/ModuleSurfaceArea'):
|
||||
Tmp = ModuleSurfaceAreaXml()
|
||||
Module = Tmp.FromXml(SubItem, 'ModuleSurfaceArea')
|
||||
Package.ModuleDict[(Module.GetGuid(), Module.GetVersion(), Module.GetModulePath())] = Module
|
||||
#
|
||||
# MiscellaneousFile
|
||||
#
|
||||
Tmp = MiscellaneousFileXml()
|
||||
MiscFileList = Tmp.FromXml(XmlNode(Item, '/PackageSurfaceArea/MiscellaneousFiles'), 'MiscellaneousFiles')
|
||||
if MiscFileList:
|
||||
Package.SetMiscFileList([MiscFileList])
|
||||
else:
|
||||
Package.SetMiscFileList([])
|
||||
|
||||
#
|
||||
# UserExtensions
|
||||
#
|
||||
for Item in XmlList(Item, '/PackageSurfaceArea/UserExtensions'):
|
||||
Tmp = UserExtensionsXml()
|
||||
UserExtension = Tmp.FromXml(Item, 'UserExtensions')
|
||||
Package.UserExtensionList.append(UserExtension)
|
||||
|
||||
self.Package = Package
|
||||
return self.Package
|
||||
|
||||
def ToXml(self, Package):
|
||||
if self.Package:
|
||||
pass
|
||||
#
|
||||
# Create PackageSurfaceArea node
|
||||
#
|
||||
DomPackage = minidom.Document().createElement('PackageSurfaceArea')
|
||||
#
|
||||
# Header
|
||||
#
|
||||
Tmp = PackageHeaderXml()
|
||||
DomPackage.appendChild(Tmp.ToXml(Package, 'Header'))
|
||||
#
|
||||
# ClonedFrom
|
||||
#
|
||||
Tmp = ClonedFromXml()
|
||||
if Package.GetClonedFromList() != []:
|
||||
DomPackage.appendChild(Tmp.ToXml(Package.GetClonedFromList[0], 'ClonedFrom'))
|
||||
#
|
||||
# LibraryClass
|
||||
#
|
||||
LibraryClassNode = CreateXmlElement('LibraryClassDeclarations', '', [], [])
|
||||
for LibraryClass in Package.GetLibraryClassList():
|
||||
Tmp = LibraryClassXml()
|
||||
LibraryClassNode.appendChild(Tmp.ToXml(LibraryClass, 'LibraryClass'))
|
||||
DomPackage.appendChild(LibraryClassNode)
|
||||
#
|
||||
# IndustryStandardHeader
|
||||
#
|
||||
IndustryStandardHeaderNode = CreateXmlElement('IndustryStandardIncludes', '', [], [])
|
||||
for Include in Package.GetStandardIncludeFileList():
|
||||
Tmp = IndustryStandardHeaderXml()
|
||||
IndustryStandardHeaderNode.appendChild(Tmp.ToXml(Include, 'IndustryStandardHeader'))
|
||||
DomPackage.appendChild(IndustryStandardHeaderNode)
|
||||
#
|
||||
# PackageHeader
|
||||
#
|
||||
PackageIncludeHeaderNode = CreateXmlElement('PackageIncludes', '', [], [])
|
||||
for Include in Package.GetPackageIncludeFileList():
|
||||
Tmp = PackageIncludeHeaderXml()
|
||||
PackageIncludeHeaderNode.appendChild(Tmp.ToXml(Include, 'PackageHeader'))
|
||||
DomPackage.appendChild(PackageIncludeHeaderNode)
|
||||
ModuleNode = CreateXmlElement('Modules', '', [], [])
|
||||
for Module in Package.GetModuleDict().values():
|
||||
Tmp = ModuleSurfaceAreaXml()
|
||||
ModuleNode.appendChild(Tmp.ToXml(Module))
|
||||
DomPackage.appendChild(ModuleNode)
|
||||
#
|
||||
# Guid
|
||||
#
|
||||
GuidProtocolPpiNode = CreateXmlElement('GuidDeclarations', '', [], [])
|
||||
for GuidProtocolPpi in Package.GetGuidList():
|
||||
Tmp = GuidXml('Package')
|
||||
GuidProtocolPpiNode.appendChild(Tmp.ToXml\
|
||||
(GuidProtocolPpi, 'Entry'))
|
||||
DomPackage.appendChild(GuidProtocolPpiNode)
|
||||
#
|
||||
# Protocol
|
||||
#
|
||||
GuidProtocolPpiNode = \
|
||||
CreateXmlElement('ProtocolDeclarations', '', [], [])
|
||||
for GuidProtocolPpi in Package.GetProtocolList():
|
||||
Tmp = ProtocolXml('Package')
|
||||
GuidProtocolPpiNode.appendChild\
|
||||
(Tmp.ToXml(GuidProtocolPpi, 'Entry'))
|
||||
DomPackage.appendChild(GuidProtocolPpiNode)
|
||||
#
|
||||
# Ppi
|
||||
#
|
||||
GuidProtocolPpiNode = CreateXmlElement('PpiDeclarations', '', [], [])
|
||||
for GuidProtocolPpi in Package.GetPpiList():
|
||||
Tmp = PpiXml('Package')
|
||||
GuidProtocolPpiNode.appendChild\
|
||||
(Tmp.ToXml(GuidProtocolPpi, 'Entry'))
|
||||
DomPackage.appendChild(GuidProtocolPpiNode)
|
||||
#
|
||||
# PcdEntry
|
||||
#
|
||||
PcdEntryNode = CreateXmlElement('PcdDeclarations', '', [], [])
|
||||
for PcdEntry in Package.GetPcdList():
|
||||
Tmp = PcdEntryXml()
|
||||
PcdEntryNode.appendChild(Tmp.ToXml2(PcdEntry, 'PcdEntry'))
|
||||
DomPackage.appendChild(PcdEntryNode)
|
||||
|
||||
#
|
||||
# MiscellaneousFile
|
||||
#
|
||||
Tmp = MiscellaneousFileXml()
|
||||
if Package.GetMiscFileList():
|
||||
DomPackage.appendChild(Tmp.ToXml(Package.GetMiscFileList()[0], 'MiscellaneousFiles'))
|
||||
|
||||
#
|
||||
# UserExtensions
|
||||
#
|
||||
if Package.GetUserExtensionList():
|
||||
for UserExtension in Package.GetUserExtensionList():
|
||||
Tmp = UserExtensionsXml()
|
||||
DomPackage.appendChild(Tmp.ToXml(UserExtension, 'UserExtensions'))
|
||||
|
||||
return DomPackage
|
403
BaseTools/Source/Python/UPT/Xml/PcdXml.py
Normal file
403
BaseTools/Source/Python/UPT/Xml/PcdXml.py
Normal file
@@ -0,0 +1,403 @@
|
||||
## @file
|
||||
# This file is used to parse a PCD file of .PKG file
|
||||
#
|
||||
# Copyright (c) 2011, 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
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
'''
|
||||
PcdXml
|
||||
'''
|
||||
|
||||
##
|
||||
# Import Modules
|
||||
#
|
||||
|
||||
from Library.Xml.XmlRoutines import XmlElement
|
||||
from Library.Xml.XmlRoutines import XmlAttribute
|
||||
from Library.Xml.XmlRoutines import XmlNode
|
||||
from Library.Xml.XmlRoutines import CreateXmlElement
|
||||
from Library.Xml.XmlRoutines import XmlList
|
||||
from Library.String import GetStringOfList
|
||||
from Library.String import ConvertNEToNOTEQ
|
||||
from Library.String import ConvertNOTEQToNE
|
||||
from Library import GlobalData
|
||||
from Object.POM.CommonObject import PcdObject
|
||||
from Object.POM.CommonObject import PcdErrorObject
|
||||
from Xml.CommonXml import HelpTextXml
|
||||
from Xml.CommonXml import CommonDefinesXml
|
||||
from Xml.XmlParserMisc import GetHelpTextList
|
||||
|
||||
##
|
||||
# PcdErrorXml
|
||||
#
|
||||
class PcdErrorXml(object):
|
||||
def __init__(self):
|
||||
self.ValidValueList = ''
|
||||
self.ValidValueListLang = ''
|
||||
self.ValidValueRange = ''
|
||||
self.Expression = ''
|
||||
self.ErrorNumber = ''
|
||||
self.ErrorMessage = []
|
||||
|
||||
def FromXml(self, Item, Key):
|
||||
self.ValidValueList = XmlElement(Item, '%s/ValidValueList' % Key)
|
||||
self.ValidValueListLang = \
|
||||
XmlAttribute(XmlNode(Item, '%s/ValidValueList' % Key), 'Lang')
|
||||
self.ValidValueRange = XmlElement(Item, '%s/ValidValueRange' % Key)
|
||||
self.Expression = XmlElement(Item, '%s/Expression' % Key)
|
||||
self.ErrorNumber = XmlElement(Item, '%s/ErrorNumber' % Key)
|
||||
for ErrMsg in XmlList(Item, '%s/ErrorMessage' % Key):
|
||||
ErrorMessageString = XmlElement(ErrMsg, 'ErrorMessage')
|
||||
ErrorMessageLang = \
|
||||
XmlAttribute(XmlNode(ErrMsg, 'ErrorMessage'), 'Lang')
|
||||
self.ErrorMessage.append((ErrorMessageLang, ErrorMessageString))
|
||||
|
||||
Error = PcdErrorObject()
|
||||
Error.SetValidValue(self.ValidValueList)
|
||||
Error.SetValidValueLang(self.ValidValueListLang)
|
||||
Error.SetValidValueRange(self.ValidValueRange)
|
||||
Error.SetExpression(self.Expression)
|
||||
Error.SetErrorNumber(self.ErrorNumber)
|
||||
Error.SetErrorMessageList(self.ErrorMessage)
|
||||
|
||||
return Error
|
||||
|
||||
def ToXml(self, PcdError, Key):
|
||||
if self.Expression:
|
||||
pass
|
||||
AttributeList = []
|
||||
NodeList = []
|
||||
if PcdError.GetValidValue():
|
||||
Element1 = \
|
||||
CreateXmlElement('ValidValueList', PcdError.GetValidValue(), [], \
|
||||
[['Lang', PcdError.GetValidValueLang()]])
|
||||
NodeList.append(Element1)
|
||||
if PcdError.GetValidValueRange():
|
||||
Element1 = \
|
||||
CreateXmlElement('ValidValueRange', \
|
||||
PcdError.GetValidValueRange(), [], [])
|
||||
NodeList.append(Element1)
|
||||
if PcdError.GetExpression():
|
||||
NodeList.append(['Expression', PcdError.GetExpression()])
|
||||
if PcdError.GetErrorNumber():
|
||||
NodeList.append(['ErrorNumber', PcdError.GetErrorNumber()])
|
||||
for Item in PcdError.GetErrorMessageList():
|
||||
Element = \
|
||||
CreateXmlElement('ErrorMessage', Item[1], [], [['Lang', Item[0]]])
|
||||
NodeList.append(Element)
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
def __str__(self):
|
||||
return "ValidValueList = %s ValidValueListLang = %s ValidValueRange \
|
||||
= %s Expression = %s ErrorNumber = %s %s" % \
|
||||
(self.ValidValueList, self.ValidValueListLang, self.ValidValueRange, \
|
||||
self.Expression, self.ErrorNumber, self.ErrorMessage)
|
||||
|
||||
##
|
||||
# PcdEntryXml
|
||||
#
|
||||
class PcdEntryXml(object):
|
||||
def __init__(self):
|
||||
self.PcdItemType = ''
|
||||
self.PcdUsage = ''
|
||||
self.TokenSpaceGuidCName = ''
|
||||
self.TokenSpaceGuidValue = ''
|
||||
self.Token = ''
|
||||
self.CName = ''
|
||||
self.PcdCName = ''
|
||||
self.DatumType = ''
|
||||
self.ValidUsage = ''
|
||||
self.DefaultValue = ''
|
||||
self.MaxDatumSize = ''
|
||||
self.Value = ''
|
||||
self.Offset = ''
|
||||
self.CommonDefines = CommonDefinesXml()
|
||||
self.HelpText = []
|
||||
self.PcdError = []
|
||||
|
||||
##
|
||||
# AsBuilt will use FromXml
|
||||
#
|
||||
def FromXml(self, Item, Key):
|
||||
self.PcdItemType = \
|
||||
XmlAttribute(XmlNode(Item, '%s' % Key), 'PcdItemType')
|
||||
self.PcdUsage = XmlAttribute(XmlNode(Item, '%s' % Key), 'PcdUsage')
|
||||
self.TokenSpaceGuidCName = \
|
||||
XmlElement(Item, '%s/TokenSpaceGuidCname' % Key)
|
||||
self.TokenSpaceGuidValue = \
|
||||
XmlElement(Item, '%s/TokenSpaceGuidValue' % Key)
|
||||
self.Token = XmlElement(Item, '%s/Token' % Key)
|
||||
self.CName = XmlElement(Item, '%s/CName' % Key)
|
||||
self.PcdCName = XmlElement(Item, '%s/PcdCName' % Key)
|
||||
self.DatumType = XmlElement(Item, '%s/DatumType' % Key)
|
||||
self.ValidUsage = XmlElement(Item, '%s/ValidUsage' % Key)
|
||||
if not GlobalData.gIS_BINARY_INF:
|
||||
self.DefaultValue = XmlElement(Item, '%s/DefaultValue' % Key)
|
||||
else:
|
||||
self.DefaultValue = XmlElement(Item, '%s/Value' % Key)
|
||||
self.MaxDatumSize = XmlElement(Item, '%s/MaxDatumSize' % Key)
|
||||
self.Value = XmlElement(Item, '%s/Value' % Key)
|
||||
self.Offset = XmlElement(Item, '%s/Offset' % Key)
|
||||
self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)
|
||||
for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
|
||||
HelpTextObj = HelpTextXml()
|
||||
HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
|
||||
self.HelpText.append(HelpTextObj)
|
||||
for PcdErrorItem in XmlList(Item, '%s/PcdError' % Key):
|
||||
PcdErrorObjXml = PcdErrorXml()
|
||||
PcdErrorObj = PcdErrorObjXml.FromXml(PcdErrorItem, 'PcdError')
|
||||
self.PcdError.append(PcdErrorObj)
|
||||
|
||||
self.DefaultValue = ConvertNOTEQToNE(self.DefaultValue)
|
||||
|
||||
PcdEntry = PcdObject()
|
||||
PcdEntry.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
PcdEntry.SetTokenSpaceGuidCName(self.TokenSpaceGuidCName)
|
||||
PcdEntry.SetTokenSpaceGuidValue(self.TokenSpaceGuidValue)
|
||||
PcdEntry.SetToken(self.Token)
|
||||
PcdEntry.SetOffset(self.Offset)
|
||||
PcdEntry.SetCName(self.CName)
|
||||
PcdEntry.SetPcdCName(self.PcdCName)
|
||||
PcdEntry.SetDatumType(self.DatumType)
|
||||
PcdEntry.SetValidUsage(self.ValidUsage)
|
||||
PcdEntry.SetDefaultValue(self.DefaultValue)
|
||||
PcdEntry.SetMaxDatumSize(self.MaxDatumSize)
|
||||
PcdEntry.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))
|
||||
PcdEntry.SetItemType(self.PcdItemType)
|
||||
|
||||
PcdEntry.SetHelpTextList(GetHelpTextList(self.HelpText))
|
||||
PcdEntry.SetPcdErrorsList(self.PcdError)
|
||||
|
||||
return PcdEntry
|
||||
##
|
||||
# Package will use FromXml2
|
||||
#
|
||||
def FromXml2(self, Item, Key):
|
||||
self.TokenSpaceGuidCName = \
|
||||
XmlElement(Item, '%s/TokenSpaceGuidCname' % Key)
|
||||
self.Token = XmlElement(Item, '%s/Token' % Key)
|
||||
self.CName = XmlElement(Item, '%s/CName' % Key)
|
||||
self.DatumType = XmlElement(Item, '%s/DatumType' % Key)
|
||||
self.ValidUsage = XmlElement(Item, '%s/ValidUsage' % Key)
|
||||
self.DefaultValue = XmlElement(Item, '%s/DefaultValue' % Key)
|
||||
self.MaxDatumSize = XmlElement(Item, '%s/MaxDatumSize' % Key)
|
||||
self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)
|
||||
for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
|
||||
HelpTextObj = HelpTextXml()
|
||||
HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
|
||||
self.HelpText.append(HelpTextObj)
|
||||
for PcdErrorItem in XmlList(Item, '%s/PcdError' % Key):
|
||||
PcdErrorObjXml = PcdErrorXml()
|
||||
PcdErrorObj = PcdErrorObjXml.FromXml(PcdErrorItem, 'PcdError')
|
||||
self.PcdError.append(PcdErrorObj)
|
||||
|
||||
self.DefaultValue = ConvertNOTEQToNE(self.DefaultValue)
|
||||
|
||||
PcdEntry = PcdObject()
|
||||
PcdEntry.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
PcdEntry.SetSupModuleList(self.CommonDefines.SupModList)
|
||||
PcdEntry.SetTokenSpaceGuidCName(self.TokenSpaceGuidCName)
|
||||
PcdEntry.SetToken(self.Token)
|
||||
PcdEntry.SetCName(self.CName)
|
||||
PcdEntry.SetDatumType(self.DatumType)
|
||||
PcdEntry.SetValidUsage(self.ValidUsage)
|
||||
PcdEntry.SetDefaultValue(self.DefaultValue)
|
||||
PcdEntry.SetMaxDatumSize(self.MaxDatumSize)
|
||||
PcdEntry.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))
|
||||
|
||||
PcdEntry.SetHelpTextList(GetHelpTextList(self.HelpText))
|
||||
PcdEntry.SetPcdErrorsList(self.PcdError)
|
||||
|
||||
return PcdEntry
|
||||
|
||||
##
|
||||
# Module will use FromXml3
|
||||
#
|
||||
def FromXml3(self, Item, Key):
|
||||
self.PcdItemType = \
|
||||
XmlAttribute(XmlNode(Item, '%s' % Key), 'PcdItemType')
|
||||
self.PcdUsage = XmlAttribute(XmlNode(Item, '%s' % Key), 'PcdUsage')
|
||||
self.TokenSpaceGuidCName = \
|
||||
XmlElement(Item, '%s/TokenSpaceGuidCName' % Key)
|
||||
self.CName = XmlElement(Item, '%s/CName' % Key)
|
||||
self.DefaultValue = XmlElement(Item, '%s/DefaultValue' % Key)
|
||||
self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)
|
||||
for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
|
||||
HelpTextObj = HelpTextXml()
|
||||
HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
|
||||
self.HelpText.append(HelpTextObj)
|
||||
for PcdErrorItem in XmlList(Item, '%s/PcdError' % Key):
|
||||
PcdErrorObj = PcdErrorXml()
|
||||
PcdErrorObj.FromXml(PcdErrorItem, 'PcdError')
|
||||
self.PcdError.append(PcdErrorObj)
|
||||
|
||||
self.DefaultValue = ConvertNOTEQToNE(self.DefaultValue)
|
||||
|
||||
PcdEntry = PcdObject()
|
||||
PcdEntry.SetSupArchList(self.CommonDefines.SupArchList)
|
||||
PcdEntry.SetTokenSpaceGuidCName(self.TokenSpaceGuidCName)
|
||||
PcdEntry.SetCName(self.CName)
|
||||
PcdEntry.SetValidUsage(self.PcdUsage)
|
||||
PcdEntry.SetDefaultValue(self.DefaultValue)
|
||||
PcdEntry.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))
|
||||
PcdEntry.SetItemType(self.PcdItemType)
|
||||
|
||||
PcdEntry.SetHelpTextList(GetHelpTextList(self.HelpText))
|
||||
PcdEntry.SetPcdErrorsList(self.PcdError)
|
||||
|
||||
return PcdEntry
|
||||
|
||||
def ToXml(self, PcdEntry, Key):
|
||||
if self.PcdCName:
|
||||
pass
|
||||
|
||||
DefaultValue = ConvertNEToNOTEQ(PcdEntry.GetDefaultValue())
|
||||
|
||||
AttributeList = \
|
||||
[['SupArchList', GetStringOfList(PcdEntry.GetSupArchList())], \
|
||||
['PcdUsage', PcdEntry.GetValidUsage()], \
|
||||
['PcdItemType', PcdEntry.GetItemType()], \
|
||||
['FeatureFlag', PcdEntry.GetFeatureFlag()],
|
||||
]
|
||||
NodeList = [['TokenSpaceGuidCname', PcdEntry.GetTokenSpaceGuidCName()],
|
||||
['TokenSpaceGuidValue', PcdEntry.GetTokenSpaceGuidValue()],
|
||||
['Token', PcdEntry.GetToken()],
|
||||
['CName', PcdEntry.GetCName()],
|
||||
['DatumType', PcdEntry.GetDatumType()],
|
||||
['ValidUsage', GetStringOfList(PcdEntry.GetValidUsage())],
|
||||
['DefaultValue', DefaultValue],
|
||||
['MaxDatumSize', PcdEntry.GetMaxDatumSize()],
|
||||
['Offset', PcdEntry.GetOffset()],
|
||||
]
|
||||
|
||||
for Item in PcdEntry.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item))
|
||||
for Item in PcdEntry.GetPcdErrorsList():
|
||||
Tmp = PcdErrorXml()
|
||||
NodeList.append(Tmp.ToXml(Item, 'PcdError'))
|
||||
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
##
|
||||
# Package will use ToXml2
|
||||
#
|
||||
def ToXml2(self, PcdEntry, Key):
|
||||
if self.PcdCName:
|
||||
pass
|
||||
|
||||
DefaultValue = ConvertNEToNOTEQ(PcdEntry.GetDefaultValue())
|
||||
|
||||
AttributeList = \
|
||||
[['SupArchList', GetStringOfList(PcdEntry.GetSupArchList())], \
|
||||
['SupModList', GetStringOfList(PcdEntry.GetSupModuleList())]
|
||||
]
|
||||
NodeList = [['TokenSpaceGuidCname', PcdEntry.GetTokenSpaceGuidCName()],
|
||||
['Token', PcdEntry.GetToken()],
|
||||
['CName', PcdEntry.GetCName()],
|
||||
['DatumType', PcdEntry.GetDatumType()],
|
||||
['ValidUsage', GetStringOfList(PcdEntry.GetValidUsage())],
|
||||
['DefaultValue', DefaultValue],
|
||||
['MaxDatumSize', PcdEntry.GetMaxDatumSize()],
|
||||
]
|
||||
for Item in PcdEntry.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item))
|
||||
|
||||
for Item in PcdEntry.GetPcdErrorsList():
|
||||
Tmp = PcdErrorXml()
|
||||
NodeList.append(Tmp.ToXml(Item, 'PcdError'))
|
||||
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
##
|
||||
# Module will use ToXml3
|
||||
#
|
||||
def ToXml3(self, PcdEntry, Key):
|
||||
if self.PcdCName:
|
||||
pass
|
||||
|
||||
DefaultValue = ConvertNEToNOTEQ(PcdEntry.GetDefaultValue())
|
||||
|
||||
AttributeList = \
|
||||
[['SupArchList', GetStringOfList(PcdEntry.GetSupArchList())], \
|
||||
['PcdUsage', PcdEntry.GetValidUsage()], \
|
||||
['PcdItemType', PcdEntry.GetItemType()], \
|
||||
['FeatureFlag', ConvertNEToNOTEQ(PcdEntry.GetFeatureFlag())],
|
||||
]
|
||||
NodeList = [['CName', PcdEntry.GetCName()],
|
||||
['TokenSpaceGuidCName', PcdEntry.GetTokenSpaceGuidCName()],
|
||||
['DefaultValue', DefaultValue],
|
||||
]
|
||||
|
||||
for Item in PcdEntry.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item))
|
||||
for Item in PcdEntry.GetPcdErrorsList():
|
||||
Tmp = PcdErrorXml()
|
||||
NodeList.append(Tmp.ToXml(Item, 'PcdError'))
|
||||
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
##
|
||||
# AsBuild Module will use ToXml4
|
||||
#
|
||||
def ToXml4(self, PcdEntry, Key):
|
||||
if self.PcdCName:
|
||||
pass
|
||||
|
||||
DefaultValue = ConvertNEToNOTEQ(PcdEntry.GetDefaultValue())
|
||||
|
||||
AttributeList = []
|
||||
|
||||
NodeList = [
|
||||
['TokenSpaceGuidValue', PcdEntry.GetTokenSpaceGuidValue()],
|
||||
['PcdCName', PcdEntry.GetCName()],
|
||||
['Token', PcdEntry.GetToken()],
|
||||
['DatumType', PcdEntry.GetDatumType()],
|
||||
['MaxDatumSize', PcdEntry.GetMaxDatumSize()],
|
||||
['Value', DefaultValue],
|
||||
['Offset', PcdEntry.GetOffset()]
|
||||
]
|
||||
|
||||
for Item in PcdEntry.GetHelpTextList():
|
||||
Tmp = HelpTextXml()
|
||||
NodeList.append(Tmp.ToXml(Item))
|
||||
for Item in PcdEntry.GetPcdErrorsList():
|
||||
Tmp = PcdErrorXml()
|
||||
NodeList.append(Tmp.ToXml(Item, 'PcdError'))
|
||||
|
||||
Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
|
||||
|
||||
return Root
|
||||
|
||||
|
||||
def __str__(self):
|
||||
Str = \
|
||||
('PcdItemType = %s PcdUsage = %s TokenSpaceGuidCName = %s \
|
||||
TokenSpaceGuidValue = %s Token = %s CName = %s PcdCName = %s \
|
||||
DatumType = %s ValidUsage = %s DefaultValue = %s MaxDatumSize = %s \
|
||||
Value = %s Offset = %s %s') % \
|
||||
(self.PcdItemType, self.PcdUsage, self.TokenSpaceGuidCName, \
|
||||
self.TokenSpaceGuidValue, self.Token, self.CName, self.PcdCName, \
|
||||
self.DatumType, self.ValidUsage, self.DefaultValue, \
|
||||
self.MaxDatumSize, self.Value, self.Offset, self.CommonDefines)
|
||||
for Item in self.HelpText:
|
||||
Str = Str + "\n\t" + str(Item)
|
||||
for Item in self.PcdError:
|
||||
Str = Str + "\n\tPcdError:" + str(Item)
|
||||
return Str
|
924
BaseTools/Source/Python/UPT/Xml/XmlParser.py
Normal file
924
BaseTools/Source/Python/UPT/Xml/XmlParser.py
Normal file
@@ -0,0 +1,924 @@
|
||||
## @file
|
||||
# This file is used to parse a xml file of .PKG file
|
||||
#
|
||||
# Copyright (c) 2011, 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
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
'''
|
||||
XmlParser
|
||||
'''
|
||||
|
||||
##
|
||||
# Import Modules
|
||||
#
|
||||
import re
|
||||
|
||||
from Library.Xml.XmlRoutines import XmlNode
|
||||
from Library.Xml.XmlRoutines import CreateXmlElement
|
||||
from Library.Xml.XmlRoutines import XmlList
|
||||
from Library.Xml.XmlRoutines import XmlParseFile
|
||||
from Core.DistributionPackageClass import DistributionPackageClass
|
||||
from Object.POM.ModuleObject import DepexObject
|
||||
from Library.ParserValidate import IsValidInfMoudleType
|
||||
from Library.ParserValidate import IsValidInstallPath
|
||||
from Library.Misc import IsEqualList
|
||||
from Library.Misc import Sdict
|
||||
|
||||
from Logger.StringTable import ERR_XML_INVALID_VARIABLENAME
|
||||
from Logger.StringTable import ERR_XML_INVALID_LIB_SUPMODLIST
|
||||
from Logger.StringTable import ERR_XML_INVALID_EXTERN_SUPARCHLIST
|
||||
from Logger.StringTable import ERR_XML_INVALID_EXTERN_SUPMODLIST
|
||||
from Logger.StringTable import ERR_XML_INVALID_EXTERN_SUPMODLIST_NOT_LIB
|
||||
from Logger.StringTable import ERR_FILE_NAME_INVALIDE
|
||||
from Logger.StringTable import ERR_XML_INVALID_BINARY_FILE_TYPE
|
||||
from Logger.ToolError import PARSER_ERROR
|
||||
from Logger.ToolError import FORMAT_INVALID
|
||||
|
||||
from Xml.CommonXml import DistributionPackageHeaderXml
|
||||
from Xml.CommonXml import MiscellaneousFileXml
|
||||
from Xml.CommonXml import UserExtensionsXml
|
||||
from Xml.XmlParserMisc import ConvertVariableName
|
||||
from Xml.XmlParserMisc import IsRequiredItemListNull
|
||||
from Xml.ModuleSurfaceAreaXml import ModuleSurfaceAreaXml
|
||||
from Xml.PackageSurfaceAreaXml import PackageSurfaceAreaXml
|
||||
|
||||
import Logger.Log as Logger
|
||||
|
||||
##
|
||||
# DistributionPackageXml
|
||||
#
|
||||
class DistributionPackageXml(object):
|
||||
def __init__(self):
|
||||
self.DistP = DistributionPackageClass()
|
||||
self.Pkg = ''
|
||||
|
||||
## ValidateDistributionPackage
|
||||
#
|
||||
# Check if any required item is missing in DistributionPackage
|
||||
#
|
||||
def ValidateDistributionPackage(self):
|
||||
XmlTreeLevel = ['DistributionPackage']
|
||||
if self.DistP:
|
||||
#
|
||||
# Check DistributionPackage -> DistributionHeader
|
||||
#
|
||||
XmlTreeLevel = ['DistributionPackage', '']
|
||||
CheckDict = {'DistributionHeader':self.DistP.Header }
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
if self.DistP.Header:
|
||||
DpHeader = self.DistP.Header
|
||||
XmlTreeLevel = ['DistributionPackage', 'DistributionHeader']
|
||||
CheckDict = Sdict()
|
||||
CheckDict['Name'] = DpHeader.GetName()
|
||||
CheckDict['GUID'] = DpHeader.GetGuid()
|
||||
CheckDict['Version'] = DpHeader.GetVersion()
|
||||
CheckDict['Copyright'] = DpHeader.GetCopyright()
|
||||
CheckDict['License'] = DpHeader.GetLicense()
|
||||
CheckDict['Abstract'] = DpHeader.GetAbstract()
|
||||
CheckDict['Vendor'] = DpHeader.GetVendor()
|
||||
CheckDict['Date'] = DpHeader.GetDate()
|
||||
CheckDict['XmlSpecification'] = DpHeader.GetXmlSpecification()
|
||||
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
else:
|
||||
XmlTreeLevel = ['DistributionPackage', 'DistributionHeader']
|
||||
CheckDict = CheckDict = {'DistributionHeader':'', }
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check Each Package
|
||||
#
|
||||
for Key in self.DistP.PackageSurfaceArea:
|
||||
ValidatePackageSurfaceArea(self.DistP.PackageSurfaceArea[Key])
|
||||
|
||||
#
|
||||
# Check Each Module
|
||||
#
|
||||
for Key in self.DistP.ModuleSurfaceArea:
|
||||
ValidateMS(self.DistP.ModuleSurfaceArea[Key], ['DistributionPackage', 'ModuleSurfaceArea'])
|
||||
|
||||
#
|
||||
# Check Each Tool
|
||||
#
|
||||
if self.DistP.Tools:
|
||||
XmlTreeLevel = ['DistributionPackage', 'Tools', 'Header']
|
||||
CheckDict = {'Name':self.DistP.Tools.GetName(), }
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
if not self.DistP.Tools.GetFileList():
|
||||
XmlTreeLevel = ['DistributionPackage', 'Tools']
|
||||
CheckDict = {'FileName':None, }
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
for Item in self.DistP.Tools.GetFileList():
|
||||
XmlTreeLevel = ['DistributionPackage', 'Tools']
|
||||
CheckDict = {'FileName':Item.GetURI(), }
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check Each Misc File
|
||||
#
|
||||
if self.DistP.MiscellaneousFiles:
|
||||
XmlTreeLevel = ['DistributionPackage', 'MiscellaneousFiles', 'Header']
|
||||
CheckDict = {'Name':self.DistP.MiscellaneousFiles.GetName(), }
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
if not self.DistP.MiscellaneousFiles.GetFileList():
|
||||
XmlTreeLevel = ['DistributionPackage', 'MiscellaneousFiles']
|
||||
CheckDict = {'FileName':None, }
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
for Item in self.DistP.MiscellaneousFiles.GetFileList():
|
||||
XmlTreeLevel = ['DistributionPackage', 'MiscellaneousFiles']
|
||||
CheckDict = {'FileName':Item.GetURI(), }
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check Each Distribution Level User Extension
|
||||
#
|
||||
for Item in self.DistP.UserExtensions:
|
||||
XmlTreeLevel = ['DistributionPackage', 'UserExtensions']
|
||||
CheckDict = {'UserId':Item.GetUserID(), }
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
|
||||
def FromXml(self, Filename=None):
|
||||
if Filename != None:
|
||||
self.DistP = DistributionPackageClass()
|
||||
#
|
||||
# Load to XML
|
||||
#
|
||||
self.Pkg = XmlParseFile(Filename)
|
||||
|
||||
#
|
||||
# Parse Header information
|
||||
#
|
||||
Tmp = DistributionPackageHeaderXml()
|
||||
DistributionPackageHeader = \
|
||||
Tmp.FromXml(XmlNode(self.Pkg, '/DistributionPackage/DistributionHeader'), 'DistributionHeader')
|
||||
self.DistP.Header = DistributionPackageHeader
|
||||
#
|
||||
# Parse each PackageSurfaceArea
|
||||
#
|
||||
for Item in XmlList(self.Pkg, '/DistributionPackage/PackageSurfaceArea'):
|
||||
Psa = PackageSurfaceAreaXml()
|
||||
Package = Psa.FromXml(Item, 'PackageSurfaceArea')
|
||||
self.DistP.PackageSurfaceArea[(Package.GetGuid(), \
|
||||
Package.GetVersion(), \
|
||||
Package.GetPackagePath())] = \
|
||||
Package
|
||||
#
|
||||
# Parse each ModuleSurfaceArea
|
||||
#
|
||||
for Item in XmlList(self.Pkg, '/DistributionPackage/ModuleSurfaceArea'):
|
||||
Msa = ModuleSurfaceAreaXml()
|
||||
Module = Msa.FromXml(Item, 'ModuleSurfaceArea', True)
|
||||
self.DistP.ModuleSurfaceArea[(Module.GetGuid(), Module.GetVersion(), Module.GetModulePath())] = Module
|
||||
#
|
||||
# Parse Tools
|
||||
#
|
||||
Tmp = MiscellaneousFileXml()
|
||||
self.DistP.Tools = Tmp.FromXml2(XmlNode(self.Pkg, '/DistributionPackage/Tools'), 'Tools')
|
||||
|
||||
#
|
||||
# Parse MiscFiles
|
||||
#
|
||||
Tmp = MiscellaneousFileXml()
|
||||
self.DistP.MiscellaneousFiles = \
|
||||
Tmp.FromXml2(XmlNode(self.Pkg, \
|
||||
'/DistributionPackage/MiscellaneousFiles'), \
|
||||
'MiscellaneousFiles')
|
||||
|
||||
#
|
||||
# Parse UserExtensions
|
||||
#
|
||||
for Item in XmlList(self.Pkg, '/DistributionPackage/UserExtensions'):
|
||||
Tmp = UserExtensionsXml()
|
||||
self.DistP.UserExtensions.append(Tmp.FromXml2(Item, 'UserExtensions'))
|
||||
|
||||
#
|
||||
# Check Required Items for XML
|
||||
#
|
||||
self.ValidateDistributionPackage()
|
||||
|
||||
return self.DistP
|
||||
|
||||
def ToXml(self, DistP):
|
||||
if self.DistP:
|
||||
pass
|
||||
if DistP != None:
|
||||
#
|
||||
# Parse DistributionPackageHeader
|
||||
#
|
||||
Attrs = [['xmlns', 'http://www.uefi.org/2011/1.1'],
|
||||
['xmlns:xsi', 'http:/www.w3.org/2001/XMLSchema-instance'],
|
||||
]
|
||||
Root = CreateXmlElement('DistributionPackage', '', [], Attrs)
|
||||
|
||||
Tmp = DistributionPackageHeaderXml()
|
||||
Root.appendChild(Tmp.ToXml(DistP.Header, 'DistributionHeader'))
|
||||
#
|
||||
# Parse each PackageSurfaceArea
|
||||
#
|
||||
for Package in DistP.PackageSurfaceArea.values():
|
||||
Psa = PackageSurfaceAreaXml()
|
||||
DomPackage = Psa.ToXml(Package)
|
||||
Root.appendChild(DomPackage)
|
||||
#
|
||||
# Parse each ModuleSurfaceArea
|
||||
#
|
||||
for Module in DistP.ModuleSurfaceArea.values():
|
||||
Msa = ModuleSurfaceAreaXml()
|
||||
DomModule = Msa.ToXml(Module)
|
||||
Root.appendChild(DomModule)
|
||||
#
|
||||
# Parse Tools
|
||||
#
|
||||
Tmp = MiscellaneousFileXml()
|
||||
ToolNode = Tmp.ToXml2(DistP.Tools, 'Tools')
|
||||
if ToolNode is not None:
|
||||
Root.appendChild(ToolNode)
|
||||
#
|
||||
# Parse MiscFiles
|
||||
#
|
||||
Tmp = MiscellaneousFileXml()
|
||||
MiscFileNode = Tmp.ToXml2(DistP.MiscellaneousFiles,
|
||||
'MiscellaneousFiles')
|
||||
if MiscFileNode is not None:
|
||||
Root.appendChild(MiscFileNode)
|
||||
|
||||
XmlContent = Root.toprettyxml(indent=' ')
|
||||
|
||||
|
||||
#
|
||||
# Remove empty element
|
||||
#
|
||||
XmlContent = re.sub(r'[\s\r\n]*<[^<>=]*/>', '', XmlContent)
|
||||
|
||||
#
|
||||
# Remove empty help text element
|
||||
#
|
||||
XmlContent = re.sub(r'[\s\r\n]*<HelpText Lang="en-US"/>', '',
|
||||
XmlContent)
|
||||
|
||||
#
|
||||
# Remove SupArchList="COMMON" or "common"
|
||||
#
|
||||
XmlContent = \
|
||||
re.sub(r'[\s\r\n]*SupArchList[\s\r\n]*=[\s\r\n]*"[\s\r\n]*COMMON'
|
||||
'[\s\r\n]*"', '', XmlContent)
|
||||
XmlContent = \
|
||||
re.sub(r'[\s\r\n]*SupArchList[\s\r\n]*=[\s\r\n]*"[\s\r\n]*common'
|
||||
'[\s\r\n]*"', '', XmlContent)
|
||||
#
|
||||
# Remove <SupArchList> COMMON </SupArchList>
|
||||
#
|
||||
XmlContent = \
|
||||
re.sub(r'[\s\r\n]*<SupArchList>[\s\r\n]*COMMON[\s\r\n]*'
|
||||
'</SupArchList>[\s\r\n]*', '', XmlContent)
|
||||
|
||||
#
|
||||
# Remove <SupArchList> common </SupArchList>
|
||||
#
|
||||
XmlContent = \
|
||||
re.sub(r'[\s\r\n]*<SupArchList>[\s\r\n]*'
|
||||
'common[\s\r\n]*</SupArchList>[\s\r\n]*', '', XmlContent)
|
||||
|
||||
#
|
||||
# Remove SupModList="COMMON" or "common"
|
||||
#
|
||||
XmlContent = \
|
||||
re.sub(r'[\s\r\n]*SupModList[\s\r\n]*=[\s\r\n]*"[\s\r\n]*COMMON'
|
||||
'[\s\r\n]*"', '', XmlContent)
|
||||
XmlContent = \
|
||||
re.sub(r'[\s\r\n]*SupModList[\s\r\n]*=[\s\r\n]*"[\s\r\n]*common'
|
||||
'[\s\r\n]*"', '', XmlContent)
|
||||
|
||||
return XmlContent
|
||||
|
||||
return ''
|
||||
|
||||
## ValidateMS
|
||||
#
|
||||
# Check if any required item is missing in ModuleSurfaceArea
|
||||
#
|
||||
# @param Module: The ModuleSurfaceArea to be checked
|
||||
# @param XmlTreeLevel: The top level of Module
|
||||
#
|
||||
def ValidateMS(Module, TopXmlTreeLevel):
|
||||
ValidateMS1(Module, TopXmlTreeLevel)
|
||||
ValidateMS2(Module, TopXmlTreeLevel)
|
||||
ValidateMS3(Module, TopXmlTreeLevel)
|
||||
|
||||
## ValidateMS1
|
||||
#
|
||||
# Check if any required item is missing in ModuleSurfaceArea
|
||||
#
|
||||
# @param Module: The ModuleSurfaceArea to be checked
|
||||
# @param XmlTreeLevel: The top level of Module
|
||||
#
|
||||
def ValidateMS1(Module, TopXmlTreeLevel):
|
||||
#
|
||||
# Check Guids -> GuidCName
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['Guids']
|
||||
for Item in Module.GetGuidList():
|
||||
if Item == None:
|
||||
CheckDict = {'GuidCName':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['Guids', 'GuidCName']
|
||||
for Item in Module.GetGuidList():
|
||||
CheckDict = {'CName':Item.GetCName(),
|
||||
'GuidType':Item.GetGuidTypeList(),
|
||||
'Usage':Item.GetUsage()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
if Item.GetVariableName():
|
||||
Result = ConvertVariableName(Item.GetVariableName())
|
||||
if Result is None:
|
||||
Msg = "->".join(Node for Node in XmlTreeLevel)
|
||||
ErrorMsg = ERR_XML_INVALID_VARIABLENAME % (Item.GetVariableName(), Item.GetCName(), Msg)
|
||||
Logger.Error('\nUPT', PARSER_ERROR, ErrorMsg, RaiseError=True)
|
||||
else:
|
||||
Item.SetVariableName(Result)
|
||||
|
||||
#
|
||||
# Check Protocols -> Protocol
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['Protocols']
|
||||
for Item in Module.GetProtocolList():
|
||||
if Item == None:
|
||||
CheckDict = {'Protocol':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['Protocols', 'Protocol']
|
||||
for Item in Module.GetProtocolList():
|
||||
CheckDict = {'CName':Item.GetCName(),
|
||||
'Usage':Item.GetUsage()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check PPIs -> Ppi
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['PPIs']
|
||||
for Item in Module.GetPpiList():
|
||||
if Item == None:
|
||||
CheckDict = {'Ppi':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['PPIs', 'Ppi']
|
||||
for Item in Module.GetPpiList():
|
||||
CheckDict = {'CName':Item.GetCName(),
|
||||
'Usage':Item.GetUsage()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check PcdCoded -> Entry
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['PcdCoded']
|
||||
for Item in Module.GetPcdList():
|
||||
if Item == None:
|
||||
CheckDict = {'PcdEntry':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['PcdCoded', 'PcdEntry']
|
||||
for Item in Module.GetPcdList():
|
||||
CheckDict = {'TokenSpaceGuidCname':Item.GetTokenSpaceGuidCName(),
|
||||
'CName':Item.GetCName(),
|
||||
'PcdUsage':Item.GetValidUsage(),
|
||||
'PcdItemType':Item.GetItemType()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check Externs -> Extern
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['Externs']
|
||||
for Item in Module.GetExternList():
|
||||
if Item == None:
|
||||
CheckDict = {'Extern':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# If SupArchList is used to identify different EntryPoint, UnloadImage, Constructor/Destructor elements and
|
||||
# that SupArchList does not match ModuleSurfaceArea.ModuleProperties:SupArchList, the tool must exit gracefully,
|
||||
# informing the user that the EDK II Build system does not support different EntryPoint, UnloadImage,
|
||||
# Constructor or Destructor elements based on Architecture type. Two SupArchList attributes are considered
|
||||
# identical if it lists the same CPU architectures in any order.
|
||||
#
|
||||
for Item in Module.GetExternList():
|
||||
if len(Item.SupArchList) > 0:
|
||||
if not IsEqualList(Item.SupArchList, Module.SupArchList):
|
||||
Logger.Error('\nUPT',
|
||||
PARSER_ERROR,
|
||||
ERR_XML_INVALID_EXTERN_SUPARCHLIST % (str(Item.SupArchList), str(Module.SupArchList)),
|
||||
RaiseError=True)
|
||||
|
||||
#
|
||||
# Check DistributionPackage -> ModuleSurfaceArea -> UserExtensions
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['UserExtensions']
|
||||
for Item in Module.GetUserExtensionList():
|
||||
CheckDict = {'UserId':Item.GetUserID(), 'Identifier':Item.GetIdentifier()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check DistributionPackage -> PackageSurfaceArea -> MiscellaneousFiles -> Filename
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['MiscellaneousFiles']
|
||||
for Item in Module.GetMiscFileList():
|
||||
if not Item.GetFileList():
|
||||
CheckDict = {'Filename':'', }
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
for File in Item.GetFileList():
|
||||
CheckDict = {'Filename':File.GetURI(), }
|
||||
|
||||
## ValidateMS2
|
||||
#
|
||||
# Check if any required item is missing in ModuleSurfaceArea
|
||||
#
|
||||
# @param Module: The ModuleSurfaceArea to be checked
|
||||
# @param XmlTreeLevel: The top level of Module
|
||||
#
|
||||
def ValidateMS2(Module, TopXmlTreeLevel):
|
||||
#
|
||||
# Check Header
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['Header']
|
||||
CheckDict = Sdict()
|
||||
CheckDict['Name'] = Module.GetName()
|
||||
CheckDict['BaseName'] = Module.GetBaseName()
|
||||
CheckDict['GUID'] = Module.GetGuid()
|
||||
CheckDict['Version'] = Module.GetVersion()
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check ModuleProperties
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties']
|
||||
CheckDict = {'ModuleType':Module.GetModuleType(),
|
||||
'Path':Module.GetModulePath()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
if not IsValidInstallPath(Module.GetModulePath()):
|
||||
Logger.Error("UPT", FORMAT_INVALID, ERR_FILE_NAME_INVALIDE % Module.GetModulePath())
|
||||
|
||||
#
|
||||
# Check ModuleProperties->BootMode
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] + ['BootMode']
|
||||
for Item in Module.GetBootModeList():
|
||||
CheckDict = {'Usage':Item.GetUsage(),
|
||||
'SupportedBootModes':Item.GetSupportedBootModes()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check ModuleProperties->Event
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] + ['Event']
|
||||
for Item in Module.GetEventList():
|
||||
CheckDict = {'Usage':Item.GetUsage(),
|
||||
'EventType':Item.GetEventType()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check ModuleProperties->Hob
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] + ['HOB']
|
||||
for Item in Module.GetHobList():
|
||||
CheckDict = {'Usage':Item.GetUsage(),
|
||||
'HobType':Item.GetHobType()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# The UDP Specification supports the module type of UEFI_RUNTIME_DRIVER, which is not present in the EDK II INF
|
||||
# File Specification v. 1.23, so UPT must perform the following translation that include the generation of a
|
||||
# [Depex] section.
|
||||
#
|
||||
if Module.ModuleType == "UEFI_RUNTIME_DRIVER":
|
||||
Module.ModuleType = "DXE_RUNTIME_DRIVER"
|
||||
DxeObj = DepexObject()
|
||||
DxeObj.SetDepex("gEfiBdsArchProtocolGuid AND \ngEfiCpuArchProtocolGuid AND\n" + \
|
||||
"gEfiMetronomeArchProtocolGuid AND \ngEfiMonotonicCounterArchProtocolGuid AND\n" + \
|
||||
"gEfiRealTimeClockArchProtocolGuid AND \ngEfiResetArchProtocolGuid AND\n" + \
|
||||
"gEfiRuntimeArchProtocolGuid AND \ngEfiSecurityArchProtocolGuid AND\n" + \
|
||||
"gEfiTimerArchProtocolGuid AND \ngEfiVariableWriteArchProtocolGuid AND\n" + \
|
||||
"gEfiVariableArchProtocolGuid AND \ngEfiWatchdogTimerArchProtocolGuid")
|
||||
DxeObj.SetModuleType(['DXE_RUNTIME_DRIVER'])
|
||||
Module.PeiDepex = []
|
||||
Module.DxeDepex = []
|
||||
Module.SmmDepex = []
|
||||
Module.DxeDepex.append(DxeObj)
|
||||
|
||||
#
|
||||
# Check LibraryClassDefinitions -> LibraryClass
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['LibraryClassDefinitions']
|
||||
for Item in Module.GetLibraryClassList():
|
||||
if Item == None:
|
||||
CheckDict = {'LibraryClass':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['LibraryClassDefinitions', 'LibraryClass']
|
||||
|
||||
IsLibraryModule = False
|
||||
LibrarySupModList = []
|
||||
for Item in Module.GetLibraryClassList():
|
||||
CheckDict = {'Keyword':Item.GetLibraryClass(),
|
||||
'Usage':Item.GetUsage()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
#
|
||||
# If the LibraryClass:SupModList is not "UNDEFINED" the LIBRARY_CLASS entry must have the list
|
||||
# appended using the format:
|
||||
# LIBRARY_CLASS = <ClassName> ["|" <Edk2ModuleTypeList>]
|
||||
#
|
||||
# Edk2ModuleTypeList ::= <ModuleType> [" " <ModuleType>]{0,}
|
||||
# <ModuleTypes> ::= {"BASE"} {"SEC"} {"PEI_CORE"} {"PEIM"}
|
||||
# {"DXE_CORE"} {"DXE_DRIVER"} {"SMM_CORE"}
|
||||
# {"DXE_SMM_DRIVER"} {"DXE_RUNTIME_DRIVER"}
|
||||
# {"DXE_SAL_DRIVER"} {"UEFI_DRIVER"}
|
||||
# {"UEFI_APPLICATION"} {"USER_DEFINED"}
|
||||
#
|
||||
if len(Item.SupModuleList) > 0:
|
||||
for SupModule in Item.SupModuleList:
|
||||
if not IsValidInfMoudleType(SupModule):
|
||||
Logger.Error('\nUPT',
|
||||
PARSER_ERROR,
|
||||
ERR_XML_INVALID_LIB_SUPMODLIST % (Item.LibraryClass, str(SupModule)),
|
||||
RaiseError=True)
|
||||
|
||||
if Item.Usage == 'PRODUCES' or Item.Usage == 'SOMETIMES_PRODUCES':
|
||||
IsLibraryModule = True
|
||||
LibrarySupModList = Item.SupModuleList
|
||||
|
||||
|
||||
#
|
||||
# For Library modules (indicated by a LIBRARY_CLASS statement in the [Defines] section)
|
||||
# If the SupModList attribute of the CONSTRUCTOR or DESTRUCTOR element does not match the Supported Module
|
||||
# Types listed after "LIBRARY_CLASS = <Keyword> |", the tool should gracefully exit with an error message
|
||||
# stating that there is a conflict in the module types the CONSTRUCTOR/DESTRUCTOR is to be used with and
|
||||
# the Module types this Library supports.
|
||||
#
|
||||
if IsLibraryModule:
|
||||
for Item in Module.GetExternList():
|
||||
if Item.Constructor or Item.Destructor:
|
||||
if hasattr(Item, 'SupModList') and len(Item.SupModList) > 0 and \
|
||||
not IsEqualList(Item.SupModList, LibrarySupModList):
|
||||
Logger.Error('\nUPT',
|
||||
PARSER_ERROR,
|
||||
ERR_XML_INVALID_EXTERN_SUPMODLIST % (str(Item.SupModList), str(LibrarySupModList)),
|
||||
RaiseError=True)
|
||||
|
||||
#
|
||||
# If the module is not a library module, the MODULE_TYPE listed in the ModuleSurfaceArea.Header must match the
|
||||
# SupModList attribute. If these conditions cannot be met, the tool must exit gracefully, informing the user
|
||||
# that the EDK II Build system does not currently support the features required by this Module.
|
||||
#
|
||||
if not IsLibraryModule:
|
||||
for Item in Module.GetExternList():
|
||||
if hasattr(Item, 'SupModList') and len(Item.SupModList) > 0 and \
|
||||
not IsEqualList(Item.SupModList, [Module.ModuleType]):
|
||||
Logger.Error('\nUPT',
|
||||
PARSER_ERROR,
|
||||
ERR_XML_INVALID_EXTERN_SUPMODLIST_NOT_LIB % (str(Module.ModuleType), str(Item.SupModList)),
|
||||
RaiseError=True)
|
||||
#
|
||||
# Check SourceFiles
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['SourceFiles']
|
||||
for Item in Module.GetSourceFileList():
|
||||
if Item == None:
|
||||
CheckDict = {'Filename':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['SourceFiles']
|
||||
for Item in Module.GetSourceFileList():
|
||||
CheckDict = {'Filename':Item.GetSourceFile()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
for ItemCount in range(len(Module.GetBinaryFileList())):
|
||||
Item = Module.GetBinaryFileList()[ItemCount]
|
||||
if Item and len(Item.FileNamList) > 0 and Item.FileNamList[0].FileType == 'FREEFORM':
|
||||
Item.FileNamList[0].FileType = 'SUBTYPE_GUID'
|
||||
Module.GetBinaryFileList()[ItemCount] = Item
|
||||
if Item and len(Item.FileNamList) > 0 and Item.FileNamList[0].FileType == 'DISPOSABLE':
|
||||
Logger.Error('\nUPT',
|
||||
PARSER_ERROR,
|
||||
ERR_XML_INVALID_BINARY_FILE_TYPE % ('DISPOSABLE'),
|
||||
RaiseError=True)
|
||||
|
||||
## ValidateMS3
|
||||
#
|
||||
# Check if any required item is missing in ModuleSurfaceArea
|
||||
#
|
||||
# @param Module: The ModuleSurfaceArea to be checked
|
||||
# @param XmlTreeLevel: The top level of Module
|
||||
#
|
||||
def ValidateMS3(Module, TopXmlTreeLevel):
|
||||
#
|
||||
# Check PackageDependencies -> Package
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['PackageDependencies']
|
||||
for Item in Module.GetPackageDependencyList():
|
||||
if Item == None:
|
||||
CheckDict = {'Package':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['PackageDependencies', 'Package']
|
||||
for Item in Module.GetPackageDependencyList():
|
||||
CheckDict = {'GUID':Item.GetGuid()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check BinaryFiles -> BinaryFile
|
||||
#
|
||||
for Item in Module.GetBinaryFileList():
|
||||
if Item == None:
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['BinaryFiles']
|
||||
CheckDict = {'BinaryFile':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
if not Item.GetFileNameList():
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['BinaryFiles', 'BinaryFile']
|
||||
CheckDict = {'Filename':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['BinaryFiles', 'BinaryFile']
|
||||
for File in Item.GetFileNameList():
|
||||
CheckDict = {'Filename':File.GetFilename(),
|
||||
'FileType':File.GetFileType()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
for AsBuilt in Item.GetAsBuiltList():
|
||||
#
|
||||
# Check LibInstance
|
||||
#
|
||||
if len(AsBuilt.LibraryInstancesList) == 1 and not AsBuilt.LibraryInstancesList[0]:
|
||||
CheckDict = {'GUID':''}
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['BinaryFiles', 'BinaryFile', 'AsBuilt', 'LibraryInstances']
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
for LibItem in AsBuilt.LibraryInstancesList:
|
||||
CheckDict = {'Guid':LibItem.Guid,
|
||||
'Version':LibItem.Version}
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['BinaryFiles', 'BinaryFile', 'AsBuilt', 'LibraryInstances']
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check PatchPcd
|
||||
#
|
||||
for PatchPcdItem in AsBuilt.PatchPcdList:
|
||||
CheckDict = {'TokenSpaceGuidValue':PatchPcdItem.TokenSpaceGuidValue,
|
||||
'PcdCName':PatchPcdItem.PcdCName,
|
||||
'Token':PatchPcdItem.Token,
|
||||
'DatumType':PatchPcdItem.DatumType,
|
||||
'Value':PatchPcdItem.DefaultValue,
|
||||
'Offset':PatchPcdItem.Offset}
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['BinaryFiles', 'BinaryFile', 'AsBuilt', 'PatchPcdValue']
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
#
|
||||
# Check PcdError
|
||||
#
|
||||
for PcdErrorItem in PatchPcdItem.PcdErrorsList:
|
||||
CheckDict = {'ErrorNumber':PcdErrorItem.ErrorNumber}
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['BinaryFiles', 'BinaryFile', 'AsBuilt',
|
||||
'PatchPcdValue', 'PcdError']
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
#
|
||||
# Check PcdEx
|
||||
#
|
||||
for PcdExItem in AsBuilt.PcdExValueList:
|
||||
CheckDict = {'TokenSpaceGuidValue':PcdExItem.TokenSpaceGuidValue,
|
||||
'Token':PcdExItem.Token,
|
||||
'DatumType':PcdExItem.DatumType,
|
||||
'Value':PcdExItem.DefaultValue}
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['BinaryFiles', 'BinaryFile', 'AsBuilt', 'PcdExValue']
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
#
|
||||
# Check PcdError
|
||||
#
|
||||
for PcdErrorItem in PcdExItem.PcdErrorsList:
|
||||
CheckDict = {'ErrorNumber':PcdErrorItem.ErrorNumber}
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['BinaryFiles', 'BinaryFile', 'AsBuilt',
|
||||
'PcdExValue', 'PcdError']
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
#
|
||||
# Check SmmDepex
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['SmmDepex']
|
||||
for Item in Module.GetSmmDepex():
|
||||
CheckDict = {'Expression':Item.GetDepex()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check PeiDepex
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['PeiDepex']
|
||||
for Item in Module.GetPeiDepex():
|
||||
CheckDict = {'Expression':Item.GetDepex()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check DxeDepex
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['DxeDepex']
|
||||
for Item in Module.GetDxeDepex():
|
||||
CheckDict = {'Expression':Item.GetDepex()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check <UserExtensions>
|
||||
#
|
||||
XmlTreeLevel = TopXmlTreeLevel + ['UserExtensions']
|
||||
for Item in Module.GetUserExtensionList():
|
||||
CheckDict = {'UserId':Item.GetUserID(), 'Identifier':Item.GetIdentifier()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
## ValidatePS1
|
||||
#
|
||||
# ValidatePS1
|
||||
#
|
||||
def ValidatePS1(Package):
|
||||
#
|
||||
# Check DistributionPackage -> PackageSurfaceArea -> Header
|
||||
#
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'Header']
|
||||
CheckDict = Sdict()
|
||||
CheckDict['Name'] = Package.GetName()
|
||||
CheckDict['BaseName'] = Package.GetBaseName()
|
||||
CheckDict['GUID'] = Package.GetGuid()
|
||||
CheckDict['Version'] = Package.GetVersion()
|
||||
CheckDict['PackagePath'] = Package.GetPackagePath()
|
||||
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
if not IsValidInstallPath(Package.GetPackagePath()):
|
||||
Logger.Error("UPT", FORMAT_INVALID, ERR_FILE_NAME_INVALIDE % Package.GetPackagePath())
|
||||
|
||||
#
|
||||
# Check DistributionPackage -> PackageSurfaceArea -> ClonedFrom
|
||||
#
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'ClonedFrom']
|
||||
for Item in Package.GetClonedFromList():
|
||||
if Item == None:
|
||||
CheckDict = Sdict()
|
||||
CheckDict['GUID'] = ''
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
CheckDict = Sdict()
|
||||
CheckDict['GUID'] = Item.GetPackageGuid()
|
||||
CheckDict['Version'] = Item.GetPackageVersion()
|
||||
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check DistributionPackage -> PackageSurfaceArea -> LibraryClassDeclarations -> LibraryClass
|
||||
#
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'LibraryClassDeclarations']
|
||||
for Item in Package.GetLibraryClassList():
|
||||
if Item == None:
|
||||
CheckDict = {'LibraryClass':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'LibraryClassDeclarations', 'LibraryClass']
|
||||
for Item in Package.GetLibraryClassList():
|
||||
CheckDict = {'Keyword':Item.GetLibraryClass(),
|
||||
'HeaderFile':Item.GetIncludeHeader()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check DistributionPackage -> PackageSurfaceArea -> IndustryStandardIncludes -> IndustryStandardHeader
|
||||
#
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'IndustryStandardIncludes']
|
||||
for Item in Package.GetStandardIncludeFileList():
|
||||
if Item == None:
|
||||
CheckDict = {'IndustryStandardHeader':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'IndustryStandardIncludes', 'IndustryStandardHeader']
|
||||
for Item in Package.GetStandardIncludeFileList():
|
||||
CheckDict = {'HeaderFile':Item.GetFilePath()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check DistributionPackage -> PackageSurfaceArea -> PackageIncludes -> PackageHeader
|
||||
#
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'PackageIncludes']
|
||||
for Item in Package.GetPackageIncludeFileList():
|
||||
if Item == None:
|
||||
CheckDict = {'PackageHeader':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'PackageIncludes', 'PackageHeader']
|
||||
for Item in Package.GetPackageIncludeFileList():
|
||||
CheckDict = {'HeaderFile':Item.GetFilePath()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
## ValidatePS2
|
||||
#
|
||||
# ValidatePS2
|
||||
#
|
||||
def ValidatePS2(Package):
|
||||
#
|
||||
# Check DistributionPackage -> PackageSurfaceArea -> Modules -> ModuleSurfaceArea
|
||||
#
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'Modules', 'ModuleSurfaceArea']
|
||||
for Item in Package.GetModuleDict().values():
|
||||
ValidateMS(Item, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check DistributionPackage -> PackageSurfaceArea -> GuidDeclarations Entry
|
||||
#
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'GuidDeclarations']
|
||||
for Item in Package.GetGuidList():
|
||||
if Item == None:
|
||||
CheckDict = {'Entry':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'GuidDeclarations', 'Entry']
|
||||
for Item in Package.GetGuidList():
|
||||
CheckDict = {'CName':Item.GetCName(),
|
||||
'GuidValue':Item.GetGuid()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check DistributionPackage -> PackageSurfaceArea -> ProtocolDeclarations -> Entry
|
||||
#
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'ProtocolDeclarations']
|
||||
for Item in Package.GetProtocolList():
|
||||
if Item == None:
|
||||
CheckDict = {'Entry':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'ProtocolDeclarations', 'Entry']
|
||||
for Item in Package.GetProtocolList():
|
||||
CheckDict = {'CName':Item.GetCName(),
|
||||
'GuidValue':Item.GetGuid()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check DistributionPackage -> PackageSurfaceArea -> PpiDeclarations -> Entry
|
||||
#
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'PpiDeclarations']
|
||||
for Item in Package.GetPpiList():
|
||||
if Item == None:
|
||||
CheckDict = {'Entry':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'PpiDeclarations', 'Entry']
|
||||
for Item in Package.GetPpiList():
|
||||
CheckDict = {'CName':Item.GetCName(),
|
||||
'GuidValue':Item.GetGuid()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check DistributionPackage -> PackageSurfaceArea -> PcdDeclarations -> Entry
|
||||
#
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'PcdDeclarations']
|
||||
for Item in Package.GetPcdList():
|
||||
if Item == None:
|
||||
CheckDict = {'PcdEntry':''}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'PcdDeclarations', 'PcdEntry']
|
||||
for Item in Package.GetPcdList():
|
||||
CheckDict = {'TokenSpaceGuidCname':Item.GetTokenSpaceGuidCName(),
|
||||
'Token':Item.GetToken(),
|
||||
'CName':Item.GetCName(),
|
||||
'DatumType':Item.GetDatumType(),
|
||||
'ValidUsage':Item.GetValidUsage(),
|
||||
'DefaultValue':Item.GetDefaultValue()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check DistributionPackage -> PackageSurfaceArea -> UserExtensions
|
||||
#
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'UserExtensions']
|
||||
for Item in Package.GetUserExtensionList():
|
||||
CheckDict = {'UserId':Item.GetUserID(), 'Identifier':Item.GetIdentifier()}
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
#
|
||||
# Check DistributionPackage -> PackageSurfaceArea -> MiscellaneousFiles -> Filename
|
||||
#
|
||||
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'MiscellaneousFiles']
|
||||
for Item in Package.GetMiscFileList():
|
||||
if not Item.GetFileList():
|
||||
CheckDict = {'Filename':'', }
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
for File in Item.GetFileList():
|
||||
CheckDict = {'Filename':File.GetURI(), }
|
||||
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
|
||||
|
||||
## ValidatePackageSurfaceArea
|
||||
#
|
||||
# Check if any required item is missing in PackageSurfaceArea
|
||||
#
|
||||
# @param Package: The PackageSurfaceArea to be checked
|
||||
#
|
||||
def ValidatePackageSurfaceArea(Package):
|
||||
ValidatePS1(Package)
|
||||
ValidatePS2(Package)
|
89
BaseTools/Source/Python/UPT/Xml/XmlParserMisc.py
Normal file
89
BaseTools/Source/Python/UPT/Xml/XmlParserMisc.py
Normal file
@@ -0,0 +1,89 @@
|
||||
## @file
|
||||
# This file is used to parse a xml file of .PKG file
|
||||
#
|
||||
# Copyright (c) 2011, 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
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
'''
|
||||
XmlParserMisc
|
||||
'''
|
||||
from Object.POM.CommonObject import TextObject
|
||||
from Logger.StringTable import ERR_XML_PARSER_REQUIRED_ITEM_MISSING
|
||||
from Logger.ToolError import PARSER_ERROR
|
||||
import Logger.Log as Logger
|
||||
|
||||
## ConvertVariableName()
|
||||
# Convert VariableName to be L"string",
|
||||
# input of UCS-2 format Hex Array or L"string" (C style.) could be converted successfully,
|
||||
# others will not.
|
||||
#
|
||||
# @param VariableName: string need to be converted
|
||||
# @retval: the L quoted string converted if success, else None will be returned
|
||||
#
|
||||
def ConvertVariableName(VariableName):
|
||||
VariableName = VariableName.strip()
|
||||
#
|
||||
# check for L quoted string
|
||||
#
|
||||
if VariableName.startswith('L"') and VariableName.endswith('"'):
|
||||
return VariableName
|
||||
|
||||
#
|
||||
# check for Hex Array, it should be little endian even number of hex numbers
|
||||
#
|
||||
ValueList = VariableName.split(' ')
|
||||
if len(ValueList)%2 == 1:
|
||||
return None
|
||||
|
||||
TransferedStr = ''
|
||||
|
||||
Index = 0
|
||||
|
||||
while Index < len(ValueList):
|
||||
FirstByte = int(ValueList[Index], 16)
|
||||
SecondByte = int(ValueList[Index + 1], 16)
|
||||
if SecondByte != 0:
|
||||
return None
|
||||
|
||||
if FirstByte not in xrange(0x20, 0x7F):
|
||||
return None
|
||||
TransferedStr += ('%c')%FirstByte
|
||||
Index = Index + 2
|
||||
|
||||
return 'L"' + TransferedStr + '"'
|
||||
|
||||
## IsRequiredItemListNull
|
||||
#
|
||||
# Check if a required XML section item/attribue is NULL
|
||||
#
|
||||
# @param ItemList: The list of items to be checked
|
||||
# @param XmlTreeLevel: The error message tree level
|
||||
#
|
||||
def IsRequiredItemListNull(ItemDict, XmlTreeLevel):
|
||||
for Key in ItemDict:
|
||||
if not ItemDict[Key]:
|
||||
Msg = "->".join(Node for Node in XmlTreeLevel)
|
||||
ErrorMsg = ERR_XML_PARSER_REQUIRED_ITEM_MISSING % (Key, Msg)
|
||||
Logger.Error('\nUPT', PARSER_ERROR, ErrorMsg, RaiseError=True)
|
||||
|
||||
|
||||
## Get help text
|
||||
#
|
||||
# @param HelpText
|
||||
#
|
||||
def GetHelpTextList(HelpText):
|
||||
HelpTextList = []
|
||||
for HelT in HelpText:
|
||||
HelpTextObj = TextObject()
|
||||
HelpTextObj.SetLang(HelT.Lang)
|
||||
HelpTextObj.SetString(HelT.HelpText)
|
||||
HelpTextList.append(HelpTextObj)
|
||||
return HelpTextList
|
20
BaseTools/Source/Python/UPT/Xml/__init__.py
Normal file
20
BaseTools/Source/Python/UPT/Xml/__init__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
## @file
|
||||
# Python 'Library' package initialization file.
|
||||
#
|
||||
# This file is required to make Python interpreter treat the directory
|
||||
# as containing package.
|
||||
#
|
||||
# Copyright (c) 2011, 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
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
'''
|
||||
Xml
|
||||
'''
|
Reference in New Issue
Block a user