]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Ecc/Check.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / Check.py
index 0491d2d4e4f13843e0918758fa27fd14babd2f33..86bb8562babc01fc7bf25f412a94a915c6edcf99 100644 (file)
@@ -2,13 +2,7 @@
 # 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
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 from __future__ import absolute_import\r
 import Common.LongFilePathOs as os\r
@@ -223,7 +217,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 +229,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
@@ -646,13 +640,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
@@ -1393,7 +1397,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
@@ -1408,7 +1412,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
@@ -1428,13 +1432,13 @@ 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 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
@@ -1445,7 +1449,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
@@ -1462,7 +1466,7 @@ 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
@@ -1482,7 +1486,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
@@ -1494,7 +1498,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