X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FUPT%2FXml%2FXmlParser.py;h=8e22a280f655b62f96bd1f148eac6aa448a1a219;hb=2e351cbe8e190271b3716284fc1076551d005472;hp=adfeca81a000328412ca8b5aa2949d3d56b807bd;hpb=4234283c3acb8c35014acc1546621fbc2621b095;p=mirror_edk2.git
diff --git a/BaseTools/Source/Python/UPT/Xml/XmlParser.py b/BaseTools/Source/Python/UPT/Xml/XmlParser.py
index adfeca81a0..8e22a280f6 100644
--- a/BaseTools/Source/Python/UPT/Xml/XmlParser.py
+++ b/BaseTools/Source/Python/UPT/Xml/XmlParser.py
@@ -1,15 +1,9 @@
## @file
# This file is used to parse a xml file of .PKG file
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.
+# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
#
-# 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.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
#
'''
@@ -38,7 +32,6 @@ 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
@@ -78,12 +71,25 @@ class DistributionPackageXml(object):
DpHeader = self.DistP.Header
XmlTreeLevel = ['DistributionPackage', 'DistributionHeader']
CheckDict = Sdict()
+ if DpHeader.GetAbstract():
+ DPAbstract = DpHeader.GetAbstract()[0][1]
+ else:
+ DPAbstract = ''
+ if DpHeader.GetCopyright():
+ DPCopyright = DpHeader.GetCopyright()[0][1]
+ else:
+ DPCopyright = ''
+ if DpHeader.GetLicense():
+ DPLicense = DpHeader.GetLicense()[0][1]
+ else:
+ DPLicense = ''
+
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['Copyright'] = DPCopyright
+ CheckDict['License'] = DPLicense
+ CheckDict['Abstract'] = DPAbstract
CheckDict['Vendor'] = DpHeader.GetVendor()
CheckDict['Date'] = DpHeader.GetDate()
CheckDict['XmlSpecification'] = DpHeader.GetXmlSpecification()
@@ -91,7 +97,7 @@ class DistributionPackageXml(object):
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
else:
XmlTreeLevel = ['DistributionPackage', 'DistributionHeader']
- CheckDict = CheckDict = {'DistributionHeader':'', }
+ CheckDict = CheckDict = {'DistributionHeader': '', }
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
#
@@ -107,20 +113,20 @@ class DistributionPackageXml(object):
ValidateMS(self.DistP.ModuleSurfaceArea[Key], ['DistributionPackage', 'ModuleSurfaceArea'])
#
- # Check Each Tool
+ # Check Each Tool
#
if self.DistP.Tools:
XmlTreeLevel = ['DistributionPackage', 'Tools', 'Header']
- CheckDict = {'Name':self.DistP.Tools.GetName(), }
+ CheckDict = {'Name': self.DistP.Tools.GetName(), }
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
if not self.DistP.Tools.GetFileList():
XmlTreeLevel = ['DistributionPackage', 'Tools']
- CheckDict = {'FileName':None, }
+ CheckDict = {'FileName': None, }
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
for Item in self.DistP.Tools.GetFileList():
XmlTreeLevel = ['DistributionPackage', 'Tools']
- CheckDict = {'FileName':Item.GetURI(), }
+ CheckDict = {'FileName': Item.GetURI(), }
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
#
@@ -128,16 +134,16 @@ class DistributionPackageXml(object):
#
if self.DistP.MiscellaneousFiles:
XmlTreeLevel = ['DistributionPackage', 'MiscellaneousFiles', 'Header']
- CheckDict = {'Name':self.DistP.MiscellaneousFiles.GetName(), }
+ CheckDict = {'Name': self.DistP.MiscellaneousFiles.GetName(), }
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
if not self.DistP.MiscellaneousFiles.GetFileList():
XmlTreeLevel = ['DistributionPackage', 'MiscellaneousFiles']
- CheckDict = {'FileName':None, }
+ CheckDict = {'FileName': None, }
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
for Item in self.DistP.MiscellaneousFiles.GetFileList():
XmlTreeLevel = ['DistributionPackage', 'MiscellaneousFiles']
- CheckDict = {'FileName':Item.GetURI(), }
+ CheckDict = {'FileName': Item.GetURI(), }
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
#
@@ -145,12 +151,12 @@ class DistributionPackageXml(object):
#
for Item in self.DistP.UserExtensions:
XmlTreeLevel = ['DistributionPackage', 'UserExtensions']
- CheckDict = {'UserId':Item.GetUserID(), }
+ CheckDict = {'UserId': Item.GetUserID(), }
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
def FromXml(self, Filename=None):
- if Filename != None:
+ if Filename is not None:
self.DistP = DistributionPackageClass()
#
# Load to XML
@@ -180,8 +186,10 @@ class DistributionPackageXml(object):
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
- #
+ ModuleKey = (Module.GetGuid(), Module.GetVersion(), Module.GetName(), Module.GetModulePath())
+ self.DistP.ModuleSurfaceArea[ModuleKey] = Module
+
+ #
# Parse Tools
#
Tmp = MiscellaneousFileXml()
@@ -213,7 +221,7 @@ class DistributionPackageXml(object):
def ToXml(self, DistP):
if self.DistP:
pass
- if DistP != None:
+ if DistP is not None:
#
# Parse DistributionPackageHeader
#
@@ -238,7 +246,7 @@ class DistributionPackageXml(object):
Msa = ModuleSurfaceAreaXml()
DomModule = Msa.ToXml(Module)
Root.appendChild(DomModule)
- #
+ #
# Parse Tools
#
Tmp = MiscellaneousFileXml()
@@ -293,7 +301,7 @@ class DistributionPackageXml(object):
#
# 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)
@@ -310,7 +318,7 @@ class DistributionPackageXml(object):
# Check if any required item is missing in ModuleSurfaceArea
#
# @param Module: The ModuleSurfaceArea to be checked
-# @param XmlTreeLevel: The top level of Module
+# @param XmlTreeLevel: The top level of Module
#
def ValidateMS(Module, TopXmlTreeLevel):
ValidateMS1(Module, TopXmlTreeLevel)
@@ -322,7 +330,7 @@ def ValidateMS(Module, TopXmlTreeLevel):
# Check if any required item is missing in ModuleSurfaceArea
#
# @param Module: The ModuleSurfaceArea to be checked
-# @param XmlTreeLevel: The top level of Module
+# @param XmlTreeLevel: The top level of Module
#
def ValidateMS1(Module, TopXmlTreeLevel):
#
@@ -330,7 +338,7 @@ def ValidateMS1(Module, TopXmlTreeLevel):
#
XmlTreeLevel = TopXmlTreeLevel + ['Guids']
for Item in Module.GetGuidList():
- if Item == None:
+ if Item is None:
CheckDict = {'GuidCName':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -355,7 +363,7 @@ def ValidateMS1(Module, TopXmlTreeLevel):
#
XmlTreeLevel = TopXmlTreeLevel + ['Protocols']
for Item in Module.GetProtocolList():
- if Item == None:
+ if Item is None:
CheckDict = {'Protocol':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -370,7 +378,7 @@ def ValidateMS1(Module, TopXmlTreeLevel):
#
XmlTreeLevel = TopXmlTreeLevel + ['PPIs']
for Item in Module.GetPpiList():
- if Item == None:
+ if Item is None:
CheckDict = {'Ppi':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -385,7 +393,7 @@ def ValidateMS1(Module, TopXmlTreeLevel):
#
XmlTreeLevel = TopXmlTreeLevel + ['PcdCoded']
for Item in Module.GetPcdList():
- if Item == None:
+ if Item is None:
CheckDict = {'PcdEntry':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -402,15 +410,15 @@ def ValidateMS1(Module, TopXmlTreeLevel):
#
XmlTreeLevel = TopXmlTreeLevel + ['Externs']
for Item in Module.GetExternList():
- if Item == None:
+ if Item is None:
CheckDict = {'Extern':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
#
- # If SupArchList is used to identify different EntryPoint, UnloadImage, Constructor/Destructor elements and
+ # 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
+ # 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():
@@ -435,17 +443,17 @@ def ValidateMS1(Module, TopXmlTreeLevel):
XmlTreeLevel = TopXmlTreeLevel + ['MiscellaneousFiles']
for Item in Module.GetMiscFileList():
if not Item.GetFileList():
- CheckDict = {'Filename':'', }
+ CheckDict = {'Filename': '', }
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
for File in Item.GetFileList():
- CheckDict = {'Filename':File.GetURI(), }
+ 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
+# @param XmlTreeLevel: The top level of Module
#
def ValidateMS2(Module, TopXmlTreeLevel):
#
@@ -471,7 +479,7 @@ def ValidateMS2(Module, TopXmlTreeLevel):
Logger.Error("UPT", FORMAT_INVALID, ERR_FILE_NAME_INVALIDE % Module.GetModulePath())
#
- # Check ModuleProperties->BootMode
+ # Check ModuleProperties->BootMode
#
XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] + ['BootMode']
for Item in Module.GetBootModeList():
@@ -480,7 +488,7 @@ def ValidateMS2(Module, TopXmlTreeLevel):
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
#
- # Check ModuleProperties->Event
+ # Check ModuleProperties->Event
#
XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] + ['Event']
for Item in Module.GetEventList():
@@ -489,7 +497,7 @@ def ValidateMS2(Module, TopXmlTreeLevel):
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
#
- # Check ModuleProperties->Hob
+ # Check ModuleProperties->Hob
#
XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] + ['HOB']
for Item in Module.GetHobList():
@@ -498,8 +506,8 @@ def ValidateMS2(Module, TopXmlTreeLevel):
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
+ # 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":
@@ -522,7 +530,7 @@ def ValidateMS2(Module, TopXmlTreeLevel):
#
XmlTreeLevel = TopXmlTreeLevel + ['LibraryClassDefinitions']
for Item in Module.GetLibraryClassList():
- if Item == None:
+ if Item is None:
CheckDict = {'LibraryClass':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -535,7 +543,7 @@ def ValidateMS2(Module, TopXmlTreeLevel):
'Usage':Item.GetUsage()}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
#
- # If the LibraryClass:SupModList is not "UNDEFINED" the LIBRARY_CLASS entry must have the list
+ # If the LibraryClass:SupModList is not "UNDEFINED" the LIBRARY_CLASS entry must have the list
# appended using the format:
# LIBRARY_CLASS = ["|" ]
#
@@ -560,10 +568,10 @@ def ValidateMS2(Module, TopXmlTreeLevel):
#
- # 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 = |", 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
+ # 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 = |", 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:
@@ -577,10 +585,10 @@ def ValidateMS2(Module, TopXmlTreeLevel):
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
+ # 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 \
@@ -594,7 +602,7 @@ def ValidateMS2(Module, TopXmlTreeLevel):
#
XmlTreeLevel = TopXmlTreeLevel + ['SourceFiles']
for Item in Module.GetSourceFileList():
- if Item == None:
+ if Item is None:
CheckDict = {'Filename':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -608,18 +616,13 @@ def ValidateMS2(Module, TopXmlTreeLevel):
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
+# @param XmlTreeLevel: The top level of Module
#
def ValidateMS3(Module, TopXmlTreeLevel):
#
@@ -627,7 +630,7 @@ def ValidateMS3(Module, TopXmlTreeLevel):
#
XmlTreeLevel = TopXmlTreeLevel + ['PackageDependencies']
for Item in Module.GetPackageDependencyList():
- if Item == None:
+ if Item is None:
CheckDict = {'Package':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -640,7 +643,7 @@ def ValidateMS3(Module, TopXmlTreeLevel):
# Check BinaryFiles -> BinaryFile
#
for Item in Module.GetBinaryFileList():
- if Item == None:
+ if Item is None:
XmlTreeLevel = TopXmlTreeLevel + ['BinaryFiles']
CheckDict = {'BinaryFile':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -657,12 +660,12 @@ def ValidateMS3(Module, TopXmlTreeLevel):
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}
@@ -695,8 +698,7 @@ def ValidateMS3(Module, TopXmlTreeLevel):
for PcdExItem in AsBuilt.PcdExValueList:
CheckDict = {'TokenSpaceGuidValue':PcdExItem.TokenSpaceGuidValue,
'Token':PcdExItem.Token,
- 'DatumType':PcdExItem.DatumType,
- 'Value':PcdExItem.DefaultValue}
+ 'DatumType':PcdExItem.DatumType}
XmlTreeLevel = TopXmlTreeLevel + ['BinaryFiles', 'BinaryFile', 'AsBuilt', 'PcdExValue']
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
#
@@ -764,7 +766,7 @@ def ValidatePS1(Package):
#
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'ClonedFrom']
for Item in Package.GetClonedFromList():
- if Item == None:
+ if Item is None:
CheckDict = Sdict()
CheckDict['GUID'] = ''
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -779,7 +781,7 @@ def ValidatePS1(Package):
#
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'LibraryClassDeclarations']
for Item in Package.GetLibraryClassList():
- if Item == None:
+ if Item is None:
CheckDict = {'LibraryClass':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -794,7 +796,7 @@ def ValidatePS1(Package):
#
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'IndustryStandardIncludes']
for Item in Package.GetStandardIncludeFileList():
- if Item == None:
+ if Item is None:
CheckDict = {'IndustryStandardHeader':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -808,7 +810,7 @@ def ValidatePS1(Package):
#
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'PackageIncludes']
for Item in Package.GetPackageIncludeFileList():
- if Item == None:
+ if Item is None:
CheckDict = {'PackageHeader':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -834,7 +836,7 @@ def ValidatePS2(Package):
#
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'GuidDeclarations']
for Item in Package.GetGuidList():
- if Item == None:
+ if Item is None:
CheckDict = {'Entry':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -849,7 +851,7 @@ def ValidatePS2(Package):
#
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'ProtocolDeclarations']
for Item in Package.GetProtocolList():
- if Item == None:
+ if Item is None:
CheckDict = {'Entry':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -864,7 +866,7 @@ def ValidatePS2(Package):
#
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'PpiDeclarations']
for Item in Package.GetPpiList():
- if Item == None:
+ if Item is None:
CheckDict = {'Entry':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -879,7 +881,7 @@ def ValidatePS2(Package):
#
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'PcdDeclarations']
for Item in Package.GetPcdList():
- if Item == None:
+ if Item is None:
CheckDict = {'PcdEntry':''}
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
@@ -907,17 +909,17 @@ def ValidatePS2(Package):
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'MiscellaneousFiles']
for Item in Package.GetMiscFileList():
if not Item.GetFileList():
- CheckDict = {'Filename':'', }
+ CheckDict = {'Filename': '', }
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
for File in Item.GetFileList():
- CheckDict = {'Filename':File.GetURI(), }
+ CheckDict = {'Filename': File.GetURI(), }
IsRequiredItemListNull(CheckDict, XmlTreeLevel)
## ValidatePackageSurfaceArea
#
# Check if any required item is missing in PackageSurfaceArea
#
-# @param Package: The PackageSurfaceArea to be checked
+# @param Package: The PackageSurfaceArea to be checked
#
def ValidatePackageSurfaceArea(Package):
ValidatePS1(Package)