summaryrefslogtreecommitdiff
path: root/tools/scan-build
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@FreeBSD.org>2010-02-16 09:31:36 +0000
committerRoman Divacky <rdivacky@FreeBSD.org>2010-02-16 09:31:36 +0000
commitecb7e5c8afe929ee38155db94de6b084ec32a645 (patch)
tree53010172e19c77ea447bcd89e117cda052ab52e0 /tools/scan-build
parent5044f5c816adfd5cba17f1adee1a10127296d0bf (diff)
Notes
Diffstat (limited to 'tools/scan-build')
-rwxr-xr-xtools/scan-build/ccc-analyzer7
-rwxr-xr-xtools/scan-build/scan-build57
-rwxr-xr-xtools/scan-build/set-xcode-analyzer77
3 files changed, 105 insertions, 36 deletions
diff --git a/tools/scan-build/ccc-analyzer b/tools/scan-build/ccc-analyzer
index f19dcb4718cb..8c64d3ffefda 100755
--- a/tools/scan-build/ccc-analyzer
+++ b/tools/scan-build/ccc-analyzer
@@ -403,7 +403,7 @@ if ($Status) { exit($Status >> 8); }
# Get the analysis options.
my $Analyses = $ENV{'CCC_ANALYZER_ANALYSIS'};
-if (!defined($Analyses)) { $Analyses = '-checker-cfref'; }
+if (!defined($Analyses)) { $Analyses = '-analyzer-check-objc-mem'; }
# Get the store model.
my $StoreModel = $ENV{'CCC_ANALYZER_STORE_MODEL'};
@@ -597,9 +597,12 @@ if ($Action eq 'compile' or $Action eq 'link') {
}
}
+ # FileLang still not defined? Skip the file.
next if (!defined $FileLang);
+
+ # Language not accepted?
next if (!defined $LangsAccepted{$FileLang});
-
+
my @CmdArgs;
my @AnalyzeArgs;
diff --git a/tools/scan-build/scan-build b/tools/scan-build/scan-build
index f978a888be83..432456b15fe7 100755
--- a/tools/scan-build/scan-build
+++ b/tools/scan-build/scan-build
@@ -82,52 +82,45 @@ sub DieDiag {
# Find 'clang'
my $ClangSB = Cwd::realpath("$RealBin/bin/clang");
-my $ClangCXXSB;
if (!defined $ClangSB || ! -x $ClangSB) {
$ClangSB = Cwd::realpath("$RealBin/clang");
- if (defined $ClangSB) { $ClangCXXSB = $ClangSB . "++"; }
}
-my $Clang = $ClangSB;
-my $ClangCXX = $ClangCXXSB;
-# Default to looking for 'clang' in the path.
-if (!defined $Clang || ! -x $Clang) {
- $Clang = "clang";
- $ClangCXX = "clang++";
+my $Clang;
+if (!defined $ClangSB || ! -x $ClangSB) {
+ # Default to looking for 'clang' in the path.
+ $Clang = `which clang`;
+ chomp $Clang;
+ if ($Clang eq "") {
+ DieDiag("No 'clang' executable found in path.");
+ }
+}
+else {
+ $Clang = $ClangSB;
}
+my $ClangCXX = $Clang . "++";
my %AvailableAnalyses;
# Query clang for analysis options.
-open(PIPE, "-|", $Clang, "-cc1", "--help") or
+open(PIPE, "-|", $Clang, "-cc1", "-help") or
DieDiag("Cannot execute '$Clang'\n");
-my $FoundAnalysis = 0;
-
while(<PIPE>) {
- if ($FoundAnalysis == 0) {
- if (/Checks and Analyses/) {
- $FoundAnalysis = 1;
- }
- next;
- }
- if (/^\s\s\s\s([^\s]+)\s(.+)$/) {
- next if ($1 =~ /-dump/ or $1 =~ /-view/
- or $1 =~ /-warn-uninit/);
- $AvailableAnalyses{$1} = $2;
+ if (/(-analyzer-check-[^\s]+)/) {
+ $AvailableAnalyses{$1} = 1;
next;
}
- last;
}
close (PIPE);
my %AnalysesDefaultEnabled = (
- '-warn-dead-stores' => 1,
- '-checker-cfref' => 1,
- '-warn-objc-methodsigs' => 1,
+ '-analyzer-check-dead-stores' => 1,
+ '-analyzer-check-objc-mem' => 1,
+ '-analyzer-check-objc-methodsigs' => 1,
# Do not enable the missing -dealloc check by default.
- # '-warn-objc-missing-dealloc' => 1,
- '-warn-objc-unused-ivars' => 1,
- '-warn-security-syntactic' => 1
+ # '-analyzer-check-objc-missing-dealloc' => 1,
+ '-analyzer-check-objc-unused-ivars' => 1,
+ '-analyzer-check-security-syntactic' => 1
);
##----------------------------------------------------------------------------##
@@ -853,10 +846,6 @@ sub RunBuildCommand {
# When 'CC' is set, xcodebuild uses it to do all linking, even if we are
# linking C++ object files. Set 'LDPLUSPLUS' so that xcodebuild uses 'g++'
# when linking such files.
- if (!defined $ENV{'CCC_CXX'}) {
- $ENV{'CCC_CXX'} = 'g++';
- }
- $ENV{'LDPLUSPLUS'} = $ENV{'CCC_CXX'};
}
return (system(@$Args) >> 8);
@@ -951,7 +940,7 @@ ENDTEXT
print " ";
}
- print " $Analysis $AvailableAnalyses{$Analysis}\n";
+ print " $Analysis\n";
}
print <<ENDTEXT
@@ -1203,7 +1192,7 @@ if (!defined $CmdCXX || ! -x $CmdCXX) {
if (!defined $ClangSB || ! -x $ClangSB) {
Diag("'clang' executable not found in '$RealBin/bin'.\n");
- Diag("Using 'clang' from path.\n");
+ Diag("Using 'clang' from path: $Clang\n");
}
$ENV{'CC'} = $Cmd;
diff --git a/tools/scan-build/set-xcode-analyzer b/tools/scan-build/set-xcode-analyzer
new file mode 100755
index 000000000000..cc068a56adf9
--- /dev/null
+++ b/tools/scan-build/set-xcode-analyzer
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import re
+import tempfile
+import shutil
+import stat
+from AppKit import *
+
+def FindClangSpecs(path):
+ for root, dirs, files in os.walk(path):
+ for f in files:
+ if f.endswith(".xcspec") and f.startswith("Clang LLVM"):
+ yield os.path.join(root, f)
+
+def ModifySpec(path, pathToChecker):
+ t = tempfile.NamedTemporaryFile(delete=False)
+ foundAnalyzer = False
+ with open(path) as f:
+ for line in f:
+ if not foundAnalyzer:
+ if line.find("Static Analyzer") >= 0:
+ foundAnalyzer = True
+ else:
+ m = re.search('^(\s*ExecPath\s*=\s*")', line)
+ if m:
+ line = "".join([m.group(0), pathToChecker, '";\n'])
+ t.write(line)
+ t.close()
+ print "(+) processing:", path
+ try:
+ shutil.copy(t.name, path)
+ os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
+ except IOError, why:
+ print " (-) Cannot update file:", why, "\n"
+ except OSError, why:
+ print " (-) Cannot update file:", why, "\n"
+ os.unlink(t.name)
+
+def main():
+ from optparse import OptionParser
+ parser = OptionParser('usage: %prog [options]')
+ parser.set_description(__doc__)
+ parser.add_option("--use-checker-build", dest="path",
+ help="Use the Clang located at the provided absolute path, e.g. /Users/foo/checker-1")
+ parser.add_option("--use-xcode-clang", action="store_const",
+ const="$(CLANG)", dest="default",
+ help="Use the Clang bundled with Xcode")
+ (options, args) = parser.parse_args()
+ if options.path is None and options.default is None:
+ parser.error("You must specify a version of Clang to use for static analysis. Specify '-h' for details")
+
+ # determine if Xcode is running
+ for x in NSWorkspace.sharedWorkspace().runningApplications():
+ if x.localizedName().find("Xcode") >= 0:
+ print "(-) You must quit Xcode first before modifying its configuration files."
+ return
+
+ if options.path:
+ # Expand tildes.
+ path = os.path.expanduser(options.path)
+ if not path.endswith("clang"):
+ print "(+) Using Clang bundled with checker build:", path
+ path = os.path.join(path, "bin", "clang");
+ else:
+ print "(+) Using Clang located at:", path
+ else:
+ print "(+) Using the Clang bundled with Xcode"
+ path = options.default
+
+ for x in FindClangSpecs('/Developer'):
+ ModifySpec(x, path)
+
+if __name__ == '__main__':
+ main()
+