diff options
author | Ted Kremenek <kremenek@apple.com> | 2012-08-28 20:20:52 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2012-08-28 20:20:52 +0000 |
commit | 5abd3d2ba4c4edb5140de5d65a16e5da4076f0b1 (patch) | |
tree | d5022f3a97e93a0085623acd224d810b02097ea3 /utils/analyzer/SATestBuild.py | |
parent | a23b91d542e336be5051ac54f394e860fb756911 (diff) |
Pass --use-analyzer to scan-build when running within the test harness.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162783 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/analyzer/SATestBuild.py')
-rwxr-xr-x | utils/analyzer/SATestBuild.py | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/utils/analyzer/SATestBuild.py b/utils/analyzer/SATestBuild.py index e28a6bdc26..71946c75c7 100755 --- a/utils/analyzer/SATestBuild.py +++ b/utils/analyzer/SATestBuild.py @@ -76,6 +76,43 @@ Checkers="alpha.security.taint,core,deadcode,security,unix,osx" Verbose = 1 +def which(command, paths = None): + """which(command, [paths]) - Look up the given command in the paths string + (or the PATH environment variable, if unspecified).""" + + if paths is None: + paths = os.environ.get('PATH','') + + # Check for absolute match first. + if os.path.exists(command): + return command + + # Would be nice if Python had a lib function for this. + if not paths: + paths = os.defpath + + # Get suffixes to search. + # On Cygwin, 'PATHEXT' may exist but it should not be used. + if os.pathsep == ';': + pathext = os.environ.get('PATHEXT', '').split(';') + else: + pathext = [''] + + # Search the paths... + for path in paths.split(os.pathsep): + for ext in pathext: + p = os.path.join(path, command + ext) + if os.path.exists(p): + return p + + return None + +# Find Clang for static analysis. +Clang = which("clang", os.environ['PATH']) +if not Clang: + print "Error: cannot find 'clang' in PATH" + sys.exit(-1) + # Make sure we flush the output after every print statement. class flushfile(object): def __init__(self, f): @@ -129,8 +166,9 @@ def runScanBuild(Dir, SBOutputDir, PBuildLogFile): BuildScriptPath = os.path.join(Dir, BuildScript) if not os.path.exists(BuildScriptPath): print "Error: build script is not defined: %s" % BuildScriptPath - sys.exit(-1) - SBOptions = "-plist-html -o " + SBOutputDir + " " + sys.exit(-1) + SBOptions = "--use-analyzer " + Clang + " " + SBOptions += "-plist-html -o " + SBOutputDir + " " SBOptions += "-enable-checker " + Checkers + " " try: SBCommandFile = open(BuildScriptPath, "r") @@ -160,7 +198,7 @@ def isValidSingleInputFile(FileName): (Ext == ".m") | (Ext == "")) : return True return False - + # Run analysis on a set of preprocessed files. def runAnalyzePreprocessed(Dir, SBOutputDir): if os.path.exists(os.path.join(Dir, BuildScript)): @@ -168,7 +206,7 @@ def runAnalyzePreprocessed(Dir, SBOutputDir): BuildScript raise Exception() - CmdPrefix = "clang -cc1 -analyze -analyzer-output=plist -w " + CmdPrefix = Clang + " -cc1 -analyze -analyzer-output=plist -w " CmdPrefix += "-analyzer-checker=" + Checkers +" -fcxx-exceptions -fblocks " PlistPath = os.path.join(Dir, SBOutputDir, "date") |