## @file\r
# This file is used to be the main entrance of ECC tool\r
#\r
-# Copyright (c) 2009, Intel Corporation\r
-# All rights reserved. This program and the accompanying materials\r
+# Copyright (c) 2009 - 2010, 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
# http://opensource.org/licenses/bsd-license.php\r
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
# Version and Copyright\r
self.VersionNumber = "0.01"\r
self.Version = "%prog Version " + self.VersionNumber\r
- self.Copyright = "Copyright (c) 2009, Intel Corporation All rights reserved."\r
+ self.Copyright = "Copyright (c) 2009 - 2010, Intel Corporation All rights reserved."\r
\r
self.InitDefaultConfigIni()\r
self.OutputFile = 'output.txt'\r
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
# 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
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
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
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
EccCheck = Check()\r
EccCheck.Check()\r
EdkLogger.quiet("Checking done!")\r
- \r
+\r
##\r
#\r
# Generate the scan report\r
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
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
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
break\r
ParentDir += os.sep\r
ParentDir += Dir\r
- \r
+\r
return RealPath\r
- \r
+\r
## ParseOption\r
#\r
# Parse options\r
def ParseOption(self):\r
EdkLogger.quiet("Loading ECC configuration ... done")\r
(Options, Target) = self.EccOptionParser()\r
- \r
+\r
+ if Options.Workspace:\r
+ os.environ["WORKSPACE"] = Options.Workspace\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
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
self.OutputFile = Options.OutputFile\r
if Options.ReportFile != None:\r
self.ReportFile = Options.ReportFile\r
+ if Options.ExceptionFile != None:\r
+ self.ExceptionFile = Options.ExceptionFile\r
if Options.Target != None:\r
if not os.path.isdir(Options.Target):\r
EdkLogger.error("ECC", BuildToolError.OPTION_VALUE_INVALID, ExtraData="Target [%s] does NOT exist" % Options.Target)\r
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
help="Specify the name of an output file, if and only if one filename was specified.")\r
Parser.add_option("-r", "--reportfile filename", action="store", type="string", dest="ReportFile",\r
help="Specify the name of an report file, if and only if one filename was specified.")\r
+ Parser.add_option("-e", "--exceptionfile filename", action="store", type="string", dest="ExceptionFile",\r
+ help="Specify the name of an exception file, if and only if one filename was specified.")\r
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
+ Parser.add_option("-w", "--workspace", action="store", type="string", dest='Workspace', help="Specify workspace.")\r
+\r
(Opt, Args)=Parser.parse_args()\r
- \r
+\r
return (Opt, Args)\r
\r
##\r