]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Ecc/Ecc.py
Sync basetools' source and binary files with r1707 of the basetools project.
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / Ecc.py
index 4767645d0576e625330a0bce59534b20518cffcf..ea9d0b343c955080add93ce9789e9c4d25acc26e 100644 (file)
@@ -29,6 +29,7 @@ from Common.FdfClassObject import Fdf
 from Common.String import NormPath\r
 from Common import BuildToolError\r
 import c\r
+import re, string\r
 from Exception import *\r
 \r
 ## Ecc\r
@@ -51,29 +52,29 @@ class Ecc(object):
         self.IsInit = True\r
         self.ScanSourceCode = True\r
         self.ScanMetaData = True\r
-        \r
+\r
         # Parse the options and args\r
         self.ParseOption()\r
 \r
         # Generate checkpoints list\r
         EccGlobalData.gConfig = Configuration(self.ConfigFile)\r
-        \r
+\r
         # Generate exception list\r
         EccGlobalData.gException = ExceptionCheck(self.ExceptionFile)\r
-        \r
+\r
         # Init Ecc database\r
         EccGlobalData.gDb = Database.Database(Database.DATABASE_PATH)\r
         EccGlobalData.gDb.InitDatabase(self.IsInit)\r
-        \r
+\r
         # Build ECC database\r
         self.BuildDatabase()\r
-        \r
+\r
         # Start to check\r
         self.Check()\r
-        \r
+\r
         # Show report\r
         self.GenReport()\r
-        \r
+\r
         # Close Database\r
         EccGlobalData.gDb.Close()\r
 \r
@@ -94,7 +95,7 @@ class Ecc(object):
         # Clean report table\r
         EccGlobalData.gDb.TblReport.Drop()\r
         EccGlobalData.gDb.TblReport.Create()\r
-        \r
+\r
         # Build database\r
         if self.IsInit:\r
             if self.ScanSourceCode:\r
@@ -103,9 +104,9 @@ class Ecc(object):
             if self.ScanMetaData:\r
                 EdkLogger.quiet("Building database for source code done!")\r
                 self.BuildMetaDataFileDatabase()\r
-        \r
+\r
         EccGlobalData.gIdentifierTableList = GetTableList((MODEL_FILE_C, MODEL_FILE_H), 'Identifier', EccGlobalData.gDb)\r
-    \r
+\r
     ## BuildMetaDataFileDatabase\r
     #\r
     # Build the database for meta data files\r
@@ -115,10 +116,11 @@ class Ecc(object):
         Op = open(EccGlobalData.gConfig.MetaDataFileCheckPathOfGenerateFileList, 'w+')\r
         #SkipDirs = Read from config file\r
         SkipDirs = EccGlobalData.gConfig.SkipDirList\r
+        SkipDirString = string.join(SkipDirs, '|')\r
+        p = re.compile(r'.*[\\/](?:%s)[\\/]?.*' % SkipDirString)\r
         for Root, Dirs, Files in os.walk(EccGlobalData.gTarget):\r
-            for Dir in Dirs:\r
-                if Dir.upper() in SkipDirs:\r
-                    Dirs.remove(Dir)\r
+            if p.match(Root.upper()):\r
+                continue\r
 \r
             for Dir in Dirs:\r
                 Dirname = os.path.join(Root, Dir)\r
@@ -152,15 +154,15 @@ class Ecc(object):
                     Filename = os.path.normpath(os.path.join(Root, File))\r
                     EdkLogger.quiet("Parsing %s" % Filename)\r
                     Op.write("%s\r" % Filename)\r
-                    Fdf(Filename, True, EccGlobalData.gWorkspace, EccGlobalData.gDb)                    \r
+                    Fdf(Filename, True, EccGlobalData.gWorkspace, EccGlobalData.gDb)\r
                     continue\r
         Op.close()\r
-        \r
+\r
         # Commit to database\r
         EccGlobalData.gDb.Conn.commit()\r
-        \r
+\r
         EdkLogger.quiet("Building database for meta data files done!")\r
-    \r
+\r
     ##\r
     #\r
     # Check each checkpoint\r
@@ -170,7 +172,7 @@ class Ecc(object):
         EccCheck = Check()\r
         EccCheck.Check()\r
         EdkLogger.quiet("Checking  done!")\r
-    \r
+\r
     ##\r
     #\r
     # Generate the scan report\r
@@ -179,7 +181,7 @@ class Ecc(object):
         EdkLogger.quiet("Generating report ...")\r
         EccGlobalData.gDb.TblReport.ToCSV(self.ReportFile)\r
         EdkLogger.quiet("Generating report done!")\r
