blob: 27883f0d86458cbc4eddf0455d70a879ab520705 [file] [log] [blame]
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001#!/usr/bin/env perl
2#
3# The LLVM Compiler Infrastructure
4#
5# This file is distributed under the University of Illinois Open Source
6# License. See LICENSE.TXT for details.
7#
8##===----------------------------------------------------------------------===##
9#
10# A script designed to wrap a build so that all calls to gcc are intercepted
11# and piped to the static analyzer.
12#
13##===----------------------------------------------------------------------===##
14
15use strict;
16use warnings;
Ted Kremenek22d6a632008-04-02 20:43:36 +000017use FindBin qw($RealBin);
Ted Kremeneka6e24812008-04-19 18:05:48 +000018use Digest::MD5;
Ted Kremenek7a4648d2008-05-02 22:04:53 +000019use File::Basename;
Ted Kremenek23cfca32008-06-16 22:40:14 +000020use Term::ANSIColor;
21use Term::ANSIColor qw(:constants);
Ted Kremenekcd25c132008-12-03 19:50:37 +000022use Cwd qw/ getcwd abs_path /;
Ted Kremenek7cba1122008-09-22 01:35:58 +000023use Sys::Hostname;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +000024
25my $Verbose = 0; # Verbose output from this script.
26my $Prog = "scan-build";
Ted Kremenekf4cdf412008-05-23 18:17:05 +000027my $BuildName;
28my $BuildDate;
Ted Kremenek95aa1052008-09-04 17:52:41 +000029my $CXX; # Leave undefined initially.
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +000030
Ted Kremenek0e689382008-09-11 18:17:51 +000031my $TERM = $ENV{'TERM'};
32my $UseColor = (defined $TERM and $TERM eq 'xterm-color' and -t STDOUT
33 and defined $ENV{'SCAN_BUILD_COLOR'});
Ted Kremenek23cfca32008-06-16 22:40:14 +000034
Ted Kremenek7cba1122008-09-22 01:35:58 +000035my $UserName = HtmlEscape(getpwuid($<) || 'unknown');
36my $HostName = HtmlEscape(hostname() || 'unknown');
37my $CurrentDir = HtmlEscape(getcwd());
38my $CurrentDirSuffix = basename($CurrentDir);
39
40my $CmdArgs;
41
42my $HtmlTitle;
43
44my $Date = localtime();
45
Ted Kremenekb7770c02008-07-15 17:06:13 +000046##----------------------------------------------------------------------------##
47# Diagnostics
48##----------------------------------------------------------------------------##
49
Ted Kremenek23cfca32008-06-16 22:40:14 +000050sub Diag {
51 if ($UseColor) {
52 print BOLD, MAGENTA "$Prog: @_";
53 print RESET;
54 }
55 else {
56 print "$Prog: @_";
57 }
58}
59
Ted Kremenek991c54b2008-08-08 20:46:42 +000060sub DiagCrashes {
61 my $Dir = shift;
Ted Kremenek938eef12009-02-17 23:31:05 +000062 Diag ("The analyzer encountered problems on some source files.\n");
63 Diag ("Preprocessed versions of these sources were deposited in '$Dir/failures'.\n");
Ted Kremenek991c54b2008-08-08 20:46:42 +000064 Diag ("Please consider submitting a bug report using these files:\n");
65 Diag (" http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs\n")
66}
67
Ted Kremenek23cfca32008-06-16 22:40:14 +000068sub DieDiag {
69 if ($UseColor) {
70 print BOLD, RED "$Prog: ";
71 print RESET, RED @_;
72 print RESET;
73 }
74 else {
75 print "$Prog: ", @_;
76 }
77 exit(0);
78}
79
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +000080##----------------------------------------------------------------------------##
Ted Kremenekb7770c02008-07-15 17:06:13 +000081# Some initial preprocessing of Clang options.
82##----------------------------------------------------------------------------##
83
Ted Kremenek833da022009-03-29 00:31:32 +000084# First, look for 'clang-cc' in libexec.
Ted Kremenek91ea79d2009-03-24 05:30:14 +000085my $ClangSB = Cwd::realpath("$RealBin/libexec/clang-cc");
Ted Kremenek833da022009-03-29 00:31:32 +000086# Second, look for 'clang-cc' in the same directory as scan-build.
Ted Kremenek43b7bd32009-03-09 23:14:38 +000087if (!defined $ClangSB || ! -x $ClangSB) {
Ted Kremenek318e6a62009-03-24 04:29:13 +000088 $ClangSB = Cwd::realpath("$RealBin/clang-cc");
Ted Kremenek43b7bd32009-03-09 23:14:38 +000089}
Ted Kremenek833da022009-03-29 00:31:32 +000090# Third, look for 'clang-cc' in ../libexec
Ted Kremenek8d10cdd2009-02-20 04:34:29 +000091if (!defined $ClangSB || ! -x $ClangSB) {
Ted Kremenek833da022009-03-29 00:31:32 +000092 $ClangSB = Cwd::realpath("$RealBin/../libexec/clang-cc");
Ted Kremenekb7770c02008-07-15 17:06:13 +000093}
Ted Kremenek833da022009-03-29 00:31:32 +000094# Finally, default to looking for 'clang-cc' in the path.
95if (!defined $ClangSB || ! -x $ClangSB) {
96 $ClangSB = "clang-cc";
97}
98my $Clang = $ClangSB;
Ted Kremenekb7770c02008-07-15 17:06:13 +000099
100my %AvailableAnalyses;
101
102# Query clang for analysis options.
Ted Kremenek63c20172008-08-04 17:34:06 +0000103open(PIPE, "-|", $Clang, "--help") or
Ted Kremenek445fa772008-10-10 00:17:08 +0000104 DieDiag("Cannot execute '$Clang'\n");
Ted Kremenek63c20172008-08-04 17:34:06 +0000105
Ted Kremenekb7770c02008-07-15 17:06:13 +0000106my $FoundAnalysis = 0;
107
108while(<PIPE>) {
109 if ($FoundAnalysis == 0) {
Ted Kremenek938eef12009-02-17 23:31:05 +0000110 if (/Checks and Analyses/) {
Ted Kremenekb7770c02008-07-15 17:06:13 +0000111 $FoundAnalysis = 1;
112 }
Ted Kremenekb7770c02008-07-15 17:06:13 +0000113 next;
114 }
115
116 if (/^\s\s\s\s([^\s]+)\s(.+)$/) {
117 next if ($1 =~ /-dump/ or $1 =~ /-view/
118 or $1 =~ /-checker-simple/ or $1 =~ /-warn-uninit/);
119
120 $AvailableAnalyses{$1} = $2;
121 next;
Ted Kremenek938eef12009-02-17 23:31:05 +0000122 }
Ted Kremenekb7770c02008-07-15 17:06:13 +0000123 last;
124}
125
126close (PIPE);
127
128my %AnalysesDefaultEnabled = (
129 '-warn-dead-stores' => 1,
130 '-checker-cfref' => 1,
Ted Kremenek90125992008-07-15 23:41:32 +0000131 '-warn-objc-methodsigs' => 1,
Ted Kremenekd76c6a32009-02-25 21:08:30 +0000132 # Do not enable the missing -dealloc check by default.
133 # '-warn-objc-missing-dealloc' => 1,
Ted Kremenek5d443492008-09-18 06:34:16 +0000134 '-warn-objc-unused-ivars' => 1,
Ted Kremenekb7770c02008-07-15 17:06:13 +0000135);
136
137##----------------------------------------------------------------------------##
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000138# GetHTMLRunDir - Construct an HTML directory name for the current sub-run.
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000139##----------------------------------------------------------------------------##
140
Sam Bishopa0e22662008-04-02 03:35:43 +0000141sub GetHTMLRunDir {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000142
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000143 die "Not enough arguments." if (@_ == 0);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000144 my $Dir = shift @_;
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000145
146 my $TmpMode = 0;
147 if (!defined $Dir) {
Ted Kremenekffda0b42008-10-31 05:48:42 +0000148 if (`uname` =~ /Darwin/) {
149 $Dir = $ENV{'TMPDIR'};
150 if (!defined $Dir) { $Dir = "/tmp"; }
151 }
152 else {
153 $Dir = "/tmp";
154 }
155
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000156 $TmpMode = 1;
157 }
Ted Kremenekbf762c92009-02-24 02:38:02 +0000158
159 # Chop off any trailing '/' characters.
160 while ($Dir =~ /\/$/) { chop $Dir; }
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000161
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000162 # Get current date and time.
163
164 my @CurrentTime = localtime();
165
166 my $year = $CurrentTime[5] + 1900;
167 my $day = $CurrentTime[3];
168 my $month = $CurrentTime[4] + 1;
169
Ted Kremenek9d7405f2008-05-14 17:23:56 +0000170 my $DateString = sprintf("%d-%02d-%02d", $year, $month, $day);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000171
172 # Determine the run number.
173
174 my $RunNumber;
175
176 if (-d $Dir) {
177
178 if (! -r $Dir) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000179 DieDiag("directory '$Dir' exists but is not readable.\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000180 }
181
182 # Iterate over all files in the specified directory.
183
184 my $max = 0;
185
186 opendir(DIR, $Dir);
Ted Kremenek29da6c52008-08-07 17:57:34 +0000187 my @FILES = grep { -d "$Dir/$_" } readdir(DIR);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000188 closedir(DIR);
189
190 foreach my $f (@FILES) {
191
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000192 # Strip the prefix '$Prog-' if we are dumping files to /tmp.
193 if ($TmpMode) {
194 next if (!($f =~ /^$Prog-(.+)/));
195 $f = $1;
196 }
197
Ted Kremenekebb74132008-09-21 06:58:09 +0000198
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000199 my @x = split/-/, $f;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000200 next if (scalar(@x) != 4);
201 next if ($x[0] != $year);
202 next if ($x[1] != $month);
203 next if ($x[2] != $day);
204
205 if ($x[3] > $max) {
206 $max = $x[3];
207 }
208 }
209
210 $RunNumber = $max + 1;
211 }
212 else {
213
214 if (-x $Dir) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000215 DieDiag("'$Dir' exists but is not a directory.\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000216 }
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000217
218 if ($TmpMode) {
Ted Kremenek445fa772008-10-10 00:17:08 +0000219 DieDiag("The directory '/tmp' does not exist or cannot be accessed.\n");
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000220 }
221
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000222 # $Dir does not exist. It will be automatically created by the
223 # clang driver. Set the run number to 1.
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000224
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000225 $RunNumber = 1;
226 }
227
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000228 die "RunNumber must be defined!" if (!defined $RunNumber);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000229
230 # Append the run number.
Ted Kremenekfc0898a2008-09-04 23:56:36 +0000231 my $NewDir;
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000232 if ($TmpMode) {
Ted Kremenekfc0898a2008-09-04 23:56:36 +0000233 $NewDir = "$Dir/$Prog-$DateString-$RunNumber";
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000234 }
235 else {
Ted Kremenekfc0898a2008-09-04 23:56:36 +0000236 $NewDir = "$Dir/$DateString-$RunNumber";
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000237 }
Ted Kremenekfc0898a2008-09-04 23:56:36 +0000238 system 'mkdir','-p',$NewDir;
239 return $NewDir;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000240}
241
Sam Bishopa0e22662008-04-02 03:35:43 +0000242sub SetHtmlEnv {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000243
244 die "Wrong number of arguments." if (scalar(@_) != 2);
245
246 my $Args = shift;
247 my $Dir = shift;
248
249 die "No build command." if (scalar(@$Args) == 0);
250
251 my $Cmd = $$Args[0];
252
253 if ($Cmd =~ /configure/) {
254 return;
255 }
256
257 if ($Verbose) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000258 Diag("Emitting reports for this run to '$Dir'.\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000259 }
260
261 $ENV{'CCC_ANALYZER_HTML'} = $Dir;
262}
263
264##----------------------------------------------------------------------------##
Ted Kremenek57cf4462008-04-18 15:09:30 +0000265# ComputeDigest - Compute a digest of the specified file.
266##----------------------------------------------------------------------------##
267
268sub ComputeDigest {
269 my $FName = shift;
Ted Kremenek23cfca32008-06-16 22:40:14 +0000270 DieDiag("Cannot read $FName to compute Digest.\n") if (! -r $FName);
Ted Kremeneka6e24812008-04-19 18:05:48 +0000271
272 # Use Digest::MD5. We don't have to be cryptographically secure. We're
Ted Kremenek7ea02e62008-04-19 18:07:44 +0000273 # just looking for duplicate files that come from a non-malicious source.
274 # We use Digest::MD5 because it is a standard Perl module that should
Ted Kremenek63c20172008-08-04 17:34:06 +0000275 # come bundled on most systems.
Ted Kremenek23cfca32008-06-16 22:40:14 +0000276 open(FILE, $FName) or DieDiag("Cannot open $FName when computing Digest.\n");
Ted Kremeneka6e24812008-04-19 18:05:48 +0000277 binmode FILE;
278 my $Result = Digest::MD5->new->addfile(*FILE)->hexdigest;
279 close(FILE);
280
Ted Kremenek63c20172008-08-04 17:34:06 +0000281 # Return the digest.
Ted Kremeneka6e24812008-04-19 18:05:48 +0000282 return $Result;
Ted Kremenek57cf4462008-04-18 15:09:30 +0000283}
284
285##----------------------------------------------------------------------------##
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000286# UpdatePrefix - Compute the common prefix of files.
287##----------------------------------------------------------------------------##
288
289my $Prefix;
290
291sub UpdatePrefix {
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000292 my $x = shift;
293 my $y = basename($x);
294 $x =~ s/\Q$y\E$//;
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000295
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000296 if (!defined $Prefix) {
297 $Prefix = $x;
298 return;
299 }
300
Ted Kremenek20b2bae2008-09-11 21:15:10 +0000301 chop $Prefix while (!($x =~ /^\Q$Prefix/));
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000302}
303
304sub GetPrefix {
305 return $Prefix;
306}
307
308##----------------------------------------------------------------------------##
309# UpdateInFilePath - Update the path in the report file.
310##----------------------------------------------------------------------------##
311
312sub UpdateInFilePath {
313 my $fname = shift;
314 my $regex = shift;
315 my $newtext = shift;
Ted Kremenek63c20172008-08-04 17:34:06 +0000316
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000317 open (RIN, $fname) or die "cannot open $fname";
Ted Kremenek63c20172008-08-04 17:34:06 +0000318 open (ROUT, ">", "$fname.tmp") or die "cannot open $fname.tmp";
319
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000320 while (<RIN>) {
321 s/$regex/$newtext/;
322 print ROUT $_;
323 }
Ted Kremenek63c20172008-08-04 17:34:06 +0000324
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000325 close (ROUT);
326 close (RIN);
Ted Kremenek20161e92008-07-15 20:18:21 +0000327 system("mv", "$fname.tmp", $fname);
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000328}
329
330##----------------------------------------------------------------------------##
Ted Kremenek5744dc22008-04-02 18:03:36 +0000331# ScanFile - Scan a report file for various identifying attributes.
332##----------------------------------------------------------------------------##
333
Ted Kremenek57cf4462008-04-18 15:09:30 +0000334# Sometimes a source file is scanned more than once, and thus produces
335# multiple error reports. We use a cache to solve this problem.
336
337my %AlreadyScanned;
338
Ted Kremenek5744dc22008-04-02 18:03:36 +0000339sub ScanFile {
340
341 my $Index = shift;
342 my $Dir = shift;
343 my $FName = shift;
344
Ted Kremenek57cf4462008-04-18 15:09:30 +0000345 # Compute a digest for the report file. Determine if we have already
346 # scanned a file that looks just like it.
347
348 my $digest = ComputeDigest("$Dir/$FName");
349
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000350 if (defined $AlreadyScanned{$digest}) {
Ted Kremenek57cf4462008-04-18 15:09:30 +0000351 # Redundant file. Remove it.
Ted Kremenek20161e92008-07-15 20:18:21 +0000352 system ("rm", "-f", "$Dir/$FName");
Ted Kremenek57cf4462008-04-18 15:09:30 +0000353 return;
354 }
355
356 $AlreadyScanned{$digest} = 1;
357
Ted Kremenek809709f2008-04-18 16:58:34 +0000358 # At this point the report file is not world readable. Make it happen.
Ted Kremenek20161e92008-07-15 20:18:21 +0000359 system ("chmod", "644", "$Dir/$FName");
Ted Kremenek684bb092008-04-18 15:18:20 +0000360
361 # Scan the report file for tags.
Ted Kremenek23cfca32008-06-16 22:40:14 +0000362 open(IN, "$Dir/$FName") or DieDiag("Cannot open '$Dir/$FName'\n");
Ted Kremenek5744dc22008-04-02 18:03:36 +0000363
Ted Kremeneka26ddab2009-01-27 01:53:39 +0000364 my $BugType = "";
Ted Kremenek22d6a632008-04-02 20:43:36 +0000365 my $BugFile = "";
Ted Kremenekebb74132008-09-21 06:58:09 +0000366 my $BugCategory;
Ted Kremenek22d6a632008-04-02 20:43:36 +0000367 my $BugPathLength = 1;
368 my $BugLine = 0;
Ted Kremenekebb74132008-09-21 06:58:09 +0000369 my $found = 0;
370
Ted Kremenek5744dc22008-04-02 18:03:36 +0000371 while (<IN>) {
Ted Kremenekebb74132008-09-21 06:58:09 +0000372
373 last if ($found == 5);
374
Ted Kremeneka26ddab2009-01-27 01:53:39 +0000375 if (/<!-- BUGTYPE (.*) -->$/) {
376 $BugType = $1;
Ted Kremenekebb74132008-09-21 06:58:09 +0000377 ++$found;
Ted Kremenek5744dc22008-04-02 18:03:36 +0000378 }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000379 elsif (/<!-- BUGFILE (.*) -->$/) {
Ted Kremenek990c2f42008-12-03 19:19:23 +0000380 $BugFile = abs_path($1);
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000381 UpdatePrefix($BugFile);
Ted Kremenekebb74132008-09-21 06:58:09 +0000382 ++$found;
Ted Kremenek22d6a632008-04-02 20:43:36 +0000383 }
384 elsif (/<!-- BUGPATHLENGTH (.*) -->$/) {
385 $BugPathLength = $1;
Ted Kremenekebb74132008-09-21 06:58:09 +0000386 ++$found;
Ted Kremenek22d6a632008-04-02 20:43:36 +0000387 }
388 elsif (/<!-- BUGLINE (.*) -->$/) {
389 $BugLine = $1;
Ted Kremenekebb74132008-09-21 06:58:09 +0000390 ++$found;
391 }
392 elsif (/<!-- BUGCATEGORY (.*) -->$/) {
393 $BugCategory = $1;
394 ++$found;
Ted Kremenek22d6a632008-04-02 20:43:36 +0000395 }
Ted Kremenek5744dc22008-04-02 18:03:36 +0000396 }
397
398 close(IN);
Ted Kremenekebb74132008-09-21 06:58:09 +0000399
400 if (!defined $BugCategory) {
401 $BugCategory = "Other";
402 }
Ted Kremenek5744dc22008-04-02 18:03:36 +0000403
Ted Kremeneka26ddab2009-01-27 01:53:39 +0000404 push @$Index,[ $FName, $BugCategory, $BugType, $BugFile, $BugLine,
Ted Kremenek81983112008-09-28 04:13:09 +0000405 $BugPathLength ];
Ted Kremenek22d6a632008-04-02 20:43:36 +0000406}
407
408##----------------------------------------------------------------------------##
Ted Kremenek3ce12072008-09-22 17:50:47 +0000409# CopyFiles - Copy resource files to target directory.
Ted Kremenek22d6a632008-04-02 20:43:36 +0000410##----------------------------------------------------------------------------##
411
Ted Kremenek3ce12072008-09-22 17:50:47 +0000412sub CopyFiles {
Ted Kremenek22d6a632008-04-02 20:43:36 +0000413
414 my $Dir = shift;
Ted Kremeneke15fa272008-10-13 21:46:42 +0000415
416 my $JS = Cwd::realpath("$RealBin/sorttable.js");
Ted Kremenek22d6a632008-04-02 20:43:36 +0000417
Ted Kremenek23cfca32008-06-16 22:40:14 +0000418 DieDiag("Cannot find 'sorttable.js'.\n")
Ted Kremeneke15fa272008-10-13 21:46:42 +0000419 if (! -r $JS);
Ted Kremenek22d6a632008-04-02 20:43:36 +0000420
Ted Kremeneke15fa272008-10-13 21:46:42 +0000421 system ("cp", $JS, "$Dir");
Ted Kremenek22d6a632008-04-02 20:43:36 +0000422
Ted Kremenek23cfca32008-06-16 22:40:14 +0000423 DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n")
Ted Kremenek22d6a632008-04-02 20:43:36 +0000424 if (! -r "$Dir/sorttable.js");
Ted Kremenek3ce12072008-09-22 17:50:47 +0000425
Ted Kremeneke15fa272008-10-13 21:46:42 +0000426 my $CSS = Cwd::realpath("$RealBin/scanview.css");
427
Ted Kremenek3ce12072008-09-22 17:50:47 +0000428 DieDiag("Cannot find 'scanview.css'.\n")
Ted Kremeneke15fa272008-10-13 21:46:42 +0000429 if (! -r $CSS);
Ted Kremenek3ce12072008-09-22 17:50:47 +0000430
Ted Kremeneke15fa272008-10-13 21:46:42 +0000431 system ("cp", $CSS, "$Dir");
Ted Kremenek3ce12072008-09-22 17:50:47 +0000432
433 DieDiag("Could not copy 'scanview.css' to '$Dir'.\n")
Ted Kremeneke15fa272008-10-13 21:46:42 +0000434 if (! -r $CSS);
Ted Kremenek5744dc22008-04-02 18:03:36 +0000435}
436
437##----------------------------------------------------------------------------##
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000438# Postprocess - Postprocess the results of an analysis scan.
439##----------------------------------------------------------------------------##
440
Sam Bishopa0e22662008-04-02 03:35:43 +0000441sub Postprocess {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000442
443 my $Dir = shift;
Ted Kremenek684bb092008-04-18 15:18:20 +0000444 my $BaseDir = shift;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000445
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000446 die "No directory specified." if (!defined $Dir);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000447
448 if (! -d $Dir) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000449 Diag("No bugs found.\n");
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000450 return 0;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000451 }
452
453 opendir(DIR, $Dir);
Ted Kremenek938eef12009-02-17 23:31:05 +0000454 my @files = grep { /^report-.*\.html$/ } readdir(DIR);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000455 closedir(DIR);
456
Ted Kremenek938eef12009-02-17 23:31:05 +0000457 if (scalar(@files) == 0 and ! -e "$Dir/failures") {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000458 Diag("Removing directory '$Dir' because it contains no reports.\n");
Ted Kremenek20161e92008-07-15 20:18:21 +0000459 system ("rm", "-fR", $Dir);
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000460 return 0;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000461 }
Ted Kremenek5744dc22008-04-02 18:03:36 +0000462
Ted Kremenek991c54b2008-08-08 20:46:42 +0000463 # Scan each report file and build an index.
464 my @Index;
Ted Kremenek5744dc22008-04-02 18:03:36 +0000465 foreach my $file (@files) { ScanFile(\@Index, $Dir, $file); }
466
Ted Kremenek938eef12009-02-17 23:31:05 +0000467 # Scan the failures directory and use the information in the .info files
Ted Kremenekd52e4252008-08-25 20:45:07 +0000468 # to update the common prefix directory.
Ted Kremenek938eef12009-02-17 23:31:05 +0000469 my @failures;
470 my @attributes_ignored;
471 if (-d "$Dir/failures") {
472 opendir(DIR, "$Dir/failures");
473 @failures = grep { /[.]info.txt$/ && !/attribute_ignored/; } readdir(DIR);
Ted Kremenekd52e4252008-08-25 20:45:07 +0000474 closedir(DIR);
Ted Kremenek938eef12009-02-17 23:31:05 +0000475 opendir(DIR, "$Dir/failures");
476 @attributes_ignored = grep { /^attribute_ignored/; } readdir(DIR);
477 closedir(DIR);
478 foreach my $file (@failures) {
479 open IN, "$Dir/failures/$file" or DieDiag("cannot open $file\n");
Ted Kremenekd52e4252008-08-25 20:45:07 +0000480 my $Path = <IN>;
481 if (defined $Path) { UpdatePrefix($Path); }
482 close IN;
483 }
484 }
485
Ted Kremenek63c20172008-08-04 17:34:06 +0000486 # Generate an index.html file.
487 my $FName = "$Dir/index.html";
488 open(OUT, ">", $FName) or DieDiag("Cannot create file '$FName'\n");
Ted Kremenek5744dc22008-04-02 18:03:36 +0000489
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000490 # Print out the header.
491
Ted Kremenek5744dc22008-04-02 18:03:36 +0000492print OUT <<ENDTEXT;
493<html>
494<head>
Ted Kremenek7cba1122008-09-22 01:35:58 +0000495<title>${HtmlTitle}</title>
Ted Kremenekf1435452008-09-23 22:34:51 +0000496<link type="text/css" rel="stylesheet" href="scanview.css"/>
Ted Kremenek22d6a632008-04-02 20:43:36 +0000497<script src="sorttable.js"></script>
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000498<script language='javascript' type="text/javascript">
499function SetDisplay(RowClass, DisplayVal)
500{
501 var Rows = document.getElementsByTagName("tr");
502 for ( var i = 0 ; i < Rows.length; ++i ) {
503 if (Rows[i].className == RowClass) {
504 Rows[i].style.display = DisplayVal;
505 }
506 }
507}
Ted Kremenekebb74132008-09-21 06:58:09 +0000508
Ted Kremenek2350a462008-10-28 19:56:52 +0000509function CopyCheckedStateToCheckButtons(SummaryCheckButton) {
510 var Inputs = document.getElementsByTagName("input");
511 for ( var i = 0 ; i < Inputs.length; ++i ) {
512 if (Inputs[i].type == "checkbox") {
513 if(Inputs[i] != SummaryCheckButton) {
514 Inputs[i].checked = SummaryCheckButton.checked;
515 Inputs[i].onclick();
516 }
517 }
518 }
519}
520
Ted Kremenek999e1202008-10-28 20:09:57 +0000521function returnObjById( id ) {
522 if (document.getElementById)
523 var returnVar = document.getElementById(id);
524 else if (document.all)
525 var returnVar = document.all[id];
526 else if (document.layers)
527 var returnVar = document.layers[id];
528 return returnVar;
529}
530
531var NumUnchecked = 0;
532
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000533function ToggleDisplay(CheckButton, ClassName) {
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000534 if (CheckButton.checked) {
535 SetDisplay(ClassName, "");
Ted Kremenek999e1202008-10-28 20:09:57 +0000536 if (--NumUnchecked == 0) {
537 returnObjById("AllBugsCheck").checked = true;
538 }
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000539 }
540 else {
541 SetDisplay(ClassName, "none");
Ted Kremenek999e1202008-10-28 20:09:57 +0000542 NumUnchecked++;
543 returnObjById("AllBugsCheck").checked = false;
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000544 }
545}
546</script>
Ted Kremenek1d1abb12008-09-22 17:52:58 +0000547<!-- SUMMARYENDHEAD -->
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000548</head>
549<body>
Ted Kremenek7cba1122008-09-22 01:35:58 +0000550<h1>${HtmlTitle}</h1>
551
552<table>
553<tr><th>User:</th><td>${UserName}\@${HostName}</td></tr>
554<tr><th>Working Directory:</th><td>${CurrentDir}</td></tr>
555<tr><th>Command Line:</th><td>${CmdArgs}</td></tr>
556<tr><th>Date:</th><td>${Date}</td></tr>
557ENDTEXT
558
559print OUT "<tr><th>Version:</th><td>${BuildName} (${BuildDate})</td></tr>\n"
560 if (defined($BuildName) && defined($BuildDate));
561
562print OUT <<ENDTEXT;
563</table>
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000564ENDTEXT
565
Ted Kremenek991c54b2008-08-08 20:46:42 +0000566 if (scalar(@files)) {
567 # Print out the summary table.
568 my %Totals;
Ted Kremenekebb74132008-09-21 06:58:09 +0000569
Ted Kremenek991c54b2008-08-08 20:46:42 +0000570 for my $row ( @Index ) {
Ted Kremenekebb74132008-09-21 06:58:09 +0000571 my $bug_type = ($row->[2]);
572 my $bug_category = ($row->[1]);
573 my $key = "$bug_category:$bug_type";
574
575 if (!defined $Totals{$key}) { $Totals{$key} = [1,$bug_category,$bug_type]; }
576 else { $Totals{$key}->[0]++; }
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000577 }
Ted Kremenek991c54b2008-08-08 20:46:42 +0000578
Ted Kremenek7cba1122008-09-22 01:35:58 +0000579 print OUT "<h2>Bug Summary</h2>";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000580
581 if (defined $BuildName) {
582 print OUT "\n<p>Results in this analysis run are based on analyzer build <b>$BuildName</b>.</p>\n"
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000583 }
Ted Kremenekf4cdf412008-05-23 18:17:05 +0000584
Ted Kremenek2350a462008-10-28 19:56:52 +0000585 my $TotalBugs = scalar(@Index);
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000586print OUT <<ENDTEXT;
Ted Kremenekebb74132008-09-21 06:58:09 +0000587<table>
588<thead><tr><td>Bug Type</td><td>Quantity</td><td class="sorttable_nosort">Display?</td></tr></thead>
Ted Kremenek999e1202008-10-28 20:09:57 +0000589<tr style="font-weight:bold"><td class="SUMM_DESC">All Bugs</td><td class="Q">$TotalBugs</td><td><center><input type="checkbox" id="AllBugsCheck" onClick="CopyCheckedStateToCheckButtons(this);" checked/></center></td></tr>
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000590ENDTEXT
591
Ted Kremenekebb74132008-09-21 06:58:09 +0000592 my $last_category;
593
594 for my $key (
595 sort {
596 my $x = $Totals{$a};
597 my $y = $Totals{$b};
598 my $res = $x->[1] cmp $y->[1];
599 $res = $x->[2] cmp $y->[2] if ($res == 0);
600 $res
601 } keys %Totals )
602 {
603 my $val = $Totals{$key};
604 my $category = $val->[1];
605 if (!defined $last_category or $last_category ne $category) {
606 $last_category = $category;
607 print OUT "<tr><th>$category</th><th colspan=2></th></tr>\n";
608 }
609 my $x = lc $key;
610 $x =~ s/[ ,'":\/()]+/_/g;
611 print OUT "<tr><td class=\"SUMM_DESC\">";
612 print OUT $val->[2];
Ted Kremenek2350a462008-10-28 19:56:52 +0000613 print OUT "</td><td class=\"Q\">";
Ted Kremenekebb74132008-09-21 06:58:09 +0000614 print OUT $val->[0];
615 print OUT "</td><td><center><input type=\"checkbox\" onClick=\"ToggleDisplay(this,'bt_$x');\" checked/></center></td></tr>\n";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000616 }
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000617
618 # Print out the table of errors.
619
620print OUT <<ENDTEXT;
621</table>
Ted Kremenek7cba1122008-09-22 01:35:58 +0000622<h2>Reports</h2>
Ted Kremenekebb74132008-09-21 06:58:09 +0000623
624<table class="sortable" style="table-layout:automatic">
625<thead><tr>
626 <td>Bug Group</td>
627 <td class="sorttable_sorted">Bug Type<span id="sorttable_sortfwdind">&nbsp;&#x25BE;</span></td>
Ted Kremenekbba1cf52008-04-03 05:50:51 +0000628 <td>File</td>
Ted Kremenekebb74132008-09-21 06:58:09 +0000629 <td class="Q">Line</td>
Ted Kremenek81983112008-09-28 04:13:09 +0000630 <td class="Q">Path Length</td>
Ted Kremenek2645c772008-07-07 16:58:44 +0000631 <td class="sorttable_nosort"></td>
Ted Kremenekebb74132008-09-21 06:58:09 +0000632 <!-- REPORTBUGCOL -->
633</tr></thead>
634<tbody>
Ted Kremenek5744dc22008-04-02 18:03:36 +0000635ENDTEXT
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000636
Ted Kremenek991c54b2008-08-08 20:46:42 +0000637 my $prefix = GetPrefix();
638 my $regex;
639 my $InFileRegex;
640 my $InFilePrefix = "File:</td><td>";
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000641
Ted Kremenek991c54b2008-08-08 20:46:42 +0000642 if (defined $prefix) {
643 $regex = qr/^\Q$prefix\E/is;
644 $InFileRegex = qr/\Q$InFilePrefix$prefix\E/is;
645 }
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000646
Ted Kremenekebb74132008-09-21 06:58:09 +0000647 for my $row ( sort { $a->[2] cmp $b->[2] } @Index ) {
648 my $x = "$row->[1]:$row->[2]";
649 $x = lc $x;
650 $x =~ s/[ ,'":\/()]+/_/g;
Ted Kremenek5744dc22008-04-02 18:03:36 +0000651
Ted Kremenek991c54b2008-08-08 20:46:42 +0000652 my $ReportFile = $row->[0];
Ted Kremenekebb74132008-09-21 06:58:09 +0000653
654 print OUT "<tr class=\"bt_$x\">";
655 print OUT "<td class=\"DESC\">";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000656 print OUT $row->[1];
Ted Kremenekebb74132008-09-21 06:58:09 +0000657 print OUT "</td>";
658 print OUT "<td class=\"DESC\">";
659 print OUT $row->[2];
660 print OUT "</td>";
661
662 # Update the file prefix.
663 my $fname = $row->[3];
Ted Kremenekebb74132008-09-21 06:58:09 +0000664
Ted Kremenek991c54b2008-08-08 20:46:42 +0000665 if (defined $regex) {
666 $fname =~ s/$regex//;
667 UpdateInFilePath("$Dir/$ReportFile", $InFileRegex, $InFilePrefix)
668 }
Ted Kremenekebb74132008-09-21 06:58:09 +0000669
Ted Kremenek91639ef2008-09-22 17:42:31 +0000670 print OUT "<td>";
Ted Kremenekebb74132008-09-21 06:58:09 +0000671 my @fname = split /\//,$fname;
672 if ($#fname > 0) {
673 while ($#fname >= 0) {
674 my $x = shift @fname;
675 print OUT $x;
676 if ($#fname >= 0) {
677 print OUT "<span class=\"W\"> </span>/";
678 }
679 }
680 }
681 else {
682 print OUT $fname;
Ted Kremenek91639ef2008-09-22 17:42:31 +0000683 }
Ted Kremenekebb74132008-09-21 06:58:09 +0000684 print OUT "</td>";
685
686 # Print out the quantities.
Ted Kremenek81983112008-09-28 04:13:09 +0000687 for my $j ( 4 .. 5 ) {
Ted Kremenekebb74132008-09-21 06:58:09 +0000688 print OUT "<td class=\"Q\">$row->[$j]</td>";
689 }
690
Ted Kremenek991c54b2008-08-08 20:46:42 +0000691 # Print the rest of the columns.
Ted Kremenek81983112008-09-28 04:13:09 +0000692 for (my $j = 6; $j <= $#{$row}; ++$j) {
Ted Kremenekebb74132008-09-21 06:58:09 +0000693 print OUT "<td>$row->[$j]</td>"
Ted Kremenek991c54b2008-08-08 20:46:42 +0000694 }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000695
Ted Kremenek991c54b2008-08-08 20:46:42 +0000696 # Emit the "View" link.
Ted Kremenek68005dd2008-09-22 17:39:18 +0000697 print OUT "<td><a href=\"$ReportFile#EndPath\">View Report</a></td>";
Ted Kremenek3cea9ee2008-07-30 17:58:08 +0000698
Daniel Dunbare43038e2008-09-19 23:18:44 +0000699 # Emit REPORTBUG markers.
Ted Kremenekebb74132008-09-21 06:58:09 +0000700 print OUT "\n<!-- REPORTBUG id=\"$ReportFile\" -->\n";
Daniel Dunbare43038e2008-09-19 23:18:44 +0000701
Ted Kremenek991c54b2008-08-08 20:46:42 +0000702 # End the row.
703 print OUT "</tr>\n";
704 }
705
Ted Kremenekebb74132008-09-21 06:58:09 +0000706 print OUT "</tbody>\n</table>\n\n";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000707 }
708
Ted Kremenek938eef12009-02-17 23:31:05 +0000709 if (scalar (@failures) || scalar(@attributes_ignored)) {
710 print OUT "<h2>Analyzer Failures</h2>\n";
711
712 if (scalar @attributes_ignored) {
713 print OUT "The analyzer's parser ignored the following attributes:<p>\n";
714 print OUT "<table>\n";
715 print OUT "<thead><tr><td>Attribute</td><td>Source File</td><td>Preprocessed File</td><td>STDERR Output</td></tr></thead>\n";
716 foreach my $file (sort @attributes_ignored) {
717 die "cannot demangle attribute name\n" if (! ($file =~ /^attribute_ignored_(.+).txt/));
718 my $attribute = $1;
719 # Open the attribute file to get the first file that failed.
720 next if (!open (ATTR, "$Dir/failures/$file"));
721 my $ppfile = <ATTR>;
722 chomp $ppfile;
723 close ATTR;
724 next if (! -e "$Dir/failures/$ppfile");
725 # Open the info file and get the name of the source file.
726 open (INFO, "$Dir/failures/$ppfile.info.txt") or
727 die "Cannot open $Dir/failures/$ppfile.info.txt\n";
728 my $srcfile = <INFO>;
729 chomp $srcfile;
730 close (INFO);
731 # Print the information in the table.
732 my $prefix = GetPrefix();
733 if (defined $prefix) { $srcfile =~ s/^\Q$prefix//; }
734 print OUT "<tr><td>$attribute</td><td>$srcfile</td><td><a href=\"failures/$ppfile\">$ppfile</a></td><td><a href=\"failures/$ppfile.stderr.txt\">$ppfile.stderr.txt</a></td></tr>\n";
735 my $ppfile_clang = $ppfile;
736 $ppfile_clang =~ s/[.](.+)$/.clang.$1/;
737 print OUT " <!-- REPORTPROBLEM src=\"$srcfile\" file=\"failures/$ppfile\" clangfile=\"failures/$ppfile_clang\" stderr=\"failures/$ppfile.stderr.txt\" info=\"failures/$ppfile.info.txt\" -->\n";
738 }
739 print OUT "</table>\n";
740 }
741
742 if (scalar @failures) {
743 print OUT "<p>The analyzer had problems processing the following files:</p>\n";
744 print OUT "<table>\n";
745 print OUT "<thead><tr><td>Problem</td><td>Source File</td><td>Preprocessed File</td><td>STDERR Output</td></tr></thead>\n";
746 foreach my $file (sort @failures) {
Ted Kremenek82a12532008-09-25 00:25:16 +0000747 $file =~ /(.+).info.txt$/;
Ted Kremenek991c54b2008-08-08 20:46:42 +0000748 # Get the preprocessed file.
749 my $ppfile = $1;
750 # Open the info file and get the name of the source file.
Ted Kremenek938eef12009-02-17 23:31:05 +0000751 open (INFO, "$Dir/failures/$file") or
752 die "Cannot open $Dir/failures/$file\n";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000753 my $srcfile = <INFO>;
Ted Kremenek5d31f832008-08-18 18:38:29 +0000754 chomp $srcfile;
755 my $problem = <INFO>;
756 chomp $problem;
Ted Kremenek991c54b2008-08-08 20:46:42 +0000757 close (INFO);
758 # Print the information in the table.
Ted Kremenekd52e4252008-08-25 20:45:07 +0000759 my $prefix = GetPrefix();
Ted Kremenek9f9b1fd2008-09-12 22:49:36 +0000760 if (defined $prefix) { $srcfile =~ s/^\Q$prefix//; }
Ted Kremenek938eef12009-02-17 23:31:05 +0000761 print OUT "<tr><td>$problem</td><td>$srcfile</td><td><a href=\"failures/$ppfile\">$ppfile</a></td><td><a href=\"failures/$ppfile.stderr.txt\">$ppfile.stderr.txt</a></td></tr>\n";
Daniel Dunbarce723ce2008-09-25 01:10:50 +0000762 my $ppfile_clang = $ppfile;
763 $ppfile_clang =~ s/[.](.+)$/.clang.$1/;
Ted Kremenek938eef12009-02-17 23:31:05 +0000764 print OUT " <!-- REPORTPROBLEM src=\"$srcfile\" file=\"failures/$ppfile\" clangfile=\"failures/$ppfile_clang\" stderr=\"failures/$ppfile.stderr.txt\" info=\"failures/$ppfile.info.txt\" -->\n";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000765 }
Ted Kremenek938eef12009-02-17 23:31:05 +0000766 print OUT "</table>\n";
767 }
768 print OUT "<p>Please consider submitting preprocessed files as <a href=\"http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs\">bug reports</a>. <!-- REPORTCRASHES --> </p>\n";
Ted Kremenek5744dc22008-04-02 18:03:36 +0000769 }
770
Ted Kremenek991c54b2008-08-08 20:46:42 +0000771 print OUT "</body></html>\n";
Ted Kremenek5744dc22008-04-02 18:03:36 +0000772 close(OUT);
Ted Kremenek3ce12072008-09-22 17:50:47 +0000773 CopyFiles($Dir);
Ted Kremenek20161e92008-07-15 20:18:21 +0000774
775 # Make sure $Dir and $BaseDir are world readable/executable.
776 system("chmod", "755", $Dir);
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000777 if (defined $BaseDir) { system("chmod", "755", $BaseDir); }
Ted Kremenek20161e92008-07-15 20:18:21 +0000778
Ted Kremenek23cfca32008-06-16 22:40:14 +0000779 my $Num = scalar(@Index);
Ted Kremenek150c2122008-07-11 19:15:05 +0000780 Diag("$Num bugs found.\n");
781 if ($Num > 0 && -r "$Dir/index.html") {
Ted Kremenek5950b3f2008-09-22 06:47:01 +0000782 Diag("Run 'scan-view $Dir' to examine bug reports.\n");
Ted Kremenek150c2122008-07-11 19:15:05 +0000783 }
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000784
Ted Kremenek938eef12009-02-17 23:31:05 +0000785 DiagCrashes($Dir) if (scalar @failures || scalar @attributes_ignored);
Ted Kremenek991c54b2008-08-08 20:46:42 +0000786
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000787 return $Num;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000788}
789
790##----------------------------------------------------------------------------##
Ted Kremenekdab11102008-04-02 04:43:42 +0000791# RunBuildCommand - Run the build command.
792##----------------------------------------------------------------------------##
793
Ted Kremenek6b628982008-04-30 23:47:12 +0000794sub AddIfNotPresent {
795 my $Args = shift;
796 my $Arg = shift;
797 my $found = 0;
798
799 foreach my $k (@$Args) {
800 if ($k eq $Arg) {
801 $found = 1;
802 last;
803 }
804 }
805
806 if ($found == 0) {
807 push @$Args, $Arg;
808 }
809}
810
Ted Kremenekdab11102008-04-02 04:43:42 +0000811sub RunBuildCommand {
812
813 my $Args = shift;
Ted Kremenek7442ca62008-04-02 16:04:51 +0000814 my $IgnoreErrors = shift;
Ted Kremenekdab11102008-04-02 04:43:42 +0000815 my $Cmd = $Args->[0];
Ted Kremenek6195c372008-06-02 21:52:47 +0000816 my $CCAnalyzer = shift;
Ted Kremenekdab11102008-04-02 04:43:42 +0000817
Ted Kremenek3301cb12008-06-30 18:18:16 +0000818 # Get only the part of the command after the last '/'.
819 if ($Cmd =~ /\/([^\/]+)$/) {
820 $Cmd = $1;
821 }
822
Ted Kremenek92548fe2008-11-19 01:46:21 +0000823 if ($Cmd =~ /(.*\/?gcc[^\/]*$)/ or
824 $Cmd =~ /(.*\/?cc[^\/]*$)/ or
825 $Cmd =~ /(.*\/?llvm-gcc[^\/]*$)/ or
826 $Cmd =~ /(.*\/?ccc-analyzer[^\/]*$)/) {
827
828 if (!($Cmd =~ /ccc-analyzer/) and !defined $ENV{"CCC_CC"}) {
829 $ENV{"CCC_CC"} = $1;
830 }
831
Ted Kremenekdab11102008-04-02 04:43:42 +0000832 shift @$Args;
Ted Kremenek6195c372008-06-02 21:52:47 +0000833 unshift @$Args, $CCAnalyzer;
Ted Kremenekdab11102008-04-02 04:43:42 +0000834 }
Ted Kremenek7442ca62008-04-02 16:04:51 +0000835 elsif ($IgnoreErrors) {
836 if ($Cmd eq "make" or $Cmd eq "gmake") {
Ted Kremenek6b628982008-04-30 23:47:12 +0000837 AddIfNotPresent($Args,"-k");
Ted Kremenek8912b542008-05-13 21:28:02 +0000838 AddIfNotPresent($Args,"-i");
Ted Kremenek7442ca62008-04-02 16:04:51 +0000839 }
840 elsif ($Cmd eq "xcodebuild") {
Ted Kremenek6b628982008-04-30 23:47:12 +0000841 AddIfNotPresent($Args,"-PBXBuildsContinueAfterErrors=YES");
Ted Kremenek7442ca62008-04-02 16:04:51 +0000842 }
Ted Kremenek6b628982008-04-30 23:47:12 +0000843 }
844
Ted Kremenek6b628982008-04-30 23:47:12 +0000845 if ($Cmd eq "xcodebuild") {
Ted Kremenekcfd4c7b2008-05-23 22:18:16 +0000846 # Disable distributed builds for xcodebuild.
Ted Kremenek6b628982008-04-30 23:47:12 +0000847 AddIfNotPresent($Args,"-nodistribute");
Ted Kremenekcfd4c7b2008-05-23 22:18:16 +0000848
849 # Disable PCH files until clang supports them.
850 AddIfNotPresent($Args,"GCC_PRECOMPILE_PREFIX_HEADER=NO");
Ted Kremenek915e9722008-05-27 23:18:07 +0000851
852 # When 'CC' is set, xcodebuild uses it to do all linking, even if we are
853 # linking C++ object files. Set 'LDPLUSPLUS' so that xcodebuild uses 'g++'
854 # when linking such files.
Ted Kremenek95aa1052008-09-04 17:52:41 +0000855 die if (!defined $CXX);
856 my $LDPLUSPLUS = `which $CXX`;
Ted Kremenek915e9722008-05-27 23:18:07 +0000857 $LDPLUSPLUS =~ s/\015?\012//; # strip newlines
858 $ENV{'LDPLUSPLUS'} = $LDPLUSPLUS;
Ted Kremenek6b628982008-04-30 23:47:12 +0000859 }
Ted Kremenekdab11102008-04-02 04:43:42 +0000860
Ted Kremenek5a4ddaf2008-08-25 20:10:45 +0000861 return (system(@$Args) >> 8);
Ted Kremenekdab11102008-04-02 04:43:42 +0000862}
863
Ted Kremenekdab11102008-04-02 04:43:42 +0000864##----------------------------------------------------------------------------##
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000865# DisplayHelp - Utility function to display all help options.
866##----------------------------------------------------------------------------##
867
Sam Bishopa0e22662008-04-02 03:35:43 +0000868sub DisplayHelp {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000869
Ted Kremenek5744dc22008-04-02 18:03:36 +0000870print <<ENDTEXT;
Sam Bishopa0e22662008-04-02 03:35:43 +0000871USAGE: $Prog [options] <build command> [build options]
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000872
Ted Kremenekf4cdf412008-05-23 18:17:05 +0000873ENDTEXT
874
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000875 if (defined $BuildName) {
Ted Kremenekf4cdf412008-05-23 18:17:05 +0000876 print "ANALYZER BUILD: $BuildName ($BuildDate)\n\n";
877 }
878
879print <<ENDTEXT;
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000880OPTIONS:
881
Ted Kremeneke15fa272008-10-13 21:46:42 +0000882 -analyze-headers - Also analyze functions in #included files.
883
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000884 -o - Target directory for HTML report files. Subdirectories
Sam Bishopa0e22662008-04-02 03:35:43 +0000885 will be created as needed to represent separate "runs" of
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000886 the analyzer. If this option is not specified, a directory
Ted Kremenekffda0b42008-10-31 05:48:42 +0000887 is created in /tmp (TMPDIR on Mac OS X) to store the reports.
Ted Kremenekdb4f5f22008-11-04 00:02:53 +0000888
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000889 -h - Display this message.
890 --help
Ted Kremenek1262fc42008-05-14 20:10:33 +0000891
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000892 -k - Add a "keep on going" option to the specified build command.
893 --keep-going This option currently supports make and xcodebuild.
Ted Kremenekf02e8db2008-04-02 16:41:25 +0000894 This is a convenience option; one can specify this
895 behavior directly using build options.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000896
Ted Kremenek7cba1122008-09-22 01:35:58 +0000897 --html-title [title] - Specify the title used on generated HTML pages.
898 --html-title=[title] If not specified, a default title will be used.
899
Ted Kremenekdb4f5f22008-11-04 00:02:53 +0000900 -plist - By default the output of scan-build is a set of HTML files.
901 This option outputs the results as a set of .plist files.
902
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000903 --status-bugs - By default, the exit status of $Prog is the same as the
904 executed build command. Specifying this option causes the
905 exit status of $Prog to be 1 if it found potential bugs
906 and 0 otherwise.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000907
Ted Kremenek386c6932008-09-03 17:59:35 +0000908 --use-cc [compiler path] - By default, $Prog uses 'gcc' to compile and link
909 --use-cc=[compiler path] your C and Objective-C code. Use this option
910 to specify an alternate compiler.
911
912 --use-c++ [compiler path] - By default, $Prog uses 'g++' to compile and link
913 --use-c++=[compiler path] your C++ and Objective-C++ code. Use this option
914 to specify an alternate compiler.
Ted Kremenekf17ef3c2008-08-21 21:47:09 +0000915
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000916 -v - Verbose output from $Prog and the analyzer.
Ted Kremenek386c6932008-09-03 17:59:35 +0000917 A second and third '-v' increases verbosity.
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000918
919 -V - View analysis results in a web browser when the build
920 --view completes.
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000921
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +0000922ADVANCED OPTIONS:
923
Ted Kremenek9f4ecb32009-02-20 21:49:22 +0000924 -constraints [model] - Specify the contraint engine used by the analyzer.
925 By default the 'range' model is used. Specifying
926 'basic' uses a simpler, less powerful constraint model
Ted Kremenekd4c76842009-02-21 04:46:41 +0000927 used by checker-0.160 and earlier.
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +0000928
929 -store [model] - Specify the store model used by the analyzer. By default,
930 the 'basic' store model is used. 'region' specifies a field-
931 sensitive store model. Be warned that the 'region' model
932 is still in very early testing phase and may often crash.
Ted Kremenekb7770c02008-07-15 17:06:13 +0000933
Ted Kremenek386c6932008-09-03 17:59:35 +0000934AVAILABLE ANALYSES (multiple analyses may be specified):
Ted Kremenekd52e4252008-08-25 20:45:07 +0000935
936ENDTEXT
Ted Kremenekb7770c02008-07-15 17:06:13 +0000937
938 foreach my $Analysis (sort keys %AvailableAnalyses) {
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000939 if (defined $AnalysesDefaultEnabled{$Analysis}) {
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000940 print " (+)";
Ted Kremenekb7770c02008-07-15 17:06:13 +0000941 }
942 else {
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000943 print " ";
Ted Kremenekb7770c02008-07-15 17:06:13 +0000944 }
945
946 print " $Analysis $AvailableAnalyses{$Analysis}\n";
947 }
948
949print <<ENDTEXT
950
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000951 NOTE: "(+)" indicates that an analysis is enabled by default unless one
952 or more analysis options are specified
Ted Kremenekb7770c02008-07-15 17:06:13 +0000953
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000954BUILD OPTIONS
955
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000956 You can specify any build option acceptable to the build command.
Ted Kremenek39eefde2008-04-02 16:47:27 +0000957
Ted Kremenek5744dc22008-04-02 18:03:36 +0000958EXAMPLE
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000959
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000960 $Prog -o /tmp/myhtmldir make -j4
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000961
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000962 The above example causes analysis reports to be deposited into
963 a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option.
964 A different subdirectory is created each time $Prog analyzes a project.
965 The analyzer should support most parallel builds, but not distributed builds.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000966
967ENDTEXT
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000968}
969
970##----------------------------------------------------------------------------##
Ted Kremenek7cba1122008-09-22 01:35:58 +0000971# HtmlEscape - HTML entity encode characters that are special in HTML
972##----------------------------------------------------------------------------##
973
974sub HtmlEscape {
975 # copy argument to new variable so we don't clobber the original
976 my $arg = shift || '';
977 my $tmp = $arg;
Ted Kremenek87f8de72008-11-03 07:44:16 +0000978 $tmp =~ s/&/&amp;/g;
979 $tmp =~ s/</&lt;/g;
980 $tmp =~ s/>/&gt;/g;
Ted Kremenek7cba1122008-09-22 01:35:58 +0000981 return $tmp;
982}
983
984##----------------------------------------------------------------------------##
985# ShellEscape - backslash escape characters that are special to the shell
986##----------------------------------------------------------------------------##
987
988sub ShellEscape {
989 # copy argument to new variable so we don't clobber the original
990 my $arg = shift || '';
Ted Kremenek87f8de72008-11-03 07:44:16 +0000991 if ($arg =~ /["\s]/) { return "'" . $arg . "'"; }
992 return $arg;
Ted Kremenek7cba1122008-09-22 01:35:58 +0000993}
994
995##----------------------------------------------------------------------------##
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000996# Process command-line arguments.
997##----------------------------------------------------------------------------##
998
Ted Kremeneke15fa272008-10-13 21:46:42 +0000999my $AnalyzeHeaders = 0;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001000my $HtmlDir; # Parent directory to store HTML files.
1001my $IgnoreErrors = 0; # Ignore build errors.
Ted Kremenek7f8a3252008-04-02 18:42:49 +00001002my $ViewResults = 0; # View results when the build terminates.
Ted Kremenek363dc3f2008-07-15 22:03:09 +00001003my $ExitStatusFoundBugs = 0; # Exit status reflects whether bugs were found
Ted Kremenekb7770c02008-07-15 17:06:13 +00001004my @AnalysesToRun;
Zhongxing Xu07c37672008-10-27 14:26:32 +00001005my $StoreModel;
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +00001006my $ConstraintsModel;
Ted Kremenekdb4f5f22008-11-04 00:02:53 +00001007my $OutputFormat;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001008
1009if (!@ARGV) {
1010 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +00001011 exit 1;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001012}
1013
1014while (@ARGV) {
1015
1016 # Scan for options we recognize.
1017
1018 my $arg = $ARGV[0];
1019
Sam Bishop2f2418e2008-04-03 14:29:47 +00001020 if ($arg eq "-h" or $arg eq "--help") {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001021 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +00001022 exit 0;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001023 }
1024
Ted Kremeneke15fa272008-10-13 21:46:42 +00001025 if ($arg eq '-analyze-headers') {
1026 shift @ARGV;
1027 $AnalyzeHeaders = 1;
1028 next;
1029 }
1030
Ted Kremenekfc1d3402008-08-04 18:15:26 +00001031 if (defined $AvailableAnalyses{$arg}) {
Ted Kremenek1262fc42008-05-14 20:10:33 +00001032 shift @ARGV;
Ted Kremenekb7770c02008-07-15 17:06:13 +00001033 push @AnalysesToRun, $arg;
Ted Kremenek1262fc42008-05-14 20:10:33 +00001034 next;
1035 }
1036
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001037 if ($arg eq "-o") {
1038 shift @ARGV;
1039
1040 if (!@ARGV) {
Ted Kremenek23cfca32008-06-16 22:40:14 +00001041 DieDiag("'-o' option requires a target directory name.\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001042 }
1043
Ted Kremenekdb51a552009-03-11 18:20:33 +00001044 # Construct an absolute path. Uses the current working directory
1045 # as a base if the original path was not absolute.
1046 $HtmlDir = abs_path(shift @ARGV);
1047
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001048 next;
1049 }
Ted Kremenek7cba1122008-09-22 01:35:58 +00001050
1051 if ($arg =~ /^--html-title(=(.+))?$/) {
1052 shift @ARGV;
1053
1054 if ($2 eq '') {
1055 if (!@ARGV) {
1056 DieDiag("'--html-title' option requires a string.\n");
1057 }
1058
1059 $HtmlTitle = shift @ARGV;
1060 } else {
1061 $HtmlTitle = $2;
1062 }
1063
1064 next;
1065 }
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001066
Ted Kremenek2b74ab62008-04-01 21:22:03 +00001067 if ($arg eq "-k" or $arg eq "--keep-going") {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001068 shift @ARGV;
1069 $IgnoreErrors = 1;
1070 next;
1071 }
1072
Ted Kremenekf17ef3c2008-08-21 21:47:09 +00001073 if ($arg =~ /^--use-cc(=(.+))?$/) {
1074 shift @ARGV;
1075 my $cc;
1076
1077 if ($2 eq "") {
1078 if (!@ARGV) {
1079 DieDiag("'--use-cc' option requires a compiler executable name.\n");
1080 }
1081 $cc = shift @ARGV;
1082 }
1083 else {
1084 $cc = $2;
1085 }
1086
1087 $ENV{"CCC_CC"} = $cc;
1088 next;
1089 }
1090
Ted Kremenek7cba1122008-09-22 01:35:58 +00001091 if ($arg =~ /^--use-c\+\+(=(.+))?$/) {
Ted Kremenek386c6932008-09-03 17:59:35 +00001092 shift @ARGV;
1093
1094 if ($2 eq "") {
1095 if (!@ARGV) {
1096 DieDiag("'--use-c++' option requires a compiler executable name.\n");
1097 }
1098 $CXX = shift @ARGV;
1099 }
1100 else {
1101 $CXX = $2;
1102 }
1103 next;
1104 }
1105
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001106 if ($arg eq "-v") {
1107 shift @ARGV;
1108 $Verbose++;
1109 next;
1110 }
1111
Ted Kremenek7f8a3252008-04-02 18:42:49 +00001112 if ($arg eq "-V" or $arg eq "--view") {
1113 shift @ARGV;
1114 $ViewResults = 1;
1115 next;
1116 }
1117
Ted Kremenek363dc3f2008-07-15 22:03:09 +00001118 if ($arg eq "--status-bugs") {
1119 shift @ARGV;
1120 $ExitStatusFoundBugs = 1;
1121 next;
1122 }
Zhongxing Xu07c37672008-10-27 14:26:32 +00001123
1124 if ($arg eq "-store") {
1125 shift @ARGV;
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +00001126 $StoreModel = shift @ARGV;
1127 next;
1128 }
1129
1130 if ($arg eq "-constraints") {
1131 shift @ARGV;
1132 $ConstraintsModel = shift @ARGV;
Zhongxing Xu07c37672008-10-27 14:26:32 +00001133 next;
1134 }
Ted Kremenek363dc3f2008-07-15 22:03:09 +00001135
Ted Kremenekdb4f5f22008-11-04 00:02:53 +00001136 if ($arg eq "-plist") {
1137 shift @ARGV;
1138 $OutputFormat = "plist";
1139 next;
1140 }
1141
Ted Kremenek23cfca32008-06-16 22:40:14 +00001142 DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/);
Ted Kremenek0062ad42008-04-02 16:35:01 +00001143
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001144 last;
1145}
1146
1147if (!@ARGV) {
Ted Kremenek23cfca32008-06-16 22:40:14 +00001148 Diag("No build command specified.\n\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001149 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +00001150 exit 1;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001151}
1152
Ted Kremenek7cba1122008-09-22 01:35:58 +00001153$CmdArgs = HtmlEscape(join(' ', map(ShellEscape($_), @ARGV)));
1154$HtmlTitle = "${CurrentDirSuffix} - scan-build results"
1155 unless (defined($HtmlTitle));
Ted Kremenek386c6932008-09-03 17:59:35 +00001156
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001157# Determine the output directory for the HTML reports.
Ted Kremenek684bb092008-04-18 15:18:20 +00001158my $BaseDir = $HtmlDir;
Sam Bishopa0e22662008-04-02 03:35:43 +00001159$HtmlDir = GetHTMLRunDir($HtmlDir);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001160
1161# Set the appropriate environment variables.
Sam Bishopa0e22662008-04-02 03:35:43 +00001162SetHtmlEnv(\@ARGV, $HtmlDir);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001163
Ted Kremenek91ea79d2009-03-24 05:30:14 +00001164my $Cmd = Cwd::realpath("$RealBin/libexec/ccc-analyzer");
Ted Kremenekce87b922009-02-25 22:54:02 +00001165if (!defined $Cmd || ! -x $Cmd) {
1166 $Cmd = Cwd::realpath("$RealBin/ccc-analyzer");
Ted Kremenek6b896362009-02-27 06:17:05 +00001167 DieDiag("Executable 'ccc-analyzer' does not exist at '$Cmd'\n") if(! -x $Cmd);
Ted Kremenekce87b922009-02-25 22:54:02 +00001168}
Ted Kremenekf22eacb2008-04-18 22:00:56 +00001169
Ted Kremenek2d62ab12009-02-23 23:01:06 +00001170if (!defined $ClangSB || ! -x $ClangSB) {
Ted Kremenek91ea79d2009-03-24 05:30:14 +00001171 Diag("'clang-cc' executable not found in '$RealBin/libexec'.\n");
Ted Kremenek318e6a62009-03-24 04:29:13 +00001172 Diag("Using 'clang-cc' from path.\n");
Ted Kremenekf22eacb2008-04-18 22:00:56 +00001173}
Ted Kremenek0b6c1532008-04-08 20:22:12 +00001174
Ted Kremenek95aa1052008-09-04 17:52:41 +00001175if (defined $CXX) {
1176 $ENV{'CXX'} = $CXX;
1177}
1178else {
1179 $CXX = 'g++'; # This variable is used by other parts of scan-build
1180 # that need to know a default C++ compiler to fall back to.
1181}
1182
Ted Kremenek4f4b17d2008-04-03 20:08:18 +00001183$ENV{'CC'} = $Cmd;
Ted Kremenekf22eacb2008-04-18 22:00:56 +00001184$ENV{'CLANG'} = $Clang;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001185
1186if ($Verbose >= 2) {
1187 $ENV{'CCC_ANALYZER_VERBOSE'} = 1;
1188}
1189
Ted Kremeneka9525c92008-05-12 22:07:14 +00001190if ($Verbose >= 3) {
1191 $ENV{'CCC_ANALYZER_LOG'} = 1;
1192}
1193
Ted Kremenek90125992008-07-15 23:41:32 +00001194if (scalar(@AnalysesToRun) == 0) {
1195 foreach my $key (keys %AnalysesDefaultEnabled) {
1196 push @AnalysesToRun,$key;
1197 }
Ted Kremenek01006782008-07-02 23:16:10 +00001198}
Ted Kremenek1262fc42008-05-14 20:10:33 +00001199
Ted Kremeneke15fa272008-10-13 21:46:42 +00001200if ($AnalyzeHeaders) {
1201 push @AnalysesToRun,"-analyzer-opt-analyze-headers";
1202}
1203
Ted Kremenek90125992008-07-15 23:41:32 +00001204$ENV{'CCC_ANALYZER_ANALYSIS'} = join ' ',@AnalysesToRun;
1205
Zhongxing Xu3cab2b12008-11-02 10:58:16 +00001206if (defined $StoreModel) {
Zhongxing Xu07c37672008-10-27 14:26:32 +00001207 $ENV{'CCC_ANALYZER_STORE_MODEL'} = $StoreModel;
1208}
1209
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +00001210if (defined $ConstraintsModel) {
1211 $ENV{'CCC_ANALYZER_CONSTRAINTS_MODEL'} = $ConstraintsModel;
1212}
1213
Ted Kremenekdb4f5f22008-11-04 00:02:53 +00001214if (defined $OutputFormat) {
1215 $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'} = $OutputFormat;
1216}
1217
1218
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001219# Run the build.
Ted Kremenek5656a982008-07-15 17:09:28 +00001220my $ExitStatus = RunBuildCommand(\@ARGV, $IgnoreErrors, $Cmd);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001221
Ted Kremenek655aba72008-11-04 00:22:12 +00001222if (defined $OutputFormat and $OutputFormat eq "plist") {
Ted Kremenek50534dc2008-09-22 17:38:23 +00001223 Diag "Analysis run complete.\n";
Ted Kremenekdb4f5f22008-11-04 00:02:53 +00001224 Diag "Analysis results (plist files) deposited in '$HtmlDir'\n";
Ted Kremenek7f8a3252008-04-02 18:42:49 +00001225}
Ted Kremenekdb4f5f22008-11-04 00:02:53 +00001226else {
1227 # Postprocess the HTML directory.
1228 my $NumBugs = Postprocess($HtmlDir, $BaseDir);
Ted Kremenek5656a982008-07-15 17:09:28 +00001229
Ted Kremenekdb4f5f22008-11-04 00:02:53 +00001230 if ($ViewResults and -r "$HtmlDir/index.html") {
1231 Diag "Analysis run complete.\n";
1232 Diag "Viewing analysis results in '$HtmlDir' using scan-view.\n";
1233 my $ScanView = Cwd::realpath("$RealBin/scan-view");
1234 if (! -x $ScanView) { $ScanView = "scan-view"; }
1235 exec $ScanView, "$HtmlDir";
1236 }
1237
1238 if ($ExitStatusFoundBugs) {
1239 exit 1 if ($NumBugs > 0);
1240 exit 0;
1241 }
Ted Kremenek363dc3f2008-07-15 22:03:09 +00001242}
1243
Ted Kremenek5656a982008-07-15 17:09:28 +00001244exit $ExitStatus;
1245