[cfe-commits] r53642 - /cfe/trunk/utils/scan-build
Ted Kremenek
kremenek at apple.com
Tue Jul 15 15:03:09 PDT 2008
Author: kremenek
Date: Tue Jul 15 17:03:09 2008
New Revision: 53642
URL: http://llvm.org/viewvc/llvm-project?rev=53642&view=rev
Log:
Added --status-bugs option to scan-build. By default, the exit status of
scan-build is the same as the exit status of the executed build command. With
this option, the exit status of scan-build is 1 if the analyzer flagged any
bugs, and 0 otherwise.
This addresses: <rdar://problem/6075320>
Modified:
cfe/trunk/utils/scan-build
Modified: cfe/trunk/utils/scan-build
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/scan-build?rev=53642&r1=53641&r2=53642&view=diff
==============================================================================
--- cfe/trunk/utils/scan-build (original)
+++ cfe/trunk/utils/scan-build Tue Jul 15 17:03:09 2008
@@ -364,7 +364,7 @@
if (! -d $Dir) {
Diag("No bugs found.\n");
- return;
+ return 0;
}
opendir(DIR, $Dir);
@@ -379,7 +379,7 @@
system ("rm", "-f", $BaseDir);
Diag("No bugs found.\n");
- return;
+ return 0;
}
# Scan each report file and build an index.
@@ -558,6 +558,8 @@
if ($Num > 0 && -r "$Dir/index.html") {
Diag("Open '$Dir/index.html' to examine bug reports.\n");
}
+
+ return $Num;
}
##----------------------------------------------------------------------------##
@@ -643,35 +645,40 @@
print <<ENDTEXT;
OPTIONS:
- -o - Target directory for HTML report files. Subdirectories
+ -o - Target directory for HTML report files. Subdirectories
will be created as needed to represent separate "runs" of
the analyzer. If this option is not specified, a directory
is created in /tmp to store the reports.
- -h - Display this message.
- --help
+ -h - Display this message.
+ --help
- -k - Add a "keep on going" option to the specified build command.
- --keep-going This option currently supports make and xcodebuild.
+ -k - Add a "keep on going" option to the specified build command.
+ --keep-going This option currently supports make and xcodebuild.
This is a convenience option; one can specify this
behavior directly using build options.
- -v - Verbose output from $Prog and the analyzer.
- A second "-v" increases verbosity.
+ --status-bugs - By default, the exit status of $Prog is the same as the
+ executed build command. Specifying this option causes the
+ exit status of $Prog to be 1 if it found potential bugs
+ and 0 otherwise.
+
+ -v - Verbose output from $Prog and the analyzer.
+ A second and third "-v" increases verbosity.
- -V - View analysis results in a web browser when the build
- --view completes.
+ -V - View analysis results in a web browser when the build
+ --view completes.
ENDTEXT
- print " Available Source Code Analyses (multiple analyses may be specified):\n\n";
+ print " Available Source Code Analyses (multiple analyses may be specified):\n\n";
foreach my $Analysis (sort keys %AvailableAnalyses) {
if (defined($AnalysesDefaultEnabled{$Analysis})) {
- print " (+)";
+ print " (+)";
}
else {
- print " ";
+ print " ";
}
print " $Analysis $AvailableAnalyses{$Analysis}\n";
@@ -679,21 +686,21 @@
print <<ENDTEXT
- (+) == analysis enabled by default unless one
- or more analysis options are specified
+ NOTE: "(+)" indicates that an analysis is enabled by default unless one
+ or more analysis options are specified
BUILD OPTIONS
- You can specify any build option acceptable to the build command.
+ You can specify any build option acceptable to the build command.
EXAMPLE
- $Prog -o /tmp/myhtmldir make -j4
+ $Prog -o /tmp/myhtmldir make -j4
- The above example causes analysis reports to be deposited into
- a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option.
- A different subdirectory is created each time $Prog analyzes a project.
- The analyzer should support most parallel builds, but not distributed builds.
+ The above example causes analysis reports to be deposited into
+ a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option.
+ A different subdirectory is created each time $Prog analyzes a project.
+ The analyzer should support most parallel builds, but not distributed builds.
ENDTEXT
}
@@ -705,8 +712,10 @@
my $HtmlDir; # Parent directory to store HTML files.
my $IgnoreErrors = 0; # Ignore build errors.
my $ViewResults = 0; # View results when the build terminates.
+my $ExitStatusFoundBugs = 0; # Exit status reflects whether bugs were found
my @AnalysesToRun;
+
if (!@ARGV) {
DisplayHelp();
exit 1;
@@ -758,6 +767,12 @@
next;
}
+ if ($arg eq "--status-bugs") {
+ shift @ARGV;
+ $ExitStatusFoundBugs = 1;
+ next;
+ }
+
DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/);
last;
@@ -822,7 +837,7 @@
# Postprocess the HTML directory.
-Postprocess($HtmlDir, $BaseDir);
+my $NumBugs = Postprocess($HtmlDir, $BaseDir);
if ($ViewResults and -r "$HtmlDir/index.html") {
# Only works on Mac OS X (for now).
@@ -830,5 +845,10 @@
system("open", "$HtmlDir/index.html");
}
+if ($ExitStatusFoundBugs) {
+ exit 1 if ($NumBugs > 0);
+ exit 0;
+}
+
exit $ExitStatus;
More information about the cfe-commits
mailing list