X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FWorkspace%2FMetaFileTable.py;h=3c8dae0e622faf550e8abb72a82eaa55b6e0444c;hp=088a118de1a1e609864cd9cd99669984d5ded393;hb=55c84777ee638be8735a5c421941e7eb71633bdf;hpb=64b2609fcff9d6412eea4c74c8e74bed33dc3235 diff --git a/BaseTools/Source/Python/Workspace/MetaFileTable.py b/BaseTools/Source/Python/Workspace/MetaFileTable.py index 088a118de1..3c8dae0e62 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileTable.py +++ b/BaseTools/Source/Python/Workspace/MetaFileTable.py @@ -1,7 +1,7 @@ ## @file # This file is used to create/update/query/erase a meta file table # -# Copyright (c) 2008, Intel Corporation. All rights reserved.
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -17,11 +17,13 @@ import uuid import Common.EdkLogger as EdkLogger +from Common.BuildToolError import FORMAT_INVALID from MetaDataTable import Table, TableFile from MetaDataTable import ConvertToSqlString from CommonDataClass.DataClass import MODEL_FILE_DSC, MODEL_FILE_DEC, MODEL_FILE_INF, \ MODEL_FILE_OTHERS +from Common.DataType import * class MetaFileTable(Table): # TRICK: use file ID as the part before '.' @@ -107,7 +109,7 @@ class ModuleTable(MetaFileTable): # @param EndColumn: EndColumn of a Inf item # @param Enabled: If this item enabled # - def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON', + def Insert(self, Model, Value1, Value2, Value3, Scope1=TAB_ARCH_COMMON, Scope2=TAB_COMMON, BelongsToItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0): (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2)) return Table.Insert( @@ -134,14 +136,16 @@ class ModuleTable(MetaFileTable): # # @retval: A recordSet of all found records # - def Query(self, Model, Arch=None, Platform=None): + def Query(self, Model, Arch=None, Platform=None, BelongsToItem=None): ConditionString = "Model=%s AND Enabled>=0" % Model ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine" - if Arch != None and Arch != 'COMMON': + if Arch is not None and Arch != TAB_ARCH_COMMON: ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch - if Platform != None and Platform != 'COMMON': + if Platform is not None and Platform != TAB_COMMON: ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Platform + if BelongsToItem is not None: + ConditionString += " AND BelongsToItem=%s" % BelongsToItem SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString) return self.Exec(SqlCommand) @@ -187,7 +191,7 @@ class PackageTable(MetaFileTable): # @param EndColumn: EndColumn of a Dec item # @param Enabled: If this item enabled # - def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON', + def Insert(self, Model, Value1, Value2, Value3, Scope1=TAB_ARCH_COMMON, Scope2=TAB_COMMON, BelongsToItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0): (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2)) return Table.Insert( @@ -215,14 +219,49 @@ class PackageTable(MetaFileTable): # def Query(self, Model, Arch=None): ConditionString = "Model=%s AND Enabled>=0" % Model - ValueString = "Value1,Value2,Value3,Scope1,ID,StartLine" + ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine" - if Arch != None and Arch != 'COMMON': + if Arch is not None and Arch != TAB_ARCH_COMMON: ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString) return self.Exec(SqlCommand) + def GetValidExpression(self, TokenSpaceGuid, PcdCName): + SqlCommand = "select Value1,StartLine from %s WHERE Value2='%s' and Value3='%s'" % (self.Table, TokenSpaceGuid, PcdCName) + self.Cur.execute(SqlCommand) + validateranges = [] + validlists = [] + expressions = [] + try: + for row in self.Cur: + comment = row[0] + + LineNum = row[1] + comment = comment.strip("#") + comment = comment.strip() + oricomment = comment + if comment.startswith("@ValidRange"): + comment = comment.replace("@ValidRange", "", 1) + validateranges.append(comment.split("|")[1].strip()) + if comment.startswith("@ValidList"): + comment = comment.replace("@ValidList", "", 1) + validlists.append(comment.split("|")[1].strip()) + if comment.startswith("@Expression"): + comment = comment.replace("@Expression", "", 1) + expressions.append(comment.split("|")[1].strip()) + except Exception, Exc: + ValidType = "" + if oricomment.startswith("@ValidRange"): + ValidType = "@ValidRange" + if oricomment.startswith("@ValidList"): + ValidType = "@ValidList" + if oricomment.startswith("@Expression"): + ValidType = "@Expression" + EdkLogger.error('Parser', FORMAT_INVALID, "The syntax for %s of PCD %s.%s is incorrect" % (ValidType,TokenSpaceGuid, PcdCName), + ExtraData=oricomment,File=self.MetaFile, Line=LineNum) + return set(), set(), set() + return set(validateranges), set(validlists), set(expressions) ## Python class representation of table storing platform data class PlatformTable(MetaFileTable): _COLUMN_ = ''' @@ -233,6 +272,7 @@ class PlatformTable(MetaFileTable): Value3 TEXT, Scope1 TEXT, Scope2 TEXT, + Scope3 TEXT, BelongsToItem REAL NOT NULL, FromItem REAL NOT NULL, StartLine INTEGER NOT NULL, @@ -242,7 +282,7 @@ class PlatformTable(MetaFileTable): Enabled INTEGER DEFAULT 0 ''' # used as table end flag, in case the changes to database is not committed to db file - _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1" + _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====','====', -1, -1, -1, -1, -1, -1, -1" ## Constructor def __init__(self, Cursor, MetaFile, Temporary): @@ -266,9 +306,9 @@ class PlatformTable(MetaFileTable): # @param EndColumn: EndColumn of a Dsc item # @param Enabled: If this item enabled # - def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON', BelongsToItem=-1, + def Insert(self, Model, Value1, Value2, Value3, Scope1=TAB_ARCH_COMMON, Scope2=TAB_COMMON, Scope3=TAB_DEFAULT_STORES_DEFAULT,BelongsToItem=-1, FromItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=1): - (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2)) + (Value1, Value2, Value3, Scope1, Scope2,Scope3) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2,Scope3)) return Table.Insert( self, Model, @@ -277,6 +317,7 @@ class PlatformTable(MetaFileTable): Value3, Scope1, Scope2, + Scope3, BelongsToItem, FromItem, StartLine, @@ -298,19 +339,25 @@ class PlatformTable(MetaFileTable): # def Query(self, Model, Scope1=None, Scope2=None, BelongsToItem=None, FromItem=None): ConditionString = "Model=%s AND Enabled>0" % Model - ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine" + ValueString = "Value1,Value2,Value3,Scope1,Scope2,Scope3,ID,StartLine" - if Scope1 != None and Scope1 != 'COMMON': + if Scope1 is not None and Scope1 != TAB_ARCH_COMMON: ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Scope1 - if Scope2 != None and Scope2 != 'COMMON': - ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Scope2 + if Scope2 is not None and Scope2 != TAB_COMMON: + # Cover the case that CodeBase is 'COMMON' for BuildOptions section + if '.' in Scope2: + Index = Scope2.index('.') + NewScope = TAB_COMMON + Scope2[Index:] + ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT' OR Scope2='%s')" % (Scope2, NewScope) + else: + ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Scope2 - if BelongsToItem != None: + if BelongsToItem is not None: ConditionString += " AND BelongsToItem=%s" % BelongsToItem else: ConditionString += " AND BelongsToItem<0" - if FromItem != None: + if FromItem is not None: ConditionString += " AND FromItem=%s" % FromItem SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)