]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/Ecc: Add some new checkpoints
authorHess Chen <hesheng.chen@intel.com>
Mon, 23 Jul 2018 05:57:57 +0000 (13:57 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Thu, 26 Jul 2018 00:45:04 +0000 (08:45 +0800)
1. Add a checkpoint to check NO TABs.
2. Add a checkpoint to check line ending with CRLF.
3. Add a checkpoint to check no trailing spaces.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hess Chen <hesheng.chen@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/Python/Ecc/Check.py
BaseTools/Source/Python/Ecc/Configuration.py
BaseTools/Source/Python/Ecc/EccToolError.py
BaseTools/Source/Python/Ecc/config.ini

index 0b81013d77e9bcf48e197501a792c30a41e5d6d1..6803afdfddb6f694d18e7948b2e0a97a7c0399be 100644 (file)
@@ -188,6 +188,60 @@ class Check(object):
     def GeneralCheck(self):\r
         self.GeneralCheckNonAcsii()\r
         self.UniCheck()\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 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], 'rb').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
 \r
     # Check whether file has non ACSII char\r
     def GeneralCheckNonAcsii(self):\r
index 29a1220761f139429eca14ef686fdbcf20542e51..f58adbf7362faab829d12145b7582917a74f4577 100644 (file)
@@ -186,6 +186,10 @@ class Configuration(object):
         self.GeneralCheckNonAcsii = 1\r
         # Check whether UNI file is valid\r
         self.GeneralCheckUni = 1\r
         self.GeneralCheckNonAcsii = 1\r
         # Check whether UNI file is valid\r
         self.GeneralCheckUni = 1\r
+        # Check Only use CRLF (Carriage Return Line Feed) line endings.\r
+        self.GeneralCheckLineEnding = 1\r
+        # Check if there is no trailing white space in one line.\r
+        self.GeneralCheckTrailingWhiteSpaceLine = 1\r
 \r
         ## Space Checking\r
         self.SpaceCheckAll = 1\r
 \r
         ## Space Checking\r
         self.SpaceCheckAll = 1\r
index 1d51da3ae19bf641950267c2301ed83bacf95e8d..ae0a31af8a8c1c10173a6ec9c8ecf7a55df3a95d 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Standardized Error Hanlding infrastructures.\r
 #\r
 ## @file\r
 # Standardized Error Hanlding infrastructures.\r
 #\r
-# Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>\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
 # 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
@@ -22,6 +22,8 @@ ERROR_GENERAL_CHECK_FILE_EXISTENCE = 1007
 ERROR_GENERAL_CHECK_NON_ACSII = 1008\r
 ERROR_GENERAL_CHECK_UNI = 1009\r
 ERROR_GENERAL_CHECK_UNI_HELP_INFO = 1010\r
 ERROR_GENERAL_CHECK_NON_ACSII = 1008\r
 ERROR_GENERAL_CHECK_UNI = 1009\r
 ERROR_GENERAL_CHECK_UNI_HELP_INFO = 1010\r
+ERROR_GENERAL_CHECK_INVALID_LINE_ENDING = 1011\r
+ERROR_GENERAL_CHECK_TRAILING_WHITE_SPACE_LINE = 1012\r
 \r
 ERROR_SPACE_CHECK_ALL = 2000\r
 \r
 \r
 ERROR_SPACE_CHECK_ALL = 2000\r
 \r
@@ -109,7 +111,7 @@ ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE = 12001
 \r
 gEccErrorMessage = {\r
     ERROR_GENERAL_CHECK_ALL : "",\r
 \r
 gEccErrorMessage = {\r
     ERROR_GENERAL_CHECK_ALL : "",\r
-    ERROR_GENERAL_CHECK_NO_TAB : "'TAB' character is not allowed in source code, please replace each 'TAB' with two spaces",\r
+    ERROR_GENERAL_CHECK_NO_TAB : "'TAB' character is not allowed in source code, please replace each 'TAB' with two spaces.",\r
     ERROR_GENERAL_CHECK_INDENTATION : "Indentation does not follow coding style",\r
     ERROR_GENERAL_CHECK_LINE : "The width of each line does not follow coding style",\r
     ERROR_GENERAL_CHECK_NO_ASM : "There should be no use of _asm in the source file",\r
     ERROR_GENERAL_CHECK_INDENTATION : "Indentation does not follow coding style",\r
     ERROR_GENERAL_CHECK_LINE : "The width of each line does not follow coding style",\r
     ERROR_GENERAL_CHECK_NO_ASM : "There should be no use of _asm in the source file",\r
@@ -119,6 +121,8 @@ gEccErrorMessage = {
     ERROR_GENERAL_CHECK_NON_ACSII : "File has invalid Non-ACSII char",\r
     ERROR_GENERAL_CHECK_UNI : "File is not a valid UTF-16 UNI file",\r
     ERROR_GENERAL_CHECK_UNI_HELP_INFO : "UNI file that is associated by INF or DEC file need define the prompt and help information.",\r
     ERROR_GENERAL_CHECK_NON_ACSII : "File has invalid Non-ACSII char",\r
     ERROR_GENERAL_CHECK_UNI : "File is not a valid UTF-16 UNI file",\r
     ERROR_GENERAL_CHECK_UNI_HELP_INFO : "UNI file that is associated by INF or DEC file need define the prompt and help information.",\r
+    ERROR_GENERAL_CHECK_INVALID_LINE_ENDING : "Only CRLF (Carriage Return Line Feed) is allowed to line ending.",\r
+    ERROR_GENERAL_CHECK_TRAILING_WHITE_SPACE_LINE : "There should be no trailing white space in one line.",\r
 \r
     ERROR_SPACE_CHECK_ALL : "",\r
 \r
 \r
     ERROR_SPACE_CHECK_ALL : "",\r
 \r
index 9a431bf1245d28ae261ad4f1edd45367ab92f2d0..6c86da74d6fcb6c24ba7004bb619d103befd5a5c 100644 (file)
@@ -72,6 +72,10 @@ GeneralCheckFileExistence = 1
 GeneralCheckNonAcsii = 1\r
 # Check whether UNI file is valid\r
 GeneralCheckUni = 1\r
 GeneralCheckNonAcsii = 1\r
 # Check whether UNI file is valid\r
 GeneralCheckUni = 1\r
+# Check Only use CRLF (Carriage Return Line Feed) line endings.\r
+self.GeneralCheckLineEnding = 1\r
+# Check if there is no trailing white space in one line.\r
+self.GeneralCheckTrailingWhiteSpaceLine = 1\r
 \r
 #\r
 # Space Checking\r
 \r
 #\r
 # Space Checking\r