XmlParser.py revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
## @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
#
# 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
##
# DistributionPackageXml
#
class DistributionPackageXml(object):
## ValidateDistributionPackage
#
# Check if any required item is missing in DistributionPackage
#
XmlTreeLevel = ['DistributionPackage']
#
# Check DistributionPackage -> DistributionHeader
#
else:
#
# Check Each Package
#
#
# Check Each Module
#
#
# Check Each Tool
#
CheckDict = {'FileName':None, }
#
# Check Each Misc File
#
CheckDict = {'FileName':None, }
#
# Check Each Distribution Level User Extension
#
if Filename != None:
#
# Load to XML
#
#
# Parse Header information
#
#
# Parse each PackageSurfaceArea
#
Package.GetVersion(), \
Package.GetPackagePath())] = \
#
# Parse each ModuleSurfaceArea
#
#
# Parse Tools
#
#
# Parse MiscFiles
#
'MiscellaneousFiles')
#
# Parse UserExtensions
#
Tmp = UserExtensionsXml()
#
# Check Required Items for XML
#
pass
if DistP != None:
#
# Parse DistributionPackageHeader
#
['xmlns:xsi', 'http:/www.w3.org/2001/XMLSchema-instance'],
]
#
# Parse each PackageSurfaceArea
#
#
# Parse each ModuleSurfaceArea
#
#
# Parse Tools
#
if ToolNode is not None:
#
# Parse MiscFiles
#
'MiscellaneousFiles')
if MiscFileNode is not None:
#
# Remove empty element
#
#
# Remove empty help text element
#
#
# Remove SupArchList="COMMON" or "common"
#
XmlContent = \
XmlContent = \
#
# Remove <SupArchList> COMMON </SupArchList>
#
XmlContent = \
#
# Remove <SupArchList> common </SupArchList>
#
XmlContent = \
#
# Remove SupModList="COMMON" or "common"
#
XmlContent = \
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
#
## ValidateMS1
#
# Check if any required item is missing in ModuleSurfaceArea
#
# @param Module: The ModuleSurfaceArea to be checked
# @param XmlTreeLevel: The top level of Module
#
#
# Check Guids -> GuidCName
#
if Item == None:
if Item.GetVariableName():
if Result is None:
else:
#
# Check Protocols -> Protocol
#
if Item == None:
#
# Check PPIs -> Ppi
#
if Item == None:
#
# Check PcdCoded -> Entry
#
if Item == None:
#
# Check Externs -> Extern
#
if Item == None:
#
# 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.
#
#
# Check DistributionPackage -> ModuleSurfaceArea -> UserExtensions
#
#
# Check DistributionPackage -> PackageSurfaceArea -> MiscellaneousFiles -> Filename
#
if not Item.GetFileList():
## ValidateMS2
#
# Check if any required item is missing in ModuleSurfaceArea
#
# @param Module: The ModuleSurfaceArea to be checked
# @param XmlTreeLevel: The top level of Module
#
#
# Check Header
#
#
# Check ModuleProperties
#
#
# Check ModuleProperties->BootMode
#
#
# Check ModuleProperties->Event
#
#
# Check ModuleProperties->Hob
#
#
# 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.
#
DxeObj = DepexObject()
"gEfiMetronomeArchProtocolGuid AND \ngEfiMonotonicCounterArchProtocolGuid AND\n" + \
"gEfiRealTimeClockArchProtocolGuid AND \ngEfiResetArchProtocolGuid AND\n" + \
"gEfiRuntimeArchProtocolGuid AND \ngEfiSecurityArchProtocolGuid AND\n" + \
"gEfiTimerArchProtocolGuid AND \ngEfiVariableWriteArchProtocolGuid AND\n" + \
"gEfiVariableArchProtocolGuid AND \ngEfiWatchdogTimerArchProtocolGuid")
#
# Check LibraryClassDefinitions -> LibraryClass
#
if Item == None:
LibrarySupModList = []
#
# 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 not IsValidInfMoudleType(SupModule):
#
# 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:
#
# 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:
#
# Check SourceFiles
#
if Item == None:
ERR_XML_INVALID_BINARY_FILE_TYPE % ('DISPOSABLE'),
## ValidateMS3
#
# Check if any required item is missing in ModuleSurfaceArea
#
# @param Module: The ModuleSurfaceArea to be checked
# @param XmlTreeLevel: The top level of Module
#
#
# Check PackageDependencies -> Package
#
if Item == None:
#
# Check BinaryFiles -> BinaryFile
#
if Item == None:
if not Item.GetFileNameList():
#
# Check LibInstance
#
#
# Check PatchPcd
#
#
# Check PcdError
#
'PatchPcdValue', 'PcdError']
#
# Check PcdEx
#
#
# Check PcdError
#
'PcdExValue', 'PcdError']
#
# Check SmmDepex
#
#
# Check PeiDepex
#
#
# Check DxeDepex
#
#
# Check <UserExtensions>
#
## ValidatePS1
#
# ValidatePS1
#
def ValidatePS1(Package):
#
# Check DistributionPackage -> PackageSurfaceArea -> Header
#
#
# Check DistributionPackage -> PackageSurfaceArea -> ClonedFrom
#
if Item == None:
#
# Check DistributionPackage -> PackageSurfaceArea -> LibraryClassDeclarations -> LibraryClass
#
if Item == None:
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'LibraryClassDeclarations', 'LibraryClass']
#
# Check DistributionPackage -> PackageSurfaceArea -> IndustryStandardIncludes -> IndustryStandardHeader
#
if Item == None:
XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'IndustryStandardIncludes', 'IndustryStandardHeader']
#
# Check DistributionPackage -> PackageSurfaceArea -> PackageIncludes -> PackageHeader
#
if Item == None:
## ValidatePS2
#
# ValidatePS2
#
def ValidatePS2(Package):
#
# Check DistributionPackage -> PackageSurfaceArea -> Modules -> ModuleSurfaceArea
#
#
# Check DistributionPackage -> PackageSurfaceArea -> GuidDeclarations Entry
#
if Item == None:
#
# Check DistributionPackage -> PackageSurfaceArea -> ProtocolDeclarations -> Entry
#
if Item == None:
#
# Check DistributionPackage -> PackageSurfaceArea -> PpiDeclarations -> Entry
#
if Item == None:
#
# Check DistributionPackage -> PackageSurfaceArea -> PcdDeclarations -> Entry
#
if Item == None:
#
# Check DistributionPackage -> PackageSurfaceArea -> UserExtensions
#
#
# Check DistributionPackage -> PackageSurfaceArea -> MiscellaneousFiles -> Filename
#
if not Item.GetFileList():
## ValidatePackageSurfaceArea
#
# Check if any required item is missing in PackageSurfaceArea
#
# @param Package: The PackageSurfaceArea to be checked
#