]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Ecc/Check.py
BaseTools/Ecc: Add some new checkpoints
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / Check.py
index 0b81013d77e9bcf48e197501a792c30a41e5d6d1..6803afdfddb6f694d18e7948b2e0a97a7c0399be 100644 (file)
@@ -188,6 +188,60 @@ class Check(object):
     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