]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Ecc/MetaDataParser.py
BaseTools: Various typo
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / MetaDataParser.py
index 98b16a0e5c4446ac694aa314d13b39558fb7eb62..aab2e92ea7f570768cb4cd1a02413d2850194e33 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to define common parser functions for meta-data\r
 #\r
-# Copyright (c) 2008 - 2014, 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
 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 #\r
 \r
+from __future__ import absolute_import\r
 import Common.LongFilePathOs as os\r
 from CommonDataClass.DataClass import *\r
-from EccToolError import *\r
-import EccGlobalData\r
+from Ecc.EccToolError import *\r
+from Common.MultipleWorkspace import MultipleWorkspace as mws\r
+from Ecc import EccGlobalData\r
 import re\r
-## Get the inlcude path list for a source file\r
+## Get the include path list for a source file\r
 #\r
 # 1. Find the source file belongs to which inf file\r
 # 2. Find the inf's package\r
@@ -33,8 +35,8 @@ def GetIncludeListOfFile(WorkSpace, Filepath, Db):
                 % (MODEL_META_DATA_PACKAGE, MODEL_EFI_SOURCE_FILE, '\\', Filepath)\r
     RecordSet = Db.TblFile.Exec(SqlCommand)\r
     for Record in RecordSet:\r