-        \r
+\r
     def GetRealPathCase(self, path):\r
         TmpPath = path.rstrip(os.sep)\r
         PathParts = TmpPath.split(os.sep)\r
@@ -193,7 +195,7 @@ class Ecc(object):
             for Dir in Dirs:\r
                 if Dir.upper() == PathParts[0].upper():\r
                     return Dir\r
-        \r
+\r
         if PathParts[0].strip().endswith(':'):\r
             PathParts[0] = PathParts[0].upper()\r
         ParentDir = PathParts[0]\r
@@ -201,7 +203,7 @@ class Ecc(object):
         if PathParts[0] == '':\r
             RealPath = os.sep\r
             ParentDir = os.sep\r
-        \r
+\r
         PathParts.remove(PathParts[0])    # need to remove the parent\r
         for Part in PathParts:\r
             Dirs = os.listdir(ParentDir + os.sep)\r
@@ -212,9 +214,9 @@ class Ecc(object):
                     break\r
             ParentDir += os.sep\r
             ParentDir += Dir\r
-            \r
+\r
         return RealPath\r
-        \r
+\r
     ## ParseOption\r
     #\r
     # Parse options\r
@@ -222,10 +224,10 @@ class Ecc(object):
     def ParseOption(self):\r
         EdkLogger.quiet("Loading ECC configuration ... done")\r
         (Options, Target) = self.EccOptionParser()\r
-        \r
+\r
         # Check workspace envirnoment\r
         if "WORKSPACE" not in os.environ:\r
-            EdkLogger.error("ECC", BuildToolError.ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found", \r
+            EdkLogger.error("ECC", BuildToolError.ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found",\r
                             ExtraData="WORKSPACE")\r
         else:\r
             EccGlobalData.gWorkspace = os.path.normpath(os.getenv("WORKSPACE"))\r
@@ -234,7 +236,7 @@ class Ecc(object):
             os.environ["WORKSPACE"] = EccGlobalData.gWorkspace\r
         # Set log level\r
         self.SetLogLevel(Options)\r
-        \r
+\r
         # Set other options\r
         if Options.ConfigFile != None:\r
             self.ConfigFile = Options.ConfigFile\r
@@ -258,12 +260,12 @@ class Ecc(object):
             self.ScanSourceCode = False\r
         if Options.sourcecode != None:\r
             self.ScanMetaData = False\r
-        \r
+\r
     ## SetLogLevel\r
     #\r
     # Set current log level of the tool based on args\r
     #\r
-    # @param Option:  The option list including log level setting \r
+    # @param Option:  The option list including log level setting\r
     #\r
     def SetLogLevel(self, Option):\r
         if Option.verbose != None:\r
@@ -295,19 +297,19 @@ class Ecc(object):
         Parser.add_option("-m", "--metadata", action="store_true", type=None, help="Only scan meta-data files information if this option is specified.")\r
         Parser.add_option("-s", "--sourcecode", action="store_true", type=None, help="Only scan source code files information if this option is specified.")\r
         Parser.add_option("-k", "--keepdatabase", action="store_true", type=None, help="The existing Ecc database will not be cleaned except report information if this option is specified.")\r
-        Parser.add_option("-l", "--log filename", action="store", dest="LogFile", help="""If specified, the tool should emit the changes that \r
-                                                                                          were made by the tool after printing the result message. \r
-                                                                                          If filename, the emit to the file, otherwise emit to \r
-                                                                                          standard output. If no modifications were made, then do not \r
+        Parser.add_option("-l", "--log filename", action="store", dest="LogFile", help="""If specified, the tool should emit the changes that\r
+                                                                                          were made by the tool after printing the result message.\r
+                                                                                          If filename, the emit to the file, otherwise emit to\r
+                                                                                          standard output. If no modifications were made, then do not\r
                                                                                           create a log file, or output a log message.""")\r
         Parser.add_option("-q", "--quiet", action="store_true", type=None, help="Disable all messages except FATAL ERRORS.")\r
         Parser.add_option("-v", "--verbose", action="store_true", type=None, help="Turn on verbose output with informational messages printed, "\\r
                                                                                    "including library instances selected, final dependency expression, "\\r
                                                                                    "and warning messages, etc.")\r
         Parser.add_option("-d", "--debug", action="store", type="int", help="Enable debug messages at specified level.")\r
-    \r
+\r
         (Opt, Args)=Parser.parse_args()\r
-        \r
+\r
         return (Opt, Args)\r
 \r
 ##\r