diff options
author | vanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524> | 2012-05-24 03:03:13 +0000 |
---|---|---|
committer | vanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524> | 2012-05-24 03:03:13 +0000 |
commit | c9a368d1be7b24185a70840d6e908e30bd15bb2a (patch) | |
tree | c7645e3b4d85b49158ed25dad3f8ac8f635aa524 /BaseTools/Source/Python/UPT/Object/Parser | |
parent | 28ec9d2d445523c87b17858724aac4b537ac679e (diff) | |
download | edk2-c9a368d1be7b24185a70840d6e908e30bd15bb2a.tar.gz edk2-c9a368d1be7b24185a70840d6e908e30bd15bb2a.tar.bz2 edk2-c9a368d1be7b24185a70840d6e908e30bd15bb2a.zip |
Copy EDKII trunk BaseTools r13353 to UDK2010.SR1 Branch.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/branches/UDK2010.SR1@13355 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'BaseTools/Source/Python/UPT/Object/Parser')
18 files changed, 5480 insertions, 0 deletions
diff --git a/BaseTools/Source/Python/UPT/Object/Parser/DecObject.py b/BaseTools/Source/Python/UPT/Object/Parser/DecObject.py new file mode 100644 index 0000000000..6336a90fb9 --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/DecObject.py @@ -0,0 +1,611 @@ +## @file
+# This file is used to define class objects for DEC file. It will consumed by
+#DecParser
+#
+# 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.
+
+'''
+DecObject
+'''
+
+## Import modules
+#
+import os.path
+
+from Library.Misc import Sdict
+from Library.DataType import TAB_GUIDS
+from Library.DataType import TAB_PPIS
+from Library.DataType import TAB_PROTOCOLS
+from Library.DataType import TAB_DEC_DEFINES
+from Library.DataType import TAB_INCLUDES
+from Library.DataType import TAB_LIBRARY_CLASSES
+from Library.DataType import TAB_USER_EXTENSIONS
+from Library.DataType import TAB_PCDS
+from Library.DataType import TAB_ARCH_COMMON
+
+## _DecComments
+#
+# Base class for all data objects which have head and tail comments
+#
+class _DecComments:
+
+ ##constructor
+ #
+ def __init__(self):
+ self._HeadComment = []
+ self._TailComment = []
+
+ ## GetComments
+ #
+ def GetComments(self):
+ return self._HeadComment, self._TailComment
+
+ ## GetHeadComment
+ #
+ def GetHeadComment(self):
+ return self._HeadComment
+
+ ## SetHeadComment
+ #
+ # @param Comment: comment content
+ #
+ def SetHeadComment(self, Comment):
+ self._HeadComment = Comment
+
+ ## GetTailComment
+ #
+ def GetTailComment(self):
+ return self._TailComment
+
+ ## SetTailComment
+ #
+ # @param Comment: comment content
+ #
+ def SetTailComment(self, Comment):
+ self._TailComment = Comment
+
+## _DecBaseObject
+#
+# Base class that hold common info
+#
+class _DecBaseObject(_DecComments):
+ def __init__(self, PkgFullName):
+ _DecComments.__init__(self)
+ #
+ # Key is combined with (Arch, SectionType)
+ # Default is common
+ #
+ self.ValueDict = Sdict()
+ self._PkgFullName = PkgFullName
+ self._PackagePath, self._FileName = os.path.split(PkgFullName)
+ self._SecName = ''
+
+ ## GetSectionName
+ #
+ def GetSectionName(self):
+ return self._SecName
+
+ ## GetPackagePath
+ #
+ def GetPackagePath(self):
+ return self._PackagePath
+
+ ## GetPackageFile
+ #
+ def GetPackageFile(self):
+ return self._FileName
+
+ ## GetPackageFullName
+ #
+ def GetPackageFullName(self):
+ return self._PkgFullName
+
+ ## AddItem
+ # Add sub-item to current object, sub-class should override it if needed
+ #
+ # @param Item: Sub-item to be added
+ # @param Scope: A list store section name and arch info
+ #
+ def AddItem(self, Item, Scope):
+ if not Scope:
+ return
+ if not Item:
+ return
+ ArchModule = []
+ for Ele in Scope:
+ if Ele[1] in self.ValueDict:
+ self.ValueDict[Ele[1]].append(Item)
+ else:
+ self.ValueDict[Ele[1]] = [Item]
+ ArchModule.append(Ele[1])
+ Item.ArchAndModuleType = ArchModule
+
+ ## _GetItemByArch
+ # Helper class used by sub-class
+ # @param Arch: arch
+ #
+ def _GetItemByArch(self, Arch):
+ Arch = Arch.upper()
+ if Arch not in self.ValueDict:
+ return []
+ return self.ValueDict[Arch]
+
+ ## _GetAllItems
+ # Get all items, union all arches, items in returned list are unique
+ #
+ def _GetAllItems(self):
+ Retlst = []
+ for Arch in self.ValueDict:
+ for Item in self.ValueDict[Arch]:
+ if Item not in Retlst:
+ Retlst.append(Item)
+ return Retlst
+
+## _DecItemBaseObject
+#
+# Module type and arch the item belongs to
+#
+class _DecItemBaseObject(_DecComments):
+ def __init__(self):
+ _DecComments.__init__(self)
+ #
+ # Item's arch, if PCD, also include PCD type
+ #
+ self.ArchAndModuleType = []
+
+ ## GetArchList
+ #
+ def GetArchList(self):
+ ArchSet = set()
+ for Arch in self.ArchAndModuleType:
+ ArchSet.add(Arch)
+ return list(ArchSet)
+
+## DecDefineObject
+#
+# Class to hold define section infomation
+#
+class DecDefineObject(_DecBaseObject):
+ def __init__(self, PkgFullName):
+ _DecBaseObject.__init__(self, PkgFullName)
+ self._SecName = TAB_DEC_DEFINES.upper()
+ self._DecSpec = ''
+ self._PkgName = ''
+ self._PkgGuid = ''
+ self._PkgVersion = ''
+ self._PkgUniFile = ''
+
+ ## GetPackageSpecification
+ #
+ def GetPackageSpecification(self):
+ return self._DecSpec
+
+ def SetPackageSpecification(self, DecSpec):
+ self._DecSpec = DecSpec
+
+ ## GetPackageName
+ #
+ def GetPackageName(self):
+ return self._PkgName
+
+ def SetPackageName(self, PkgName):
+ self._PkgName = PkgName
+
+ ## GetPackageGuid
+ #
+ def GetPackageGuid(self):
+ return self._PkgGuid
+
+ def SetPackageGuid(self, PkgGuid):
+ self._PkgGuid = PkgGuid
+
+ ## GetPackageVersion
+ #
+ def GetPackageVersion(self):
+ return self._PkgVersion
+
+ def SetPackageVersion(self, PkgVersion):
+ self._PkgVersion = PkgVersion
+
+ ## GetPackageUniFile
+ #
+ def GetPackageUniFile(self):
+ return self._PkgUniFile
+
+ def SetPackageUniFile(self, PkgUniFile):
+ self._PkgUniFile = PkgUniFile
+
+ ## GetDefines
+ #
+ def GetDefines(self):
+ return self._GetItemByArch(TAB_ARCH_COMMON)
+
+ ## GetAllDefines
+ #
+ def GetAllDefines(self):
+ return self._GetAllItems()
+
+## DecDefineItemObject
+#
+# Each item of define section
+#
+class DecDefineItemObject(_DecItemBaseObject):
+ def __init__(self):
+ _DecItemBaseObject.__init__(self)
+ self.Key = ''
+ self.Value = ''
+
+ ## __hash__
+ #
+ def __hash__(self):
+ return hash(self.Key + self.Value)
+
+ ## __eq__
+ #
+ def __eq__(self, Other):
+ return id(self) == id(Other)
+
+ ## __str__
+ #
+ def __str__(self):
+ return str(self.ArchAndModuleType) + '\n' + self.Key + \
+ ' = ' + self.Value
+
+## DecIncludeObject
+#
+# Class to hold include section info
+#
+class DecIncludeObject(_DecBaseObject):
+ def __init__(self, PkgFullName):
+ _DecBaseObject.__init__(self, PkgFullName)
+ self._SecName = TAB_INCLUDES.upper()
+
+ ## GetIncludes
+ #
+ def GetIncludes(self, Arch=TAB_ARCH_COMMON):
+ return self._GetItemByArch(Arch)
+
+ ## GetAllIncludes
+ #
+ def GetAllIncludes(self):
+ return self._GetAllItems()
+
+## DecIncludeItemObject
+#
+# Item of include section
+#
+class DecIncludeItemObject(_DecItemBaseObject):
+ def __init__(self, File, Root):
+ self.File = File
+ self.Root = Root
+ _DecItemBaseObject.__init__(self)
+
+ ## __hash__
+ #
+ def __hash__(self):
+ return hash(self.File)
+
+ ## __eq__
+ #
+ def __eq__(self, Other):
+ return id(self) == id(Other)
+
+ ## __str__
+ #
+ def __str__(self):
+ return self.File
+
+## DecLibraryclassObject
+#
+# Class to hold library class section info
+#
+class DecLibraryclassObject(_DecBaseObject):
+ def __init__(self, PkgFullName):
+ _DecBaseObject.__init__(self, PkgFullName)
+ self._PackagePath, self._FileName = os.path.split(PkgFullName)
+ self._SecName = TAB_LIBRARY_CLASSES.upper()
+
+ ## GetLibraryclasses
+ #
+ def GetLibraryclasses(self, Arch=TAB_ARCH_COMMON):
+ return self._GetItemByArch(Arch)
+
+ ## GetAllLibraryclasses
+ #
+ def GetAllLibraryclasses(self):
+ return self._GetAllItems()
+
+## DecLibraryclassItemObject
+# Item of library class section
+#
+class DecLibraryclassItemObject(_DecItemBaseObject):
+ def __init__(self, Libraryclass, File, Root):
+ _DecItemBaseObject.__init__(self)
+ self.File = File
+ self.Root = Root
+ self.Libraryclass = Libraryclass
+
+ ## __hash__
+ #
+ def __hash__(self):
+ return hash(self.Libraryclass + self.File)
+
+ ## __eq__
+ #
+ def __eq__(self, Other):
+ return id(self) == id(Other)
+
+ ## __str__
+ #
+ def __str__(self):
+ return self.Libraryclass + '|' + self.File
+
+## DecPcdObject
+# Class to hold PCD section
+#
+class DecPcdObject(_DecBaseObject):
+ def __init__(self, PkgFullName):
+ _DecBaseObject.__init__(self, PkgFullName)
+ self._SecName = TAB_PCDS.upper()
+
+ ## AddItem
+ #
+ # Diff from base class
+ #
+ # @param Item: Item
+ # @param Scope: Scope
+ #
+ def AddItem(self, Item, Scope):
+ if not Scope:
+ return
+ if not Item:
+ return
+ ArchModule = []
+ for Type, Arch in Scope:
+ if (Type, Arch) in self.ValueDict:
+ self.ValueDict[Type, Arch].append(Item)
+ else:
+ self.ValueDict[Type, Arch] = [Item]
+ ArchModule.append([Type, Arch])
+ Item.ArchAndModuleType = ArchModule
+
+ ## GetPcds
+ #
+ # @param PcdType: PcdType
+ # @param Arch: Arch
+ #
+ def GetPcds(self, PcdType, Arch=TAB_ARCH_COMMON):
+ PcdType = PcdType.upper()
+ Arch = Arch.upper()
+ if (PcdType, Arch) not in self.ValueDict:
+ return []
+ return self.ValueDict[PcdType, Arch]
+
+ ## GetPcdsByType
+ #
+ # @param PcdType: PcdType
+ #
+ def GetPcdsByType(self, PcdType):
+ PcdType = PcdType.upper()
+ Retlst = []
+ for TypeInDict, Arch in self.ValueDict:
+ if TypeInDict != PcdType:
+ continue
+ for Item in self.ValueDict[PcdType, Arch]:
+ if Item not in Retlst:
+ Retlst.append(Item)
+ return Retlst
+
+## DecPcdItemObject
+#
+# Item of PCD section
+#
+# @param _DecItemBaseObject: _DecItemBaseObject object
+#
+class DecPcdItemObject(_DecItemBaseObject):
+ def __init__(self, Guid, Name, Value, DatumType,
+ Token, MaxDatumSize=''):
+ _DecItemBaseObject.__init__(self)
+ self.TokenCName = Name
+ self.TokenSpaceGuidCName = Guid
+ self.DatumType = DatumType
+ self.DefaultValue = Value
+ self.TokenValue = Token
+ self.MaxDatumSize = MaxDatumSize
+
+ ## __hash__
+ #
+ def __hash__(self):
+ return hash(self.TokenSpaceGuidCName + self.TokenCName)
+
+ ## __eq__
+ #
+ def __eq__(self, Other):
+ return id(self) == id(Other)
+
+ ## GetArchListOfType
+ #
+ # @param PcdType: PcdType
+ #
+ def GetArchListOfType(self, PcdType):
+ ItemSet = set()
+ PcdType = PcdType.upper()
+ for Type, Arch in self.ArchAndModuleType:
+ if Type != PcdType:
+ continue
+ ItemSet.add(Arch)
+ return list(ItemSet)
+
+## DecGuidObjectBase
+#
+# Base class for PPI, Protocol, and GUID.
+# Hold same data but has different method for clarification in sub-class
+#
+# @param _DecBaseObject: Dec Base Object
+#
+class DecGuidObjectBase(_DecBaseObject):
+ def __init__(self, PkgFullName):
+ _DecBaseObject.__init__(self, PkgFullName)
+
+ ## GetGuidStyleItems
+ #
+ # @param Arch: Arch
+ #
+ def GetGuidStyleItems(self, Arch=TAB_ARCH_COMMON):
+ return self._GetItemByArch(Arch)
+
+ ## GetGuidStyleAllItems
+ #
+ def GetGuidStyleAllItems(self):
+ return self._GetAllItems()
+
+## DecGuidItemObject
+#
+# Item of GUID, PPI and Protocol section
+#
+# @param _DecItemBaseObject: Dec Item Base Object
+#
+class DecGuidItemObject(_DecItemBaseObject):
+ def __init__(self, CName, GuidCValue, GuidString):
+ _DecItemBaseObject.__init__(self)
+ self.GuidCName = CName
+ self.GuidCValue = GuidCValue
+ self.GuidString = GuidString
+
+ ## __hash__
+ #
+ def __hash__(self):
+ return hash(self.GuidCName)
+
+ ## __eq__
+ #
+ def __eq__(self, Other):
+ return id(self) == id(Other)
+
+ ## __str__
+ #
+ def __str__(self):
+ return self.GuidCName + ' = ' + self.GuidCValue
+
+## DecGuidObject
+#
+# Class for GUID section
+#
+# @param DecGuidObjectBase: Dec Guid Object Base
+#
+class DecGuidObject(DecGuidObjectBase):
+ def __init__(self, PkgFullName):
+ DecGuidObjectBase.__init__(self, PkgFullName)
+ self._SecName = TAB_GUIDS.upper()
+
+ ## GetGuids
+ #
+ # @param Arch: Arch
+ #
+ def GetGuids(self, Arch=TAB_ARCH_COMMON):
+ return self._GetItemByArch(Arch)
+
+ ## GetAllGuids
+ #
+ def GetAllGuids(self):
+ return self._GetAllItems()
+
+## DecPpiObject
+#
+# Class for PPI seciont
+#
+# @param DecGuidObjectBase: Dec Guid Object Base
+#
+class DecPpiObject(DecGuidObjectBase):
+ def __init__(self, PkgFullName):
+ DecGuidObjectBase.__init__(self, PkgFullName)
+ self._SecName = TAB_PPIS.upper()
+
+ ## GetPpis
+ #
+ # @param Arch: Arch
+ #
+ def GetPpis(self, Arch=TAB_ARCH_COMMON):
+ return self._GetItemByArch(Arch)
+
+ ## GetAllPpis
+ #
+ def GetAllPpis(self):
+ return self._GetAllItems()
+
+## DecProtocolObject
+#
+# Class for protocol section
+#
+# @param DecGuidObjectBase: Dec Guid Object Base
+#
+class DecProtocolObject(DecGuidObjectBase):
+ def __init__(self, PkgFullName):
+ DecGuidObjectBase.__init__(self, PkgFullName)
+ self._SecName = TAB_PROTOCOLS.upper()
+
+ ## GetProtocols
+ #
+ # @param Arch: Arch
+ #
+ def GetProtocols(self, Arch=TAB_ARCH_COMMON):
+ return self._GetItemByArch(Arch)
+
+ ## GetAllProtocols
+ #
+ def GetAllProtocols(self):
+ return self._GetAllItems()
+
+## DecUserExtensionObject
+#
+# Class for user extension section
+#
+# @param _DecBaseObject: Dec Guid Object Base
+#
+class DecUserExtensionObject(_DecBaseObject):
+ def __init__(self, PkgFullName):
+ _DecBaseObject.__init__(self, PkgFullName)
+ self._SecName = TAB_USER_EXTENSIONS.upper()
+ self.ItemList = []
+
+ ## GetProtocols
+ #
+ # @param Item: Item
+ # @param Scope: Scope
+ #
+ def AddItem(self, Item, Scope):
+ if not Scope:
+ pass
+ if not Item:
+ return
+ self.ItemList.append(Item)
+
+ ## GetAllUserExtensions
+ #
+ def GetAllUserExtensions(self):
+ return self.ItemList
+
+
+## DecUserExtensionItemObject
+# Item for user extension section
+#
+# @param _DecItemBaseObject: Dec Item Base Object
+#
+class DecUserExtensionItemObject(_DecItemBaseObject):
+ def __init__(self):
+ _DecItemBaseObject.__init__(self)
+ self.UserString = ''
+ self.UserId = ''
+ self.IdString = ''
+
+
+
+
diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfBinaryObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfBinaryObject.py new file mode 100644 index 0000000000..3685fedd5c --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfBinaryObject.py @@ -0,0 +1,621 @@ +## @file
+# This file is used to define class objects of INF file [Binaries] section.
+# It will consumed by InfParser.
+#
+# 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.
+
+'''
+InfBinaryObject
+'''
+
+import os
+
+from copy import deepcopy
+from Library import DataType as DT
+from Library import GlobalData
+import Logger.Log as Logger
+from Logger import ToolError
+from Logger import StringTable as ST
+from Library.Misc import Sdict
+
+from Object.Parser.InfCommonObject import InfSectionCommonDef
+from Object.Parser.InfCommonObject import CurrentLine
+from Library.Misc import ConvPathFromAbsToRel
+from Library.ExpressionValidate import IsValidFeatureFlagExp
+from Library.Misc import ValidFile
+from Library.ParserValidate import IsValidPath
+
+
+class InfBianryItem():
+ def __init__(self):
+ self.FileName = ''
+ self.Target = ''
+ self.FeatureFlagExp = ''
+ self.HelpString = ''
+ self.Type = ''
+ self.SupArchList = []
+
+ def SetFileName(self, FileName):
+ self.FileName = FileName
+ def GetFileName(self):
+ return self.FileName
+
+ def SetTarget(self, Target):
+ self.Target = Target
+ def GetTarget(self):
+ return self.Target
+
+ def SetFeatureFlagExp(self, FeatureFlagExp):
+ self.FeatureFlagExp = FeatureFlagExp
+ def GetFeatureFlagExp(self):
+ return self.FeatureFlagExp
+
+ def SetHelpString(self, HelpString):
+ self.HelpString = HelpString
+ def GetHelpString(self):
+ return self.HelpString
+
+ def SetType(self, Type):
+ self.Type = Type
+ def GetType(self):
+ return self.Type
+ def SetSupArchList(self, SupArchList):
+ self.SupArchList = SupArchList
+ def GetSupArchList(self):
+ return self.SupArchList
+
+class InfBianryVerItem(InfBianryItem, CurrentLine):
+ def __init__(self):
+ InfBianryItem.__init__(self)
+ CurrentLine.__init__(self)
+ self.VerTypeName = ''
+
+ def SetVerTypeName(self, VerTypeName):
+ self.VerTypeName = VerTypeName
+ def GetVerTypeName(self):
+ return self.VerTypeName
+
+class InfBianryUiItem(InfBianryItem, CurrentLine):
+ def __init__(self):
+ InfBianryItem.__init__(self)
+ CurrentLine.__init__(self)
+ self.UiTypeName = ''
+
+ def SetUiTypeName(self, UiTypeName):
+ self.UiTypeName = UiTypeName
+ def GetVerTypeName(self):
+ return self.UiTypeName
+
+class InfBianryCommonItem(InfBianryItem, CurrentLine):
+ def __init__(self):
+ self.CommonType = ''
+ self.TagName = ''
+ self.Family = ''
+ InfBianryItem.__init__(self)
+ CurrentLine.__init__(self)
+
+ def SetCommonType(self, CommonType):
+ self.CommonType = CommonType
+ def GetCommonType(self):
+ return self.CommonType
+
+ def SetTagName(self, TagName):
+ self.TagName = TagName
+ def GetTagName(self):
+ return self.TagName
+
+ def SetFamily(self, Family):
+ self.Family = Family
+ def GetFamily(self):
+ return self.Family
+
+##
+#
+#
+#
+class InfBinariesObject(InfSectionCommonDef):
+ def __init__(self):
+ self.Binaries = Sdict()
+ #
+ # Macro defined in this section should be only used in this section.
+ #
+ self.Macros = {}
+ InfSectionCommonDef.__init__(self)
+
+ ## CheckVer
+ #
+ #
+ def CheckVer(self, Ver, __SupArchList):
+ #
+ # Check Ver
+ #
+ for VerItem in Ver:
+ IsValidFileFlag = False
+ VerContent = VerItem[0]
+ VerComment = VerItem[1]
+ VerCurrentLine = VerItem[2]
+ GlobalData.gINF_CURRENT_LINE = VerCurrentLine
+ InfBianryVerItemObj = None
+ #
+ # Should not less than 2 elements
+ #
+ if len(VerContent) < 2:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID % (VerContent[0]),
+ File=VerCurrentLine.GetFileName(),
+ Line=VerCurrentLine.GetLineNo(),
+ ExtraData=VerCurrentLine.GetLineString())
+ return False
+ if len(VerContent) > 4:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX % (VerContent[0], 4),
+ File=VerCurrentLine.GetFileName(),
+ Line=VerCurrentLine.GetLineNo(),
+ ExtraData=VerCurrentLine.GetLineString())
+ return False
+ if len(VerContent) >= 2:
+ #
+ # Create a Ver Object.
+ #
+ InfBianryVerItemObj = InfBianryVerItem()
+
+ if VerContent[0] != DT.BINARY_FILE_TYPE_VER:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_BINARY_VER_TYPE % DT.BINARY_FILE_TYPE_VER,
+ File=VerCurrentLine.GetFileName(),
+ Line=VerCurrentLine.GetLineNo(),
+ ExtraData=VerCurrentLine.GetLineString())
+
+ InfBianryVerItemObj.SetVerTypeName(VerContent[0])
+ InfBianryVerItemObj.SetType(VerContent[0])
+ #
+ # Verify File exist or not
+ #
+ FullFileName = os.path.normpath(os.path.realpath(os.path.join(GlobalData.gINF_MODULE_DIR,
+ VerContent[1])))
+ if not (ValidFile(FullFileName) or ValidFile(VerContent[1])):
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST % (VerContent[1]),
+ File=VerCurrentLine.GetFileName(),
+ Line=VerCurrentLine.GetLineNo(),
+ ExtraData=VerCurrentLine.GetLineString())
+ #
+ # Validate file exist/format.
+ #
+ if IsValidPath(VerContent[1], GlobalData.gINF_MODULE_DIR):
+ IsValidFileFlag = True
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID % (VerContent[1]),
+ File=VerCurrentLine.GetFileName(),
+ Line=VerCurrentLine.GetLineNo(),
+ ExtraData=VerCurrentLine.GetLineString())
+ return False
+ if IsValidFileFlag:
+ VerContent[0] = ConvPathFromAbsToRel(VerContent[0],
+ GlobalData.gINF_MODULE_DIR)
+ InfBianryVerItemObj.SetFileName(VerContent[1])
+ if len(VerContent) >= 3:
+ #
+ # Add Target information
+ #
+ InfBianryVerItemObj.SetTarget(VerContent[2])
+ if len(VerContent) == 4:
+ if VerContent[3].strip() == '':
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
+ File=VerCurrentLine.GetFileName(),
+ Line=VerCurrentLine.GetLineNo(),
+ ExtraData=VerCurrentLine.GetLineString())
+ #
+ # Validate Feature Flag Express
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(VerContent[3].\
+ strip())
+ if not FeatureFlagRtv[0]:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]),
+ File=VerCurrentLine.GetFileName(),
+ Line=VerCurrentLine.GetLineNo(),
+ ExtraData=VerCurrentLine.GetLineString())
+ InfBianryVerItemObj.SetFeatureFlagExp(VerContent[3])
+
+ InfBianryVerItemObj.SetSupArchList(__SupArchList)
+
+ #
+ # Determine binary file name duplicate. Follow below rule:
+ #
+ # A binary filename must not be duplicated within
+ # a [Binaries] section. A binary filename may appear in
+ # multiple architectural [Binaries] sections. A binary
+ # filename listed in an architectural [Binaries] section
+ # must not be listed in the common architectural
+ # [Binaries] section.
+ #
+ # NOTE: This check will not report error now.
+ #
+ for Item in self.Binaries:
+ if Item.GetFileName() == InfBianryVerItemObj.GetFileName():
+ ItemSupArchList = Item.GetSupArchList()
+ for ItemArch in ItemSupArchList:
+ for VerItemObjArch in __SupArchList:
+ if ItemArch == VerItemObjArch:
+ #
+ # ST.ERR_INF_PARSER_ITEM_DUPLICATE
+ #
+ pass
+ if ItemArch.upper() == 'COMMON' or VerItemObjArch.upper() == 'COMMON':
+ #
+ # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
+ #
+ pass
+
+ if InfBianryVerItemObj != None:
+ if self.Binaries.has_key((InfBianryVerItemObj)):
+ BinariesList = self.Binaries[InfBianryVerItemObj]
+ BinariesList.append((InfBianryVerItemObj, VerComment))
+ self.Binaries[InfBianryVerItemObj] = BinariesList
+ else:
+ BinariesList = []
+ BinariesList.append((InfBianryVerItemObj, VerComment))
+ self.Binaries[InfBianryVerItemObj] = BinariesList
+
+ ## ParseCommonBinary
+ #
+ # ParseCommonBinary
+ #
+ def ParseCommonBinary(self, CommonBinary, __SupArchList):
+ #
+ # Check common binary definitions
+ # Type | FileName | Target | Family | TagName | FeatureFlagExp
+ #
+ for Item in CommonBinary:
+ IsValidFileFlag = False
+ ItemContent = Item[0]
+ ItemComment = Item[1]
+ CurrentLineOfItem = Item[2]
+ GlobalData.gINF_CURRENT_LINE = CurrentLineOfItem
+ InfBianryCommonItemObj = None
+ if len(ItemContent) < 2:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID % (ItemContent[0]),
+ File=CurrentLineOfItem.GetFileName(),
+ Line=CurrentLineOfItem.GetLineNo(),
+ ExtraData=CurrentLineOfItem.GetLineString())
+ return False
+ if len(ItemContent) > 6:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX % (ItemContent[0], 6),
+ File=CurrentLineOfItem.GetFileName(),
+ Line=CurrentLineOfItem.GetLineNo(),
+ ExtraData=CurrentLineOfItem.GetLineString())
+ return False
+ if len(ItemContent) >= 2:
+ #
+ # Create a Common Object.
+ #
+ InfBianryCommonItemObj = InfBianryCommonItem()
+ #
+ # Convert Binary type.
+ #
+ BinaryFileType = ItemContent[0].strip()
+ if BinaryFileType == 'RAW' or BinaryFileType == 'ACPI' or BinaryFileType == 'ASL':
+ BinaryFileType = 'BIN'
+
+ if BinaryFileType not in DT.BINARY_FILE_TYPE_LIST:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_BINARY_ITEM_INVALID_FILETYPE % \
+ (DT.BINARY_FILE_TYPE_LIST.__str__()),
+ File=CurrentLineOfItem.GetFileName(),
+ Line=CurrentLineOfItem.GetLineNo(),
+ ExtraData=CurrentLineOfItem.GetLineString())
+
+ if BinaryFileType == 'SUBTYPE_GUID':
+ BinaryFileType = 'FREEFORM'
+
+ if BinaryFileType == 'LIB' or BinaryFileType == 'UEFI_APP':
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_BINARY_ITEM_INVALID_FILETYPE % \
+ (DT.BINARY_FILE_TYPE_LIST.__str__()),
+ File=CurrentLineOfItem.GetFileName(),
+ Line=CurrentLineOfItem.GetLineNo(),
+ ExtraData=CurrentLineOfItem.GetLineString())
+
+ InfBianryCommonItemObj.SetType(BinaryFileType)
+ InfBianryCommonItemObj.SetCommonType(ItemContent[0])
+ #
+ # Verify File exist or not
+ #
+ FullFileName = os.path.normpath(os.path.realpath(os.path.join(GlobalData.gINF_MODULE_DIR,
+ ItemContent[1])))
+ if not (ValidFile(FullFileName) or ValidFile(ItemContent[1])):
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST % (ItemContent[1]),
+ File=CurrentLineOfItem.GetFileName(),
+ Line=CurrentLineOfItem.GetLineNo(),
+ ExtraData=CurrentLineOfItem.GetLineString())
+ #
+ # Validate file exist/format.
+ #
+ if IsValidPath(ItemContent[1], GlobalData.gINF_MODULE_DIR):
+ IsValidFileFlag = True
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID % (ItemContent[1]),
+ File=CurrentLineOfItem.GetFileName(),
+ Line=CurrentLineOfItem.GetLineNo(),
+ ExtraData=CurrentLineOfItem.GetLineString())
+ return False
+ if IsValidFileFlag:
+ ItemContent[0] = ConvPathFromAbsToRel(ItemContent[0], GlobalData.gINF_MODULE_DIR)
+ InfBianryCommonItemObj.SetFileName(ItemContent[1])
+ if len(ItemContent) >= 3:
+ #
+ # Add Target information
+ #
+ InfBianryCommonItemObj.SetTarget(ItemContent[2])
+ if len(ItemContent) >= 4:
+ #
+ # Add Family information
+ #
+ InfBianryCommonItemObj.SetFamily(ItemContent[3])
+ if len(ItemContent) >= 5:
+ #
+ # TagName entries are build system specific. If there
+ # is content in the entry, the tool must exit
+ # gracefully with an error message that indicates build
+ # system specific content cannot be distributed using
+ # the UDP
+ #
+ if ItemContent[4].strip() != '':
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED % (ItemContent[4]),
+ File=CurrentLineOfItem.GetFileName(),
+ Line=CurrentLineOfItem.GetLineNo(),
+ ExtraData=CurrentLineOfItem.GetLineString())
+ if len(ItemContent) == 6:
+ #
+ # Add FeatureFlagExp
+ #
+ if ItemContent[5].strip() == '':
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
+ File=CurrentLineOfItem.GetFileName(),
+ Line=CurrentLineOfItem.GetLineNo(),
+ ExtraData=CurrentLineOfItem.GetLineString())
+ #
+ # Validate Feature Flag Express
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(ItemContent[5].strip())
+ if not FeatureFlagRtv[0]:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]),
+ File=CurrentLineOfItem.GetFileName(),
+ Line=CurrentLineOfItem.GetLineNo(),
+ ExtraData=CurrentLineOfItem.GetLineString())
+ InfBianryCommonItemObj.SetFeatureFlagExp(ItemContent[5])
+
+ InfBianryCommonItemObj.SetSupArchList(__SupArchList)
+
+ #
+ # Determine binary file name duplicate. Follow below rule:
+ #
+ # A binary filename must not be duplicated within
+ # a [Binaries] section. A binary filename may appear in
+ # multiple architectural [Binaries] sections. A binary
+ # filename listed in an architectural [Binaries] section
+ # must not be listed in the common architectural
+ # [Binaries] section.
+ #
+ # NOTE: This check will not report error now.
+ #
+# for Item in self.Binaries:
+# if Item.GetFileName() == InfBianryCommonItemObj.GetFileName():
+# ItemSupArchList = Item.GetSupArchList()
+# for ItemArch in ItemSupArchList:
+# for ComItemObjArch in __SupArchList:
+# if ItemArch == ComItemObjArch:
+# #
+# # ST.ERR_INF_PARSER_ITEM_DUPLICATE
+# #
+# pass
+#
+# if ItemArch.upper() == 'COMMON' or ComItemObjArch.upper() == 'COMMON':
+# #
+# # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
+# #
+# pass
+
+ if InfBianryCommonItemObj != None:
+ if self.Binaries.has_key((InfBianryCommonItemObj)):
+ BinariesList = self.Binaries[InfBianryCommonItemObj]
+ BinariesList.append((InfBianryCommonItemObj, ItemComment))
+ self.Binaries[InfBianryCommonItemObj] = BinariesList
+ else:
+ BinariesList = []
+ BinariesList.append((InfBianryCommonItemObj, ItemComment))
+ self.Binaries[InfBianryCommonItemObj] = BinariesList
+
+ def SetBinary(self, UiInf=None, Ver=None, CommonBinary=None, ArchList=None):
+
+ __SupArchList = []
+ for ArchItem in ArchList:
+ #
+ # Validate Arch
+ #
+ if (ArchItem == '' or ArchItem == None):
+ ArchItem = 'COMMON'
+ __SupArchList.append(ArchItem)
+
+ if UiInf != None:
+ if len(UiInf) > 0:
+ #
+ # Check UI
+ #
+ for UiItem in UiInf:
+ IsValidFileFlag = False
+ InfBianryUiItemObj = None
+ UiContent = UiItem[0]
+ UiComment = UiItem[1]
+ UiCurrentLine = UiItem[2]
+ GlobalData.gINF_CURRENT_LINE = deepcopy(UiItem[2])
+ #
+ # Should not less than 2 elements
+ #
+ if len(UiContent) < 2:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID % (UiContent[0]),
+ File=UiCurrentLine.GetFileName(),
+ Line=UiCurrentLine.GetLineNo(),
+ ExtraData=UiCurrentLine.GetLineString())
+ return False
+
+ if len(UiContent) > 4:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX % (UiContent[0], 4),
+ File=UiCurrentLine.GetFileName(),
+ Line=UiCurrentLine.GetLineNo(),
+ ExtraData=UiCurrentLine.GetLineString())
+ return False
+ if len(UiContent) >= 2:
+ #
+ # Create an Ui Object.
+ #
+ InfBianryUiItemObj = InfBianryUiItem()
+ if UiContent[0] != 'UI':
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_BINARY_VER_TYPE % ('UI'),
+ File=UiCurrentLine.GetFileName(),
+ Line=UiCurrentLine.GetLineNo(),
+ ExtraData=UiCurrentLine.GetLineString())
+ InfBianryUiItemObj.SetUiTypeName(UiContent[0])
+ InfBianryUiItemObj.SetType(UiContent[0])
+ #
+ # Verify File exist or not
+ #
+ FullFileName = os.path.normpath(os.path.realpath(os.path.join(GlobalData.gINF_MODULE_DIR,
+ UiContent[1])))
+ if not (ValidFile(FullFileName) or ValidFile(UiContent[1])):
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST % (UiContent[1]),
+ File=UiCurrentLine.GetFileName(),
+ Line=UiCurrentLine.GetLineNo(),
+ ExtraData=UiCurrentLine.GetLineString())
+ #
+ # Validate file exist/format.
+ #
+ if IsValidPath(UiContent[1], GlobalData.gINF_MODULE_DIR):
+ IsValidFileFlag = True
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID % (UiContent[1]),
+ File=UiCurrentLine.GetFileName(),
+ Line=UiCurrentLine.GetLineNo(),
+ ExtraData=UiCurrentLine.GetLineString())
+ return False
+ if IsValidFileFlag:
+ UiContent[0] = ConvPathFromAbsToRel(UiContent[0], GlobalData.gINF_MODULE_DIR)
+ InfBianryUiItemObj.SetFileName(UiContent[1])
+ if len(UiContent) >= 3:
+ #
+ # Add Target information
+ #
+ InfBianryUiItemObj.SetTarget(UiContent[2])
+ if len(UiContent) == 4:
+ if UiContent[3].strip() == '':
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
+ File=UiCurrentLine.GetFileName(),
+ Line=UiCurrentLine.GetLineNo(),
+ ExtraData=UiCurrentLine.GetLineString())
+ #
+ # Validate Feature Flag Express
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(UiContent[3].strip())
+ if not FeatureFlagRtv[0]:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]),
+ File=UiCurrentLine.GetFileName(),
+ Line=UiCurrentLine.GetLineNo(),
+ ExtraData=UiCurrentLine.GetLineString())
+ InfBianryUiItemObj.SetFeatureFlagExp(UiContent[3])
+
+ InfBianryUiItemObj.SetSupArchList(__SupArchList)
+
+ #
+ # Determine binary file name duplicate. Follow below rule:
+ #
+ # A binary filename must not be duplicated within
+ # a [Binaries] section. A binary filename may appear in
+ # multiple architectural [Binaries] sections. A binary
+ # filename listed in an architectural [Binaries] section
+ # must not be listed in the common architectural
+ # [Binaries] section.
+ #
+ # NOTE: This check will not report error now.
+ #
+# for Item in self.Binaries:
+# if Item.GetFileName() == InfBianryUiItemObj.GetFileName():
+# ItemSupArchList = Item.GetSupArchList()
+# for ItemArch in ItemSupArchList:
+# for UiItemObjArch in __SupArchList:
+# if ItemArch == UiItemObjArch:
+# #
+# # ST.ERR_INF_PARSER_ITEM_DUPLICATE
+# #
+# pass
+# if ItemArch.upper() == 'COMMON' or UiItemObjArch.upper() == 'COMMON':
+# #
+# # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
+# #
+# pass
+
+ if InfBianryUiItemObj != None:
+ if self.Binaries.has_key((InfBianryUiItemObj)):
+ BinariesList = self.Binaries[InfBianryUiItemObj]
+ BinariesList.append((InfBianryUiItemObj, UiComment))
+ self.Binaries[InfBianryUiItemObj] = BinariesList
+ else:
+ BinariesList = []
+ BinariesList.append((InfBianryUiItemObj, UiComment))
+ self.Binaries[InfBianryUiItemObj] = BinariesList
+ if Ver != None and len(Ver) > 0:
+ self.CheckVer(Ver, __SupArchList)
+ if CommonBinary and len(CommonBinary) > 0:
+ self.ParseCommonBinary(CommonBinary, __SupArchList)
+
+ return True
+
+ def GetBinary(self):
+ return self.Binaries
diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfBuildOptionObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfBuildOptionObject.py new file mode 100644 index 0000000000..5549525a6c --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfBuildOptionObject.py @@ -0,0 +1,93 @@ +## @file
+# This file is used to define class objects of INF file [BuildOptions] section.
+# It will consumed by InfParser.
+#
+# 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.
+
+'''
+InfBuildOptionObject
+'''
+
+from Library import GlobalData
+
+from Object.Parser.InfCommonObject import InfSectionCommonDef
+
+class InfBuildOptionItem():
+ def __init__(self):
+ self.Content = ''
+ self.SupArchList = []
+ self.AsBuildList = []
+
+ def SetContent(self, Content):
+ self.Content = Content
+ def GetContent(self):
+ return self.Content
+
+ def SetSupArchList(self, SupArchList):
+ self.SupArchList = SupArchList
+ def GetSupArchList(self):
+ return self.SupArchList
+
+ #
+ # AsBuild Information
+ #
+ def SetAsBuildList(self, AsBuildList):
+ self.AsBuildList = AsBuildList
+ def GetAsBuildList(self):
+ return self.AsBuildList
+
+
+## INF BuildOption section
+# Macro define is not permitted for this section.
+#
+#
+class InfBuildOptionsObject(InfSectionCommonDef):
+ def __init__(self):
+ self.BuildOptions = []
+ InfSectionCommonDef.__init__(self)
+ ## SetBuildOptions function
+ #
+ # For BuildOptionName, need to validate it's format
+ # For BuildOptionValue, just ignore it.
+ #
+ # @param Arch Indicated which arch of build options belong to.
+ # @param BuildOptCont A list contain BuildOption related information.
+ # The element in the list contain 3 members.
+ # BuildOptionName, BuildOptionValue and IsReplace
+ # flag.
+ #
+ # @return True Build options set/validate successfully
+ # @return False Build options set/validate failed
+ #
+ def SetBuildOptions(self, BuildOptCont, ArchList = None, SectionContent = ''):
+
+ if not GlobalData.gIS_BINARY_INF:
+
+ if SectionContent.strip() != '':
+ InfBuildOptionItemObj = InfBuildOptionItem()
+ InfBuildOptionItemObj.SetContent(SectionContent)
+ InfBuildOptionItemObj.SetSupArchList(ArchList)
+
+ self.BuildOptions.append(InfBuildOptionItemObj)
+ else:
+ #
+ # For AsBuild INF file
+ #
+ if len(BuildOptCont) >= 1:
+ InfBuildOptionItemObj = InfBuildOptionItem()
+ InfBuildOptionItemObj.SetAsBuildList(BuildOptCont)
+ self.BuildOptions.append(InfBuildOptionItemObj)
+
+
+ return True
+
+ def GetBuildOptions(self):
+ return self.BuildOptions
\ No newline at end of file diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfCommonObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfCommonObject.py new file mode 100644 index 0000000000..217b0941da --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfCommonObject.py @@ -0,0 +1,162 @@ +## @file
+# This file is used to define common class objects for INF file.
+# It will consumed by InfParser
+#
+# 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.
+
+'''
+InfCommonObject
+'''
+
+## InfLineCommentObject
+#
+# Comment Object for any line in the INF file
+#
+# #
+# # HeaderComment
+# #
+# Line # TailComment
+#
+class InfLineCommentObject():
+ def __init__(self):
+ self.HeaderComments = ''
+ self.TailComments = ''
+
+ def SetHeaderComments(self, HeaderComments):
+ self.HeaderComments = HeaderComments
+
+ def GetHeaderComments(self):
+ return self.HeaderComments
+
+ def SetTailComments(self, TailComments):
+ self.TailComments = TailComments
+
+ def GetTailComments(self):
+ return self.TailComments
+
+## CurrentLine
+#
+class CurrentLine():
+ def __init__(self):
+ self.LineNo = ''
+ self.LineString = ''
+ self.FileName = ''
+
+ ## SetLineNo
+ #
+ # @param LineNo: LineNo
+ #
+ def SetLineNo(self, LineNo):
+ self.LineNo = LineNo
+
+ ## GetLineNo
+ #
+ def GetLineNo(self):
+ return self.LineNo
+
+ ## SetLineString
+ #
+ # @param LineString: Line String content
+ #
+ def SetLineString(self, LineString):
+ self.LineString = LineString
+
+ ## GetLineString
+ #
+ def GetLineString(self):
+ return self.LineString
+
+ ## SetFileName
+ #
+ # @param FileName: File Name
+ #
+ def SetFileName(self, FileName):
+ self.FileName = FileName
+
+ ## GetFileName
+ #
+ def GetFileName(self):
+ return self.FileName
+
+##
+# Inf Section common data
+#
+class InfSectionCommonDef():
+ def __init__(self):
+ #
+ # #
+ # # HeaderComments at here
+ # #
+ # [xxSection] TailComments at here
+ # data
+ #
+ self.HeaderComments = ''
+ self.TailComments = ''
+ #
+ # The support arch list of this section
+ #
+ self.SupArchList = []
+
+ #
+ # Store all section content
+ # Key is supported Arch
+ #
+ self.AllContent = {}
+
+ ## SetHeaderComments
+ #
+ # @param HeaderComments: HeaderComments
+ #
+ def SetHeaderComments(self, HeaderComments):
+ self.HeaderComments = HeaderComments
+
+ ## GetHeaderComments
+ #
+ def GetHeaderComments(self):
+ return self.HeaderComments
+
+ ## SetTailComments
+ #
+ # @param TailComments: TailComments
+ #
+ def SetTailComments(self, TailComments):
+ self.TailComments = TailComments
+
+ ## GetTailComments
+ #
+ def GetTailComments(self):
+ return self.TailComments
+
+ ## SetSupArchList
+ #
+ # @param Arch: Arch
+ #
+ def SetSupArchList(self, Arch):
+ if Arch not in self.SupArchList:
+ self.SupArchList.append(Arch)
+
+ ## GetSupArchList
+ #
+ def GetSupArchList(self):
+ return self.SupArchList
+
+ ## SetAllContent
+ #
+ # @param ArchList: ArchList
+ # @param Content: Content
+ #
+ def SetAllContent(self, Content):
+ self.AllContent = Content
+
+ ## GetAllContent
+ #
+ def GetAllContent(self):
+ return self.AllContent
diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfDefineCommonObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfDefineCommonObject.py new file mode 100644 index 0000000000..d565e65a65 --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfDefineCommonObject.py @@ -0,0 +1,89 @@ +## @file
+# This file is used to define common class objects of [Defines] section for INF file.
+# It will consumed by InfParser
+#
+# 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.
+
+'''
+InfDefineCommonObject
+'''
+
+from Object.Parser.InfCommonObject import InfLineCommentObject
+
+## InfDefineImageExeParamItem
+#
+class InfDefineImageExeParamItem():
+ def __init__(self):
+ self.CName = ''
+ self.FeatureFlagExp = ''
+ self.Comments = InfLineCommentObject()
+
+ def SetCName(self, CName):
+ self.CName = CName
+ def GetCName(self):
+ return self.CName
+ def SetFeatureFlagExp(self, FeatureFlagExp):
+ self.FeatureFlagExp = FeatureFlagExp
+ def GetFeatureFlagExp(self):
+ return self.FeatureFlagExp
+
+## InfDefineEntryPointItem
+#
+class InfDefineEntryPointItem(InfDefineImageExeParamItem):
+ def __init__(self):
+ InfDefineImageExeParamItem.__init__(self)
+
+## InfDefineUnloadImageItem
+#
+class InfDefineUnloadImageItem(InfDefineImageExeParamItem):
+ def __init__(self):
+ InfDefineImageExeParamItem.__init__(self)
+
+## InfDefineConstructorItem
+#
+class InfDefineConstructorItem(InfDefineImageExeParamItem):
+ def __init__(self):
+ InfDefineImageExeParamItem.__init__(self)
+ self.SupModList = []
+
+ def SetSupModList(self, SupModList):
+ self.SupModList = SupModList
+ def GetSupModList(self):
+ return self.SupModList
+
+## InfDefineDestructorItem
+#
+class InfDefineDestructorItem(InfDefineImageExeParamItem):
+ def __init__(self):
+ InfDefineImageExeParamItem.__init__(self)
+ self.SupModList = []
+
+ def SetSupModList(self, SupModList):
+ self.SupModList = SupModList
+ def GetSupModList(self):
+ return self.SupModList
+
+## InfDefineLibraryItem
+#
+class InfDefineLibraryItem():
+ def __init__(self):
+ self.LibraryName = ''
+ self.Types = []
+ self.Comments = InfLineCommentObject()
+
+ def SetLibraryName(self, Name):
+ self.LibraryName = Name
+ def GetLibraryName(self):
+ return self.LibraryName
+ def SetTypes(self, Type):
+ self.Types = Type
+ def GetTypes(self):
+ return self.Types
\ No newline at end of file diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfDefineObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfDefineObject.py new file mode 100644 index 0000000000..c7883e6980 --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfDefineObject.py @@ -0,0 +1,995 @@ +## @file
+# This file is used to define class objects of [Defines] section for INF file.
+# It will consumed by InfParser
+#
+# 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.
+
+'''
+InfDefineObject
+'''
+
+import os
+import re
+
+from Logger import StringTable as ST
+from Logger import ToolError
+from Library import GlobalData
+from Library import DataType as DT
+from Library.String import GetSplitValueList
+from Library.Misc import CheckGuidRegFormat
+from Library.Misc import Sdict
+from Library.Misc import ConvPathFromAbsToRel
+from Library.ExpressionValidate import IsValidFeatureFlagExp
+from Library.ParserValidate import IsValidWord
+from Library.ParserValidate import IsValidInfMoudleType
+from Library.ParserValidate import IsValidHex
+from Library.ParserValidate import IsValidHexVersion
+from Library.ParserValidate import IsValidDecVersion
+from Library.ParserValidate import IsValidCVariableName
+from Library.ParserValidate import IsValidBoolType
+from Library.ParserValidate import IsValidPath
+from Library.ParserValidate import IsValidFamily
+from Library.ParserValidate import IsValidIdentifier
+from Library.ParserValidate import IsValidDecVersionVal
+from Object.Parser.InfCommonObject import InfLineCommentObject
+from Object.Parser.InfCommonObject import CurrentLine
+from Object.Parser.InfCommonObject import InfSectionCommonDef
+from Object.Parser.InfMisc import ErrorInInf
+from Object.Parser.InfDefineCommonObject import InfDefineLibraryItem
+from Object.Parser.InfDefineCommonObject import InfDefineEntryPointItem
+from Object.Parser.InfDefineCommonObject import InfDefineUnloadImageItem
+from Object.Parser.InfDefineCommonObject import InfDefineConstructorItem
+from Object.Parser.InfDefineCommonObject import InfDefineDestructorItem
+
+class InfDefSectionOptionRomInfo():
+ def __init__(self):
+ self.PciVendorId = None
+ self.PciDeviceId = None
+ self.PciClassCode = None
+ self.PciRevision = None
+ self.PciCompress = None
+ self.CurrentLine = ['', -1, '']
+ def SetPciVendorId(self, PciVendorId, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.PciVendorId != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND%(DT.TAB_INF_DEFINES_PCI_VENDOR_ID),
+ LineInfo=self.CurrentLine)
+ return False
+ #
+ # The PciVendorId should be hex string.
+ #
+ if (IsValidHex(PciVendorId)):
+ self.PciVendorId = InfDefMember()
+ self.PciVendorId.SetValue(PciVendorId)
+ self.PciVendorId.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(PciVendorId),
+ LineInfo=self.CurrentLine)
+ return False
+
+ def GetPciVendorId(self):
+ return self.PciVendorId
+
+ def SetPciDeviceId(self, PciDeviceId, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.PciDeviceId != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND%(DT.TAB_INF_DEFINES_PCI_DEVICE_ID),
+ LineInfo=self.CurrentLine)
+ return False
+ #
+ # The PciDeviceId should be hex string.
+ #
+ if (IsValidHex(PciDeviceId)):
+ self.PciDeviceId = InfDefMember()
+ self.PciDeviceId.SetValue(PciDeviceId)
+ self.PciDeviceId.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(PciDeviceId),
+ LineInfo=self.CurrentLine)
+ return False
+
+ def GetPciDeviceId(self):
+ return self.PciDeviceId
+
+ def SetPciClassCode(self, PciClassCode, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.PciClassCode != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND%(DT.TAB_INF_DEFINES_PCI_CLASS_CODE),
+ LineInfo=self.CurrentLine)
+ return False
+ #
+ # The PciClassCode should be 4 bytes hex string.
+ #
+ if (IsValidHex(PciClassCode)):
+ self.PciClassCode = InfDefMember()
+ self.PciClassCode.SetValue(PciClassCode)
+ self.PciClassCode.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%\
+ (PciClassCode),
+ LineInfo=self.CurrentLine)
+ return False
+
+ def GetPciClassCode(self):
+ return self.PciClassCode
+
+ def SetPciRevision(self, PciRevision, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.PciRevision != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND%(DT.TAB_INF_DEFINES_PCI_REVISION),
+ LineInfo=self.CurrentLine)
+ return False
+ #
+ # The PciRevision should be 4 bytes hex string.
+ #
+ if (IsValidHex(PciRevision)):
+ self.PciRevision = InfDefMember()
+ self.PciRevision.SetValue(PciRevision)
+ self.PciRevision.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(PciRevision),
+ LineInfo=self.CurrentLine)
+ return False
+
+ def GetPciRevision(self):
+ return self.PciRevision
+
+ def SetPciCompress(self, PciCompress, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.PciCompress != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND%(DT.TAB_INF_DEFINES_PCI_COMPRESS),
+ LineInfo=self.CurrentLine)
+ return False
+
+ #
+ # The PciCompress should be 'TRUE' or 'FALSE'.
+ #
+ if (PciCompress == 'TRUE' or PciCompress == 'FALSE'):
+ self.PciCompress = InfDefMember()
+ self.PciCompress.SetValue(PciCompress)
+ self.PciCompress.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(PciCompress),
+ LineInfo=self.CurrentLine)
+ return False
+ def GetPciCompress(self):
+ return self.PciCompress
+##
+# INF [Define] section Object
+#
+class InfDefSection(InfDefSectionOptionRomInfo):
+ def __init__(self):
+ self.BaseName = None
+ self.FileGuid = None
+ self.ModuleType = None
+ self.InfVersion = None
+ self.EdkReleaseVersion = None
+ self.UefiSpecificationVersion = None
+ self.PiSpecificationVersion = None
+ self.LibraryClass = []
+ self.Package = None
+ self.VersionString = None
+ self.PcdIsDriver = None
+ self.EntryPoint = []
+ self.UnloadImages = []
+ self.Constructor = []
+ self.Destructor = []
+ self.Shadow = None
+ self.CustomMakefile = []
+ self.Specification = []
+ self.UefiHiiResourceSection = None
+ self.DpxSource = []
+ self.CurrentLine = ['', -1, '']
+ InfDefSectionOptionRomInfo.__init__(self)
+
+ ## SetHeadComment
+ #
+ # @param BaseName: BaseName
+ #
+ def SetBaseName(self, BaseName, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.BaseName != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND%(DT.TAB_INF_DEFINES_BASE_NAME),
+ LineInfo=self.CurrentLine)
+ return False
+
+ if not (BaseName == '' or BaseName == None):
+ if IsValidWord(BaseName) and not BaseName.startswith("_"):
+ self.BaseName = InfDefMember()
+ self.BaseName.SetValue(BaseName)
+ self.BaseName.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_NAME_INVALID%(BaseName),
+ LineInfo=self.CurrentLine)
+ return False
+
+ ## GetBaseName
+ #
+ def GetBaseName(self):
+ return self.BaseName
+
+ ## SetFileGuid
+ #
+ # @param FileGuid: FileGuid
+ #
+ def SetFileGuid(self, FileGuid, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.FileGuid != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
+ %(DT.TAB_INF_DEFINES_FILE_GUID),
+ LineInfo=self.CurrentLine)
+ return False
+ #
+ # Do verification of GUID content/format
+ #
+ if (CheckGuidRegFormat(FileGuid)):
+ self.FileGuid = InfDefMember()
+ self.FileGuid.SetValue(FileGuid)
+ self.FileGuid.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_GUID_INVALID%(FileGuid),
+ LineInfo=self.CurrentLine)
+ return False
+
+ ## GetFileGuid
+ #
+ def GetFileGuid(self):
+ return self.FileGuid
+
+ ## SetModuleType
+ #
+ # @param ModuleType: ModuleType
+ #
+ def SetModuleType(self, ModuleType, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.ModuleType != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
+ %(DT.TAB_INF_DEFINES_MODULE_TYPE),
+ LineInfo=self.CurrentLine)
+ return False
+ #
+ # Valid Module Type or not
+ #
+ if (IsValidInfMoudleType(ModuleType)):
+ self.ModuleType = InfDefMember()
+ self.ModuleType.SetValue(ModuleType)
+ self.ModuleType.CurrentLine = CurrentLine()
+ self.ModuleType.CurrentLine.SetLineNo(self.CurrentLine[1])
+ self.ModuleType.CurrentLine.SetLineString(self.CurrentLine[2])
+ self.ModuleType.CurrentLine.SetFileName(self.CurrentLine[0])
+ self.ModuleType.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID%\
+ (ModuleType),
+ LineInfo=self.CurrentLine)
+ return False
+
+ ## GetModuleType
+ #
+ def GetModuleType(self):
+ return self.ModuleType
+
+ ## SetInfVersion
+ #
+ # @param InfVersion: InfVersion
+ #
+ def SetInfVersion(self, InfVersion, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.InfVersion != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
+ %(DT.TAB_INF_DEFINES_INF_VERSION),
+ LineInfo=self.CurrentLine)
+ return False
+ #
+ # The InfVersion should be 4 bytes hex string.
+ #
+ if (IsValidHex(InfVersion)):
+ if (InfVersion < '0x00010005'):
+ ErrorInInf(ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF,
+ ErrorCode=ToolError.EDK1_INF_ERROR,
+ LineInfo=self.CurrentLine)
+
+ self.InfVersion = InfDefMember()
+ self.InfVersion.SetValue(InfVersion)
+ self.InfVersion.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(InfVersion),
+ LineInfo=self.CurrentLine)
+ return False
+
+ ## GetInfVersion
+ #
+ def GetInfVersion(self):
+ return self.InfVersion
+
+ ## SetEdkReleaseVersion
+ #
+ # @param EdkReleaseVersion: EdkReleaseVersion
+ #
+ def SetEdkReleaseVersion(self, EdkReleaseVersion, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.EdkReleaseVersion != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
+ %(DT.TAB_INF_DEFINES_EDK_RELEASE_VERSION),
+ LineInfo=self.CurrentLine)
+ return False
+ #
+ # The EdkReleaseVersion should be 4 bytes hex string.
+ #
+ if IsValidHexVersion(EdkReleaseVersion) or \
+ IsValidDecVersionVal(EdkReleaseVersion):
+ self.EdkReleaseVersion = InfDefMember()
+ self.EdkReleaseVersion.SetValue(EdkReleaseVersion)
+ self.EdkReleaseVersion.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
+ %(EdkReleaseVersion),
+ LineInfo=self.CurrentLine)
+ return False
+
+ ## GetEdkReleaseVersion
+ #
+ def GetEdkReleaseVersion(self):
+ return self.EdkReleaseVersion
+
+ ## SetUefiSpecificationVersion
+ #
+ # @param UefiSpecificationVersion: UefiSpecificationVersion
+ #
+ def SetUefiSpecificationVersion(self, UefiSpecificationVersion, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.UefiSpecificationVersion != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
+ %(DT.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION),
+ LineInfo=self.CurrentLine)
+ return False
+ #
+ # The EdkReleaseVersion should be 4 bytes hex string.
+ #
+ if IsValidHexVersion(UefiSpecificationVersion) or \
+ IsValidDecVersionVal(UefiSpecificationVersion):
+ self.UefiSpecificationVersion = InfDefMember()
+ self.UefiSpecificationVersion.SetValue(UefiSpecificationVersion)
+ self.UefiSpecificationVersion.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
+ %(UefiSpecificationVersion),
+ LineInfo=self.CurrentLine)
+ return False
+
+ ## GetUefiSpecificationVersion
+ #
+ def GetUefiSpecificationVersion(self):
+ return self.UefiSpecificationVersion
+
+ ## SetPiSpecificationVersion
+ #
+ # @param PiSpecificationVersion: PiSpecificationVersion
+ #
+ def SetPiSpecificationVersion(self, PiSpecificationVersion, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.PiSpecificationVersion != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
+ %(DT.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION),
+ LineInfo=self.CurrentLine)
+ return False
+ #
+ # The EdkReleaseVersion should be 4 bytes hex string.
+ #
+ if IsValidHexVersion(PiSpecificationVersion) or \
+ IsValidDecVersionVal(PiSpecificationVersion):
+ self.PiSpecificationVersion = InfDefMember()
+ self.PiSpecificationVersion.SetValue(PiSpecificationVersion)
+ self.PiSpecificationVersion.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
+ %(PiSpecificationVersion),
+ LineInfo=self.CurrentLine)
+ return False
+
+ ## GetPiSpecificationVersion
+ #
+ def GetPiSpecificationVersion(self):
+ return self.PiSpecificationVersion
+
+ ## SetLibraryClass
+ #
+ # @param LibraryClass: LibraryClass
+ #
+ def SetLibraryClass(self, LibraryClass, Comments):
+ ValueList = GetSplitValueList(LibraryClass)
+ Name = ValueList[0]
+ if IsValidWord(Name):
+ InfDefineLibraryItemObj = InfDefineLibraryItem()
+ InfDefineLibraryItemObj.SetLibraryName(Name)
+ InfDefineLibraryItemObj.Comments = Comments
+ if len(ValueList) == 2:
+ Type = ValueList[1]
+ TypeList = GetSplitValueList(Type, ' ')
+ TypeList = [Type for Type in TypeList if Type != '']
+ for Item in TypeList:
+ if Item not in DT.MODULE_LIST:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(Item),
+ LineInfo=self.CurrentLine)
+ return False
+ InfDefineLibraryItemObj.SetTypes(TypeList)
+ self.LibraryClass.append(InfDefineLibraryItemObj)
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(Name),
+ LineInfo=self.CurrentLine)
+ return False
+
+ return True
+
+ def GetLibraryClass(self):
+ return self.LibraryClass
+
+ def SetVersionString(self, VersionString, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.VersionString != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
+ %(DT.TAB_INF_DEFINES_VERSION_STRING),
+ LineInfo=self.CurrentLine)
+ return False
+ if not IsValidDecVersion(VersionString):
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
+ %(VersionString),
+ LineInfo=self.CurrentLine)
+ self.VersionString = InfDefMember()
+ self.VersionString.SetValue(VersionString)
+ self.VersionString.Comments = Comments
+ return True
+
+
+ def GetVersionString(self):
+ return self.VersionString
+
+ def SetPcdIsDriver(self, PcdIsDriver, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.PcdIsDriver != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
+ %(DT.TAB_INF_DEFINES_PCD_IS_DRIVER),
+ LineInfo=self.CurrentLine)
+ return False
+ if PcdIsDriver == 'PEI_PCD_DRIVER' or PcdIsDriver == 'DXE_PCD_DRIVER':
+ self.PcdIsDriver = InfDefMember()
+ self.PcdIsDriver.SetValue(PcdIsDriver)
+ self.PcdIsDriver.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(PcdIsDriver),
+ LineInfo=self.CurrentLine)
+ return False
+
+ def GetPcdIsDriver(self):
+ return self.PcdIsDriver
+
+ #
+ # SetEntryPoint
+ #
+ def SetEntryPoint(self, EntryPoint, Comments):
+ #
+ # It can be a list
+ #
+ ValueList = []
+
+ TokenList = GetSplitValueList(EntryPoint, DT.TAB_VALUE_SPLIT)
+ ValueList[0:len(TokenList)] = TokenList
+
+ InfDefineEntryPointItemObj = InfDefineEntryPointItem()
+ if not IsValidCVariableName(ValueList[0]):
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%\
+ (ValueList[0]),
+ LineInfo=self.CurrentLine)
+ InfDefineEntryPointItemObj.SetCName(ValueList[0])
+ if len(ValueList) == 2:
+ if ValueList[1].strip() == '':
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%\
+ (ValueList[1]),
+ LineInfo=self.CurrentLine)
+ #
+ # Validate FFE
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(ValueList[1].strip())
+ if not FeatureFlagRtv[0]:
+ ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%\
+ (FeatureFlagRtv[1]),
+ LineInfo=self.CurrentLine)
+
+ InfDefineEntryPointItemObj.SetFeatureFlagExp(ValueList[1])
+ if len(ValueList) > 2:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(EntryPoint),
+ LineInfo=self.CurrentLine)
+
+ InfDefineEntryPointItemObj.Comments = Comments
+ self.EntryPoint.append(InfDefineEntryPointItemObj)
+
+ def GetEntryPoint(self):
+ return self.EntryPoint
+
+ #
+ # SetUnloadImages
+ #
+ def SetUnloadImages(self, UnloadImages, Comments):
+ #
+ # It can be a list
+ #
+ ValueList = []
+
+ TokenList = GetSplitValueList(UnloadImages, DT.TAB_VALUE_SPLIT)
+ ValueList[0:len(TokenList)] = TokenList
+
+ InfDefineUnloadImageItemObj = InfDefineUnloadImageItem()
+ if not IsValidCVariableName(ValueList[0]):
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(ValueList[0]),
+ LineInfo=self.CurrentLine)
+ InfDefineUnloadImageItemObj.SetCName(ValueList[0])
+ if len(ValueList) == 2:
+ if ValueList[1].strip() == '':
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(ValueList[1]),
+ LineInfo=self.CurrentLine)
+ #
+ # Validate FFE
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(ValueList[1].strip())
+ if not FeatureFlagRtv[0]:
+ ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]),
+ LineInfo=self.CurrentLine)
+ InfDefineUnloadImageItemObj.SetFeatureFlagExp(ValueList[1])
+
+ if len(ValueList) > 2:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(UnloadImages),
+ LineInfo=self.CurrentLine)
+
+ InfDefineUnloadImageItemObj.Comments = Comments
+ self.UnloadImages.append(InfDefineUnloadImageItemObj)
+
+ def GetUnloadImages(self):
+ return self.UnloadImages
+
+ #
+ # SetConstructor
+ #
+ def SetConstructor(self, Constructor, Comments):
+ #
+ # It can be a list
+ #
+ ValueList = []
+
+ TokenList = GetSplitValueList(Constructor, DT.TAB_VALUE_SPLIT)
+ ValueList[0:len(TokenList)] = TokenList
+
+ InfDefineConstructorItemObj = InfDefineConstructorItem()
+ if not IsValidCVariableName(ValueList[0]):
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(ValueList[0]),
+ LineInfo=self.CurrentLine)
+ InfDefineConstructorItemObj.SetCName(ValueList[0])
+ if len(ValueList) >= 2:
+ ModList = GetSplitValueList(ValueList[1], ' ')
+ if ValueList[1].strip() == '':
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(ValueList[1]),
+ LineInfo=self.CurrentLine)
+ for ModItem in ModList:
+ if ModItem not in DT.MODULE_LIST:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID%(ModItem),
+ LineInfo=self.CurrentLine)
+ InfDefineConstructorItemObj.SetSupModList(ModList)
+ if len(ValueList) == 3:
+ if ValueList[2].strip() == '':
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(ValueList[2]),
+ LineInfo=self.CurrentLine)
+ #
+ # Validate FFE
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(ValueList[2].strip())
+ if not FeatureFlagRtv[0]:
+ ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[2]),
+ LineInfo=self.CurrentLine)
+ InfDefineConstructorItemObj.SetFeatureFlagExp(ValueList[2])
+
+ if len(ValueList) > 3:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(Constructor),
+ LineInfo=self.CurrentLine)
+
+ InfDefineConstructorItemObj.Comments = Comments
+ self.Constructor.append(InfDefineConstructorItemObj)
+
+ def GetConstructor(self):
+ return self.Constructor
+
+ #
+ # SetDestructor
+ #
+ def SetDestructor(self, Destructor, Comments):
+ #
+ # It can be a list and only 1 set to TRUE
+ #
+ ValueList = []
+
+ TokenList = GetSplitValueList(Destructor, DT.TAB_VALUE_SPLIT)
+ ValueList[0:len(TokenList)] = TokenList
+
+ InfDefineDestructorItemObj = InfDefineDestructorItem()
+ if not IsValidCVariableName(ValueList[0]):
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(ValueList[0]),
+ LineInfo=self.CurrentLine)
+ InfDefineDestructorItemObj.SetCName(ValueList[0])
+ if len(ValueList) >= 2:
+ ModList = GetSplitValueList(ValueList[1].strip(), ' ')
+ if ValueList[1].strip() == '':
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(ValueList[1]),
+ LineInfo=self.CurrentLine)
+ for ModItem in ModList:
+ if ModItem not in DT.MODULE_LIST:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID%(ModItem),
+ LineInfo=self.CurrentLine)
+ InfDefineDestructorItemObj.SetSupModList(ModList)
+ if len(ValueList) == 3:
+ if ValueList[2].strip() == '':
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(ValueList[2]),
+ LineInfo=self.CurrentLine)
+ #
+ # Validate FFE
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(ValueList[2].strip())
+ if not FeatureFlagRtv[0]:
+ ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]),
+ LineInfo=self.CurrentLine)
+ InfDefineDestructorItemObj.SetFeatureFlagExp(ValueList[2])
+
+ if len(ValueList) > 3:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(Destructor),
+ LineInfo=self.CurrentLine)
+
+ InfDefineDestructorItemObj.Comments = Comments
+ self.Destructor.append(InfDefineDestructorItemObj)
+
+ def GetDestructor(self):
+ return self.Destructor
+
+ def SetShadow(self, Shadow, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.Shadow != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND%(DT.TAB_INF_DEFINES_SHADOW),
+ LineInfo=self.CurrentLine)
+ return False
+ if (IsValidBoolType(Shadow)):
+ self.Shadow = InfDefMember()
+ self.Shadow.SetValue(Shadow)
+ self.Shadow.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(Shadow),
+ LineInfo=self.CurrentLine)
+ return False
+ def GetShadow(self):
+ return self.Shadow
+
+
+
+ #
+ # <Family> ::= {"MSFT"} {"GCC"}
+ # <CustomMake> ::= [<Family> "|"] <Filename>
+ #
+ def SetCustomMakefile(self, CustomMakefile, Comments):
+ if not (CustomMakefile == '' or CustomMakefile == None):
+ ValueList = GetSplitValueList(CustomMakefile)
+ if len(ValueList) == 1:
+ FileName = ValueList[0]
+ Family = ''
+ else:
+ Family = ValueList[0]
+ FileName = ValueList[1]
+ Family = Family.strip()
+ if Family != '':
+ if not IsValidFamily(Family):
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(Family),
+ LineInfo=self.CurrentLine)
+ return False
+ #
+ # The MakefileName specified file should exist
+ #
+ IsValidFileFlag = False
+ ModulePath = os.path.split(self.CurrentLine[0])[0]
+ if IsValidPath(FileName, ModulePath):
+ IsValidFileFlag = True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID%(FileName),
+ LineInfo=self.CurrentLine)
+ return False
+ if IsValidFileFlag:
+ FileName = ConvPathFromAbsToRel(FileName, GlobalData.gINF_MODULE_DIR)
+ self.CustomMakefile.append((Family, FileName, Comments))
+ IsValidFileFlag = False
+ return True
+ else:
+ return False
+
+ def GetCustomMakefile(self):
+ return self.CustomMakefile
+
+ #
+ # ["SPEC" <Spec> <EOL>]*{0,}
+ # <Spec> ::= <Word> "=" <VersionVal>
+ # <VersionVal> ::= {<HexVersion>] {<DecVersion>}
+ # <HexNumber> ::= "0x" [<HexDigit>]{1,}
+ # <DecVersion> ::= (0-9){1,} ["." (0-9){1,2}]
+ #
+ def SetSpecification(self, Specification, Comments):
+ #
+ # Valid the value of Specification
+ #
+ __ValueList = []
+ TokenList = GetSplitValueList(Specification, DT.TAB_EQUAL_SPLIT, 1)
+ __ValueList[0:len(TokenList)] = TokenList
+ if len(__ValueList) != 2:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_NO_NAME + ' Or ' + ST.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE,
+ LineInfo=self.CurrentLine)
+ Name = __ValueList[0].strip()
+ Version = __ValueList[1].strip()
+ if IsValidIdentifier(Name):
+ if IsValidDecVersion(Version):
+ self.Specification.append((Name, Version, Comments))
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(Version),
+ LineInfo=self.CurrentLine)
+ return False
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(Name),
+ LineInfo=self.CurrentLine)
+ return False
+
+ return True
+
+ def GetSpecification(self):
+ return self.Specification
+
+ #
+ # [<UefiHiiResource> <EOL>]{0,1}
+ # <UefiHiiResource> ::= "UEFI_HII_RESOURCE_SECTION" "=" <BoolType>
+ #
+ def SetUefiHiiResourceSection(self, UefiHiiResourceSection, Comments):
+ #
+ # Value has been set before.
+ #
+ if self.UefiHiiResourceSection != None:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
+ %(DT.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION),
+ LineInfo=self.CurrentLine)
+ return False
+ if not (UefiHiiResourceSection == '' or UefiHiiResourceSection == None):
+ if (IsValidBoolType(UefiHiiResourceSection)):
+ self.UefiHiiResourceSection = InfDefMember()
+ self.UefiHiiResourceSection.SetValue(UefiHiiResourceSection)
+ self.UefiHiiResourceSection.Comments = Comments
+ return True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(UefiHiiResourceSection),
+ LineInfo=self.CurrentLine)
+ return False
+ else:
+ return False
+
+ def GetUefiHiiResourceSection(self):
+ return self.UefiHiiResourceSection
+
+ def SetDpxSource(self, DpxSource, Comments):
+ #
+ # The MakefileName specified file should exist
+ #
+ IsValidFileFlag = False
+ ModulePath = os.path.split(self.CurrentLine[0])[0]
+ if IsValidPath(DpxSource, ModulePath):
+ IsValidFileFlag = True
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID%(DpxSource),
+ LineInfo=self.CurrentLine)
+ return False
+ if IsValidFileFlag:
+ DpxSource = ConvPathFromAbsToRel(DpxSource,
+ GlobalData.gINF_MODULE_DIR)
+ self.DpxSource.append((DpxSource, Comments))
+ IsValidFileFlag = False
+ return True
+
+ def GetDpxSource(self):
+ return self.DpxSource
+
+gFUNCTION_MAPPING_FOR_DEFINE_SECTION = {
+ #
+ # Required Fields
+ #
+ DT.TAB_INF_DEFINES_BASE_NAME : InfDefSection.SetBaseName,
+ DT.TAB_INF_DEFINES_FILE_GUID : InfDefSection.SetFileGuid,
+ DT.TAB_INF_DEFINES_MODULE_TYPE : InfDefSection.SetModuleType,
+ #
+ # Required by EDKII style INF file
+ #
+ DT.TAB_INF_DEFINES_INF_VERSION : InfDefSection.SetInfVersion,
+ #
+ # Optional Fields
+ #
+ DT.TAB_INF_DEFINES_EDK_RELEASE_VERSION : InfDefSection.SetEdkReleaseVersion,
+ DT.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION : InfDefSection.SetUefiSpecificationVersion,
+ DT.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION : InfDefSection.SetPiSpecificationVersion,
+ DT.TAB_INF_DEFINES_LIBRARY_CLASS : InfDefSection.SetLibraryClass,
+ DT.TAB_INF_DEFINES_VERSION_STRING : InfDefSection.SetVersionString,
+ DT.TAB_INF_DEFINES_PCD_IS_DRIVER : InfDefSection.SetPcdIsDriver,
+ DT.TAB_INF_DEFINES_ENTRY_POINT : InfDefSection.SetEntryPoint,
+ DT.TAB_INF_DEFINES_UNLOAD_IMAGE : InfDefSection.SetUnloadImages,
+ DT.TAB_INF_DEFINES_CONSTRUCTOR : InfDefSection.SetConstructor,
+ DT.TAB_INF_DEFINES_DESTRUCTOR : InfDefSection.SetDestructor,
+ DT.TAB_INF_DEFINES_SHADOW : InfDefSection.SetShadow,
+ DT.TAB_INF_DEFINES_PCI_VENDOR_ID : InfDefSection.SetPciVendorId,
+ DT.TAB_INF_DEFINES_PCI_DEVICE_ID : InfDefSection.SetPciDeviceId,
+ DT.TAB_INF_DEFINES_PCI_CLASS_CODE : InfDefSection.SetPciClassCode,
+ DT.TAB_INF_DEFINES_PCI_REVISION : InfDefSection.SetPciRevision,
+ DT.TAB_INF_DEFINES_PCI_COMPRESS : InfDefSection.SetPciCompress,
+ DT.TAB_INF_DEFINES_CUSTOM_MAKEFILE : InfDefSection.SetCustomMakefile,
+ DT.TAB_INF_DEFINES_SPEC : InfDefSection.SetSpecification,
+ DT.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION : InfDefSection.SetUefiHiiResourceSection,
+ DT.TAB_INF_DEFINES_DPX_SOURCE : InfDefSection.SetDpxSource
+}
+
+## InfDefMember
+#
+#
+class InfDefMember():
+ def __init__(self, Name='', Value=''):
+ self.Comments = InfLineCommentObject()
+ self.Name = Name
+ self.Value = Value
+ self.CurrentLine = CurrentLine()
+
+ def GetName(self):
+ return self.Name
+ def SetName(self, Name):
+ self.Name = Name
+ def GetValue(self):
+ return self.Value
+ def SetValue(self, Value):
+ self.Value = Value
+
+## InfDefObject
+#
+#
+class InfDefObject(InfSectionCommonDef):
+ def __init__(self):
+ self.Defines = Sdict()
+ InfSectionCommonDef.__init__(self)
+ def SetDefines(self, DefineContent, Arch = None):
+ #
+ # Validate Arch
+ #
+ HasFoundInfVersionFalg = False
+ LineInfo = ['', -1, '']
+ ArchListString = ' '.join(Arch)
+
+ #
+ # Parse Define items.
+ #
+ for InfDefMemberObj in DefineContent:
+ ProcessFunc = None
+ Name = InfDefMemberObj.GetName()
+ Value = InfDefMemberObj.GetValue()
+ InfLineCommentObj = InfLineCommentObject()
+ InfLineCommentObj.SetHeaderComments(InfDefMemberObj.Comments.GetHeaderComments())
+ InfLineCommentObj.SetTailComments(InfDefMemberObj.Comments.GetTailComments())
+ if Name == 'COMPONENT_TYPE':
+ ErrorInInf(ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF,
+ ErrorCode=ToolError.EDK1_INF_ERROR,
+ RaiseError=True)
+ if Name == DT.TAB_INF_DEFINES_INF_VERSION:
+ HasFoundInfVersionFalg = True
+
+ if not (Name == '' or Name == None):
+ #
+ # Process "SPEC" Keyword definition.
+ #
+ ReName = re.compile(r"SPEC ", re.DOTALL)
+ if ReName.match(Name):
+ SpecValue = Name[Name.find("SPEC") + len("SPEC"):].strip()
+ Name = "SPEC"
+ Value = SpecValue + " = " + Value
+ if self.Defines.has_key(ArchListString):
+ DefineList = self.Defines[ArchListString]
+ LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName()
+ LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo()
+ LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString()
+ DefineList.CurrentLine = LineInfo
+ #
+ # Found the process function from mapping table.
+ #
+ if Name not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION.keys():
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID%(Name),
+ LineInfo=LineInfo)
+
+ else:
+ ProcessFunc = gFUNCTION_MAPPING_FOR_DEFINE_SECTION[Name]
+ if (ProcessFunc != None):
+ ProcessFunc(DefineList, Value, InfLineCommentObj)
+ self.Defines[ArchListString] = DefineList
+ else:
+ DefineList = InfDefSection()
+ LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName()
+ LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo()
+ LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString()
+ DefineList.CurrentLine = LineInfo
+ #
+ # Found the process function from mapping table.
+ #
+ if Name not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION.keys():
+ ErrorInInf(ST.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID%(Name),
+ LineInfo=LineInfo)
+ #
+ # Found the process function from mapping table.
+ #
+ else:
+ ProcessFunc = gFUNCTION_MAPPING_FOR_DEFINE_SECTION[Name]
+ if (ProcessFunc != None):
+ ProcessFunc(DefineList, Value, InfLineCommentObj)
+ self.Defines[ArchListString] = DefineList
+
+ #
+ # After set, check whether INF_VERSION defined.
+ #
+ if not HasFoundInfVersionFalg:
+ ErrorInInf(ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF,
+ ErrorCode=ToolError.EDK1_INF_ERROR,
+ RaiseError=True)
+ return True
+
+ def GetDefines(self):
+ return self.Defines
+
\ No newline at end of file diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfDepexObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfDepexObject.py new file mode 100644 index 0000000000..55d6bbc69e --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfDepexObject.py @@ -0,0 +1,166 @@ +## @file
+# This file is used to define class objects of INF file [Depex] section.
+# It will consumed by InfParser.
+#
+# 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.
+
+'''
+InfDepexObject
+'''
+
+from Library import DataType as DT
+from Library import GlobalData
+import Logger.Log as Logger
+from Logger import ToolError
+from Logger import StringTable as ST
+
+from Object.Parser.InfCommonObject import InfSectionCommonDef
+from Library.ParserValidate import IsValidArch
+
+class InfDepexContentItem():
+ def __init__(self):
+ self.SectionType = ''
+ self.SectionString = ''
+
+ def SetSectionType(self, SectionType):
+ self.SectionType = SectionType
+ def GetSectionType(self):
+ return self.SectionType
+
+ def SetSectionString(self, SectionString):
+ self.SectionString = SectionString
+ def GetSectionString(self):
+ return self.SectionString
+
+
+class InfDepexItem():
+ def __init__(self):
+ self.DepexContent = ''
+ self.ModuleType = ''
+ self.SupArch = ''
+ self.HelpString = ''
+ self.FeatureFlagExp = ''
+ self.InfDepexContentItemList = []
+
+ def SetFeatureFlagExp(self, FeatureFlagExp):
+ self.FeatureFlagExp = FeatureFlagExp
+ def GetFeatureFlagExp(self):
+ return self.FeatureFlagExp
+
+ def SetSupArch(self, Arch):
+ self.SupArch = Arch
+ def GetSupArch(self):
+ return self.SupArch
+
+ def SetHelpString(self, HelpString):
+ self.HelpString = HelpString
+ def GetHelpString(self):
+ return self.HelpString
+
+ def SetModuleType(self, Type):
+ self.ModuleType = Type
+ def GetModuleType(self):
+ return self.ModuleType
+
+ def SetDepexConent(self, Content):
+ self.DepexContent = Content
+ def GetDepexContent(self):
+ return self.DepexContent
+
+ def SetInfDepexContentItemList(self, InfDepexContentItemList):
+ self.InfDepexContentItemList = InfDepexContentItemList
+ def GetInfDepexContentItemList(self):
+ return self.InfDepexContentItemList
+
+## InfDepexObject
+#
+#
+#
+class InfDepexObject(InfSectionCommonDef):
+ def __init__(self):
+ self.Depex = []
+ self.AllContent = ''
+ self.SectionContent = ''
+ InfSectionCommonDef.__init__(self)
+
+ def SetDepex(self, DepexContent, KeyList=None, CommentList=None):
+ for KeyItem in KeyList:
+ Arch = KeyItem[0]
+ ModuleType = KeyItem[1]
+ InfDepexItemIns = InfDepexItem()
+
+ #
+ # Validate Arch
+ #
+ if IsValidArch(Arch.strip().upper()):
+ InfDepexItemIns.SetSupArch(Arch)
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_DEFINE_NAME_INVALID % (Arch),
+ File=GlobalData.gINF_MODULE_NAME,
+ Line=KeyItem[2])
+
+ #
+ # Validate Module Type
+ #
+ if ModuleType and ModuleType != 'COMMON':
+ if ModuleType in DT.VALID_DEPEX_MODULE_TYPE_LIST:
+ InfDepexItemIns.SetModuleType(ModuleType)
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_DEPEX_SECTION_MODULE_TYPE_ERROR % (ModuleType),
+ File=GlobalData.gINF_MODULE_NAME,
+ Line=KeyItem[2])
+
+ #
+ # Parser content in [Depex] section.
+ #
+ DepexString = ''
+ HelpString = ''
+ #
+ # Get Depex Expression
+ #
+ for Line in DepexContent:
+ LineContent = Line[0].strip()
+ if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1:
+ LineContent = LineContent[:LineContent.find(DT.TAB_COMMENT_SPLIT)]
+ if LineContent:
+ DepexString = DepexString + LineContent + DT.END_OF_LINE
+ continue
+
+ if DepexString.endswith(DT.END_OF_LINE):
+ DepexString = DepexString[:-1]
+
+ if not DepexString.strip():
+ continue
+
+ #
+ # Get Help Text
+ #
+ for HelpLine in CommentList:
+ HelpString = HelpString + HelpLine + DT.END_OF_LINE
+ if HelpString.endswith(DT.END_OF_LINE):
+ HelpString = HelpString[:-1]
+
+ InfDepexItemIns.SetDepexConent(DepexString)
+ InfDepexItemIns.SetHelpString(HelpString)
+
+ self.Depex.append(InfDepexItemIns)
+
+ return True
+
+ def GetDepex(self):
+ return self.Depex
+
+ def GetAllContent(self):
+ return self.AllContent
diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfGuidObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfGuidObject.py new file mode 100644 index 0000000000..4f1a3f4e81 --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfGuidObject.py @@ -0,0 +1,350 @@ +## @file
+# This file is used to define class objects of INF file [Guids] section.
+# It will consumed by InfParser.
+#
+# 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.
+
+'''
+InfGuidObject
+'''
+
+from Library.ParserValidate import IsValidCVariableName
+from Library.CommentParsing import ParseComment
+from Library.ExpressionValidate import IsValidFeatureFlagExp
+
+from Library.Misc import Sdict
+from Library import DataType as DT
+import Logger.Log as Logger
+from Logger import ToolError
+from Logger import StringTable as ST
+
+class InfGuidItemCommentContent():
+ def __init__(self):
+ #
+ # ## SOMETIMES_CONSUMES ## Variable:L"MemoryTypeInformation"
+ # TailString.
+ #
+ #
+ # SOMETIMES_CONSUMES
+ #
+ self.UsageItem = ''
+ #
+ # Variable
+ #
+ self.GuidTypeItem = ''
+ #
+ # MemoryTypeInformation
+ #
+ self.VariableNameItem = ''
+ #
+ # TailString
+ #
+ self.HelpStringItem = ''
+
+ def SetUsageItem(self, UsageItem):
+ self.UsageItem = UsageItem
+ def GetUsageItem(self):
+ return self.UsageItem
+
+ def SetGuidTypeItem(self, GuidTypeItem):
+ self.GuidTypeItem = GuidTypeItem
+ def GetGuidTypeItem(self):
+ return self.GuidTypeItem
+
+ def SetVariableNameItem(self, VariableNameItem):
+ self.VariableNameItem = VariableNameItem
+ def GetVariableNameItem(self):
+ return self.VariableNameItem
+
+ def SetHelpStringItem(self, HelpStringItem):
+ self.HelpStringItem = HelpStringItem
+ def GetHelpStringItem(self):
+ return self.HelpStringItem
+
+class InfGuidItem():
+ def __init__(self):
+ self.Name = ''
+ self.FeatureFlagExp = ''
+ #
+ # A list contain instance of InfGuidItemCommentContent
+ #
+ self.CommentList = []
+ self.SupArchList = []
+
+ def SetName(self, Name):
+ self.Name = Name
+ def GetName(self):
+ return self.Name
+
+ def SetFeatureFlagExp(self, FeatureFlagExp):
+ self.FeatureFlagExp = FeatureFlagExp
+ def GetFeatureFlagExp(self):
+ return self.FeatureFlagExp
+
+ def SetCommentList(self, CommentList):
+ self.CommentList = CommentList
+ def GetCommentList(self):
+ return self.CommentList
+
+ def SetSupArchList(self, SupArchList):
+ self.SupArchList = SupArchList
+ def GetSupArchList(self):
+ return self.SupArchList
+
+## ParseComment
+#
+# ParseComment
+#
+def ParseGuidComment(CommentsList, InfGuidItemObj):
+ #
+ # Get/Set Usage and HelpString
+ #
+ if CommentsList != None and len(CommentsList) != 0 :
+ CommentInsList = []
+ PreUsage = None
+ PreGuidType = None
+ PreHelpText = ''
+ BlockFlag = -1
+ Count = 0
+ for CommentItem in CommentsList:
+ Count = Count + 1
+ CommentItemUsage, \
+ CommentItemGuidType, \
+ CommentItemVarString, \
+ CommentItemHelpText = \
+ ParseComment(CommentItem,
+ DT.ALL_USAGE_TOKENS,
+ DT.GUID_TYPE_TOKENS,
+ [],
+ True)
+
+ if CommentItemHelpText == None:
+ CommentItemHelpText = ''
+ if Count == len(CommentsList) and CommentItemUsage == CommentItemGuidType == DT.ITEM_UNDEFINED:
+ CommentItemHelpText = DT.END_OF_LINE
+
+ if Count == len(CommentsList):
+ if BlockFlag == 1 or BlockFlag == 2:
+ if CommentItemUsage == CommentItemGuidType == DT.ITEM_UNDEFINED:
+ BlockFlag = 4
+ else:
+ BlockFlag = 3
+ if BlockFlag == -1:
+ BlockFlag = 4
+ if BlockFlag == -1 or BlockFlag == 1 or BlockFlag == 2:
+ if CommentItemUsage == CommentItemGuidType == DT.ITEM_UNDEFINED:
+ if BlockFlag == -1:
+ BlockFlag = 1
+ elif BlockFlag == 1:
+ BlockFlag = 2
+ else:
+ if BlockFlag == 1 or BlockFlag == 2:
+ BlockFlag = 3
+ elif BlockFlag == -1:
+ BlockFlag = 4
+
+ #
+ # Combine two comment line if they are generic comment
+ #
+ if CommentItemUsage == CommentItemGuidType == PreUsage == PreGuidType == DT.ITEM_UNDEFINED:
+ CommentItemHelpText = PreHelpText + DT.END_OF_LINE + CommentItemHelpText
+
+ PreHelpText = CommentItemHelpText
+
+ if BlockFlag == 4:
+ CommentItemIns = InfGuidItemCommentContent()
+ CommentItemIns.SetUsageItem(CommentItemUsage)
+ CommentItemIns.SetGuidTypeItem(CommentItemGuidType)
+ CommentItemIns.SetVariableNameItem(CommentItemVarString)
+ CommentItemIns.SetHelpStringItem(CommentItemHelpText)
+ CommentInsList.append(CommentItemIns)
+
+ BlockFlag = -1
+ PreUsage = None
+ PreGuidType = None
+ PreHelpText = ''
+
+ elif BlockFlag == 3:
+ #
+ # Add previous help string
+ #
+ CommentItemIns = InfGuidItemCommentContent()
+ CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
+ CommentItemIns.SetGuidTypeItem(DT.ITEM_UNDEFINED)
+ if PreHelpText == '' or PreHelpText.endswith(DT.END_OF_LINE):
+ PreHelpText += DT.END_OF_LINE
+ CommentItemIns.SetHelpStringItem(PreHelpText)
+ CommentInsList.append(CommentItemIns)
+ #
+ # Add Current help string
+ #
+ CommentItemIns = InfGuidItemCommentContent()
+ CommentItemIns.SetUsageItem(CommentItemUsage)
+ CommentItemIns.SetGuidTypeItem(CommentItemGuidType)
+ CommentItemIns.SetVariableNameItem(CommentItemVarString)
+ CommentItemIns.SetHelpStringItem(CommentItemHelpText)
+ CommentInsList.append(CommentItemIns)
+
+ BlockFlag = -1
+ PreUsage = None
+ PreGuidType = None
+ PreHelpText = ''
+
+ else:
+ PreUsage = CommentItemUsage
+ PreGuidType = CommentItemGuidType
+ PreHelpText = CommentItemHelpText
+
+ InfGuidItemObj.SetCommentList(CommentInsList)
+ else:
+ #
+ # Still need to set the USAGE/GUIDTYPE to undefined.
+ #
+ CommentItemIns = InfGuidItemCommentContent()
+ CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
+ CommentItemIns.SetGuidTypeItem(DT.ITEM_UNDEFINED)
+ InfGuidItemObj.SetCommentList([CommentItemIns])
+
+ return InfGuidItemObj
+
+## InfGuidObject
+#
+# InfGuidObject
+#
+class InfGuidObject():
+ def __init__(self):
+ self.Guids = Sdict()
+ #
+ # Macro defined in this section should be only used in this section.
+ #
+ self.Macros = {}
+
+ def SetGuid(self, GuidList, Arch = None):
+ __SupportArchList = []
+ for ArchItem in Arch:
+ #
+ # Validate Arch
+ #
+ if (ArchItem == '' or ArchItem == None):
+ ArchItem = 'COMMON'
+
+ __SupportArchList.append(ArchItem)
+
+ for Item in GuidList:
+ #
+ # Get Comment content of this protocol
+ #
+ CommentsList = None
+ if len(Item) == 3:
+ CommentsList = Item[1]
+ CurrentLineOfItem = Item[2]
+ Item = Item[0]
+ InfGuidItemObj = InfGuidItem()
+ if len(Item) >= 1 and len(Item) <= 2:
+ #
+ # Only GuildName contained
+ #
+ if not IsValidCVariableName(Item[0]):
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_INVALID_CNAME%(Item[0]),
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ if (Item[0] != ''):
+ InfGuidItemObj.SetName(Item[0])
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_CNAME_MISSING,
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ if len(Item) == 2:
+ #
+ # Contained CName and Feature Flag Express
+ # <statements> ::= <CName> ["|" <FeatureFlagExpress>]
+ # For GUID entry.
+ #
+ if Item[1].strip() == '':
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ #
+ # Validate Feature Flag Express
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip())
+ if not FeatureFlagRtv[0]:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]),
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ InfGuidItemObj.SetFeatureFlagExp(Item[1])
+ if len(Item) != 1 and len(Item) != 2:
+ #
+ # Invalid format of GUID statement
+ #
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR,
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+
+ InfGuidItemObj = ParseGuidComment(CommentsList, InfGuidItemObj)
+ InfGuidItemObj.SetSupArchList(__SupportArchList)
+
+ #
+ # Determine GUID name duplicate. Follow below rule:
+ #
+ # A GUID must not be duplicated within a [Guids] section.
+ # A GUID may appear in multiple architectural [Guids]
+ # sections. A GUID listed in an architectural [Guids]
+ # section must not be listed in the common architectural
+ # [Guids] section.
+ #
+ # NOTE: This check will not report error now.
+ #
+ for Item in self.Guids:
+ if Item.GetName() == InfGuidItemObj.GetName():
+ ItemSupArchList = Item.GetSupArchList()
+ for ItemArch in ItemSupArchList:
+ for GuidItemObjArch in __SupportArchList:
+ if ItemArch == GuidItemObjArch:
+ #
+ # ST.ERR_INF_PARSER_ITEM_DUPLICATE
+ #
+ pass
+
+ if ItemArch.upper() == 'COMMON' or GuidItemObjArch.upper() == 'COMMON':
+ #
+ # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
+ #
+ pass
+
+ if self.Guids.has_key((InfGuidItemObj)):
+ GuidList = self.Guids[InfGuidItemObj]
+ GuidList.append(InfGuidItemObj)
+ self.Guids[InfGuidItemObj] = GuidList
+ else:
+ GuidList = []
+ GuidList.append(InfGuidItemObj)
+ self.Guids[InfGuidItemObj] = GuidList
+
+ return True
+
+ def GetGuid(self):
+ return self.Guids
\ No newline at end of file diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfHeaderObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfHeaderObject.py new file mode 100644 index 0000000000..45fba31aaa --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfHeaderObject.py @@ -0,0 +1,119 @@ +## @file
+# This file is used to define class objects of INF file header.
+# It will consumed by InfParser.
+#
+# 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.
+
+'''
+InfHeaderObject
+'''
+
+## INF file header object
+#
+# A sample file header
+#
+# ## @file xxx.inf FileName
+# # Abstract
+# #
+# # Description
+# #
+# # Copyright
+# #
+# # License
+# #
+#
+class InfHeaderObject():
+ def __init__(self):
+ self.FileName = ''
+ self.Abstract = ''
+ self.Description = ''
+ self.Copyright = ''
+ self.License = ''
+
+ ## SetFileName
+ #
+ # @param FileName: File Name
+ #
+ def SetFileName(self, FileName):
+ if not (FileName == '' or FileName == None):
+ self.FileName = FileName
+ return True
+ else:
+ return False
+
+ ## GetFileName
+ #
+ def GetFileName(self):
+ return self.FileName
+
+ ## SetAbstract
+ #
+ # @param Abstract: Abstract
+ #
+ def SetAbstract(self, Abstract):
+ if not (Abstract == '' or Abstract == None):
+ self.Abstract = Abstract
+ return True
+ else:
+ return False
+
+ ## GetAbstract
+ #
+ def GetAbstract(self):
+ return self.Abstract
+
+ ## SetDescription
+ #
+ # @param Description: Description content
+ #
+ def SetDescription(self, Description):
+ if not (Description == '' or Description == None):
+ self.Description = Description
+ return True
+ else:
+ return False
+
+ ## GetAbstract
+ #
+ def GetDescription(self):
+ return self.Description
+
+ ## SetCopyright
+ #
+ # @param Copyright: Copyright content
+ #
+ def SetCopyright(self, Copyright):
+ if not (Copyright == '' or Copyright == None):
+ self.Copyright = Copyright
+ return True
+ else:
+ return False
+
+ ## GetCopyright
+ #
+ def GetCopyright(self):
+ return self.Copyright
+
+ ## SetCopyright
+ #
+ # @param License: License content
+ #
+ def SetLicense(self, License):
+ if not (License == '' or License == None):
+ self.License = License
+ return True
+ else:
+ return False
+
+ ## GetLicense
+ #
+ def GetLicense(self):
+ return self.License
\ No newline at end of file diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfLibraryClassesObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfLibraryClassesObject.py new file mode 100644 index 0000000000..a37692ee23 --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfLibraryClassesObject.py @@ -0,0 +1,252 @@ +## @file
+# This file is used to define class objects of INF file [LibraryClasses] section.
+# It will consumed by InfParser.
+#
+# 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.
+
+'''
+InfLibraryClassesObject
+'''
+
+from Logger import StringTable as ST
+from Logger import ToolError
+import Logger.Log as Logger
+from Library import GlobalData
+
+from Library.Misc import Sdict
+from Object.Parser.InfCommonObject import CurrentLine
+from Library.ExpressionValidate import IsValidFeatureFlagExp
+from Library.ParserValidate import IsValidLibName
+
+## GetArchModuleType
+#
+# Get Arch List and ModuleType List
+#
+def GetArchModuleType(KeyList):
+ __SupArchList = []
+ __SupModuleList = []
+
+ for (ArchItem, ModuleItem) in KeyList:
+ #
+ # Validate Arch
+ #
+ if (ArchItem == '' or ArchItem == None):
+ ArchItem = 'COMMON'
+
+ if (ModuleItem == '' or ModuleItem == None):
+ ModuleItem = 'COMMON'
+
+ if ArchItem not in __SupArchList:
+ __SupArchList.append(ArchItem)
+
+ List = ModuleItem.split('|')
+ for Entry in List:
+ if Entry not in __SupModuleList:
+ __SupModuleList.append(Entry)
+
+ return (__SupArchList, __SupModuleList)
+
+
+class InfLibraryClassItem():
+ def __init__(self, LibName='', FeatureFlagExp='', HelpString=None):
+ self.LibName = LibName
+ self.FeatureFlagExp = FeatureFlagExp
+ self.HelpString = HelpString
+ self.CurrentLine = CurrentLine()
+ self.SupArchList = []
+ self.SupModuleList = []
+ self.FileGuid = ''
+ self.Version = ''
+
+ def SetLibName(self, LibName):
+ self.LibName = LibName
+ def GetLibName(self):
+ return self.LibName
+
+ def SetHelpString(self, HelpString):
+ self.HelpString = HelpString
+ def GetHelpString(self):
+ return self.HelpString
+
+ def SetFeatureFlagExp(self, FeatureFlagExp):
+ self.FeatureFlagExp = FeatureFlagExp
+ def GetFeatureFlagExp(self):
+ return self.FeatureFlagExp
+
+ def SetSupArchList(self, SupArchList):
+ self.SupArchList = SupArchList
+ def GetSupArchList(self):
+ return self.SupArchList
+
+ def SetSupModuleList(self, SupModuleList):
+ self.SupModuleList = SupModuleList
+ def GetSupModuleList(self):
+ return self.SupModuleList
+
+ #
+ # As Build related information
+ #
+ def SetFileGuid(self, FileGuid):
+ self.FileGuid = FileGuid
+ def GetFileGuid(self):
+ return self.FileGuid
+
+ def SetVersion(self, Version):
+ self.Version = Version
+ def GetVersion(self):
+ return self.Version
+
+## INF LibraryClass Section
+#
+#
+#
+class InfLibraryClassObject():
+ def __init__(self):
+ self.LibraryClasses = Sdict()
+ #
+ # Macro defined in this section should be only used in this section.
+ #
+ self.Macros = {}
+
+ ##SetLibraryClasses
+ #
+ #
+ # @param HelpString: It can be a common comment or contain a recommend
+ # instance.
+ #
+ def SetLibraryClasses(self, LibContent, KeyList=None):
+ #
+ # Validate Arch
+ #
+ (__SupArchList, __SupModuleList) = GetArchModuleType(KeyList)
+
+ for LibItem in LibContent:
+ LibItemObj = InfLibraryClassItem()
+ if not GlobalData.gIS_BINARY_INF:
+ HelpStringObj = LibItem[1]
+ LibItemObj.CurrentLine.SetFileName(LibItem[2][2])
+ LibItemObj.CurrentLine.SetLineNo(LibItem[2][1])
+ LibItemObj.CurrentLine.SetLineString(LibItem[2][0])
+ LibItem = LibItem[0]
+ if HelpStringObj != None:
+ LibItemObj.SetHelpString(HelpStringObj)
+ if len(LibItem) >= 1:
+ if LibItem[0].strip() != '':
+ if IsValidLibName(LibItem[0].strip()):
+ if LibItem[0].strip() != 'NULL':
+ LibItemObj.SetLibName(LibItem[0])
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_DEFINE_LIB_NAME_INVALID,
+ File=GlobalData.gINF_MODULE_NAME,
+ Line=LibItemObj.CurrentLine.GetLineNo(),
+ ExtraData=LibItemObj.CurrentLine.GetLineString())
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (LibItem[0]),
+ File=GlobalData.gINF_MODULE_NAME,
+ Line=LibItemObj.CurrentLine.GetLineNo(),
+ ExtraData=LibItemObj.CurrentLine.GetLineString())
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_LIBRARY_SECTION_LIBNAME_MISSING,
+ File=GlobalData.gINF_MODULE_NAME,
+ Line=LibItemObj.CurrentLine.GetLineNo(),
+ ExtraData=LibItemObj.CurrentLine.GetLineString())
+ if len(LibItem) == 2:
+ if LibItem[1].strip() == '':
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
+ File=GlobalData.gINF_MODULE_NAME,
+ Line=LibItemObj.CurrentLine.GetLineNo(),
+ ExtraData=LibItemObj.CurrentLine.GetLineString())
+ #
+ # Validate FFE
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(LibItem[1].strip())
+ if not FeatureFlagRtv[0]:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]),
+ File=GlobalData.gINF_MODULE_NAME,
+ Line=LibItemObj.CurrentLine.GetLineNo(),
+ ExtraData=LibItemObj.CurrentLine.GetLineString())
+ LibItemObj.SetFeatureFlagExp(LibItem[1].strip())
+
+ #
+ # Invalid strings
+ #
+ if len(LibItem) < 1 or len(LibItem) > 2:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_LIBRARY_SECTION_CONTENT_ERROR,
+ File=GlobalData.gINF_MODULE_NAME,
+ Line=LibItemObj.CurrentLine.GetLineNo(),
+ ExtraData=LibItemObj.CurrentLine.GetLineString())
+
+ LibItemObj.SetSupArchList(__SupArchList)
+ LibItemObj.SetSupModuleList(__SupModuleList)
+
+ #
+ # Determine Library class duplicate. Follow below rule:
+ #
+ # A library class keyword must not be duplicated within a
+ # [LibraryClasses] section. Library class keywords may appear in
+ # multiple architectural and module type [LibraryClasses] sections.
+ # A library class keyword listed in an architectural or module type
+ # [LibraryClasses] section must not be listed in the common
+ # architectural or module type [LibraryClasses] section.
+ #
+ # NOTE: This check will not report error now. But keep code for future enhancement.
+ #
+# for Item in self.LibraryClasses:
+# if Item.GetLibName() == LibItemObj.GetLibName():
+# ItemSupArchList = Item.GetSupArchList()
+# ItemSupModuleList = Item.GetSupModuleList()
+# for ItemArch in ItemSupArchList:
+# for ItemModule in ItemSupModuleList:
+# for LibItemObjArch in __SupArchList:
+# for LibItemObjModule in __SupModuleList:
+# if ItemArch == LibItemObjArch and LibItemObjModule == ItemModule:
+# #
+# # ERR_INF_PARSER_ITEM_DUPLICATE
+# #
+# pass
+# if (ItemArch.upper() == 'COMMON' or LibItemObjArch.upper() == 'COMMON') \
+# and LibItemObjModule == ItemModule:
+# #
+# # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
+# #
+# pass
+ else:
+ #
+ # Assume the file GUID is well formatted.
+ #
+ LibItemObj.SetFileGuid(LibItem[0])
+ LibItemObj.SetVersion(LibItem[1])
+
+ if self.LibraryClasses.has_key((LibItemObj)):
+ LibraryList = self.LibraryClasses[LibItemObj]
+ LibraryList.append(LibItemObj)
+ self.LibraryClasses[LibItemObj] = LibraryList
+ else:
+ LibraryList = []
+ LibraryList.append(LibItemObj)
+ self.LibraryClasses[LibItemObj] = LibraryList
+
+ return True
+
+ def GetLibraryClasses(self):
+ return self.LibraryClasses
diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfMisc.py b/BaseTools/Source/Python/UPT/Object/Parser/InfMisc.py new file mode 100644 index 0000000000..74099e2088 --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfMisc.py @@ -0,0 +1,148 @@ +## @file
+# This file is used to define class objects of INF file miscellaneous.
+# Include BootMode/HOB/Event and others. It will consumed by InfParser.
+#
+# 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.
+
+'''
+InfMisc
+'''
+
+import Logger.Log as Logger
+from Logger import ToolError
+
+from Library import DataType as DT
+from Object.Parser.InfCommonObject import InfSectionCommonDef
+from Library.Misc import Sdict
+
+##
+# BootModeObject
+#
+class InfBootModeObject():
+ def __init__(self):
+ self.SupportedBootModes = ''
+ self.HelpString = ''
+ self.Usage = ''
+
+ def SetSupportedBootModes(self, SupportedBootModes):
+ self.SupportedBootModes = SupportedBootModes
+ def GetSupportedBootModes(self):
+ return self.SupportedBootModes
+
+ def SetHelpString(self, HelpString):
+ self.HelpString = HelpString
+ def GetHelpString(self):
+ return self.HelpString
+
+ def SetUsage(self, Usage):
+ self.Usage = Usage
+ def GetUsage(self):
+ return self.Usage
+##
+# EventObject
+#
+class InfEventObject():
+ def __init__(self):
+ self.EventType = ''
+ self.HelpString = ''
+ self.Usage = ''
+
+ def SetEventType(self, EventType):
+ self.EventType = EventType
+
+ def GetEventType(self):
+ return self.EventType
+
+ def SetHelpString(self, HelpString):
+ self.HelpString = HelpString
+ def GetHelpString(self):
+ return self.HelpString
+
+ def SetUsage(self, Usage):
+ self.Usage = Usage
+ def GetUsage(self):
+ return self.Usage
+##
+# HobObject
+#
+class InfHobObject():
+ def __init__(self):
+ self.HobType = ''
+ self.Usage = ''
+ self.SupArchList = []
+ self.HelpString = ''
+
+ def SetHobType(self, HobType):
+ self.HobType = HobType
+
+ def GetHobType(self):
+ return self.HobType
+
+ def SetUsage(self, Usage):
+ self.Usage = Usage
+ def GetUsage(self):
+ return self.Usage
+
+ def SetSupArchList(self, ArchList):
+ self.SupArchList = ArchList
+ def GetSupArchList(self):
+ return self.SupArchList
+
+ def SetHelpString(self, HelpString):
+ self.HelpString = HelpString
+ def GetHelpString(self):
+ return self.HelpString
+
+##
+# InfSpecialCommentObject
+#
+class InfSpecialCommentObject(InfSectionCommonDef):
+ def __init__(self):
+ self.SpecialComments = Sdict()
+ InfSectionCommonDef.__init__(self)
+
+ def SetSpecialComments(self, SepcialSectionList = None, Type = ''):
+ if Type == DT.TYPE_HOB_SECTION or \
+ Type == DT.TYPE_EVENT_SECTION or \
+ Type == DT.TYPE_BOOTMODE_SECTION:
+ for Item in SepcialSectionList:
+ if self.SpecialComments.has_key(Type):
+ ObjList = self.SpecialComments[Type]
+ ObjList.append(Item)
+ self.SpecialComments[Type] = ObjList
+ else:
+ ObjList = []
+ ObjList.append(Item)
+ self.SpecialComments[Type] = ObjList
+
+ return True
+
+ def GetSpecialComments(self):
+ return self.SpecialComments
+
+
+
+## ErrorInInf
+#
+# An encapsulate of Error for INF parser.
+#
+def ErrorInInf(Message=None, ErrorCode=None, LineInfo=None, RaiseError=True):
+ if ErrorCode == None:
+ ErrorCode = ToolError.FORMAT_INVALID
+ if LineInfo == None:
+ LineInfo = ['', -1, '']
+ Logger.Error("InfParser",
+ ErrorCode,
+ Message=Message,
+ File=LineInfo[0],
+ Line=LineInfo[1],
+ ExtraData=LineInfo[2],
+ RaiseError=RaiseError)
\ No newline at end of file diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfPackagesObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfPackagesObject.py new file mode 100644 index 0000000000..37399134db --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfPackagesObject.py @@ -0,0 +1,187 @@ +## @file
+# This file is used to define class objects of INF file [Packages] section.
+# It will consumed by InfParser.
+#
+# 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.
+
+'''
+InfPackageObject
+'''
+
+from Logger import StringTable as ST
+from Logger import ToolError
+import Logger.Log as Logger
+from Library import GlobalData
+
+from Library.Misc import Sdict
+from Library.ParserValidate import IsValidPath
+from Library.ExpressionValidate import IsValidFeatureFlagExp
+
+class InfPackageItem():
+ def __init__(self,
+ PackageName = '',
+ FeatureFlagExp = '',
+ HelpString = ''):
+ self.PackageName = PackageName
+ self.FeatureFlagExp = FeatureFlagExp
+ self.HelpString = HelpString
+ self.SupArchList = []
+
+ def SetPackageName(self, PackageName):
+ self.PackageName = PackageName
+ def GetPackageName(self):
+ return self.PackageName
+
+ def SetFeatureFlagExp(self, FeatureFlagExp):
+ self.FeatureFlagExp = FeatureFlagExp
+ def GetFeatureFlagExp(self):
+ return self.FeatureFlagExp
+
+ def SetHelpString(self, HelpString):
+ self.HelpString = HelpString
+ def GetHelpString(self):
+ return self.HelpString
+
+ def SetSupArchList(self, SupArchList):
+ self.SupArchList = SupArchList
+ def GetSupArchList(self):
+ return self.SupArchList
+
+
+## INF package section
+#
+#
+#
+class InfPackageObject():
+ def __init__(self):
+ self.Packages = Sdict()
+ #
+ # Macro defined in this section should be only used in this section.
+ #
+ self.Macros = {}
+
+ def SetPackages(self, PackageData, Arch = None):
+ IsValidFileFlag = False
+ SupArchList = []
+ for ArchItem in Arch:
+ #
+ # Validate Arch
+ #
+ if (ArchItem == '' or ArchItem == None):
+ ArchItem = 'COMMON'
+ SupArchList.append(ArchItem)
+
+ for PackageItem in PackageData:
+ PackageItemObj = InfPackageItem()
+ HelpStringObj = PackageItem[1]
+ CurrentLineOfPackItem = PackageItem[2]
+ PackageItem = PackageItem[0]
+ if HelpStringObj != None:
+ HelpString = HelpStringObj.HeaderComments + HelpStringObj.TailComments
+ PackageItemObj.SetHelpString(HelpString)
+ if len(PackageItem) >= 1:
+ #
+ # Validate file exist/format.
+ #
+ if IsValidPath(PackageItem[0], ''):
+ IsValidFileFlag = True
+ elif IsValidPath(PackageItem[0], GlobalData.gINF_MODULE_DIR):
+ IsValidFileFlag = True
+ elif IsValidPath(PackageItem[0], GlobalData.gWORKSPACE):
+ IsValidFileFlag = True
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID%(PackageItem[0]),
+ File=CurrentLineOfPackItem[2],
+ Line=CurrentLineOfPackItem[1],
+ ExtraData=CurrentLineOfPackItem[0])
+ return False
+ if IsValidFileFlag:
+ PackageItemObj.SetPackageName(PackageItem[0])
+ if len(PackageItem) == 2:
+ #
+ # Validate Feature Flag Express
+ #
+ if PackageItem[1].strip() == '':
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
+ File=CurrentLineOfPackItem[2],
+ Line=CurrentLineOfPackItem[1],
+ ExtraData=CurrentLineOfPackItem[0])
+ #
+ # Validate FFE
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(PackageItem[1].strip())
+ if not FeatureFlagRtv[0]:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]),
+ File=CurrentLineOfPackItem[2],
+ Line=CurrentLineOfPackItem[1],
+ ExtraData=CurrentLineOfPackItem[0])
+
+ PackageItemObj.SetFeatureFlagExp(PackageItem[1].strip())
+
+ if len(PackageItem) > 2:
+ #
+ # Invalid format of Package statement
+ #
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_PACKAGE_SECTION_CONTENT_ERROR,
+ File=CurrentLineOfPackItem[2],
+ Line=CurrentLineOfPackItem[1],
+ ExtraData=CurrentLineOfPackItem[0])
+ PackageItemObj.SetSupArchList(SupArchList)
+
+ #
+ # Determine package file name duplicate. Follow below rule:
+ #
+ # A package filename must not be duplicated within a [Packages]
+ # section. Package filenames may appear in multiple architectural
+ # [Packages] sections. A package filename listed in an
+ # architectural [Packages] section must not be listed in the common
+ # architectural [Packages] section.
+ #
+ # NOTE: This check will not report error now.
+ #
+ for Item in self.Packages:
+ if Item.GetPackageName() == PackageItemObj.GetPackageName():
+ ItemSupArchList = Item.GetSupArchList()
+ for ItemArch in ItemSupArchList:
+ for PackageItemObjArch in SupArchList:
+ if ItemArch == PackageItemObjArch:
+ #
+ # ST.ERR_INF_PARSER_ITEM_DUPLICATE
+ #
+ pass
+ if ItemArch.upper() == 'COMMON' or PackageItemObjArch.upper() == 'COMMON':
+ #
+ # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
+ #
+ pass
+
+ if self.Packages.has_key((PackageItemObj)):
+ PackageList = self.Packages[PackageItemObj]
+ PackageList.append(PackageItemObj)
+ self.Packages[PackageItemObj] = PackageList
+ else:
+ PackageList = []
+ PackageList.append(PackageItemObj)
+ self.Packages[PackageItemObj] = PackageList
+
+ return True
+
+ def GetPackages(self, Arch = None):
+ if Arch == None:
+ return self.Packages
\ No newline at end of file diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfPcdObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfPcdObject.py new file mode 100644 index 0000000000..fc5227451a --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfPcdObject.py @@ -0,0 +1,640 @@ +## @file
+# This file is used to define class objects of INF file [Pcds] section.
+# It will consumed by InfParser.
+#
+# 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.
+
+'''
+InfPcdObject
+'''
+import os
+import re
+
+from Logger import StringTable as ST
+from Logger import ToolError
+import Logger.Log as Logger
+from Library import GlobalData
+from Library import DataType as DT
+
+from Library.Misc import Sdict
+from Library.Misc import GetHelpStringByRemoveHashKey
+from Library.ParserValidate import IsValidPcdType
+from Library.ParserValidate import IsValidCVariableName
+from Library.ParserValidate import IsValidPcdValue
+from Library.ParserValidate import IsValidArch
+from Library.CommentParsing import ParseComment
+from Library.String import GetSplitValueList
+from Library.String import IsHexDigitUINT32
+from Library.ExpressionValidate import IsValidFeatureFlagExp
+from Parser.InfAsBuiltProcess import GetPackageListInfo
+from Parser.DecParser import Dec
+
+from Object.Parser.InfPackagesObject import InfPackageItem
+
+def ValidateArch(ArchItem, PcdTypeItem1, LineNo, SupArchDict, SupArchList):
+ #
+ # Validate Arch
+ #
+ if (ArchItem == '' or ArchItem == None):
+ ArchItem = 'COMMON'
+
+ if PcdTypeItem1.upper != DT.TAB_INF_FEATURE_PCD.upper():
+ ArchList = GetSplitValueList(ArchItem, ' ')
+ for ArchItemNew in ArchList:
+ if not IsValidArch(ArchItemNew):
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(ArchItemNew),
+ File=GlobalData.gINF_MODULE_NAME,
+ Line=LineNo,
+ ExtraData=ArchItemNew)
+ SupArchDict[PcdTypeItem1] = ArchList
+ else:
+ SupArchList.append(ArchItem)
+
+ return SupArchList, SupArchDict
+
+def ParsePcdComment(CommentList, PcdTypeItem, PcdItemObj):
+ CommentInsList = []
+ PreUsage = None
+ PreHelpText = ''
+ BlockFlag = -1
+ FFEHelpText = ''
+ CommentItemHelpText = ''
+ Count = 0
+ for CommentItem in CommentList:
+ Count = Count + 1
+ CommentItemUsage, CommentType, CommentString, CommentItemHelpText = ParseComment(CommentItem,
+ DT.ALL_USAGE_TOKENS,
+ {},
+ [],
+ False)
+ if CommentType and CommentString:
+ pass
+
+ if PcdTypeItem == 'FeaturePcd':
+ CommentItemUsage = DT.USAGE_ITEM_CONSUMES
+ if CommentItemHelpText == None:
+ CommentItemHelpText = ''
+
+ if Count == 1:
+ FFEHelpText = CommentItemHelpText
+ else:
+ FFEHelpText = FFEHelpText + DT.END_OF_LINE + CommentItemHelpText
+
+ if Count == len(CommentList):
+ CommentItemHelpText = FFEHelpText
+ BlockFlag = 4
+ else:
+ continue
+
+ if CommentItemHelpText == None:
+ CommentItemHelpText = ''
+ if Count == len(CommentList) and CommentItemUsage == DT.ITEM_UNDEFINED:
+ CommentItemHelpText = DT.END_OF_LINE
+
+ if Count == len(CommentList) and (BlockFlag == 1 or BlockFlag == 2):
+ if CommentItemUsage == DT.ITEM_UNDEFINED:
+ BlockFlag = 4
+ else:
+ BlockFlag = 3
+ elif BlockFlag == -1 and Count == len(CommentList):
+ BlockFlag = 4
+
+ if BlockFlag == -1 or BlockFlag == 1 or BlockFlag == 2:
+ if CommentItemUsage == DT.ITEM_UNDEFINED:
+ if BlockFlag == -1:
+ BlockFlag = 1
+ elif BlockFlag == 1:
+ BlockFlag = 2
+ else:
+ if BlockFlag == 1 or BlockFlag == 2:
+ BlockFlag = 3
+ elif BlockFlag == -1:
+ BlockFlag = 4
+ #
+ # Combine two comment line if they are generic comment
+ #
+ if CommentItemUsage == PreUsage == DT.ITEM_UNDEFINED:
+ CommentItemHelpText = PreHelpText + DT.END_OF_LINE + CommentItemHelpText
+
+ PreHelpText = CommentItemHelpText
+
+ if BlockFlag == 4:
+ CommentItemIns = InfPcdItemCommentContent()
+ CommentItemIns.SetUsageItem(CommentItemUsage)
+ CommentItemIns.SetHelpStringItem(CommentItemHelpText)
+ CommentInsList.append(CommentItemIns)
+
+ BlockFlag = -1
+ PreUsage = None
+ PreHelpText = ''
+
+ elif BlockFlag == 3:
+ #
+ # Add previous help string
+ #
+ CommentItemIns = InfPcdItemCommentContent()
+ CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
+ if PreHelpText == '' or PreHelpText.endswith(DT.END_OF_LINE):
+ PreHelpText += DT.END_OF_LINE
+ CommentItemIns.SetHelpStringItem(PreHelpText)
+ CommentInsList.append(CommentItemIns)
+ #
+ # Add Current help string
+ #
+ CommentItemIns = InfPcdItemCommentContent()
+ CommentItemIns.SetUsageItem(CommentItemUsage)
+ CommentItemIns.SetHelpStringItem(CommentItemHelpText)
+ CommentInsList.append(CommentItemIns)
+
+ BlockFlag = -1
+ PreUsage = None
+ PreHelpText = ''
+
+ else:
+ PreUsage = CommentItemUsage
+ PreHelpText = CommentItemHelpText
+
+ PcdItemObj.SetHelpStringList(CommentInsList)
+
+ return PcdItemObj
+
+class InfPcdItemCommentContent():
+ def __init__(self):
+ #
+ # ## SOMETIMES_CONSUMES ## HelpString
+ #
+ self.UsageItem = ''
+ #
+ # Help String
+ #
+ self.HelpStringItem = ''
+
+ def SetUsageItem(self, UsageItem):
+ self.UsageItem = UsageItem
+ def GetUsageItem(self):
+ return self.UsageItem
+
+ def SetHelpStringItem(self, HelpStringItem):
+ self.HelpStringItem = HelpStringItem
+ def GetHelpStringItem(self):
+ return self.HelpStringItem
+
+## InfPcdItem
+#
+# This class defined Pcd item used in Module files
+#
+# @param CName: Input value for CName, default is ''
+# @param Token: Input value for Token, default is ''
+# @param TokenSpaceGuidCName: Input value for TokenSpaceGuidCName, default
+# is ''
+# @param DatumType: Input value for DatumType, default is ''
+# @param MaxDatumSize: Input value for MaxDatumSize, default is ''
+# @param DefaultValue: Input value for DefaultValue, default is ''
+# @param ItemType: Input value for ItemType, default is ''
+# @param ValidUsage: Input value for ValidUsage, default is []
+# @param SkuInfoList: Input value for SkuInfoList, default is {}
+# @param SupModuleList: Input value for SupModuleList, default is []
+#
+class InfPcdItem():
+ def __init__(self):
+ self.CName = ''
+ self.Token = ''
+ self.TokenSpaceGuidCName = ''
+ self.TokenSpaceGuidValue = ''
+ self.DatumType = ''
+ self.MaxDatumSize = ''
+ self.DefaultValue = ''
+ self.Offset = ''
+ self.ValidUsage = ''
+ self.ItemType = ''
+ self.SupModuleList = []
+ self.HelpStringList = []
+ self.FeatureFlagExp = ''
+ self.SupArchList = []
+ self.PcdErrorsList = []
+
+ def SetCName(self, CName):
+ self.CName = CName
+ def GetCName(self):
+ return self.CName
+
+ def SetToken(self, Token):
+ self.Token = Token
+ def GetToken(self):
+ return self.Token
+
+ def SetTokenSpaceGuidCName(self, TokenSpaceGuidCName):
+ self.TokenSpaceGuidCName = TokenSpaceGuidCName
+ def GetTokenSpaceGuidCName(self):
+ return self.TokenSpaceGuidCName
+
+ def SetTokenSpaceGuidValue(self, TokenSpaceGuidValue):
+ self.TokenSpaceGuidValue = TokenSpaceGuidValue
+ def GetTokenSpaceGuidValue(self):
+ return self.TokenSpaceGuidValue
+
+ def SetDatumType(self, DatumType):
+ self.DatumType = DatumType
+ def GetDatumType(self):
+ return self.DatumType
+
+ def SetMaxDatumSize(self, MaxDatumSize):
+ self.MaxDatumSize = MaxDatumSize
+ def GetMaxDatumSize(self):
+ return self.MaxDatumSize
+
+ def SetDefaultValue(self, DefaultValue):
+ self.DefaultValue = DefaultValue
+ def GetDefaultValue(self):
+ return self.DefaultValue
+
+ def SetPcdErrorsList(self, PcdErrorsList):
+ self.PcdErrorsList = PcdErrorsList
+ def GetPcdErrorsList(self):
+ return self.PcdErrorsList
+
+ def SetItemType(self, ItemType):
+ self.ItemType = ItemType
+ def GetItemType(self):
+ return self.ItemType
+
+ def SetSupModuleList(self, SupModuleList):
+ self.SupModuleList = SupModuleList
+ def GetSupModuleList(self):
+ return self.SupModuleList
+
+ def SetHelpStringList(self, HelpStringList):
+ self.HelpStringList = HelpStringList
+ def GetHelpStringList(self):
+ return self.HelpStringList
+
+ def SetFeatureFlagExp(self, FeatureFlagExp):
+ self.FeatureFlagExp = FeatureFlagExp
+ def GetFeatureFlagExp(self):
+ return self.FeatureFlagExp
+
+ def SetSupportArchList(self, ArchList):
+ self.SupArchList = ArchList
+ def GetSupportArchList(self):
+ return self.SupArchList
+
+ def SetOffset(self, Offset):
+ self.Offset = Offset
+ def GetOffset(self):
+ return self.Offset
+
+##
+#
+#
+#
+class InfPcdObject():
+ def __init__(self, FileName):
+ self.Pcds = Sdict()
+ self.FileName = FileName
+
+ def SetPcds(self, PcdContent, KeysList = None, PackageInfo = None):
+
+ if GlobalData.gIS_BINARY_INF:
+ self.SetAsBuildPcds(PcdContent, KeysList, PackageInfo)
+ return True
+
+ #
+ # Validate Arch
+ #
+ SupArchList = []
+ SupArchDict = {}
+ PcdTypeItem = ''
+ for (PcdTypeItem1, ArchItem, LineNo) in KeysList:
+ SupArchList, SupArchDict = ValidateArch(ArchItem, PcdTypeItem1, LineNo, SupArchDict, SupArchList)
+
+ #
+ # Validate PcdType
+ #
+ if (PcdTypeItem1 == '' or PcdTypeItem1 == None):
+ return False
+ else:
+ if not IsValidPcdType(PcdTypeItem1):
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_PCD_SECTION_TYPE_ERROR%(DT.PCD_USAGE_TYPE_LIST_OF_MODULE),
+ File=GlobalData.gINF_MODULE_NAME,
+ Line=LineNo,
+ ExtraData=PcdTypeItem1)
+ return False
+
+ PcdTypeItem = PcdTypeItem1
+
+ for PcdItem in PcdContent:
+ PcdItemObj = InfPcdItem()
+ CommentList = PcdItem[1]
+ CurrentLineOfPcdItem = PcdItem[2]
+ PcdItem = PcdItem[0]
+
+ if CommentList != None and len(CommentList) != 0:
+ PcdItemObj = ParsePcdComment(CommentList, PcdTypeItem, PcdItemObj)
+ else:
+ CommentItemIns = InfPcdItemCommentContent()
+ CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
+ PcdItemObj.SetHelpStringList([CommentItemIns])
+
+ if len(PcdItem) >= 1 and len(PcdItem) <= 3:
+ PcdItemObj = SetPcdName(PcdItem, CurrentLineOfPcdItem, PcdItemObj)
+
+ if len(PcdItem) >= 2 and len(PcdItem) <= 3:
+ #
+ # Contain PcdName and Value, validate value.
+ #
+ if IsValidPcdValue(PcdItem[1]) or PcdItem[1].strip() == "":
+ PcdItemObj.SetDefaultValue(PcdItem[1])
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_PCD_VALUE_INVALID,
+ File=CurrentLineOfPcdItem[2],
+ Line=CurrentLineOfPcdItem[1],
+ ExtraData=PcdItem[1])
+
+ if len(PcdItem) == 3:
+ #
+ # Contain PcdName, value, and FeatureFlag express
+ #
+ #
+ # Validate Feature Flag Express
+ #
+ if PcdItem[2].strip() == '':
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
+ File=CurrentLineOfPcdItem[2],
+ Line=CurrentLineOfPcdItem[1],
+ ExtraData=CurrentLineOfPcdItem[0])
+ #
+ # Validate FFE
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(PcdItem[2].strip())
+ if not FeatureFlagRtv[0]:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]),
+ File=CurrentLineOfPcdItem[2],
+ Line=CurrentLineOfPcdItem[1],
+ ExtraData=CurrentLineOfPcdItem[0])
+ PcdItemObj.SetFeatureFlagExp(PcdItem[2])
+
+ if len(PcdItem) < 1 or len(PcdItem) > 3:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_PCD_SECTION_CONTENT_ERROR,
+ File=CurrentLineOfPcdItem[2],
+ Line=CurrentLineOfPcdItem[1],
+ ExtraData=CurrentLineOfPcdItem[0])
+ return False
+
+ if PcdTypeItem.upper != DT.TAB_INF_FEATURE_PCD.upper():
+ PcdItemObj.SetSupportArchList(SupArchDict[PcdTypeItem])
+ else:
+ PcdItemObj.SetSupportArchList(SupArchList)
+
+ if self.Pcds.has_key((PcdTypeItem, PcdItemObj)):
+ PcdsList = self.Pcds[PcdTypeItem, PcdItemObj]
+ PcdsList.append(PcdItemObj)
+ self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList
+ else:
+ PcdsList = []
+ PcdsList.append(PcdItemObj)
+ self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList
+
+ return True
+
+ def SetAsBuildPcds(self, PcdContent, KeysList = None, PackageInfo = None):
+ for PcdItem in PcdContent:
+ PcdItemObj = InfPcdItem()
+ CommentList = PcdItem[1]
+ CurrentLineOfPcdItem = PcdItem[2]
+ PcdItem = PcdItem[0]
+ CommentString = ''
+ for CommmentLine in CommentList:
+ CommentString += GetHelpStringByRemoveHashKey(CommmentLine)
+
+ PcdItemObj.SetHelpStringList(CommentString)
+ PcdItemObj.SetItemType(KeysList[0][0])
+ #
+ # Set PcdTokenSpaceCName and CName
+ #
+ PcdItemObj = SetPcdName(PcdItem, CurrentLineOfPcdItem, PcdItemObj)
+ #
+ # Set Value/DatumType/MaxDatumSize/Token
+ #
+ PcdItemObj = SetValueDatumTypeMaxSizeToken(PcdItem,
+ CurrentLineOfPcdItem,
+ PcdItemObj,
+ KeysList[0][1],
+ PackageInfo)
+
+ PcdTypeItem = KeysList[0][0]
+ if self.Pcds.has_key((PcdTypeItem, PcdItemObj)):
+ PcdsList = self.Pcds[PcdTypeItem, PcdItemObj]
+ PcdsList.append(PcdItemObj)
+ self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList
+ else:
+ PcdsList = []
+ PcdsList.append(PcdItemObj)
+ self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList
+
+ def GetPcds(self):
+ return self.Pcds
+
+def ParserPcdInfoInDec(String):
+ ValueList = GetSplitValueList(String, DT.TAB_VALUE_SPLIT, 3)
+
+ #
+ # DatumType, Token
+ #
+ return ValueList[2], ValueList[3]
+
+def SetValueDatumTypeMaxSizeToken(PcdItem, CurrentLineOfPcdItem, PcdItemObj, Arch, PackageInfo = None):
+ #
+ # Package information not been generated currently, we need to parser INF file to get information.
+ #
+ if not PackageInfo:
+ PackageInfo = []
+ InfFileName = CurrentLineOfPcdItem[2]
+ PackageInfoList = GetPackageListInfo(InfFileName, GlobalData.gWORKSPACE, -1)
+ for PackageInfoListItem in PackageInfoList:
+ PackageInfoIns = InfPackageItem()
+ PackageInfoIns.SetPackageName(PackageInfoListItem)
+ PackageInfo.append(PackageInfoIns)
+
+ PcdInfoInDecHasFound = False
+ for PackageItem in PackageInfo:
+ if PcdInfoInDecHasFound:
+ break
+ PackageName = PackageItem.PackageName
+ #
+ # Open DEC file to get information
+ #
+ FullFileName = os.path.normpath(os.path.realpath(os.path.join(GlobalData.gWORKSPACE, PackageName)))
+
+ DecParser = Dec(FullFileName)
+ #
+ # Find PCD information.
+ #
+ DecPcdsDict = DecParser.GetPcdSectionObject().ValueDict
+ for Key in DecPcdsDict.keys():
+ if (Key[0] == 'PCDSDYNAMICEX' and PcdItemObj.GetItemType() == 'PcdEx') and \
+ (Key[1] == 'COMMON' or Key[1] == Arch):
+ for PcdInDec in DecPcdsDict[Key]:
+ if PcdInDec.TokenCName == PcdItemObj.CName and \
+ PcdInDec.TokenSpaceGuidCName == PcdItemObj.TokenSpaceGuidCName:
+ PcdItemObj.SetToken(PcdInDec.TokenValue)
+ PcdItemObj.SetDatumType(PcdInDec.DatumType)
+ PcdItemObj.SetSupportArchList([Arch])
+
+ if (Key[0] == 'PCDSPATCHABLEINMODULE' and PcdItemObj.GetItemType() == 'PatchPcd') and \
+ (Key[1] == 'COMMON' or Key[1] == Arch):
+ for PcdInDec in DecPcdsDict[Key]:
+ if PcdInDec.TokenCName == PcdItemObj.CName and \
+ PcdInDec.TokenSpaceGuidCName == PcdItemObj.TokenSpaceGuidCName:
+ PcdItemObj.SetToken(PcdInDec.TokenValue)
+ PcdItemObj.SetDatumType(PcdInDec.DatumType)
+ PcdItemObj.SetSupportArchList([Arch])
+
+ if PcdItemObj.GetDatumType() == 'VOID*':
+ PcdItemObj.SetMaxDatumSize('%s'%(len(GetSplitValueList(PcdItem[1], DT.TAB_COMMA_SPLIT))))
+
+ DecGuidsDict = DecParser.GetGuidSectionObject().ValueDict
+ for Key in DecGuidsDict.keys():
+ if Key == 'COMMON' or Key == Arch:
+ for GuidInDec in DecGuidsDict[Key]:
+ if GuidInDec.GuidCName == PcdItemObj.TokenSpaceGuidCName:
+ PcdItemObj.SetTokenSpaceGuidValue(GuidInDec.GuidString)
+
+ #
+ # Validate Value.
+ #
+ if ValidatePcdValueOnDatumType(PcdItem[1], PcdItemObj.GetDatumType()):
+ PcdItemObj.SetDefaultValue(PcdItem[1])
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_ASBUILD_PCD_VALUE_INVALID%("\"" + PcdItem[1] + "\"", "\"" +
+ PcdItemObj.GetDatumType() + "\""),
+ File=CurrentLineOfPcdItem[2],
+ Line=CurrentLineOfPcdItem[1],
+ ExtraData=CurrentLineOfPcdItem[0])
+ #
+ # validate offset
+ #
+ if PcdItemObj.GetItemType().upper() == DT.TAB_INF_PATCH_PCD.upper():
+ if not IsHexDigitUINT32(PcdItem[2]):
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_ASBUILD_PCD_OFFSET_FORMAT_INVALID%("\"" + PcdItem[2] + "\""),
+ File=CurrentLineOfPcdItem[2],
+ Line=CurrentLineOfPcdItem[1],
+ ExtraData=CurrentLineOfPcdItem[0])
+ PcdItemObj.SetOffset(PcdItem[2])
+
+ if PcdItemObj.GetToken() == '' or PcdItemObj.GetDatumType() == '':
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_ASBUILD_PCD_DECLARITION_MISS%("\"" + PcdItem[0] + "\""),
+ File=CurrentLineOfPcdItem[2],
+ Line=CurrentLineOfPcdItem[1],
+ ExtraData=CurrentLineOfPcdItem[0])
+
+ return PcdItemObj
+
+def ValidatePcdValueOnDatumType(Value, Type):
+
+ Value = Value.strip()
+ #
+ # Boolean type only allow 0x00 or 0x01 as value per INF spec
+ #
+ if Type == 'BOOLEAN':
+ if not (Value == '0x00' or Value == '0x01'):
+ return False
+ elif Type == 'VOID*':
+ if not Value.startswith("{"):
+ return False
+ if not Value.endswith("}"):
+ return False
+ #
+ # Strip "{" at head and "}" at tail.
+ #
+ Value = Value[1:-1]
+ ValueList = GetSplitValueList(Value, DT.TAB_COMMA_SPLIT)
+
+ ReIsValidHexByte = re.compile("^0x[0-9a-f]{1,2}$", re.IGNORECASE)
+ for ValueItem in ValueList:
+ if not ReIsValidHexByte.match(ValueItem):
+ return False
+
+ elif Type == 'UINT8' or Type == 'UINT16' or Type == 'UINT32' or Type == 'UINT64':
+
+ ReIsValidUint8z = re.compile('^0[x|X][a-fA-F0-9]{2}$')
+ ReIsValidUint16z = re.compile('^0[x|X][a-fA-F0-9]{4}$')
+ ReIsValidUint32z = re.compile('^0[x|X][a-fA-F0-9]{8}$')
+ ReIsValidUint64z = re.compile('^0[x|X][a-fA-F0-9]{16}$')
+
+ if not ReIsValidUint8z.match(Value) and Type == 'UINT8':
+ return False
+ elif not ReIsValidUint16z.match(Value) and Type == 'UINT16':
+ return False
+ elif not ReIsValidUint32z.match(Value) and Type == 'UINT32':
+ return False
+ elif not ReIsValidUint64z.match(Value) and Type == 'UINT64':
+ return False
+ else:
+ #
+ # Since we assume the DEC file always correct, should never go to here.
+ #
+ pass
+
+ return True
+
+def SetPcdName(PcdItem, CurrentLineOfPcdItem, PcdItemObj):
+ #
+ # Only PCD Name specified
+ # <PcdName> ::= <TokenSpaceGuidCName> "." <TokenCName>
+ #
+ PcdId = GetSplitValueList(PcdItem[0], DT.TAB_SPLIT)
+ if len(PcdId) != 2:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_PCD_NAME_FORMAT_ERROR,
+ File=CurrentLineOfPcdItem[2],
+ Line=CurrentLineOfPcdItem[1],
+ ExtraData=CurrentLineOfPcdItem[0])
+ else:
+ #
+ # Validate PcdTokenSpaceGuidCName
+ #
+ if not IsValidCVariableName(PcdId[0]):
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_PCD_CVAR_GUID,
+ File=CurrentLineOfPcdItem[2],
+ Line=CurrentLineOfPcdItem[1],
+ ExtraData=PcdId[0])
+ if not IsValidCVariableName(PcdId[1]):
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_PCD_CVAR_PCDCNAME,
+ File=CurrentLineOfPcdItem[2],
+ Line=CurrentLineOfPcdItem[1],
+ ExtraData=PcdId[1])
+ PcdItemObj.SetTokenSpaceGuidCName(PcdId[0])
+ PcdItemObj.SetCName(PcdId[1])
+
+ return PcdItemObj
\ No newline at end of file diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfPpiObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfPpiObject.py new file mode 100644 index 0000000000..4df62bb459 --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfPpiObject.py @@ -0,0 +1,343 @@ +## @file
+# This file is used to define class objects of INF file [Ppis] section.
+# It will consumed by InfParser.
+#
+# 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.
+
+'''
+InfPpiObject
+'''
+
+from Library.ParserValidate import IsValidCVariableName
+from Library.CommentParsing import ParseComment
+from Library.ExpressionValidate import IsValidFeatureFlagExp
+
+from Library.Misc import Sdict
+from Library import DataType as DT
+import Logger.Log as Logger
+from Logger import ToolError
+from Logger import StringTable as ST
+
+def ParsePpiComment(CommentsList, InfPpiItemObj):
+ PreNotify = None
+ PreUsage = None
+ PreHelpText = ''
+ BlockFlag = -1
+ CommentInsList = []
+ Count = 0
+ for CommentItem in CommentsList:
+ Count = Count + 1
+ CommentItemUsage, \
+ CommentItemNotify, \
+ CommentItemString, \
+ CommentItemHelpText = \
+ ParseComment(CommentItem,
+ DT.ALL_USAGE_TOKENS,
+ DT.PPI_NOTIFY_TOKENS,
+ ['PPI'],
+ False)
+
+ #
+ # To avoid PyLint error
+ #
+ if CommentItemString:
+ pass
+
+ if CommentItemHelpText == None:
+ CommentItemHelpText = ''
+ if Count == len(CommentsList) and CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
+ CommentItemHelpText = DT.END_OF_LINE
+ #
+ # For the Last comment Item, set BlockFlag.
+ #
+ if Count == len(CommentsList):
+ if BlockFlag == 1 or BlockFlag == 2:
+ if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
+ BlockFlag = 4
+ else:
+ BlockFlag = 3
+ elif BlockFlag == -1:
+ BlockFlag = 4
+
+ #
+ # Comment USAGE and NOTIFY information are "UNDEFINED"
+ #
+ if BlockFlag == -1 or BlockFlag == 1 or BlockFlag == 2:
+ if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
+ if BlockFlag == -1:
+ BlockFlag = 1
+ elif BlockFlag == 1:
+ BlockFlag = 2
+ else:
+ if BlockFlag == 1 or BlockFlag == 2:
+ BlockFlag = 3
+ #
+ # An item have Usage or Notify information and the first time get this information
+ #
+ elif BlockFlag == -1:
+ BlockFlag = 4
+
+ #
+ # Combine two comment line if they are generic comment
+ #
+ if CommentItemUsage == CommentItemNotify == PreUsage == PreNotify == DT.ITEM_UNDEFINED:
+ CommentItemHelpText = PreHelpText + DT.END_OF_LINE + CommentItemHelpText
+ #
+ # Store this information for next line may still need combine operation.
+ #
+ PreHelpText = CommentItemHelpText
+
+ if BlockFlag == 4:
+ CommentItemIns = InfPpiItemCommentContent()
+ CommentItemIns.SetUsage(CommentItemUsage)
+ CommentItemIns.SetNotify(CommentItemNotify)
+ CommentItemIns.SetHelpStringItem(CommentItemHelpText)
+ CommentInsList.append(CommentItemIns)
+
+ BlockFlag = -1
+ PreUsage = None
+ PreNotify = None
+ PreHelpText = ''
+
+ elif BlockFlag == 3:
+ #
+ # Add previous help string
+ #
+ CommentItemIns = InfPpiItemCommentContent()
+ CommentItemIns.SetUsage(DT.ITEM_UNDEFINED)
+ CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)
+ if PreHelpText == '' or PreHelpText.endswith(DT.END_OF_LINE):
+ PreHelpText += DT.END_OF_LINE
+ CommentItemIns.SetHelpStringItem(PreHelpText)
+ CommentInsList.append(CommentItemIns)
+ #
+ # Add Current help string
+ #
+ CommentItemIns = InfPpiItemCommentContent()
+ CommentItemIns.SetUsage(CommentItemUsage)
+ CommentItemIns.SetNotify(CommentItemNotify)
+ CommentItemIns.SetHelpStringItem(CommentItemHelpText)
+ CommentInsList.append(CommentItemIns)
+
+ BlockFlag = -1
+ PreUsage = None
+ PreNotify = None
+ PreHelpText = ''
+ else:
+ PreUsage = CommentItemUsage
+ PreNotify = CommentItemNotify
+ PreHelpText = CommentItemHelpText
+
+ InfPpiItemObj.SetCommentList(CommentInsList)
+
+ return InfPpiItemObj
+
+class InfPpiItemCommentContent():
+ def __init__(self):
+ #
+ # ## SOMETIMES_CONSUMES ## HelpString
+ #
+ self.UsageItem = ''
+ #
+ # Help String
+ #
+ self.HelpStringItem = ''
+ self.Notify = ''
+ self.CommentList = []
+
+ def SetUsage(self, UsageItem):
+ self.UsageItem = UsageItem
+ def GetUsage(self):
+ return self.UsageItem
+
+ def SetNotify(self, Notify):
+ if Notify != DT.ITEM_UNDEFINED:
+ self.Notify = 'true'
+ def GetNotify(self):
+ return self.Notify
+
+ def SetHelpStringItem(self, HelpStringItem):
+ self.HelpStringItem = HelpStringItem
+ def GetHelpStringItem(self):
+ return self.HelpStringItem
+
+class InfPpiItem():
+ def __init__(self):
+ self.Name = ''
+ self.FeatureFlagExp = ''
+ self.SupArchList = []
+ self.CommentList = []
+
+ def SetName(self, Name):
+ self.Name = Name
+ def GetName(self):
+ return self.Name
+
+ def SetSupArchList(self, SupArchList):
+ self.SupArchList = SupArchList
+ def GetSupArchList(self):
+ return self.SupArchList
+
+ def SetCommentList(self, CommentList):
+ self.CommentList = CommentList
+ def GetCommentList(self):
+ return self.CommentList
+
+ def SetFeatureFlagExp(self, FeatureFlagExp):
+ self.FeatureFlagExp = FeatureFlagExp
+ def GetFeatureFlagExp(self):
+ return self.FeatureFlagExp
+##
+#
+#
+#
+class InfPpiObject():
+ def __init__(self):
+ self.Ppis = Sdict()
+ #
+ # Macro defined in this section should be only used in this section.
+ #
+ self.Macros = {}
+
+ def SetPpi(self, PpiList, Arch = None):
+ __SupArchList = []
+ for ArchItem in Arch:
+ #
+ # Validate Arch
+ #
+ if (ArchItem == '' or ArchItem == None):
+ ArchItem = 'COMMON'
+ __SupArchList.append(ArchItem)
+
+ for Item in PpiList:
+ #
+ # Get Comment content of this protocol
+ #
+ CommentsList = None
+ if len(Item) == 3:
+ CommentsList = Item[1]
+ CurrentLineOfItem = Item[2]
+ Item = Item[0]
+ InfPpiItemObj = InfPpiItem()
+ if len(Item) >= 1 and len(Item) <= 2:
+ #
+ # Only CName contained
+ #
+ if not IsValidCVariableName(Item[0]):
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_INVALID_CNAME%(Item[0]),
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ if (Item[0] != ''):
+ InfPpiItemObj.SetName(Item[0])
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_CNAME_MISSING,
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ #
+ # Have FeatureFlag information
+ #
+ if len(Item) == 2:
+ #
+ # Contained CName and Feature Flag Express
+ # <statements> ::= <CName> ["|" <FeatureFlagExpress>]
+ # Item[1] should not be empty
+ #
+ if Item[1].strip() == '':
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ #
+ # Validate Feature Flag Express for PPI entry
+ # Item[1] contain FFE information
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip())
+ if not FeatureFlagRtv[0]:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]),
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ InfPpiItemObj.SetFeatureFlagExp(Item[1])
+ if len(Item) != 1 and len(Item) != 2:
+ #
+ # Invalid format of Ppi statement
+ #
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR,
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+
+ #
+ # Get/Set Usage and HelpString for PPI entry
+ #
+ if CommentsList != None and len(CommentsList) != 0:
+ InfPpiItemObj = ParsePpiComment(CommentsList, InfPpiItemObj)
+ else:
+ CommentItemIns = InfPpiItemCommentContent()
+ CommentItemIns.SetUsage(DT.ITEM_UNDEFINED)
+ CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)
+ InfPpiItemObj.SetCommentList([CommentItemIns])
+
+ InfPpiItemObj.SetSupArchList(__SupArchList)
+
+ #
+ # Determine PPI name duplicate. Follow below rule:
+ #
+ # A PPI must not be duplicated within a [Ppis] section.
+ # A PPI may appear in multiple architectural [Ppis]
+ # sections. A PPI listed in an architectural [Ppis]
+ # section must not be listed in the common architectural
+ # [Ppis] section.
+ #
+ # NOTE: This check will not report error now.
+ #
+ for Item in self.Ppis:
+ if Item.GetName() == InfPpiItemObj.GetName():
+ ItemSupArchList = Item.GetSupArchList()
+ for ItemArch in ItemSupArchList:
+ for PpiItemObjArch in __SupArchList:
+ if ItemArch == PpiItemObjArch:
+ #
+ # ST.ERR_INF_PARSER_ITEM_DUPLICATE
+ #
+ pass
+ if ItemArch.upper() == 'COMMON' or PpiItemObjArch.upper() == 'COMMON':
+ #
+ # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
+ #
+ pass
+
+ if self.Ppis.has_key((InfPpiItemObj)):
+ PpiList = self.Ppis[InfPpiItemObj]
+ PpiList.append(InfPpiItemObj)
+ self.Ppis[InfPpiItemObj] = PpiList
+ else:
+ PpiList = []
+ PpiList.append(InfPpiItemObj)
+ self.Ppis[InfPpiItemObj] = PpiList
+
+ return True
+
+
+ def GetPpi(self):
+ return self.Ppis
\ No newline at end of file diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfProtocolObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfProtocolObject.py new file mode 100644 index 0000000000..c94e53c98f --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfProtocolObject.py @@ -0,0 +1,311 @@ +## @file
+# This file is used to define class objects of INF file [Protocols] section.
+# It will consumed by InfParser.
+#
+# 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.
+
+'''
+InfProtocolObject
+'''
+
+from Library.ParserValidate import IsValidCVariableName
+from Library.CommentParsing import ParseComment
+from Library.ExpressionValidate import IsValidFeatureFlagExp
+
+from Library.Misc import Sdict
+
+from Object.Parser.InfMisc import ErrorInInf
+
+from Library import DataType as DT
+from Logger import StringTable as ST
+
+def ParseProtocolComment(CommentsList, InfProtocolItemObj):
+ CommentInsList = []
+ PreUsage = None
+ PreNotify = None
+ PreHelpText = ''
+ BlockFlag = -1
+ Count = 0
+ for CommentItem in CommentsList:
+ Count = Count + 1
+ CommentItemUsage, \
+ CommentItemNotify, \
+ CommentItemString, \
+ CommentItemHelpText = \
+ ParseComment(CommentItem,
+ DT.PROTOCOL_USAGE_TOKENS,
+ DT.PROTOCOL_NOTIFY_TOKENS,
+ ['PROTOCOL'],
+ False)
+
+ if CommentItemString:
+ pass
+
+ if CommentItemHelpText == None:
+ CommentItemHelpText = ''
+ if Count == len(CommentsList) and CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
+ CommentItemHelpText = DT.END_OF_LINE
+
+ if Count == len(CommentsList):
+ if BlockFlag == 1 or BlockFlag == 2:
+ if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
+ BlockFlag = 4
+ else:
+ BlockFlag = 3
+ elif BlockFlag == -1:
+ BlockFlag = 4
+
+ if BlockFlag == -1 or BlockFlag == 1 or BlockFlag == 2:
+ if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
+ if BlockFlag == -1:
+ BlockFlag = 1
+ elif BlockFlag == 1:
+ BlockFlag = 2
+ else:
+ if BlockFlag == 1 or BlockFlag == 2:
+ BlockFlag = 3
+ elif BlockFlag == -1:
+ BlockFlag = 4
+
+ #
+ # Combine two comment line if they are generic comment
+ #
+ if CommentItemUsage == CommentItemNotify == PreUsage == PreNotify == DT.ITEM_UNDEFINED:
+ CommentItemHelpText = PreHelpText + DT.END_OF_LINE + CommentItemHelpText
+
+ PreHelpText = CommentItemHelpText
+
+ if BlockFlag == 4:
+ CommentItemIns = InfProtocolItemCommentContent()
+ CommentItemIns.SetUsageItem(CommentItemUsage)
+ CommentItemIns.SetNotify(CommentItemNotify)
+ CommentItemIns.SetHelpStringItem(CommentItemHelpText)
+ CommentInsList.append(CommentItemIns)
+
+ BlockFlag = -1
+ PreUsage = None
+ PreNotify = None
+ PreHelpText = ''
+
+ elif BlockFlag == 3:
+ #
+ # Add previous help string
+ #
+ CommentItemIns = InfProtocolItemCommentContent()
+ CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
+ CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)
+ if PreHelpText == '' or PreHelpText.endswith(DT.END_OF_LINE):
+ PreHelpText += DT.END_OF_LINE
+ CommentItemIns.SetHelpStringItem(PreHelpText)
+ CommentInsList.append(CommentItemIns)
+ #
+ # Add Current help string
+ #
+ CommentItemIns = InfProtocolItemCommentContent()
+ CommentItemIns.SetUsageItem(CommentItemUsage)
+ CommentItemIns.SetNotify(CommentItemNotify)
+ CommentItemIns.SetHelpStringItem(CommentItemHelpText)
+ CommentInsList.append(CommentItemIns)
+
+ BlockFlag = -1
+ PreUsage = None
+ PreNotify = None
+ PreHelpText = ''
+
+ else:
+ PreUsage = CommentItemUsage
+ PreNotify = CommentItemNotify
+ PreHelpText = CommentItemHelpText
+
+ InfProtocolItemObj.SetCommentList(CommentInsList)
+
+ return InfProtocolItemObj
+
+class InfProtocolItemCommentContent():
+ def __init__(self):
+ #
+ # ## SOMETIMES_CONSUMES ## HelpString
+ #
+ self.UsageItem = ''
+ #
+ # Help String
+ #
+ self.HelpStringItem = ''
+ self.Notify = ''
+ self.CommentList = []
+
+ def SetUsageItem(self, UsageItem):
+ self.UsageItem = UsageItem
+ def GetUsageItem(self):
+ return self.UsageItem
+
+ def SetNotify(self, Notify):
+ if Notify != DT.ITEM_UNDEFINED:
+ self.Notify = 'true'
+ def GetNotify(self):
+ return self.Notify
+
+ def SetHelpStringItem(self, HelpStringItem):
+ self.HelpStringItem = HelpStringItem
+ def GetHelpStringItem(self):
+ return self.HelpStringItem
+
+class InfProtocolItem():
+ def __init__(self):
+ self.Name = ''
+ self.FeatureFlagExp = ''
+ self.SupArchList = []
+ self.CommentList = []
+
+ def SetName(self, Name):
+ self.Name = Name
+ def GetName(self):
+ return self.Name
+
+ def SetFeatureFlagExp(self, FeatureFlagExp):
+ self.FeatureFlagExp = FeatureFlagExp
+ def GetFeatureFlagExp(self):
+ return self.FeatureFlagExp
+
+ def SetSupArchList(self, SupArchList):
+ self.SupArchList = SupArchList
+ def GetSupArchList(self):
+ return self.SupArchList
+
+ def SetCommentList(self, CommentList):
+ self.CommentList = CommentList
+ def GetCommentList(self):
+ return self.CommentList
+
+##
+#
+#
+#
+class InfProtocolObject():
+ def __init__(self):
+ self.Protocols = Sdict()
+ #
+ # Macro defined in this section should be only used in this section.
+ #
+ self.Macros = {}
+
+ def SetProtocol(self, ProtocolContent, Arch = None,):
+ __SupArchList = []
+ for ArchItem in Arch:
+ #
+ # Validate Arch
+ #
+ if (ArchItem == '' or ArchItem == None):
+ ArchItem = 'COMMON'
+ __SupArchList.append(ArchItem)
+
+ for Item in ProtocolContent:
+ #
+ # Get Comment content of this protocol
+ #
+ CommentsList = None
+ if len(Item) == 3:
+ CommentsList = Item[1]
+ CurrentLineOfItem = Item[2]
+ LineInfo = (CurrentLineOfItem[2], CurrentLineOfItem[1], CurrentLineOfItem[0])
+ Item = Item[0]
+ InfProtocolItemObj = InfProtocolItem()
+ if len(Item) >= 1 and len(Item) <= 2:
+ #
+ # Only CName contained
+ #
+ if not IsValidCVariableName(Item[0]):
+ ErrorInInf(ST.ERR_INF_PARSER_INVALID_CNAME%(Item[0]),
+ LineInfo=LineInfo)
+ if (Item[0] != ''):
+ InfProtocolItemObj.SetName(Item[0])
+ else:
+ ErrorInInf(ST.ERR_INF_PARSER_CNAME_MISSING,
+ LineInfo=LineInfo)
+ if len(Item) == 2:
+ #
+ # Contained CName and Feature Flag Express
+ # <statements> ::= <CName> ["|"
+ # <FeatureFlagExpress>]
+ # For Protocol Object
+ #
+ if Item[1].strip() == '':
+ ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
+ LineInfo=LineInfo)
+ #
+ # Validate Feature Flag Express for Item[1]
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip())
+ if not FeatureFlagRtv[0]:
+ ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]),
+ LineInfo=LineInfo)
+ InfProtocolItemObj.SetFeatureFlagExp(Item[1])
+
+ if len(Item) < 1 or len(Item) > 2:
+ #
+ # Invalid format of Protocols statement
+ #
+ ErrorInInf(ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR,
+ LineInfo=LineInfo)
+
+ #
+ # Get/Set Usage and HelpString for Protocol entry
+ #
+ if CommentsList != None and len(CommentsList) != 0:
+ InfProtocolItemObj = ParseProtocolComment(CommentsList, InfProtocolItemObj)
+ else:
+ CommentItemIns = InfProtocolItemCommentContent()
+ CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
+ CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)
+ InfProtocolItemObj.SetCommentList([CommentItemIns])
+
+ InfProtocolItemObj.SetSupArchList(__SupArchList)
+
+ #
+ # Determine protocol name duplicate. Follow below rule:
+ #
+ # A protocol must not be duplicated within a [Protocols] section.
+ # A protocol may appear in multiple architectural [Protocols]
+ # sections. A protocol listed in an architectural [Protocols]
+ # section must not be listed in the common architectural
+ # [Protocols] section.
+ #
+ # NOTE: This check will not report error now.
+ #
+ for Item in self.Protocols:
+ if Item.GetName() == InfProtocolItemObj.GetName():
+ ItemSupArchList = Item.GetSupArchList()
+ for ItemArch in ItemSupArchList:
+ for ProtocolItemObjArch in __SupArchList:
+ if ItemArch == ProtocolItemObjArch:
+ #
+ # ST.ERR_INF_PARSER_ITEM_DUPLICATE
+ #
+ pass
+ if ItemArch.upper() == 'COMMON' or ProtocolItemObjArch.upper() == 'COMMON':
+ #
+ # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
+ #
+ pass
+
+ if self.Protocols.has_key((InfProtocolItemObj)):
+ ProcotolList = self.Protocols[InfProtocolItemObj]
+ ProcotolList.append(InfProtocolItemObj)
+ self.Protocols[InfProtocolItemObj] = ProcotolList
+ else:
+ ProcotolList = []
+ ProcotolList.append(InfProtocolItemObj)
+ self.Protocols[InfProtocolItemObj] = ProcotolList
+
+ return True
+
+ def GetProtocol(self):
+ return self.Protocols
diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfSoucesObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfSoucesObject.py new file mode 100644 index 0000000000..9988f8ecfe --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfSoucesObject.py @@ -0,0 +1,240 @@ +## @file
+# This file is used to define class objects of INF file [Sources] section.
+# It will consumed by InfParser.
+#
+# 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.
+
+'''
+InfSourcesObject
+'''
+
+import os
+
+from Logger import StringTable as ST
+from Logger import ToolError
+import Logger.Log as Logger
+from Library import GlobalData
+
+from Library.Misc import Sdict
+from Library.ExpressionValidate import IsValidFeatureFlagExp
+from Object.Parser.InfCommonObject import InfSectionCommonDef
+from Library.Misc import ValidFile
+from Library.ParserValidate import IsValidFamily
+from Library.ParserValidate import IsValidPath
+
+## __GenSourceInstance
+#
+#
+def GenSourceInstance(Item, CurrentLineOfItem, ItemObj):
+
+ IsValidFileFlag = False
+
+ if len(Item) < 6 and len(Item) >= 1:
+ #
+ # File | Family | TagName | ToolCode | FeatureFlagExpr
+ #
+ if len(Item) == 5:
+ #
+ # Validate Feature Flag Express
+ #
+ if Item[4].strip() == '':
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ #
+ # Validate FFE
+ #
+ FeatureFlagRtv = IsValidFeatureFlagExp(Item[4].strip())
+ if not FeatureFlagRtv[0]:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]),
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ ItemObj.SetFeatureFlagExp(Item[4])
+ if len(Item) >= 4:
+ if Item[3].strip() == '':
+ ItemObj.SetToolCode(Item[3])
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_TOOLCODE_NOT_PERMITTED%(Item[2]),
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ if len(Item) >= 3:
+ if Item[2].strip() == '':
+ ItemObj.SetTagName(Item[2])
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED%(Item[2]),
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ if len(Item) >= 2:
+ if IsValidFamily(Item[1].strip()):
+ #
+ # To align with UDP specification. "*" is not permitted in UDP specification
+ #
+ if Item[1].strip() == "*":
+ Item[1] = ""
+ ItemObj.SetFamily(Item[1])
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_SOURCE_SECTION_FAMILY_INVALID%(Item[1]),
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ if len(Item) >= 1:
+ #
+ # Validate file name exist.
+ #
+ FullFileName = os.path.normpath(os.path.realpath(os.path.join(GlobalData.gINF_MODULE_DIR, Item[0])))
+ if not (ValidFile(FullFileName) or ValidFile(Item[0])):
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_FILELIST_EXIST%(Item[0]),
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+
+ #
+ # Validate file exist/format.
+ #
+
+ if IsValidPath(Item[0], GlobalData.gINF_MODULE_DIR):
+ IsValidFileFlag = True
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID%(Item[0]),
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+ return False
+ if IsValidFileFlag:
+ ItemObj.SetSourceFileName(Item[0])
+ else:
+ Logger.Error("InfParser",
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_SOURCES_SECTION_CONTENT_ERROR,
+ File=CurrentLineOfItem[2],
+ Line=CurrentLineOfItem[1],
+ ExtraData=CurrentLineOfItem[0])
+
+ return ItemObj
+
+## InfSourcesItemObject()
+#
+#
+class InfSourcesItemObject():
+ def __init__(self, \
+ SourceFileName = '', \
+ Family = '', \
+ TagName = '', \
+ ToolCode = '', \
+ FeatureFlagExp = ''):
+ self.SourceFileName = SourceFileName
+ self.Family = Family
+ self.TagName = TagName
+ self.ToolCode = ToolCode
+ self.FeatureFlagExp = FeatureFlagExp
+ self.HeaderString = ''
+ self.TailString = ''
+ self.SupArchList = []
+
+ def SetSourceFileName(self, SourceFilename):
+ self.SourceFileName = SourceFilename
+ def GetSourceFileName(self):
+ return self.SourceFileName
+
+ def SetFamily(self, Family):
+ self.Family = Family
+ def GetFamily(self):
+ return self.Family
+
+ def SetTagName(self, TagName):
+ self.TagName = TagName
+ def GetTagName(self):
+ return self.TagName
+
+ def SetToolCode(self, ToolCode):
+ self.ToolCode = ToolCode
+ def GetToolCode(self):
+ return self.ToolCode
+
+ def SetFeatureFlagExp(self, FeatureFlagExp):
+ self.FeatureFlagExp = FeatureFlagExp
+ def GetFeatureFlagExp(self):
+ return self.FeatureFlagExp
+
+ def SetHeaderString(self, HeaderString):
+ self.HeaderString = HeaderString
+ def GetHeaderString(self):
+ return self.HeaderString
+
+ def SetTailString(self, TailString):
+ self.TailString = TailString
+ def GetTailString(self):
+ return self.TailString
+
+ def SetSupArchList(self, SupArchList):
+ self.SupArchList = SupArchList
+ def GetSupArchList(self):
+ return self.SupArchList
+##
+#
+#
+#
+class InfSourcesObject(InfSectionCommonDef):
+ def __init__(self):
+ self.Sources = Sdict()
+ InfSectionCommonDef.__init__(self)
+
+ def SetSources(self, SourceList, Arch = None):
+ __SupArchList = []
+ for ArchItem in Arch:
+ #
+ # Validate Arch
+ #
+ if (ArchItem == '' or ArchItem == None):
+ ArchItem = 'COMMON'
+ __SupArchList.append(ArchItem)
+
+ for Item in SourceList:
+ ItemObj = InfSourcesItemObject()
+ CurrentLineOfItem = Item[2]
+ Item = Item[0]
+
+ ItemObj = GenSourceInstance(Item, CurrentLineOfItem, ItemObj)
+
+ ItemObj.SetSupArchList(__SupArchList)
+
+ if self.Sources.has_key((ItemObj)):
+ SourceContent = self.Sources[ItemObj]
+ SourceContent.append(ItemObj)
+ self.Sources[ItemObj] = SourceContent
+ else:
+ SourceContent = []
+ SourceContent.append(ItemObj)
+ self.Sources[ItemObj] = SourceContent
+
+ return True
+
+ def GetSources(self):
+ return self.Sources
+
\ No newline at end of file diff --git a/BaseTools/Source/Python/UPT/Object/Parser/InfUserExtensionObject.py b/BaseTools/Source/Python/UPT/Object/Parser/InfUserExtensionObject.py new file mode 100644 index 0000000000..d576cffbd0 --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/InfUserExtensionObject.py @@ -0,0 +1,133 @@ +## @file
+# This file is used to define class objects of INF file [UserExtension] section.
+# It will consumed by InfParser.
+#
+# 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.
+
+'''
+InfUserExtensionsObject
+'''
+
+from Logger import StringTable as ST
+from Logger import ToolError
+import Logger.Log as Logger
+from Library import GlobalData
+
+from Library.Misc import Sdict
+
+class InfUserExtensionItem():
+ def __init__(self,
+ Content = '',
+ UserId = '',
+ IdString = ''):
+ self.Content = Content
+ self.UserId = UserId
+ self.IdString = IdString
+ self.SupArchList = []
+
+ def SetContent(self, Content):
+ self.Content = Content
+ def GetContent(self):
+ return self.Content
+
+ def SetUserId(self, UserId):
+ self.UserId = UserId
+ def GetUserId(self):
+ return self.UserId
+
+ def SetIdString(self, IdString):
+ self.IdString = IdString
+ def GetIdString(self):
+ return self.IdString
+
+ def SetSupArchList(self, SupArchList):
+ self.SupArchList = SupArchList
+ def GetSupArchList(self):
+ return self.SupArchList
+
+##
+#
+#
+#
+class InfUserExtensionObject():
+ def __init__(self):
+ self.UserExtension = Sdict()
+
+ def SetUserExtension(self, UserExtensionCont, IdContent=None, LineNo=None):
+ if not UserExtensionCont or UserExtensionCont == '':
+ return True
+ #
+ # IdContent is a list contain UserId and IdString
+ # For this call the general section header parser, if no definition of
+ # IdString/UserId, it will return 'COMMON'
+ #
+ for IdContentItem in IdContent:
+ InfUserExtensionItemObj = InfUserExtensionItem()
+ if IdContentItem[0] == 'COMMON':
+ UserId = ''
+ else:
+ UserId = IdContentItem[0]
+
+ if IdContentItem[1] == 'COMMON':
+ IdString = ''
+ else:
+ IdString = IdContentItem[1]
+
+ #
+ # Fill UserExtensionObj members.
+ #
+ InfUserExtensionItemObj.SetUserId(UserId)
+ InfUserExtensionItemObj.SetIdString(IdString)
+ InfUserExtensionItemObj.SetContent(UserExtensionCont)
+ InfUserExtensionItemObj.SetSupArchList(IdContentItem[2])
+
+ for CheckItem in self.UserExtension:
+ if IdContentItem[0] == CheckItem[0] and IdContentItem[1] == CheckItem[1]:
+ if IdContentItem[2].upper() == 'COMMON' or CheckItem[2].upper() == 'COMMON':
+ #
+ # For COMMON ARCH type, do special check.
+ #
+ Logger.Error('InfParser',
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR%\
+ (IdContentItem[0] + '.' + IdContentItem[1] + '.' + IdContentItem[2]),
+ File=GlobalData.gINF_MODULE_NAME,
+ Line=LineNo,
+ ExtraData=None)
+
+ if self.UserExtension.has_key(IdContentItem):
+ #
+ # Each UserExtensions section header must have a unique set
+ # of UserId, IdString and Arch values.
+ # This means that the same UserId can be used in more than one
+ # section header, provided the IdString or Arch values are
+ # different. The same IdString values can be used in more than
+ # one section header if the UserId or Arch values are
+ # different. The same UserId and the same IdString can be used
+ # in a section header if the Arch values are different in each
+ # of the section headers.
+ #
+ Logger.Error('InfParser',
+ ToolError.FORMAT_INVALID,
+ ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR%\
+ (IdContentItem[0] + '.' + IdContentItem[1] + '.' + IdContentItem[2]),
+ File=GlobalData.gINF_MODULE_NAME,
+ Line=LineNo,
+ ExtraData=None)
+ else:
+ UserExtensionList = []
+ UserExtensionList.append(InfUserExtensionItemObj)
+ self.UserExtension[IdContentItem] = UserExtensionList
+
+ return True
+
+ def GetUserExtension(self):
+ return self.UserExtension
\ No newline at end of file diff --git a/BaseTools/Source/Python/UPT/Object/Parser/__init__.py b/BaseTools/Source/Python/UPT/Object/Parser/__init__.py new file mode 100644 index 0000000000..b457c3c97b --- /dev/null +++ b/BaseTools/Source/Python/UPT/Object/Parser/__init__.py @@ -0,0 +1,20 @@ +## @file
+# Python 'Object' 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.
+#
+
+'''
+PARSER
+'''
\ No newline at end of file |