X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FEcc%2FCheck.py;h=5864758950ce973ccfb0094a732b24cf7b647adb;hb=e1511113debf54ec2aceb20ee8eeecb331acd498;hp=6f5f9fd0b5570e4318db377c5f78f023a900319c;hpb=2bcc713e74b944bb5aefb433ef33fb4002a62d76;p=mirror_edk2.git diff --git a/BaseTools/Source/Python/Ecc/Check.py b/BaseTools/Source/Python/Ecc/Check.py index 6f5f9fd0b5..5864758950 100644 --- a/BaseTools/Source/Python/Ecc/Check.py +++ b/BaseTools/Source/Python/Ecc/Check.py @@ -1,7 +1,7 @@ ## @file # This file is used to define checkpoints used by ECC tool # -# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.
+# Copyright (c) 2008 - 2017, 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 @@ -10,13 +10,16 @@ # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. # -import os +import Common.LongFilePathOs as os import re from CommonDataClass.DataClass import * -from Common.DataType import SUP_MODULE_LIST_STRING, TAB_VALUE_SPLIT +import Common.DataType as DT from EccToolError import * +from MetaDataParser import ParseHeaderCommentSection import EccGlobalData import c +from Common.LongFilePathSupport import OpenLongFilePath as open +from Common.MultipleWorkspace import MultipleWorkspace as mws ## Check # @@ -38,17 +41,159 @@ class Check(object): self.DeclAndDataTypeCheck() self.FunctionLayoutCheck() self.NamingConventionCheck() + self.SmmCommParaCheck() + + def SmmCommParaCheck(self): + self.SmmCommParaCheckBufferType() + + + # Check if SMM communication function has correct parameter type + # 1. Get function calling with instance./->Communicate() interface + # and make sure the protocol instance is of type EFI_SMM_COMMUNICATION_PROTOCOL. + # 2. Find the origin of the 2nd parameter of Communicate() interface, if - + # a. it is a local buffer on stack + # report error. + # b. it is a global buffer, check the driver that holds the global buffer is of type DXE_RUNTIME_DRIVER + # report success. + # c. it is a buffer by AllocatePage/AllocatePool (may be wrapped by nested function calls), + # check the EFI_MEMORY_TYPE to be EfiRuntimeServicesCode,EfiRuntimeServicesData, + # EfiACPIMemoryNVS or EfiReservedMemoryType + # report success. + # d. it is a buffer located via EFI_SYSTEM_TABLE.ConfigurationTable (may be wrapped by nested function calls) + # report warning to indicate human code review. + # e. it is a buffer from other kind of pointers (may need to trace into nested function calls to locate), + # repeat checks in a.b.c and d. + def SmmCommParaCheckBufferType(self): + if EccGlobalData.gConfig.SmmCommParaCheckBufferType == '1' or EccGlobalData.gConfig.SmmCommParaCheckAll == '1': + EdkLogger.quiet("Checking SMM communication parameter type ...") + # Get all EFI_SMM_COMMUNICATION_PROTOCOL interface + CommApiList = [] + for IdentifierTable in EccGlobalData.gIdentifierTableList: + SqlCommand = """select ID, Name, BelongsToFile from %s + where Modifier = 'EFI_SMM_COMMUNICATION_PROTOCOL*' """ % (IdentifierTable) + RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand) + if RecordSet: + for Record in RecordSet: + if Record[1] not in CommApiList: + CommApiList.append(Record[1]) + # For each interface, check the second parameter + for CommApi in CommApiList: + for IdentifierTable in EccGlobalData.gIdentifierTableList: + SqlCommand = """select ID, Name, Value, BelongsToFile, StartLine from %s + where Name = '%s->Communicate' and Model = %s""" \ + % (IdentifierTable, CommApi, MODEL_IDENTIFIER_FUNCTION_CALLING) + RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand) + if RecordSet: + # print IdentifierTable + for Record in RecordSet: + # Get the second parameter for Communicate function + SecondPara = Record[2].split(',')[1].strip() + SecondParaIndex = None + if SecondPara.startswith('&'): + SecondPara = SecondPara[1:] + if SecondPara.endswith(']'): + SecondParaIndex = SecondPara[SecondPara.find('[') + 1:-1] + SecondPara = SecondPara[:SecondPara.find('[')] + # Get the ID + Id = Record[0] + # Get the BelongsToFile + BelongsToFile = Record[3] + # Get the source file path + SqlCommand = """select FullPath from File where ID = %s""" % BelongsToFile + NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand) + FullPath = NewRecordSet[0][0] + # Get the line no of function calling + StartLine = Record[4] + # Get the module type + SqlCommand = """select Value3 from INF where BelongsToFile = (select ID from File + where Path = (select Path from File where ID = %s) and Model = 1011) + and Value2 = 'MODULE_TYPE'""" % BelongsToFile + NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand) + ModuleType = NewRecordSet[0][0] if NewRecordSet else None + + # print BelongsToFile, FullPath, StartLine, ModuleType, SecondPara + + Value = FindPara(FullPath, SecondPara, StartLine) + # Find the value of the parameter + if Value: + if 'AllocatePage' in Value \ + or 'AllocatePool' in Value \ + or 'AllocateRuntimePool' in Value \ + or 'AllocateZeroPool' in Value: + pass + else: + if '->' in Value: + if not EccGlobalData.gException.IsException( + ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, Value): + EccGlobalData.gDb.TblReport.Insert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, + OtherMsg="Please review the buffer type" + + "is correct or not. If it is correct" + + " please add [%s] to exception list" + % Value, + BelongsToTable=IdentifierTable, + BelongsToItem=Id) + else: + if not EccGlobalData.gException.IsException( + ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, Value): + EccGlobalData.gDb.TblReport.Insert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, + OtherMsg="Please review the buffer type" + + "is correct or not. If it is correct" + + " please add [%s] to exception list" + % Value, + BelongsToTable=IdentifierTable, + BelongsToItem=Id) + + + # Not find the value of the parameter + else: + SqlCommand = """select ID, Modifier, Name, Value, Model, BelongsToFunction from %s + where Name = '%s' and StartLine < %s order by StartLine DESC""" \ + % (IdentifierTable, SecondPara, StartLine) + NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand) + if NewRecordSet: + Value = NewRecordSet[0][1] + if 'AllocatePage' in Value \ + or 'AllocatePool' in Value \ + or 'AllocateRuntimePool' in Value \ + or 'AllocateZeroPool' in Value: + pass + else: + if not EccGlobalData.gException.IsException( + ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, Value): + EccGlobalData.gDb.TblReport.Insert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, + OtherMsg="Please review the buffer type" + + "is correct or not. If it is correct" + + " please add [%s] to exception list" + % Value, + BelongsToTable=IdentifierTable, + BelongsToItem=Id) + else: + pass + + # Check UNI files + def UniCheck(self): + if EccGlobalData.gConfig.GeneralCheckUni == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': + EdkLogger.quiet("Checking whether UNI file is UTF-16 ...") + SqlCommand = """select ID, FullPath, ExtName from File where ExtName like 'uni'""" + RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand) + for Record in RecordSet: + File = Record[1] + FileIn = open(File, 'rb').read(2) + if FileIn != '\xff\xfe': + OtherMsg = "File %s is not a valid UTF-16 UNI file" % Record[1] + EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_UNI, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0]) # General Checking def GeneralCheck(self): self.GeneralCheckNonAcsii() + self.UniCheck() # Check whether file has non ACSII char def GeneralCheckNonAcsii(self): if EccGlobalData.gConfig.GeneralCheckNonAcsii == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': EdkLogger.quiet("Checking Non-ACSII char in file ...") - SqlCommand = """select ID, FullPath, ExtName from File""" - RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand) + SqlCommand = """select ID, FullPath, ExtName from File where ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')""" + RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand) for Record in RecordSet: if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList: op = open(Record[1]).readlines() @@ -84,6 +229,9 @@ class Check(object): Dirnames.append(Dirname) if IgnoredPattern.match(Dirpath.upper()): continue + for f in Filenames[:]: + if f.lower() in EccGlobalData.gConfig.SkipFileList: + Filenames.remove(f) yield (Dirpath, Dirnames, Filenames) # Check whether return type exists and in the first line @@ -361,9 +509,7 @@ class Check(object): for Key in RecordDict: if len(RecordDict[Key]) > 1: for Item in RecordDict[Key]: - Path = Item[1].replace(EccGlobalData.gWorkspace, '') - if Path.startswith('\\') or Path.startswith('/'): - Path = Path[1:] + Path = mws.relpath(Item[1], EccGlobalData.gWorkspace) if not EccGlobalData.gException.IsException(ERROR_INCLUDE_FILE_CHECK_NAME, Path): EccGlobalData.gDb.TblReport.Insert(ERROR_INCLUDE_FILE_CHECK_NAME, OtherMsg="The file name for [%s] is duplicate" % Path, BelongsToTable='File', BelongsToItem=Item[0]) @@ -415,13 +561,81 @@ class Check(object): elif Ext in ('.inf', '.dec', '.dsc', '.fdf'): FullName = os.path.join(Dirpath, F) op = open(FullName).readlines() - if not op[0].startswith('## @file') and op[6].startswith('## @file') and op[7].startswith('## @file'): + FileLinesList = op + LineNo = 0 + CurrentSection = MODEL_UNKNOWN + HeaderSectionLines = [] + HeaderCommentStart = False + HeaderCommentEnd = False + + for Line in FileLinesList: + LineNo = LineNo + 1 + Line = Line.strip() + if (LineNo < len(FileLinesList) - 1): + NextLine = FileLinesList[LineNo].strip() + + # + # blank line + # + if (Line == '' or not Line) and LineNo == len(FileLinesList): + LastSectionFalg = True + + # + # check whether file header comment section started + # + if Line.startswith('#') and \ + (Line.find('@file') > -1) and \ + not HeaderCommentStart: + if CurrentSection != MODEL_UNKNOWN: + SqlStatement = """ select ID from File where FullPath like '%s'""" % FullName + ResultSet = EccGlobalData.gDb.TblFile.Exec(SqlStatement) + for Result in ResultSet: + Msg = 'INF/DEC/DSC/FDF file header comment should begin with ""## @file"" or ""# @file""at the very top file' + EccGlobalData.gDb.TblReport.Insert(ERROR_DOXYGEN_CHECK_FILE_HEADER, Msg, "File", Result[0]) + + else: + CurrentSection = MODEL_IDENTIFIER_FILE_HEADER + # + # Append the first line to section lines. + # + HeaderSectionLines.append((Line, LineNo)) + HeaderCommentStart = True + continue + + # + # Collect Header content. + # + if (Line.startswith('#') and CurrentSection == MODEL_IDENTIFIER_FILE_HEADER) and\ + HeaderCommentStart and not Line.startswith('##') and not\ + HeaderCommentEnd and NextLine != '': + HeaderSectionLines.append((Line, LineNo)) + continue + # + # Header content end + # + if (Line.startswith('##') or not Line.strip().startswith("#")) and HeaderCommentStart \ + and not HeaderCommentEnd: + if Line.startswith('##'): + HeaderCommentEnd = True + HeaderSectionLines.append((Line, LineNo)) + ParseHeaderCommentSection(HeaderSectionLines, FullName) + break + if HeaderCommentStart == False: SqlStatement = """ select ID from File where FullPath like '%s'""" % FullName ResultSet = EccGlobalData.gDb.TblFile.Exec(SqlStatement) for Result in ResultSet: - Msg = 'INF/DEC/DSC/FDF file header comment should begin with ""## @file""' + Msg = 'INF/DEC/DSC/FDF file header comment should begin with ""## @file"" or ""# @file"" at the very top file' EccGlobalData.gDb.TblReport.Insert(ERROR_DOXYGEN_CHECK_FILE_HEADER, Msg, "File", Result[0]) + if HeaderCommentEnd == False: + SqlStatement = """ select ID from File where FullPath like '%s'""" % FullName + ResultSet = EccGlobalData.gDb.TblFile.Exec(SqlStatement) + for Result in ResultSet: + Msg = 'INF/DEC/DSC/FDF file header comment should end with ""##"" at the end of file header comment block' + # Check whether File header Comment End with '##' + if EccGlobalData.gConfig.HeaderCheckFileCommentEnd == '1' or EccGlobalData.gConfig.HeaderCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': + EccGlobalData.gDb.TblReport.Insert(ERROR_DOXYGEN_CHECK_FILE_HEADER, Msg, "File", Result[0]) + # Check whether the function headers are followed Doxygen special documentation blocks in section 2.3.5 def DoxygenCheckFunctionHeader(self): @@ -477,6 +691,7 @@ class Check(object): self.MetaDataFileCheckLibraryInstanceDependent() self.MetaDataFileCheckLibraryInstanceOrder() self.MetaDataFileCheckLibraryNoUse() + self.MetaDataFileCheckLibraryDefinedInDec() self.MetaDataFileCheckBinaryInfInFdf() self.MetaDataFileCheckPcdDuplicate() self.MetaDataFileCheckPcdFlash() @@ -485,6 +700,10 @@ class Check(object): self.MetaDataFileCheckModuleFileNoUse() self.MetaDataFileCheckPcdType() self.MetaDataFileCheckModuleFileGuidDuplication() + self.MetaDataFileCheckModuleFileGuidFormat() + self.MetaDataFileCheckModuleFileProtocolFormat() + self.MetaDataFileCheckModuleFilePpiFormat() + self.MetaDataFileCheckModuleFilePcdFormat() # Check whether each file defined in meta-data exists def MetaDataFileCheckPathName(self): @@ -504,9 +723,9 @@ class Check(object): def MetaDataFileCheckLibraryInstance(self): if EccGlobalData.gConfig.MetaDataFileCheckLibraryInstance == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': EdkLogger.quiet("Checking for library instance type issue ...") - SqlCommand = """select A.ID, A.Value2, B.Value2 from Inf as A left join Inf as B - where A.Value1 = 'LIBRARY_CLASS' and A.Model = %s - and B.Value1 = 'MODULE_TYPE' and B.Model = %s and A.BelongsToFile = B.BelongsToFile + SqlCommand = """select A.ID, A.Value3, B.Value3 from Inf as A left join Inf as B + where A.Value2 = 'LIBRARY_CLASS' and A.Model = %s + and B.Value2 = 'MODULE_TYPE' and B.Model = %s and A.BelongsToFile = B.BelongsToFile group by A.BelongsToFile""" % (MODEL_META_DATA_HEADER, MODEL_META_DATA_HEADER) RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand) LibraryClasses = {} @@ -514,7 +733,7 @@ class Check(object): List = Record[1].split('|', 1) SupModType = [] if len(List) == 1: - SupModType = SUP_MODULE_LIST_STRING.split(TAB_VALUE_SPLIT) + SupModType = DT.SUP_MODULE_LIST_STRING.split(DT.TAB_VALUE_SPLIT) elif len(List) == 2: SupModType = List[1].split() @@ -528,8 +747,8 @@ class Check(object): if Record[2] != 'BASE' and Record[2] not in SupModType: EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_INSTANCE_2, OtherMsg="The Library Class '%s' does not specify its supported module types" % (List[0]), BelongsToTable='Inf', BelongsToItem=Record[0]) - SqlCommand = """select A.ID, A.Value1, B.Value2 from Inf as A left join Inf as B - where A.Model = %s and B.Value1 = '%s' and B.Model = %s + SqlCommand = """select A.ID, A.Value1, B.Value3 from Inf as A left join Inf as B + where A.Model = %s and B.Value2 = '%s' and B.Model = %s and B.BelongsToFile = A.BelongsToFile""" \ % (MODEL_EFI_LIBRARY_CLASS, 'MODULE_TYPE', MODEL_META_DATA_HEADER) RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand) @@ -558,11 +777,17 @@ class Check(object): SqlCommand = """select ID, Value1, Value2 from Dsc where Model = %s""" % MODEL_EFI_LIBRARY_CLASS LibraryClasses = EccGlobalData.gDb.TblDsc.Exec(SqlCommand) for LibraryClass in LibraryClasses: - if LibraryClass[1].upper() != 'NULL': - LibraryIns = os.path.normpath(os.path.join(EccGlobalData.gWorkspace, LibraryClass[2])) - SqlCommand = """select Value2 from Inf where BelongsToFile = + if LibraryClass[1].upper() == 'NULL' or LibraryClass[1].startswith('!ifdef') or LibraryClass[1].startswith('!ifndef') or LibraryClass[1].endswith('!endif'): + continue + else: + LibraryIns = os.path.normpath(mws.join(EccGlobalData.gWorkspace, LibraryClass[2])) + SkipDirString = '|'.join(EccGlobalData.gConfig.SkipDirList) + p = re.compile(r'.*[\\/](?:%s^\S)[\\/]?.*' % SkipDirString) + if p.match(os.path.split(LibraryIns)[0].upper()): + continue + SqlCommand = """select Value3 from Inf where BelongsToFile = (select ID from File where lower(FullPath) = lower('%s')) - and Value1 = '%s'""" % (LibraryIns, 'LIBRARY_CLASS') + and Value2 = '%s'""" % (LibraryIns, 'LIBRARY_CLASS') RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand) IsFound = False for Record in RecordSet: @@ -591,18 +816,35 @@ class Check(object): EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_NO_USE, OtherMsg="The Library Class [%s] is not used in any platform" % (Record[1]), BelongsToTable='Inf', BelongsToItem=Record[0]) SqlCommand = """ select A.ID, A.Value1, A.BelongsToFile, A.StartLine, B.StartLine from Dsc as A left join Dsc as B - where A.Model = %s and B.Model = %s and A.Value3 = B.Value3 and A.Arch = B.Arch and A.ID <> B.ID - and A.Value1 = B.Value1 and A.StartLine <> B.StartLine and B.BelongsToFile = A.BelongsToFile""" \ + where A.Model = %s and B.Model = %s and A.Scope1 = B.Scope1 and A.Scope2 = B.Scope2 and A.ID <> B.ID + and A.Value1 = B.Value1 and A.Value2 <> B.Value2 and A.BelongsToItem = -1 and B.BelongsToItem = -1 and A.StartLine <> B.StartLine and B.BelongsToFile = A.BelongsToFile""" \ % (MODEL_EFI_LIBRARY_CLASS, MODEL_EFI_LIBRARY_CLASS) RecordSet = EccGlobalData.gDb.TblDsc.Exec(SqlCommand) for Record in RecordSet: - if Record[3] and Record[4] and Record[3] != Record[4]: + if Record[3] and Record[4] and Record[3] != Record[4] and Record[1] != 'NULL': SqlCommand = """select FullPath from File where ID = %s""" % (Record[2]) FilePathList = EccGlobalData.gDb.TblFile.Exec(SqlCommand) for FilePath in FilePathList: if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_NAME_DUPLICATE, Record[1]): EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_NAME_DUPLICATE, OtherMsg="The Library Class [%s] is duplicated in '%s' line %s and line %s." % (Record[1], FilePath, Record[3], Record[4]), BelongsToTable='Dsc', BelongsToItem=Record[0]) - + + # Check the header file in Include\Library directory whether be defined in the package DEC file. + def MetaDataFileCheckLibraryDefinedInDec(self): + if EccGlobalData.gConfig.MetaDataFileCheckLibraryDefinedInDec == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': + EdkLogger.quiet("Checking for library instance whether be defined in the package dec file ...") + SqlCommand = """ + select A.Value1, A.StartLine, A.ID, B.Value1 from Inf as A left join Dec as B + on A.Model = B.Model and A.Value1 = B.Value1 where A.Model=%s + """ % MODEL_EFI_LIBRARY_CLASS + RecordSet = EccGlobalData.gDb.TblDsc.Exec(SqlCommand) + for Record in RecordSet: + LibraryInInf, Line, ID, LibraryDec = Record + if not LibraryDec: + if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_NOT_DEFINED, LibraryInInf): + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_NOT_DEFINED, \ + OtherMsg="The Library Class [%s] in %s line is not defined in the associated package file." % (LibraryInInf, Line), + BelongsToTable='Inf', BelongsToItem=ID) + # Check whether an Inf file is specified in the FDF file, but not in the Dsc file, then the Inf file must be for a Binary module only def MetaDataFileCheckBinaryInfInFdf(self): if EccGlobalData.gConfig.MetaDataFileCheckBinaryInfInFdf == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': @@ -618,7 +860,7 @@ class Check(object): for Record in RecordSet: FdfID = Record[0] FilePath = Record[1] - FilePath = os.path.normpath(os.path.join(EccGlobalData.gWorkspace, FilePath)) + FilePath = os.path.normpath(mws.join(EccGlobalData.gWorkspace, FilePath)) SqlCommand = """select ID from Inf where Model = %s and BelongsToFile = (select ID from File where FullPath like '%s') """ % (MODEL_EFI_SOURCE_FILE, FilePath) NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand) @@ -631,9 +873,10 @@ class Check(object): if EccGlobalData.gConfig.MetaDataFileCheckPcdDuplicate == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': EdkLogger.quiet("Checking for duplicate PCDs defined in both DSC and FDF files ...") SqlCommand = """ - select A.ID, A.Value2, A.BelongsToFile, B.ID, B.Value2, B.BelongsToFile from Dsc as A, Fdf as B + select A.ID, A.Value1, A.Value2, A.BelongsToFile, B.ID, B.Value1, B.Value2, B.BelongsToFile from Dsc as A, Fdf as B where A.Model >= %s and A.Model < %s and B.Model >= %s and B.Model < %s + and A.Value1 = B.Value1 and A.Value2 = B.Value2 and A.Enabled > -1 and B.Enabled > -1 @@ -641,71 +884,74 @@ class Check(object): """ % (MODEL_PCD, MODEL_META_DATA_HEADER, MODEL_PCD, MODEL_META_DATA_HEADER) RecordSet = EccGlobalData.gDb.TblDsc.Exec(SqlCommand) for Record in RecordSet: - SqlCommand1 = """select Name from File where ID = %s""" % Record[2] - SqlCommand2 = """select Name from File where ID = %s""" % Record[5] + SqlCommand1 = """select Name from File where ID = %s""" % Record[3] + SqlCommand2 = """select Name from File where ID = %s""" % Record[7] DscFileName = os.path.splitext(EccGlobalData.gDb.TblDsc.Exec(SqlCommand1)[0][0])[0] FdfFileName = os.path.splitext(EccGlobalData.gDb.TblDsc.Exec(SqlCommand2)[0][0])[0] if DscFileName != FdfFileName: continue - if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, Record[1]): - EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, OtherMsg="The PCD [%s] is defined in both FDF file and DSC file" % (Record[1]), BelongsToTable='Dsc', BelongsToItem=Record[0]) - if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, Record[3]): - EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, OtherMsg="The PCD [%s] is defined in both FDF file and DSC file" % (Record[4]), BelongsToTable='Fdf', BelongsToItem=Record[3]) + if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, Record[1] + '.' + Record[2]): + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, OtherMsg="The PCD [%s] is defined in both FDF file and DSC file" % (Record[1] + '.' + Record[2]), BelongsToTable='Dsc', BelongsToItem=Record[0]) + if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, Record[5] + '.' + Record[6]): + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, OtherMsg="The PCD [%s] is defined in both FDF file and DSC file" % (Record[5] + '.' + Record[6]), BelongsToTable='Fdf', BelongsToItem=Record[4]) EdkLogger.quiet("Checking for duplicate PCDs defined in DEC files ...") SqlCommand = """ - select A.ID, A.Value2 from Dec as A, Dec as B + select A.ID, A.Value1, A.Value2, A.Model, B.Model from Dec as A left join Dec as B where A.Model >= %s and A.Model < %s and B.Model >= %s and B.Model < %s + and A.Value1 = B.Value1 and A.Value2 = B.Value2 - and ((A.Arch = B.Arch) and (A.Arch != 'COMMON' or B.Arch != 'COMMON')) - and A.ID != B.ID + and A.Scope1 = B.Scope1 + and A.ID <> B.ID + and A.Model = B.Model and A.Enabled > -1 and B.Enabled > -1 and A.BelongsToFile = B.BelongsToFile group by A.ID """ % (MODEL_PCD, MODEL_META_DATA_HEADER, MODEL_PCD, MODEL_META_DATA_HEADER) - RecordSet = EccGlobalData.gDb.TblDsc.Exec(SqlCommand) + RecordSet = EccGlobalData.gDb.TblDec.Exec(SqlCommand) for Record in RecordSet: - if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, Record[1]): - EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, OtherMsg="The PCD [%s] is defined duplicated in DEC file" % (Record[1]), BelongsToTable='Dec', BelongsToItem=Record[0]) + RecordCat = Record[1] + '.' + Record[2] + if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, RecordCat): + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, OtherMsg="The PCD [%s] is defined duplicated in DEC file" % RecordCat, BelongsToTable='Dec', BelongsToItem=Record[0]) # Check whether PCD settings in the FDF file can only be related to flash. def MetaDataFileCheckPcdFlash(self): if EccGlobalData.gConfig.MetaDataFileCheckPcdFlash == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': EdkLogger.quiet("Checking only Flash related PCDs are used in FDF ...") SqlCommand = """ - select ID, Value2, BelongsToFile from Fdf as A + select ID, Value1, Value2, BelongsToFile from Fdf as A where A.Model >= %s and Model < %s and A.Enabled > -1 and A.Value2 not like '%%Flash%%' """ % (MODEL_PCD, MODEL_META_DATA_HEADER) RecordSet = EccGlobalData.gDb.TblFdf.Exec(SqlCommand) for Record in RecordSet: - if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_FLASH, Record[1]): - EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_FLASH, OtherMsg="The PCD [%s] defined in FDF file is not related to Flash" % (Record[1]), BelongsToTable='Fdf', BelongsToItem=Record[0]) + if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_FLASH, Record[1] + '.' + Record[2]): + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_FLASH, OtherMsg="The PCD [%s] defined in FDF file is not related to Flash" % (Record[1] + '.' + Record[2]), BelongsToTable='Fdf', BelongsToItem=Record[0]) # Check whether PCDs used in Inf files but not specified in Dsc or FDF files def MetaDataFileCheckPcdNoUse(self): if EccGlobalData.gConfig.MetaDataFileCheckPcdNoUse == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': EdkLogger.quiet("Checking for non-specified PCDs ...") SqlCommand = """ - select ID, Value2, BelongsToFile from Inf as A + select ID, Value1, Value2, BelongsToFile from Inf as A where A.Model >= %s and Model < %s and A.Enabled > -1 - and A.Value2 not in - (select Value2 from Dsc as B + and (A.Value1, A.Value2) not in + (select Value1, Value2 from Dsc as B where B.Model >= %s and B.Model < %s and B.Enabled > -1) - and A.Value2 not in - (select Value2 from Fdf as C + and (A.Value1, A.Value2) not in + (select Value1, Value2 from Fdf as C where C.Model >= %s and C.Model < %s and C.Enabled > -1) """ % (MODEL_PCD, MODEL_META_DATA_HEADER, MODEL_PCD, MODEL_META_DATA_HEADER, MODEL_PCD, MODEL_META_DATA_HEADER) RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand) for Record in RecordSet: - if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_NO_USE, Record[1]): - EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_NO_USE, OtherMsg="The PCD [%s] defined in INF file is not specified in either DSC or FDF files" % (Record[1]), BelongsToTable='Inf', BelongsToItem=Record[0]) + if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_NO_USE, Record[1] + '.' + Record[2]): + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_NO_USE, OtherMsg="The PCD [%s] defined in INF file is not specified in either DSC or FDF files" % (Record[1] + '.' + Record[2]), BelongsToTable='Inf', BelongsToItem=Record[0]) # Check whether having duplicate guids defined for Guid/Protocol/Ppi def MetaDataFileCheckGuidDuplicate(self): @@ -729,7 +975,7 @@ class Check(object): if EccGlobalData.gConfig.MetaDataFileCheckModuleFileNoUse == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': EdkLogger.quiet("Checking for no used module files ...") SqlCommand = """ - select upper(Path) from File where ID in (select BelongsToFile from INF where BelongsToFile != -1) + select upper(Path) from File where ID in (select BelongsToFile from Inf where BelongsToFile != -1) """ InfPathSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand) InfPathList = [] @@ -756,15 +1002,15 @@ class Check(object): if EccGlobalData.gConfig.MetaDataFileCheckPcdType == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': EdkLogger.quiet("Checking for pcd type in c code function usage ...") SqlCommand = """ - select ID, Model, Value1, BelongsToFile from INF where Model > %s and Model < %s + select ID, Model, Value1, Value2, BelongsToFile from INF where Model > %s and Model < %s """ % (MODEL_PCD, MODEL_META_DATA_HEADER) PcdSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand) for Pcd in PcdSet: Model = Pcd[1] PcdName = Pcd[2] - if len(Pcd[2].split(".")) > 1: - PcdName = Pcd[2].split(".")[1] - BelongsToFile = Pcd[3] + if Pcd[3]: + PcdName = Pcd[3] + BelongsToFile = Pcd[4] SqlCommand = """ select ID from File where FullPath in (select B.Path || '\\' || A.Value1 from INF as A, File as B where A.Model = %s and A.BelongsToFile = %s @@ -798,9 +1044,7 @@ class Check(object): RecordSet = Table.Exec(SqlCommand) Path = "" for Record in RecordSet: - Path = Record[0].replace(EccGlobalData.gWorkspace, '') - if Path.startswith('\\') or Path.startswith('/'): - Path = Path[1:] + Path = mws.relpath(Record[0], EccGlobalData.gWorkspace) return Path # Check whether two module INFs under one workspace has the same FILE_GUID value @@ -809,9 +1053,9 @@ class Check(object): EdkLogger.quiet("Checking for pcd type in c code function usage ...") Table = EccGlobalData.gDb.TblInf SqlCommand = """ - select A.ID, A.Value2, A.BelongsToFile, B.BelongsToFile from %s as A, %s as B - where A.Value1 = 'FILE_GUID' and B.Value1 = 'FILE_GUID' and - A.Value2 = B.Value2 and A.ID <> B.ID group by A.ID + select A.ID, A.Value3, A.BelongsToFile, B.BelongsToFile from %s as A, %s as B + where A.Value2 = 'FILE_GUID' and B.Value2 = 'FILE_GUID' and + A.Value3 = B.Value3 and A.ID <> B.ID group by A.ID """ % (Table.Table, Table.Table) RecordSet = Table.Exec(SqlCommand) for Record in RecordSet: @@ -823,6 +1067,142 @@ class Check(object): EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_MODULE_FILE_GUID_DUPLICATION, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0]) + # Check Guid Format in module INF + def MetaDataFileCheckModuleFileGuidFormat(self): + if EccGlobalData.gConfig.MetaDataFileCheckModuleFileGuidFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': + EdkLogger.quiet("Check Guid Format in module INF ...") + Table = EccGlobalData.gDb.TblInf + SqlCommand = """ + select ID, Value1, Usage, BelongsToFile from %s where Model = %s group by ID + """ % (Table.Table, MODEL_EFI_GUID) + RecordSet = Table.Exec(SqlCommand) + for Record in RecordSet: + Value1 = Record[1] + Value2 = Record[2] + GuidCommentList = [] + InfPath = self.GetInfFilePathFromID(Record[3]) + Msg = "The GUID format of %s in INF file [%s] does not follow rules" % (Value1, InfPath) + if Value2.startswith(DT.TAB_SPECIAL_COMMENT): + GuidCommentList = Value2[2:].split(DT.TAB_SPECIAL_COMMENT) + if GuidCommentList[0].strip().startswith(DT.TAB_INF_USAGE_UNDEFINED): + continue + elif len(GuidCommentList) > 1: + if not GuidCommentList[0].strip().startswith((DT.TAB_INF_USAGE_PRO, + DT.TAB_INF_USAGE_SOME_PRO, + DT.TAB_INF_USAGE_CON, + DT.TAB_INF_USAGE_SOME_CON)): + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_GUID, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0]) + if not (GuidCommentList[1].strip()).startswith(DT.TAB_INF_GUIDTYPE_VAR) and \ + not GuidCommentList[1].strip().startswith((DT.TAB_INF_GUIDTYPE_EVENT, + DT.TAB_INF_GUIDTYPE_HII, + DT.TAB_INF_GUIDTYPE_FILE, + DT.TAB_INF_GUIDTYPE_HOB, + DT.TAB_INF_GUIDTYPE_FV, + DT.TAB_INF_GUIDTYPE_ST, + DT.TAB_INF_GUIDTYPE_TSG, + DT.TAB_INF_GUIDTYPE_GUID, + DT.TAB_INF_GUIDTYPE_PROTOCOL, + DT.TAB_INF_GUIDTYPE_PPI, + DT.TAB_INF_USAGE_UNDEFINED)): + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_GUID, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0]) + else: + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_GUID, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0]) + else: + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_GUID, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0]) + + # Check Protocol Format in module INF + def MetaDataFileCheckModuleFileProtocolFormat(self): + if EccGlobalData.gConfig.MetaDataFileCheckModuleFileProtocolFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': + EdkLogger.quiet("Check Protocol Format in module INF ...") + Table = EccGlobalData.gDb.TblInf + SqlCommand = """ + select ID, Value1, Usage, BelongsToFile from %s where Model = %s group by ID + """ % (Table.Table, MODEL_EFI_PROTOCOL) + RecordSet = Table.Exec(SqlCommand) + for Record in RecordSet: + Value1 = Record[1] + Value2 = Record[2] + GuidCommentList = [] + InfPath = self.GetInfFilePathFromID(Record[3]) + Msg = "The Protocol format of %s in INF file [%s] does not follow rules" % (Value1, InfPath) + if Value2.startswith(DT.TAB_SPECIAL_COMMENT): + GuidCommentList = Value2[2:].split(DT.TAB_SPECIAL_COMMENT) + if len(GuidCommentList) >= 1: + if not GuidCommentList[0].strip().startswith((DT.TAB_INF_USAGE_PRO, + DT.TAB_INF_USAGE_SOME_PRO, + DT.TAB_INF_USAGE_CON, + DT.TAB_INF_USAGE_SOME_CON, + DT.TAB_INF_USAGE_NOTIFY, + DT.TAB_INF_USAGE_TO_START, + DT.TAB_INF_USAGE_BY_START, + DT.TAB_INF_USAGE_UNDEFINED)): + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PROTOCOL, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0]) + else: + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PROTOCOL, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0]) + + + # Check Ppi Format in module INF + def MetaDataFileCheckModuleFilePpiFormat(self): + if EccGlobalData.gConfig.MetaDataFileCheckModuleFilePpiFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': + EdkLogger.quiet("Check Ppi Format in module INF ...") + Table = EccGlobalData.gDb.TblInf + SqlCommand = """ + select ID, Value1, Usage, BelongsToFile from %s where Model = %s group by ID + """ % (Table.Table, MODEL_EFI_PPI) + RecordSet = Table.Exec(SqlCommand) + for Record in RecordSet: + Value1 = Record[1] + Value2 = Record[2] + GuidCommentList = [] + InfPath = self.GetInfFilePathFromID(Record[3]) + Msg = "The Ppi format of %s in INF file [%s] does not follow rules" % (Value1, InfPath) + if Value2.startswith(DT.TAB_SPECIAL_COMMENT): + GuidCommentList = Value2[2:].split(DT.TAB_SPECIAL_COMMENT) + if len(GuidCommentList) >= 1: + if not GuidCommentList[0].strip().startswith((DT.TAB_INF_USAGE_PRO, + DT.TAB_INF_USAGE_SOME_PRO, + DT.TAB_INF_USAGE_CON, + DT.TAB_INF_USAGE_SOME_CON, + DT.TAB_INF_USAGE_NOTIFY, + DT.TAB_INF_USAGE_UNDEFINED)): + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PPI, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0]) + else: + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PPI, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0]) + + # Check Pcd Format in module INF + def MetaDataFileCheckModuleFilePcdFormat(self): + if EccGlobalData.gConfig.MetaDataFileCheckModuleFilePcdFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': + EdkLogger.quiet("Check Pcd Format in module INF ...") + Table = EccGlobalData.gDb.TblInf + SqlCommand = """ + select ID, Model, Value1, Value2, Usage, BelongsToFile from %s where Model >= %s and Model < %s group by ID + """ % (Table.Table, MODEL_PCD, MODEL_META_DATA_HEADER) + RecordSet = Table.Exec(SqlCommand) + for Record in RecordSet: + Model = Record[1] + PcdName = Record[2] + '.' + Record[3] + Usage = Record[4] + PcdCommentList = [] + InfPath = self.GetInfFilePathFromID(Record[5]) + Msg = "The Pcd format of %s in INF file [%s] does not follow rules" % (PcdName, InfPath) + if Usage.startswith(DT.TAB_SPECIAL_COMMENT): + PcdCommentList = Usage[2:].split(DT.TAB_SPECIAL_COMMENT) + if len(PcdCommentList) >= 1: + if Model in [MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_FEATURE_FLAG] \ + and not PcdCommentList[0].strip().startswith((DT.TAB_INF_USAGE_SOME_PRO, + DT.TAB_INF_USAGE_CON, + DT.TAB_INF_USAGE_UNDEFINED)): + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PCD, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0]) + if Model in [MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_DYNAMIC, MODEL_PCD_DYNAMIC_EX] \ + and not PcdCommentList[0].strip().startswith((DT.TAB_INF_USAGE_PRO, + DT.TAB_INF_USAGE_SOME_PRO, + DT.TAB_INF_USAGE_CON, + DT.TAB_INF_USAGE_SOME_CON, + DT.TAB_INF_USAGE_UNDEFINED)): + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PCD, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0]) + else: + EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PCD, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0]) + # Check whether these is duplicate Guid/Ppi/Protocol name def CheckGuidProtocolPpi(self, ErrorID, Model, Table): Name = '' @@ -835,8 +1215,8 @@ class Check(object): SqlCommand = """ select A.ID, A.Value1 from %s as A, %s as B where A.Model = %s and B.Model = %s - and A.Value1 = B.Value1 and A.ID <> B.ID - and A.Arch = B.Arch + and A.Value1 like B.Value1 and A.ID <> B.ID + and A.Scope1 = B.Scope1 and A.Enabled > -1 and B.Enabled > -1 group by A.ID @@ -857,16 +1237,16 @@ class Check(object): if Model == MODEL_EFI_PPI: Name = 'ppi' SqlCommand = """ - select A.ID, A.Value2 from %s as A, %s as B + select A.ID, A.Value1, A.Value2 from %s as A, %s as B where A.Model = %s and B.Model = %s - and A.Value2 = B.Value2 and A.ID <> B.ID - and A.Arch = B.Arch + and A.Value2 like B.Value2 and A.ID <> B.ID + and A.Scope1 = B.Scope1 and A.Value1 <> B.Value1 group by A.ID """ % (Table.Table, Table.Table, Model, Model) RecordSet = Table.Exec(SqlCommand) - for Record in RecordSet: - if not EccGlobalData.gException.IsException(ErrorID, Record[1]): - EccGlobalData.gDb.TblReport.Insert(ErrorID, OtherMsg="The %s value [%s] is used more than one time" % (Name.upper(), Record[1]), BelongsToTable=Table.Table, BelongsToItem=Record[0]) + for Record in RecordSet: + if not EccGlobalData.gException.IsException(ErrorID, Record[2]): + EccGlobalData.gDb.TblReport.Insert(ErrorID, OtherMsg="The %s value [%s] is used more than one time" % (Name.upper(), Record[2]), BelongsToTable=Table.Table, BelongsToItem=Record[0]) # Naming Convention Check def NamingConventionCheck(self): @@ -887,9 +1267,10 @@ class Check(object): FileTable = 'Identifier' + str(Id) self.NamingConventionCheckDefineStatement(FileTable) self.NamingConventionCheckTypedefStatement(FileTable) - self.NamingConventionCheckIfndefStatement(FileTable) self.NamingConventionCheckVariableName(FileTable) self.NamingConventionCheckSingleCharacterVariable(FileTable) + if os.path.splitext(F)[1] in ('.h'): + self.NamingConventionCheckIfndefStatement(FileTable) self.NamingConventionCheckPathName() self.NamingConventionCheckFunctionName() @@ -931,7 +1312,7 @@ class Check(object): # Check whether the #ifndef at the start of an include file uses both prefix and postfix underscore characters, '_'. def NamingConventionCheckIfndefStatement(self, FileTable): - if EccGlobalData.gConfig.NamingConventionCheckTypedefStatement == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': + if EccGlobalData.gConfig.NamingConventionCheckIfndefStatement == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': EdkLogger.quiet("Checking naming covention of #ifndef statement ...") SqlCommand = """select ID, Value from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_MACRO_IFNDEF) @@ -972,7 +1353,10 @@ class Check(object): SqlCommand = """select ID, Name from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_VARIABLE) RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand) for Record in RecordSet: - if not Pattern.match(Record[1]): + Var = Record[1] + if Var.startswith('CONST'): + Var = Var[5:].lstrip() + if not Pattern.match(Var): if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, Record[1]): EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, OtherMsg="The variable name [%s] does not follow the rules" % (Record[1]), BelongsToTable=FileTable, BelongsToItem=Record[0]) @@ -1005,6 +1389,19 @@ class Check(object): if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_SINGLE_CHARACTER_VARIABLE, Record[1]): EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_SINGLE_CHARACTER_VARIABLE, OtherMsg="The variable name [%s] does not follow the rules" % (Record[1]), BelongsToTable=FileTable, BelongsToItem=Record[0]) +def FindPara(FilePath, Para, CallingLine): + Lines = open(FilePath).readlines() + Line = '' + for Index in range(CallingLine - 1, 0, -1): + # Find the nearest statement for Para + Line = Lines[Index].strip() + if Line.startswith('%s = ' % Para): + Line = Line.strip() + return Line + break + + return '' + ## # # This acts like the main() function for the script, unless it is 'import'ed into another