## @file\r
# This file is used to define checkpoints used by ECC tool\r
#\r
-# Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>\r
-# This program and the accompanying materials\r
-# are licensed and made available under the terms and conditions of the BSD License\r
-# which accompanies this distribution. The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
#\r
+from __future__ import absolute_import\r
import Common.LongFilePathOs as os\r
import re\r
from CommonDataClass.DataClass import *\r
-from Common.DataType import SUP_MODULE_LIST_STRING, TAB_VALUE_SPLIT\r
-from EccToolError import *\r
-from MetaDataParser import ParseHeaderCommentSection\r
-import EccGlobalData\r
-import c\r
+import Common.DataType as DT\r
+from Ecc.EccToolError import *\r
+from Ecc.MetaDataParser import ParseHeaderCommentSection\r
+from Ecc import EccGlobalData\r
+from Ecc import c\r
+from Common.LongFilePathSupport import OpenLongFilePath as open\r
+from Common.MultipleWorkspace import MultipleWorkspace as mws\r
\r
## Check\r
#\r
self.DeclAndDataTypeCheck()\r
self.FunctionLayoutCheck()\r
self.NamingConventionCheck()\r
+ self.SmmCommParaCheck()\r
+\r
+ def SmmCommParaCheck(self):\r
+ self.SmmCommParaCheckBufferType()\r
+\r
+\r
+ # Check if SMM communication function has correct parameter type\r
+ # 1. Get function calling with instance./->Communicate() interface\r
+ # and make sure the protocol instance is of type EFI_SMM_COMMUNICATION_PROTOCOL.\r
+ # 2. Find the origin of the 2nd parameter of Communicate() interface, if -\r
+ # a. it is a local buffer on stack\r
+ # report error.\r
+ # b. it is a global buffer, check the driver that holds the global buffer is of type DXE_RUNTIME_DRIVER\r
+ # report success.\r
+ # c. it is a buffer by AllocatePage/AllocatePool (may be wrapped by nested function calls),\r
+ # check the EFI_MEMORY_TYPE to be EfiRuntimeServicesCode,EfiRuntimeServicesData,\r
+ # EfiACPIMemoryNVS or EfiReservedMemoryType\r
+ # report success.\r
+ # d. it is a buffer located via EFI_SYSTEM_TABLE.ConfigurationTable (may be wrapped by nested function calls)\r
+ # report warning to indicate human code review.\r
+ # e. it is a buffer from other kind of pointers (may need to trace into nested function calls to locate),\r
+ # repeat checks in a.b.c and d.\r
+ def SmmCommParaCheckBufferType(self):\r
+ if EccGlobalData.gConfig.SmmCommParaCheckBufferType == '1' or EccGlobalData.gConfig.SmmCommParaCheckAll == '1':\r
+ EdkLogger.quiet("Checking SMM communication parameter type ...")\r
+ # Get all EFI_SMM_COMMUNICATION_PROTOCOL interface\r
+ CommApiList = []\r
+ for IdentifierTable in EccGlobalData.gIdentifierTableList:\r
+ SqlCommand = """select ID, Name, BelongsToFile from %s\r
+ where Modifier = 'EFI_SMM_COMMUNICATION_PROTOCOL*' """ % (IdentifierTable)\r
+ RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ if RecordSet:\r
+ for Record in RecordSet:\r
+ if Record[1] not in CommApiList:\r
+ CommApiList.append(Record[1])\r
+ # For each interface, check the second parameter\r
+ for CommApi in CommApiList:\r
+ for IdentifierTable in EccGlobalData.gIdentifierTableList:\r
+ SqlCommand = """select ID, Name, Value, BelongsToFile, StartLine from %s\r
+ where Name = '%s->Communicate' and Model = %s""" \\r
+ % (IdentifierTable, CommApi, MODEL_IDENTIFIER_FUNCTION_CALLING)\r
+ RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ if RecordSet:\r
+ # print IdentifierTable\r
+ for Record in RecordSet:\r
+ # Get the second parameter for Communicate function\r
+ SecondPara = Record[2].split(',')[1].strip()\r
+ SecondParaIndex = None\r
+ if SecondPara.startswith('&'):\r
+ SecondPara = SecondPara[1:]\r
+ if SecondPara.endswith(']'):\r
+ SecondParaIndex = SecondPara[SecondPara.find('[') + 1:-1]\r
+ SecondPara = SecondPara[:SecondPara.find('[')]\r
+ # Get the ID\r
+ Id = Record[0]\r
+ # Get the BelongsToFile\r
+ BelongsToFile = Record[3]\r
+ # Get the source file path\r
+ SqlCommand = """select FullPath from File where ID = %s""" % BelongsToFile\r
+ NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ FullPath = NewRecordSet[0][0]\r
+ # Get the line no of function calling\r
+ StartLine = Record[4]\r
+ # Get the module type\r
+ SqlCommand = """select Value3 from INF where BelongsToFile = (select ID from File\r
+ where Path = (select Path from File where ID = %s) and Model = 1011)\r
+ and Value2 = 'MODULE_TYPE'""" % BelongsToFile\r
+ NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ ModuleType = NewRecordSet[0][0] if NewRecordSet else None\r
+\r
+ # print BelongsToFile, FullPath, StartLine, ModuleType, SecondPara\r
+\r
+ Value = FindPara(FullPath, SecondPara, StartLine)\r
+ # Find the value of the parameter\r
+ if Value:\r
+ if 'AllocatePage' in Value \\r
+ or 'AllocatePool' in Value \\r
+ or 'AllocateRuntimePool' in Value \\r
+ or 'AllocateZeroPool' in Value:\r
+ pass\r
+ else:\r
+ if '->' in Value:\r
+ if not EccGlobalData.gException.IsException(\r
+ ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, Value):\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE,\r
+ OtherMsg="Please review the buffer type"\r
+ + "is correct or not. If it is correct" +\r
+ " please add [%s] to exception list"\r
+ % Value,\r
+ BelongsToTable=IdentifierTable,\r
+ BelongsToItem=Id)\r
+ else:\r
+ if not EccGlobalData.gException.IsException(\r
+ ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, Value):\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE,\r
+ OtherMsg="Please review the buffer type"\r
+ + "is correct or not. If it is correct" +\r
+ " please add [%s] to exception list"\r
+ % Value,\r
+ BelongsToTable=IdentifierTable,\r
+ BelongsToItem=Id)\r
+\r
+\r
+ # Not find the value of the parameter\r
+ else:\r
+ SqlCommand = """select ID, Modifier, Name, Value, Model, BelongsToFunction from %s\r
+ where Name = '%s' and StartLine < %s order by StartLine DESC""" \\r
+ % (IdentifierTable, SecondPara, StartLine)\r
+ NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ if NewRecordSet:\r
+ Value = NewRecordSet[0][1]\r
+ if 'AllocatePage' in Value \\r
+ or 'AllocatePool' in Value \\r
+ or 'AllocateRuntimePool' in Value \\r
+ or 'AllocateZeroPool' in Value:\r
+ pass\r
+ else:\r
+ if not EccGlobalData.gException.IsException(\r
+ ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, Value):\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE,\r
+ OtherMsg="Please review the buffer type"\r
+ + "is correct or not. If it is correct" +\r
+ " please add [%s] to exception list"\r
+ % Value,\r
+ BelongsToTable=IdentifierTable,\r
+ BelongsToItem=Id)\r
+ else:\r
+ pass\r
+\r
+ # Check UNI files\r
+ def UniCheck(self):\r
+ if EccGlobalData.gConfig.GeneralCheckUni == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Checking whether UNI file is UTF-16 ...")\r
+ SqlCommand = """select ID, FullPath, ExtName from File where ExtName like 'uni'"""\r
+ RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ File = Record[1]\r
+ FileIn = open(File, 'rb').read(2)\r
+ if FileIn != '\xff\xfe':\r
+ OtherMsg = "File %s is not a valid UTF-16 UNI file" % Record[1]\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_UNI, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0])\r
\r
# General Checking\r
def GeneralCheck(self):\r
self.GeneralCheckNonAcsii()\r
+ self.UniCheck()\r
+ self.GeneralCheckNoTab()\r
+ self.GeneralCheckLineEnding()\r
+ self.GeneralCheckTrailingWhiteSpaceLine()\r
+\r
+ # Check whether NO Tab is used, replaced with spaces\r
+ def GeneralCheckNoTab(self):\r
+ if EccGlobalData.gConfig.GeneralCheckNoTab == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Checking No TAB used in file ...")\r
+ SqlCommand = """select ID, FullPath, ExtName from File where ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')"""\r
+ RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList:\r
+ op = open(Record[1]).readlines()\r
+ IndexOfLine = 0\r
+ for Line in op:\r
+ IndexOfLine += 1\r
+ IndexOfChar = 0\r
+ for Char in Line:\r
+ IndexOfChar += 1\r
+ if Char == '\t':\r
+ OtherMsg = "File %s has TAB char at line %s column %s" % (Record[1], IndexOfLine, IndexOfChar)\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_NO_TAB, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0])\r
+\r
+ # Check Only use CRLF (Carriage Return Line Feed) line endings.\r
+ def GeneralCheckLineEnding(self):\r
+ if EccGlobalData.gConfig.GeneralCheckLineEnding == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Checking line ending in file ...")\r
+ SqlCommand = """select ID, FullPath, ExtName from File where ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')"""\r
+ RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList:\r
+ op = open(Record[1], 'rb').readlines()\r
+ IndexOfLine = 0\r
+ for Line in op:\r
+ IndexOfLine += 1\r
+ if not bytes.decode(Line).endswith('\r\n'):\r
+ OtherMsg = "File %s has invalid line ending at line %s" % (Record[1], IndexOfLine)\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_INVALID_LINE_ENDING, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0])\r
+\r
+ # Check if there is no trailing white space in one line.\r
+ def GeneralCheckTrailingWhiteSpaceLine(self):\r
+ if EccGlobalData.gConfig.GeneralCheckTrailingWhiteSpaceLine == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Checking trailing white space line in file ...")\r
+ SqlCommand = """select ID, FullPath, ExtName from File where ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')"""\r
+ RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList:\r
+ op = open(Record[1], 'r').readlines()\r
+ IndexOfLine = 0\r
+ for Line in op:\r
+ IndexOfLine += 1\r
+ if Line.replace('\r', '').replace('\n', '').endswith(' '):\r
+ OtherMsg = "File %s has trailing white spaces at line %s" % (Record[1], IndexOfLine)\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_TRAILING_WHITE_SPACE_LINE, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0])\r
\r
# Check whether file has non ACSII char\r
def GeneralCheckNonAcsii(self):\r
if EccGlobalData.gConfig.GeneralCheckNonAcsii == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
EdkLogger.quiet("Checking Non-ACSII char in file ...")\r
- SqlCommand = """select ID, FullPath, ExtName from File"""\r
+ SqlCommand = """select ID, FullPath, ExtName from File where ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')"""\r
RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
for Record in RecordSet:\r
if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList:\r
self.FunctionLayoutCheckPrototype()\r
self.FunctionLayoutCheckBody()\r
self.FunctionLayoutCheckLocalVariable()\r
+ self.FunctionLayoutCheckDeprecated()\r
+ \r
+ # To check if the deprecated functions are used\r
+ def FunctionLayoutCheckDeprecated(self):\r
+ if EccGlobalData.gConfig.CFunctionLayoutCheckNoDeprecated == '1' or EccGlobalData.gConfig.CFunctionLayoutCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Checking function no deprecated one being used ...")\r
+\r
+ DeprecatedFunctionSet = ('UnicodeValueToString',\r
+ 'AsciiValueToString',\r
+ 'StrCpy',\r
+ 'StrnCpy',\r
+ 'StrCat',\r
+ 'StrnCat',\r
+ 'UnicodeStrToAsciiStr',\r
+ 'AsciiStrCpy',\r
+ 'AsciiStrnCpy',\r
+ 'AsciiStrCat',\r
+ 'AsciiStrnCat',\r
+ 'AsciiStrToUnicodeStr',\r
+ 'PcdSet8',\r
+ 'PcdSet16',\r
+ 'PcdSet32',\r
+ 'PcdSet64',\r
+ 'PcdSetPtr',\r
+ 'PcdSetBool',\r
+ 'PcdSetEx8',\r
+ 'PcdSetEx16',\r
+ 'PcdSetEx32',\r
+ 'PcdSetEx64',\r
+ 'PcdSetExPtr',\r
+ 'PcdSetExBool',\r
+ 'LibPcdSet8',\r
+ 'LibPcdSet16',\r
+ 'LibPcdSet32',\r
+ 'LibPcdSet64',\r
+ 'LibPcdSetPtr',\r
+ 'LibPcdSetBool',\r
+ 'LibPcdSetEx8',\r
+ 'LibPcdSetEx16',\r
+ 'LibPcdSetEx32',\r
+ 'LibPcdSetEx64',\r
+ 'LibPcdSetExPtr',\r
+ 'LibPcdSetExBool',\r
+ 'GetVariable',\r
+ 'GetEfiGlobalVariable',\r
+ )\r
+\r
+ for IdentifierTable in EccGlobalData.gIdentifierTableList:\r
+ SqlCommand = """select ID, Name, BelongsToFile from %s\r
+ where Model = %s """ % (IdentifierTable, MODEL_IDENTIFIER_FUNCTION_CALLING)\r
+ RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ for Key in DeprecatedFunctionSet:\r
+ if Key == Record[1]:\r
+ if not EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_NO_DEPRECATE, Key):\r
+ OtherMsg = 'The function [%s] is deprecated which should NOT be used' % Key\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_C_FUNCTION_LAYOUT_CHECK_NO_DEPRECATE,\r
+ OtherMsg=OtherMsg,\r
+ BelongsToTable=IdentifierTable,\r
+ BelongsToItem=Record[0])\r
\r
def WalkTree(self):\r
IgnoredPattern = c.GetIgnoredDirListPattern()\r
Dirnames.append(Dirname)\r
if IgnoredPattern.match(Dirpath.upper()):\r
continue\r
+ for f in Filenames[:]:\r
+ if f.lower() in EccGlobalData.gConfig.SkipFileList:\r
+ Filenames.remove(f)\r
yield (Dirpath, Dirnames, Filenames)\r
\r
# Check whether return type exists and in the first line\r
for Key in RecordDict:\r
if len(RecordDict[Key]) > 1:\r
for Item in RecordDict[Key]:\r
- Path = Item[1].replace(EccGlobalData.gWorkspace, '')\r
- if Path.startswith('\\') or Path.startswith('/'):\r
- Path = Path[1:]\r
+ Path = mws.relpath(Item[1], EccGlobalData.gWorkspace)\r
if not EccGlobalData.gException.IsException(ERROR_INCLUDE_FILE_CHECK_NAME, Path):\r
EccGlobalData.gDb.TblReport.Insert(ERROR_INCLUDE_FILE_CHECK_NAME, OtherMsg="The file name for [%s] is duplicate" % Path, BelongsToTable='File', BelongsToItem=Item[0])\r
\r
if EccGlobalData.gConfig.IncludeFileCheckData == '1' or EccGlobalData.gConfig.IncludeFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
EdkLogger.quiet("Checking header file data ...")\r
\r
+ # Get all typedef functions\r
+ gAllTypedefFun = []\r
+ for IdentifierTable in EccGlobalData.gIdentifierTableList:\r
+ SqlCommand = """select Name from %s\r
+ where Model = %s """ % (IdentifierTable, MODEL_IDENTIFIER_TYPEDEF)\r
+ RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ if Record[0].startswith('('):\r
+ gAllTypedefFun.append(Record[0])\r
+\r
# for Dirpath, Dirnames, Filenames in self.WalkTree():\r
# for F in Filenames:\r
# if os.path.splitext(F)[1] in ('.h'):\r
# FullName = os.path.join(Dirpath, F)\r
# MsgList = c.CheckHeaderFileData(FullName)\r
for FullName in EccGlobalData.gHFileList:\r
- MsgList = c.CheckHeaderFileData(FullName)\r
+ MsgList = c.CheckHeaderFileData(FullName, gAllTypedefFun)\r
\r
# Doxygen document checking\r
def DoxygenCheck(self):\r
op = open(FullName).readlines()\r
FileLinesList = op\r
LineNo = 0\r
- CurrentSection = MODEL_UNKNOWN \r
+ CurrentSection = MODEL_UNKNOWN\r
HeaderSectionLines = []\r
- HeaderCommentStart = False \r
+ HeaderCommentStart = False\r
HeaderCommentEnd = False\r
- \r
+\r
for Line in FileLinesList:\r
LineNo = LineNo + 1\r
Line = Line.strip()\r
if (LineNo < len(FileLinesList) - 1):\r
NextLine = FileLinesList[LineNo].strip()\r
- \r
+\r
#\r
# blank line\r
#\r
#\r
HeaderSectionLines.append((Line, LineNo))\r
HeaderCommentStart = True\r
- continue \r
- \r
+ continue\r
+\r
#\r
# Collect Header content.\r
#\r
if EccGlobalData.gConfig.HeaderCheckFileCommentEnd == '1' or EccGlobalData.gConfig.HeaderCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
EccGlobalData.gDb.TblReport.Insert(ERROR_DOXYGEN_CHECK_FILE_HEADER, Msg, "File", Result[0])\r
\r
- \r
+\r
\r
# Check whether the function headers are followed Doxygen special documentation blocks in section 2.3.5\r
def DoxygenCheckFunctionHeader(self):\r
self.MetaDataFileCheckLibraryInstanceDependent()\r
self.MetaDataFileCheckLibraryInstanceOrder()\r
self.MetaDataFileCheckLibraryNoUse()\r
+ self.MetaDataFileCheckLibraryDefinedInDec()\r
self.MetaDataFileCheckBinaryInfInFdf()\r
self.MetaDataFileCheckPcdDuplicate()\r
self.MetaDataFileCheckPcdFlash()\r
self.MetaDataFileCheckModuleFileNoUse()\r
self.MetaDataFileCheckPcdType()\r
self.MetaDataFileCheckModuleFileGuidDuplication()\r
+ self.MetaDataFileCheckModuleFileGuidFormat()\r
+ self.MetaDataFileCheckModuleFileProtocolFormat()\r
+ self.MetaDataFileCheckModuleFilePpiFormat()\r
+ self.MetaDataFileCheckModuleFilePcdFormat()\r
\r
# Check whether each file defined in meta-data exists\r
def MetaDataFileCheckPathName(self):\r
List = Record[1].split('|', 1)\r
SupModType = []\r
if len(List) == 1:\r
- SupModType = SUP_MODULE_LIST_STRING.split(TAB_VALUE_SPLIT)\r
+ SupModType = DT.SUP_MODULE_LIST_STRING.split(DT.TAB_VALUE_SPLIT)\r
elif len(List) == 2:\r
SupModType = List[1].split()\r
\r
if Item not in LibraryClasses[List[0]]:\r
LibraryClasses[List[0]].append(Item)\r
\r
- if Record[2] != 'BASE' and Record[2] not in SupModType:\r
+ if Record[2] != DT.SUP_MODULE_BASE and Record[2] not in SupModType:\r
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])\r
\r
SqlCommand = """select A.ID, A.Value1, B.Value3 from Inf as A left join Inf as B\r
\r
for Record in RecordSet:\r
if Record[1] in LibraryClasses:\r
- if Record[2] not in LibraryClasses[Record[1]] and 'BASE' not in RecordDict[Record[1]]:\r
+ if Record[2] not in LibraryClasses[Record[1]] and DT.SUP_MODULE_BASE not in RecordDict[Record[1]]:\r
if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_INSTANCE_1, Record[1]):\r
EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_INSTANCE_1, OtherMsg="The type of Library Class [%s] defined in Inf file does not match the type of the module" % (Record[1]), BelongsToTable='Inf', BelongsToItem=Record[0])\r
else:\r
if LibraryClass[1].upper() == 'NULL' or LibraryClass[1].startswith('!ifdef') or LibraryClass[1].startswith('!ifndef') or LibraryClass[1].endswith('!endif'):\r
continue\r
else:\r
- LibraryIns = os.path.normpath(os.path.join(EccGlobalData.gWorkspace, LibraryClass[2]))\r
+ LibraryIns = os.path.normpath(mws.join(EccGlobalData.gWorkspace, LibraryClass[2]))\r
+ SkipDirString = '|'.join(EccGlobalData.gConfig.SkipDirList)\r
+ p = re.compile(r'.*[\\/](?:%s^\S)[\\/]?.*' % SkipDirString)\r
+ if p.match(os.path.split(LibraryIns)[0].upper()):\r
+ continue\r
SqlCommand = """select Value3 from Inf where BelongsToFile =\r
(select ID from File where lower(FullPath) = lower('%s'))\r
- and Value2 = '%s'""" % (LibraryIns, 'LIBRARY_CLASS')\r
+ and Value2 = '%s'""" % (LibraryIns, DT.PLATFORM_COMPONENT_TYPE_LIBRARY_CLASS)\r
RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand)\r
IsFound = False\r
for Record in RecordSet:\r
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])\r
SqlCommand = """\r
select A.ID, A.Value1, A.BelongsToFile, A.StartLine, B.StartLine from Dsc as A left join Dsc as B\r
- where A.Model = %s and B.Model = %s and A.Scope1 = B.Scope1 and A.Scope2 = B.Scope2 and A.ID <> B.ID\r
- 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""" \\r
+ where A.Model = %s and B.Model = %s and A.Scope1 = B.Scope1 and A.Scope2 = B.Scope2 and A.ID != B.ID\r
+ 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""" \\r
% (MODEL_EFI_LIBRARY_CLASS, MODEL_EFI_LIBRARY_CLASS)\r
RecordSet = EccGlobalData.gDb.TblDsc.Exec(SqlCommand)\r
for Record in RecordSet:\r
- if Record[3] and Record[4] and Record[3] != Record[4]:\r
+ if Record[3] and Record[4] and Record[3] != Record[4] and Record[1] != 'NULL':\r
SqlCommand = """select FullPath from File where ID = %s""" % (Record[2])\r
FilePathList = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
for FilePath in FilePathList:\r
if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_NAME_DUPLICATE, Record[1]):\r
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])\r
- \r
+\r
+ # Check the header file in Include\Library directory whether be defined in the package DEC file.\r
+ def MetaDataFileCheckLibraryDefinedInDec(self):\r
+ if EccGlobalData.gConfig.MetaDataFileCheckLibraryDefinedInDec == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Checking for library instance whether be defined in the package dec file ...")\r
+ SqlCommand = """\r
+ select A.Value1, A.StartLine, A.ID, B.Value1 from Inf as A left join Dec as B\r
+ on A.Model = B.Model and A.Value1 = B.Value1 where A.Model=%s\r
+ """ % MODEL_EFI_LIBRARY_CLASS\r
+ RecordSet = EccGlobalData.gDb.TblDsc.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ LibraryInInf, Line, ID, LibraryDec = Record\r
+ if not LibraryDec:\r
+ if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_NOT_DEFINED, LibraryInInf):\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_NOT_DEFINED, \\r
+ OtherMsg="The Library Class [%s] in %s line is not defined in the associated package file." % (LibraryInInf, Line),\r
+ BelongsToTable='Inf', BelongsToItem=ID)\r
+\r
# 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\r
def MetaDataFileCheckBinaryInfInFdf(self):\r
if EccGlobalData.gConfig.MetaDataFileCheckBinaryInfInFdf == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
for Record in RecordSet:\r
FdfID = Record[0]\r
FilePath = Record[1]\r
- FilePath = os.path.normpath(os.path.join(EccGlobalData.gWorkspace, FilePath))\r
+ FilePath = os.path.normpath(mws.join(EccGlobalData.gWorkspace, FilePath))\r
SqlCommand = """select ID from Inf where Model = %s and BelongsToFile = (select ID from File where FullPath like '%s')\r
""" % (MODEL_EFI_SOURCE_FILE, FilePath)\r
NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
and A.Value1 = B.Value1\r
and A.Value2 = B.Value2\r
and A.Scope1 = B.Scope1\r
- and A.ID <> B.ID\r
+ and A.ID != B.ID\r
and A.Model = B.Model\r
and A.Enabled > -1\r
and B.Enabled > -1\r
RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand)\r
for Record in RecordSet:\r
Path = Record[1]\r
- Path = Path.upper().replace('\X64', '').replace('\IA32', '').replace('\EBC', '').replace('\IPF', '').replace('\ARM', '').replace('\AARCH64', '')\r
+ Path = Path.upper().replace('\X64', '').replace('\IA32', '').replace('\EBC', '').replace('\IPF', '').replace('\ARM', '')\r
if Path in InfPathList:\r
if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_MODULE_FILE_NO_USE, Record[2]):\r
EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_MODULE_FILE_NO_USE, OtherMsg="The source file [%s] is existing in module directory but it is not described in INF file." % (Record[2]), BelongsToTable='File', BelongsToItem=Record[0])\r
RecordSet = Table.Exec(SqlCommand)\r
Path = ""\r
for Record in RecordSet:\r
- Path = Record[0].replace(EccGlobalData.gWorkspace, '')\r
- if Path.startswith('\\') or Path.startswith('/'):\r
- Path = Path[1:]\r
+ Path = mws.relpath(Record[0], EccGlobalData.gWorkspace)\r
return Path\r
\r
# Check whether two module INFs under one workspace has the same FILE_GUID value\r
SqlCommand = """\r
select A.ID, A.Value3, A.BelongsToFile, B.BelongsToFile from %s as A, %s as B\r
where A.Value2 = 'FILE_GUID' and B.Value2 = 'FILE_GUID' and\r
- A.Value3 = B.Value3 and A.ID <> B.ID group by A.ID\r
+ A.Value3 = B.Value3 and A.ID != B.ID group by A.ID\r
""" % (Table.Table, Table.Table)\r
RecordSet = Table.Exec(SqlCommand)\r
for Record in RecordSet:\r
EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_MODULE_FILE_GUID_DUPLICATION, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
\r
\r
+ # Check Guid Format in module INF\r
+ def MetaDataFileCheckModuleFileGuidFormat(self):\r
+ if EccGlobalData.gConfig.MetaDataFileCheckModuleFileGuidFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Check Guid Format in module INF ...")\r
+ Table = EccGlobalData.gDb.TblInf\r
+ SqlCommand = """\r
+ select ID, Value1, Usage, BelongsToFile from %s where Model = %s group by ID\r
+ """ % (Table.Table, MODEL_EFI_GUID)\r
+ RecordSet = Table.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ Value1 = Record[1]\r
+ Value2 = Record[2]\r
+ GuidCommentList = []\r
+ InfPath = self.GetInfFilePathFromID(Record[3])\r
+ Msg = "The GUID format of %s in INF file [%s] does not follow rules" % (Value1, InfPath)\r
+ if Value2.startswith(DT.TAB_SPECIAL_COMMENT):\r
+ GuidCommentList = Value2[2:].split(DT.TAB_SPECIAL_COMMENT)\r
+ if GuidCommentList[0].strip().startswith(DT.TAB_INF_USAGE_UNDEFINED):\r
+ continue\r
+ elif len(GuidCommentList) > 1:\r
+ if not GuidCommentList[0].strip().startswith((DT.TAB_INF_USAGE_PRO,\r
+ DT.TAB_INF_USAGE_SOME_PRO,\r
+ DT.TAB_INF_USAGE_CON,\r
+ DT.TAB_INF_USAGE_SOME_CON)):\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_GUID, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
+ if not (GuidCommentList[1].strip()).startswith(DT.TAB_INF_GUIDTYPE_VAR) and \\r
+ not GuidCommentList[1].strip().startswith((DT.TAB_INF_GUIDTYPE_EVENT,\r
+ DT.TAB_INF_GUIDTYPE_HII,\r
+ DT.TAB_INF_GUIDTYPE_FILE,\r
+ DT.TAB_INF_GUIDTYPE_HOB,\r
+ DT.TAB_INF_GUIDTYPE_FV,\r
+ DT.TAB_INF_GUIDTYPE_ST,\r
+ DT.TAB_INF_GUIDTYPE_TSG,\r
+ DT.TAB_INF_GUIDTYPE_GUID,\r
+ DT.TAB_INF_GUIDTYPE_PROTOCOL,\r
+ DT.TAB_INF_GUIDTYPE_PPI,\r
+ DT.TAB_INF_USAGE_UNDEFINED)):\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_GUID, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
+ else:\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_GUID, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
+ else:\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_GUID, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
+\r
+ # Check Protocol Format in module INF\r
+ def MetaDataFileCheckModuleFileProtocolFormat(self):\r
+ if EccGlobalData.gConfig.MetaDataFileCheckModuleFileProtocolFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Check Protocol Format in module INF ...")\r
+ Table = EccGlobalData.gDb.TblInf\r
+ SqlCommand = """\r
+ select ID, Value1, Usage, BelongsToFile from %s where Model = %s group by ID\r
+ """ % (Table.Table, MODEL_EFI_PROTOCOL)\r
+ RecordSet = Table.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ Value1 = Record[1]\r
+ Value2 = Record[2]\r
+ GuidCommentList = []\r
+ InfPath = self.GetInfFilePathFromID(Record[3])\r
+ Msg = "The Protocol format of %s in INF file [%s] does not follow rules" % (Value1, InfPath)\r
+ if Value2.startswith(DT.TAB_SPECIAL_COMMENT):\r
+ GuidCommentList = Value2[2:].split(DT.TAB_SPECIAL_COMMENT)\r
+ if len(GuidCommentList) >= 1:\r
+ if not GuidCommentList[0].strip().startswith((DT.TAB_INF_USAGE_PRO,\r
+ DT.TAB_INF_USAGE_SOME_PRO,\r
+ DT.TAB_INF_USAGE_CON,\r
+ DT.TAB_INF_USAGE_SOME_CON,\r
+ DT.TAB_INF_USAGE_NOTIFY,\r
+ DT.TAB_INF_USAGE_TO_START,\r
+ DT.TAB_INF_USAGE_BY_START,\r
+ DT.TAB_INF_USAGE_UNDEFINED)):\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PROTOCOL, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
+ else:\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PROTOCOL, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
+\r
+\r
+ # Check Ppi Format in module INF\r
+ def MetaDataFileCheckModuleFilePpiFormat(self):\r
+ if EccGlobalData.gConfig.MetaDataFileCheckModuleFilePpiFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Check Ppi Format in module INF ...")\r
+ Table = EccGlobalData.gDb.TblInf\r
+ SqlCommand = """\r
+ select ID, Value1, Usage, BelongsToFile from %s where Model = %s group by ID\r
+ """ % (Table.Table, MODEL_EFI_PPI)\r
+ RecordSet = Table.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ Value1 = Record[1]\r
+ Value2 = Record[2]\r
+ GuidCommentList = []\r
+ InfPath = self.GetInfFilePathFromID(Record[3])\r
+ Msg = "The Ppi format of %s in INF file [%s] does not follow rules" % (Value1, InfPath)\r
+ if Value2.startswith(DT.TAB_SPECIAL_COMMENT):\r
+ GuidCommentList = Value2[2:].split(DT.TAB_SPECIAL_COMMENT)\r
+ if len(GuidCommentList) >= 1:\r
+ if not GuidCommentList[0].strip().startswith((DT.TAB_INF_USAGE_PRO,\r
+ DT.TAB_INF_USAGE_SOME_PRO,\r
+ DT.TAB_INF_USAGE_CON,\r
+ DT.TAB_INF_USAGE_SOME_CON,\r
+ DT.TAB_INF_USAGE_NOTIFY,\r
+ DT.TAB_INF_USAGE_UNDEFINED)):\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PPI, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
+ else:\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PPI, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
+\r
+ # Check Pcd Format in module INF\r
+ def MetaDataFileCheckModuleFilePcdFormat(self):\r
+ if EccGlobalData.gConfig.MetaDataFileCheckModuleFilePcdFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Check Pcd Format in module INF ...")\r
+ Table = EccGlobalData.gDb.TblInf\r
+ SqlCommand = """\r
+ select ID, Model, Value1, Value2, Usage, BelongsToFile from %s where Model >= %s and Model < %s group by ID\r
+ """ % (Table.Table, MODEL_PCD, MODEL_META_DATA_HEADER)\r
+ RecordSet = Table.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ Model = Record[1]\r
+ PcdName = Record[2] + '.' + Record[3]\r
+ Usage = Record[4]\r
+ PcdCommentList = []\r
+ InfPath = self.GetInfFilePathFromID(Record[5])\r
+ Msg = "The Pcd format of %s in INF file [%s] does not follow rules" % (PcdName, InfPath)\r
+ if Usage.startswith(DT.TAB_SPECIAL_COMMENT):\r
+ PcdCommentList = Usage[2:].split(DT.TAB_SPECIAL_COMMENT)\r
+ if len(PcdCommentList) >= 1:\r
+ if Model in [MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_FEATURE_FLAG] \\r
+ and not PcdCommentList[0].strip().startswith((DT.TAB_INF_USAGE_SOME_PRO,\r
+ DT.TAB_INF_USAGE_CON,\r
+ DT.TAB_INF_USAGE_UNDEFINED)):\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PCD, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
+ if Model in [MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_DYNAMIC, MODEL_PCD_DYNAMIC_EX] \\r
+ and not PcdCommentList[0].strip().startswith((DT.TAB_INF_USAGE_PRO,\r
+ DT.TAB_INF_USAGE_SOME_PRO,\r
+ DT.TAB_INF_USAGE_CON,\r
+ DT.TAB_INF_USAGE_SOME_CON,\r
+ DT.TAB_INF_USAGE_UNDEFINED)):\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PCD, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
+ else:\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PCD, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
+\r
# Check whether these is duplicate Guid/Ppi/Protocol name\r
def CheckGuidProtocolPpi(self, ErrorID, Model, Table):\r
Name = ''\r
SqlCommand = """\r
select A.ID, A.Value1 from %s as A, %s as B\r
where A.Model = %s and B.Model = %s\r
- and A.Value1 = B.Value1 and A.ID <> B.ID\r
+ and A.Value1 like B.Value1 and A.ID != B.ID\r
and A.Scope1 = B.Scope1\r
and A.Enabled > -1\r
and B.Enabled > -1\r
SqlCommand = """\r
select A.ID, A.Value1, A.Value2 from %s as A, %s as B\r
where A.Model = %s and B.Model = %s\r
- and A.Value2 = B.Value2 and A.ID <> B.ID\r
- and A.Scope1 = B.Scope1 and A.Value1 <> B.Value1\r
+ and A.Value2 like B.Value2 and A.ID != B.ID\r
+ and A.Scope1 = B.Scope1 and A.Value1 != B.Value1\r
group by A.ID\r
""" % (Table.Table, Table.Table, Model, Model)\r
RecordSet = Table.Exec(SqlCommand)\r
- for Record in RecordSet: \r
- if not EccGlobalData.gException.IsException(ErrorID, Record[1] + ':' + Record[2]):\r
+ for Record in RecordSet:\r
+ if not EccGlobalData.gException.IsException(ErrorID, Record[2]):\r
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])\r
\r
# Naming Convention Check\r
FileTable = 'Identifier' + str(Id)\r
self.NamingConventionCheckDefineStatement(FileTable)\r
self.NamingConventionCheckTypedefStatement(FileTable)\r
- self.NamingConventionCheckIfndefStatement(FileTable)\r
self.NamingConventionCheckVariableName(FileTable)\r
self.NamingConventionCheckSingleCharacterVariable(FileTable)\r
+ if os.path.splitext(F)[1] in ('.h'):\r
+ self.NamingConventionCheckIfndefStatement(FileTable)\r
\r
self.NamingConventionCheckPathName()\r
self.NamingConventionCheckFunctionName()\r
# Check whether only capital letters are used for #define declarations\r
def NamingConventionCheckDefineStatement(self, FileTable):\r
if EccGlobalData.gConfig.NamingConventionCheckDefineStatement == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
- EdkLogger.quiet("Checking naming covention of #define statement ...")\r
+ EdkLogger.quiet("Checking naming convention of #define statement ...")\r
\r
SqlCommand = """select ID, Value from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_MACRO_DEFINE)\r
RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
# Check whether only capital letters are used for typedef declarations\r
def NamingConventionCheckTypedefStatement(self, FileTable):\r
if EccGlobalData.gConfig.NamingConventionCheckTypedefStatement == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
- EdkLogger.quiet("Checking naming covention of #typedef statement ...")\r
+ EdkLogger.quiet("Checking naming convention of #typedef statement ...")\r
\r
SqlCommand = """select ID, Name from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_TYPEDEF)\r
RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
for Record in RecordSet:\r
Name = Record[1].strip()\r
- if Name != '' and Name != None:\r
+ if Name != '' and Name is not None:\r
if Name[0] == '(':\r
Name = Name[1:Name.find(')')]\r
if Name.find('(') > -1:\r
\r
# Check whether the #ifndef at the start of an include file uses both prefix and postfix underscore characters, '_'.\r
def NamingConventionCheckIfndefStatement(self, FileTable):\r
- if EccGlobalData.gConfig.NamingConventionCheckTypedefStatement == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
- EdkLogger.quiet("Checking naming covention of #ifndef statement ...")\r
+ if EccGlobalData.gConfig.NamingConventionCheckIfndefStatement == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Checking naming convention of #ifndef statement ...")\r
\r
SqlCommand = """select ID, Value from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_MACRO_IFNDEF)\r
RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
for Record in RecordSet:\r
Name = Record[1].replace('#ifndef', '').strip()\r
- if Name[0] != '_' or Name[-1] != '_':\r
+ if Name[-1] != '_':\r
if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_IFNDEF_STATEMENT, Name):\r
EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_IFNDEF_STATEMENT, OtherMsg="The #ifndef name [%s] does not follow the rules" % (Name), BelongsToTable=FileTable, BelongsToItem=Record[0])\r
\r
# Check whether the path name followed the rule\r
def NamingConventionCheckPathName(self):\r
if EccGlobalData.gConfig.NamingConventionCheckPathName == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
- EdkLogger.quiet("Checking naming covention of file path name ...")\r
+ EdkLogger.quiet("Checking naming convention of file path name ...")\r
Pattern = re.compile(r'^[A-Z]+\S*[a-z]\S*$')\r
SqlCommand = """select ID, Name from File"""\r
RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
# Check whether the variable name followed the rule\r
def NamingConventionCheckVariableName(self, FileTable):\r
if EccGlobalData.gConfig.NamingConventionCheckVariableName == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
- EdkLogger.quiet("Checking naming covention of variable name ...")\r
+ EdkLogger.quiet("Checking naming convention of variable name ...")\r
Pattern = re.compile(r'^[A-Zgm]+\S*[a-z]\S*$')\r
\r
SqlCommand = """select ID, Name from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_VARIABLE)\r
RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
for Record in RecordSet:\r
- if not Pattern.match(Record[1]):\r
+ Var = Record[1]\r
+ if Var.startswith('CONST'):\r
+ Var = Var[5:].lstrip()\r
+ if not Pattern.match(Var):\r
if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, Record[1]):\r
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])\r
\r
# Check whether the function name followed the rule\r
def NamingConventionCheckFunctionName(self):\r
if EccGlobalData.gConfig.NamingConventionCheckFunctionName == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
- EdkLogger.quiet("Checking naming covention of function name ...")\r
+ EdkLogger.quiet("Checking naming convention of function name ...")\r
Pattern = re.compile(r'^[A-Z]+\S*[a-z]\S*$')\r
SqlCommand = """select ID, Name from Function"""\r
RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
# Check whether NO use short variable name with single character\r
def NamingConventionCheckSingleCharacterVariable(self, FileTable):\r
if EccGlobalData.gConfig.NamingConventionCheckSingleCharacterVariable == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
- EdkLogger.quiet("Checking naming covention of single character variable name ...")\r
+ EdkLogger.quiet("Checking naming convention of single character variable name ...")\r
\r
SqlCommand = """select ID, Name from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_VARIABLE)\r
RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_SINGLE_CHARACTER_VARIABLE, Record[1]):\r
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])\r
\r
+def FindPara(FilePath, Para, CallingLine):\r
+ Lines = open(FilePath).readlines()\r
+ Line = ''\r
+ for Index in range(CallingLine - 1, 0, -1):\r
+ # Find the nearest statement for Para\r
+ Line = Lines[Index].strip()\r
+ if Line.startswith('%s = ' % Para):\r
+ Line = Line.strip()\r
+ return Line\r
+ break\r
+\r
+ return ''\r
+\r
##\r
#\r
# This acts like the main() function for the script, unless it is 'import'ed into another\r