]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Ecc/c.py
Sync BaseTool trunk (version r2460) into EDKII BaseTools. The change mainly includes:
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / c.py
index 532f4a0918a8a16f2fa642ea1d875a3a5b4533a6..ea7d99fecd22186bf7fd27118dee2b18845755c1 100644 (file)
@@ -2305,28 +2305,90 @@ def CheckFileHeaderDoxygenComments(FullFileName):
                    """ % (FileTable, DataClass.MODEL_IDENTIFIER_COMMENT)\r
     ResultSet = Db.TblFile.Exec(SqlStatement)\r
     if len(ResultSet) == 0:\r
-        PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'No Comment appear at the very beginning of file.', 'File', FileID)\r
+        PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'No File License header appear at the very beginning of file.', 'File', FileID)\r
         return ErrorMsgList\r
 \r
-    IsFoundError1 = True\r
-    IsFoundError2 = True\r
-    IsFoundError3 = True\r
+    NoHeaderCommentStartFlag = True\r
+    NoHeaderCommentEndFlag = True\r
+    NoHeaderCommentPeriodFlag = True\r
+    NoCopyrightFlag = True\r
+    NoLicenseFlag = True\r
+    NoRevReferFlag = True\r
+    NextLineIndex = 0\r
     for Result in ResultSet:\r
+        FileStartFlag = False\r
+        CommentStrList = []\r
         CommentStr = Result[0].strip()\r
+        CommentStrListTemp = CommentStr.split('\n')\r
+        if (len(CommentStrListTemp) <= 1):\r
+            # For Mac\r
+            CommentStrListTemp = CommentStr.split('\r')\r
+        # Skip the content before the file  header    \r
+        for CommentLine in CommentStrListTemp:\r
+            if CommentLine.strip().startswith('/** @file'):\r
+                FileStartFlag = True\r
+            if FileStartFlag ==  True:\r
+                CommentStrList.append(CommentLine)\r
+                       \r
         ID = Result[1]\r
-        if CommentStr.startswith('/** @file'):\r
-            IsFoundError1 = False\r
-        if CommentStr.endswith('**/'):\r
-            IsFoundError2 = False\r
-        if CommentStr.find('.') != -1:\r
-            IsFoundError3 = False\r
-\r
-    if IsFoundError1:\r
+        Index = 0\r
+        if CommentStrList and CommentStrList[0].strip().startswith('/** @file'):\r
+            NoHeaderCommentStartFlag = False\r
+        else:\r
+            continue\r
+        if CommentStrList and CommentStrList[-1].strip().endswith('**/'):\r
+            NoHeaderCommentEndFlag = False\r
+        else:\r
+            continue\r
+\r
+        for CommentLine in CommentStrList:\r
+            Index = Index + 1\r
+            NextLineIndex = Index\r
+            if CommentLine.startswith('/** @file'):\r
+                continue\r
+            if CommentLine.startswith('**/'):\r
+                break\r
+            # Check whether C File header Comment content start with two spaces.\r
+            if EccGlobalData.gConfig.HeaderCheckCFileCommentStartSpacesNum == '1' or EccGlobalData.gConfig.HeaderCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+                if CommentLine.startswith('/** @file') == False and CommentLine.startswith('**/') == False and CommentLine.strip() and CommentLine.startswith('  ') == False:\r
+                    PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'File header comment content should start with two spaces at each line', FileTable, ID)\r
+            \r
+            CommentLine = CommentLine.strip()\r
+            if CommentLine.startswith('Copyright'):\r
+                NoCopyrightFlag = False\r
+                if CommentLine.find('All rights reserved') == -1:\r
+                    PrintErrorMsg(ERROR_HEADER_CHECK_FILE, '""All rights reserved"" announcement should be following the ""Copyright"" at the same line', FileTable, ID)\r
+                if CommentLine.endswith('<BR>') == -1:\r
+                    PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'The ""<BR>"" at the end of the Copyright line is required', FileTable, ID)\r
+                if NextLineIndex < len(CommentStrList) and CommentStrList[NextLineIndex].strip().startswith('Copyright') == False and CommentStrList[NextLineIndex].strip():\r
+                    NoLicenseFlag = False\r
+            if CommentLine.startswith('@par Revision Reference:'):\r
+                NoRevReferFlag = False\r
+                RefListFlag = False\r
+                for RefLine in CommentStrList[NextLineIndex:]:\r
+                    if RefLine.strip() and (NextLineIndex + 1) < len(CommentStrList) and CommentStrList[NextLineIndex+1].strip() and CommentStrList[NextLineIndex+1].strip().startswith('**/') == False:\r
+                        RefListFlag = True\r
+                    if RefLine.strip() == False or RefLine.strip().startswith('**/'):\r
+                        RefListFlag = False\r
+                        break\r
+                    # Check whether C File header Comment's each reference at list should begin with a bullet character.\r
+                    if EccGlobalData.gConfig.HeaderCheckCFileCommentReferenceFormat == '1' or EccGlobalData.gConfig.HeaderCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+                        if RefListFlag == True:\r
+                            if RefLine.strip() and RefLine.strip().startswith('**/') == False and RefLine.startswith('  -') == False:                            \r
+                                PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'Each reference on a separate line should begin with a bullet character ""-"" ', FileTable, ID)                    \r
+    \r
+    if NoHeaderCommentStartFlag:\r
         PrintErrorMsg(ERROR_DOXYGEN_CHECK_FILE_HEADER, 'File header comment should begin with ""/** @file""', FileTable, ID)\r
-    if IsFoundError2:\r
+        return\r
+    if NoHeaderCommentEndFlag:\r
         PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'File header comment should end with ""**/""', FileTable, ID)\r
-    if IsFoundError3:\r
-        PrintErrorMsg(ERROR_DOXYGEN_CHECK_COMMENT_DESCRIPTION, 'Comment description should end with period "".""', FileTable, ID)\r
+        return\r
+    if NoCopyrightFlag:\r
+        PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'File header comment missing the ""Copyright""', FileTable, ID)\r
+    #Check whether C File header Comment have the License immediately after the ""Copyright"" line.\r
+    if EccGlobalData.gConfig.HeaderCheckCFileCommentLicenseFormat == '1' or EccGlobalData.gConfig.HeaderCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+        if NoLicenseFlag:\r
+            PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'File header comment should have the License immediately after the ""Copyright"" line', FileTable, ID)\r
 \r
 def CheckFuncHeaderDoxygenComments(FullFileName):\r
     ErrorMsgList = []\r