-        DecFullPath = os.path.normpath(os.path.join(WorkSpace, Record[0]))\r
-        InfFullPath = os.path.normpath(os.path.join(WorkSpace, Record[1]))\r
+        DecFullPath = os.path.normpath(mws.join(WorkSpace, Record[0]))\r
+        InfFullPath = os.path.normpath(mws.join(WorkSpace, Record[1]))\r
         (DecPath, DecName) = os.path.split(DecFullPath)\r
         (InfPath, InfName) = os.path.split(InfFullPath)\r
         SqlCommand = """select Value1 from Dec where BelongsToFile =\r
@@ -86,16 +88,16 @@ def GetTableList(FileModelList, Table, Db):
 # @param FileName:      FileName of the comment\r
 #\r
 def ParseHeaderCommentSection(CommentList, FileName = None):\r
-    \r
+\r
     Abstract = ''\r
     Description = ''\r
     Copyright = ''\r
     License = ''\r
     EndOfLine = "\n"\r
     STR_HEADER_COMMENT_START = "@file"\r
-    \r
+\r
     #\r
-    # used to indicate the state of processing header comment section of dec, \r
+    # used to indicate the state of processing header comment section of dec,\r
     # inf files\r
     #\r
     HEADER_COMMENT_NOT_STARTED = -1\r
@@ -111,16 +113,16 @@ def ParseHeaderCommentSection(CommentList, FileName = None):
     #\r
     Last = 0\r
     HeaderCommentStage = HEADER_COMMENT_NOT_STARTED\r
-    for Index in xrange(len(CommentList)-1, 0, -1):\r
+    for Index in range(len(CommentList) - 1, 0, -1):\r
         Line = CommentList[Index][0]\r
         if _IsCopyrightLine(Line):\r
             Last = Index\r
             break\r
-    \r
+\r
     for Item in CommentList:\r
         Line = Item[0]\r
         LineNo = Item[1]\r
-        \r
+\r
         if not Line.startswith('#') and Line:\r
             SqlStatement = """ select ID from File where FullPath like '%s'""" % FileName\r
             ResultSet = EccGlobalData.gDb.TblFile.Exec(SqlStatement)\r
@@ -130,14 +132,14 @@ def ParseHeaderCommentSection(CommentList, FileName = None):
         Comment = CleanString2(Line)[1]\r
         Comment = Comment.strip()\r
         #\r
-        # if there are blank lines between License or Description, keep them as they would be \r
+        # if there are blank lines between License or Description, keep them as they would be\r
         # indication of different block; or in the position that Abstract should be, also keep it\r
         # as it indicates that no abstract\r
         #\r
         if not Comment and HeaderCommentStage not in [HEADER_COMMENT_LICENSE, \\r
                                                       HEADER_COMMENT_DESCRIPTION, HEADER_COMMENT_ABSTRACT]:\r
             continue\r
-        \r
+\r
         if HeaderCommentStage == HEADER_COMMENT_NOT_STARTED:\r
             if Comment.startswith(STR_HEADER_COMMENT_START):\r
                 HeaderCommentStage = HEADER_COMMENT_ABSTRACT\r
@@ -151,58 +153,65 @@ def ParseHeaderCommentSection(CommentList, FileName = None):
                 if not Comment:\r
                     Abstract = ''\r
                     HeaderCommentStage = HEADER_COMMENT_DESCRIPTION\r
-                elif _IsCopyrightLine(Comment):                    \r
+                elif _IsCopyrightLine(Comment):\r
                     Copyright += Comment + EndOfLine\r
                     HeaderCommentStage = HEADER_COMMENT_COPYRIGHT\r
-                else:                    \r
+                else:\r
                     Abstract += Comment + EndOfLine\r
                     HeaderCommentStage = HEADER_COMMENT_DESCRIPTION\r
             elif HeaderCommentStage == HEADER_COMMENT_DESCRIPTION:\r
                 #\r
                 # in case there is no description\r
-                #                \r
-                if _IsCopyrightLine(Comment):                    \r
+                #\r
+                if _IsCopyrightLine(Comment):\r
                     Copyright += Comment + EndOfLine\r
                     HeaderCommentStage = HEADER_COMMENT_COPYRIGHT\r
                 else:\r
-                    Description += Comment + EndOfLine                \r
+                    Description += Comment + EndOfLine\r
             elif HeaderCommentStage == HEADER_COMMENT_COPYRIGHT:\r
-                if _IsCopyrightLine(Comment):                    \r
+                if _IsCopyrightLine(Comment):\r
                     Copyright += Comment + EndOfLine\r
                 else:\r
                     #\r
                     # Contents after copyright line are license, those non-copyright lines in between\r
-                    # copyright line will be discarded \r
+                    # copyright line will be discarded\r
                     #\r
                     if LineNo > Last:\r
                         if License:\r
                             License += EndOfLine\r
                         License += Comment + EndOfLine\r
-                        HeaderCommentStage = HEADER_COMMENT_LICENSE                \r
+                        HeaderCommentStage = HEADER_COMMENT_LICENSE\r
             else:\r
                 if not Comment and not License:\r
                     continue\r
                 License += Comment + EndOfLine\r
-    \r
-    if not Copyright:\r
+\r
+    if not Copyright.strip():\r
         SqlStatement = """ select ID from File where FullPath like '%s'""" % FileName\r
         ResultSet = EccGlobalData.gDb.TblFile.Exec(SqlStatement)\r
         for Result in ResultSet:\r
             Msg = 'Header comment section must have copyright information'\r
             EccGlobalData.gDb.TblReport.Insert(ERROR_DOXYGEN_CHECK_FILE_HEADER, Msg, "File", Result[0])\r
 \r
-    if not License:\r
+    if not License.strip():\r
         SqlStatement = """ select ID from File where FullPath like '%s'""" % FileName\r
         ResultSet = EccGlobalData.gDb.TblFile.Exec(SqlStatement)\r
         for Result in ResultSet:\r
             Msg = 'Header comment section must have license information'\r
             EccGlobalData.gDb.TblReport.Insert(ERROR_DOXYGEN_CHECK_FILE_HEADER, Msg, "File", Result[0])\r
-                     \r
+\r
+    if not Abstract.strip() or Abstract.find('Component description file') > -1:\r
+        SqlStatement = """ select ID from File where FullPath like '%s'""" % FileName\r
+        ResultSet = EccGlobalData.gDb.TblFile.Exec(SqlStatement)\r
+        for Result in ResultSet:\r
+            Msg = 'Header comment section must have Abstract information.'\r
+            EccGlobalData.gDb.TblReport.Insert(ERROR_DOXYGEN_CHECK_FILE_HEADER, Msg, "File", Result[0])\r
+\r
     return Abstract.strip(), Description.strip(), Copyright.strip(), License.strip()\r
 \r
 ## _IsCopyrightLine\r
-# check whether current line is copyright line, the criteria is whether there is case insensitive keyword "Copyright" \r
-# followed by zero or more white space characters followed by a "(" character \r
+# check whether current line is copyright line, the criteria is whether there is case insensitive keyword "Copyright"\r
+# followed by zero or more white space characters followed by a "(" character\r
 #\r
 # @param LineContent:  the line need to be checked\r
 # @return: True if current line is copyright line, False else\r
@@ -210,11 +219,11 @@ def ParseHeaderCommentSection(CommentList, FileName = None):
 def _IsCopyrightLine (LineContent):\r
     LineContent = LineContent.upper()\r
     Result = False\r
-    \r
+\r
     ReIsCopyrightRe = re.compile(r"""(^|\s)COPYRIGHT *\(""", re.DOTALL)\r
     if ReIsCopyrightRe.search(LineContent):\r
         Result = True\r
-        \r
+\r
     return Result\r
 \r
 \r
@@ -224,7 +233,7 @@ def _IsCopyrightLine (LineContent):
 # Remove spaces\r
 #\r
 # @param Line:              The string to be cleaned\r
-# @param CommentCharacter:  Comment char, used to ignore comment content, \r
+# @param CommentCharacter:  Comment char, used to ignore comment content,\r
 #                           default is DataType.TAB_COMMENT_SPLIT\r
 #\r
 def CleanString2(Line, CommentCharacter='#', AllowCppStyleComment=False):\r