]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Ecc/Check.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / Check.py
index fc86ad96f2cf2fbdfc388abd74d77db43e29fb5b..33060db5f27a73bc0a72885053f6b7cbec7a771d 100644 (file)
@@ -1,14 +1,9 @@
 ## @file\r
 # This file is used to define checkpoints used by ECC tool\r
 #\r
-# Copyright (c) 2008 - 2018, 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) 2021, Arm Limited. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2020, 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
@@ -223,7 +218,7 @@ class Check(object):
                     IndexOfLine = 0\r
                     for Line in op:\r
                         IndexOfLine += 1\r
-                        if not Line.endswith('\r\n'):\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
@@ -235,7 +230,7 @@ class Check(object):
             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
+                    op = open(Record[1], 'r').readlines()\r
                     IndexOfLine = 0\r
                     for Line in op:\r
                         IndexOfLine += 1\r
@@ -270,6 +265,66 @@ class Check(object):
         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
@@ -387,7 +442,7 @@ class Check(object):
         self.DeclCheckUnionType()\r
 \r
 \r
-    # Check whether no use of int, unsigned, char, void, static, long in any .c, .h or .asl files.\r
+    # Check whether no use of int, unsigned, char, void, long in any .c, .h or .asl files.\r
     def DeclCheckNoUseCType(self):\r
         if EccGlobalData.gConfig.DeclarationDataTypeCheckNoUseCType == '1' or EccGlobalData.gConfig.DeclarationDataTypeCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
             EdkLogger.quiet("Checking Declaration No use C type ...")\r
@@ -586,13 +641,23 @@ class Check(object):
         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
@@ -1039,11 +1104,11 @@ class Check(object):
                     InfPathList.append(Item[0])\r
             SqlCommand = """\r
                          select ID, Path, FullPath from File where upper(FullPath) not in\r
-                            (select upper(A.Path) || '\\' || upper(B.Value1) from File as A, INF as B\r
+                            (select upper(A.Path) || '%s' || upper(B.Value1) from File as A, INF as B\r
                             where A.ID in (select BelongsToFile from INF where Model = %s group by BelongsToFile) and\r
                             B.BelongsToFile = A.ID and B.Model = %s)\r
                             and (Model = %s or Model = %s)\r
-                        """ % (MODEL_EFI_SOURCE_FILE, MODEL_EFI_SOURCE_FILE, MODEL_FILE_C, MODEL_FILE_H)\r
+                        """ % (os.sep, MODEL_EFI_SOURCE_FILE, MODEL_EFI_SOURCE_FILE, MODEL_FILE_C, MODEL_FILE_H)\r
             RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand)\r
             for Record in RecordSet:\r
                 Path = Record[1]\r
@@ -1068,9 +1133,9 @@ class Check(object):
                 BelongsToFile = Pcd[4]\r
                 SqlCommand = """\r
                              select ID from File where FullPath in\r
-                            (select B.Path || '\\' || A.Value1 from INF as A, File as B where A.Model = %s and A.BelongsToFile = %s\r
+                            (select B.Path || '%s' || A.Value1 from INF as A, File as B where A.Model = %s and A.BelongsToFile = %s\r
                              and B.ID = %s and (B.Model = %s or B.Model = %s))\r
-                             """ % (MODEL_EFI_SOURCE_FILE, BelongsToFile, BelongsToFile, MODEL_FILE_C, MODEL_FILE_H)\r
+                             """ % (os.sep, MODEL_EFI_SOURCE_FILE, BelongsToFile, BelongsToFile, MODEL_FILE_C, MODEL_FILE_H)\r
                 TableSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
                 for Tbl in TableSet:\r
                     TblName = 'Identifier' + str(Tbl[0])\r
@@ -1333,7 +1398,7 @@ class Check(object):
     # 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
@@ -1348,7 +1413,7 @@ class Check(object):
     # 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
@@ -1368,15 +1433,17 @@ class Check(object):
     # 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.NamingConventionCheckIfndefStatement == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
-            EdkLogger.quiet("Checking naming covention of #ifndef statement ...")\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 RecordSet:\r
+                # Only check the first ifndef statement of the file\r
+                FirstDefine = sorted(RecordSet, key=lambda Record: Record[0])[0]\r
+                Name = FirstDefine[1].replace('#ifndef', '').strip()\r
+                if Name[0] == '_' or Name[-1] != '_' or Name[-2] == '_':\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
+                        EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_IFNDEF_STATEMENT, OtherMsg="The #ifndef name [%s] does not follow the rules" % (Name), BelongsToTable=FileTable, BelongsToItem=FirstDefine[0])\r
 \r
     # Rule for path name, variable name and function name\r
     # 1. First character should be upper case\r
@@ -1385,7 +1452,7 @@ class Check(object):
     # 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
@@ -1402,16 +1469,17 @@ class Check(object):
     # 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
+            SqlCommand = """select ID, Name, Modifier from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_VARIABLE)\r
             RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
             for Record in RecordSet:\r
                 Var = Record[1]\r
+                Modifier = Record[2]\r
                 if Var.startswith('CONST'):\r
                     Var = Var[5:].lstrip()\r
-                if not Pattern.match(Var):\r
+                if not Pattern.match(Var) and not (Modifier.endswith('*') and Var.startswith('p')):\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
@@ -1422,7 +1490,7 @@ class Check(object):
     # 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
@@ -1434,7 +1502,7 @@ class Check(object):
     # 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