Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1 | #!/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 | |
| 15 | use strict; |
| 16 | use warnings; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 17 | use FindBin qw($RealBin); |
Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 18 | use Digest::MD5; |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 19 | use File::Basename; |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 20 | use Term::ANSIColor; |
| 21 | use Term::ANSIColor qw(:constants); |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 22 | use Cwd; |
| 23 | use Sys::Hostname; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 24 | |
| 25 | my $Verbose = 0; # Verbose output from this script. |
| 26 | my $Prog = "scan-build"; |
Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 27 | my $BuildName; |
| 28 | my $BuildDate; |
Ted Kremenek | 95aa105 | 2008-09-04 17:52:41 +0000 | [diff] [blame] | 29 | my $CXX; # Leave undefined initially. |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 30 | |
Ted Kremenek | 0e68938 | 2008-09-11 18:17:51 +0000 | [diff] [blame] | 31 | my $TERM = $ENV{'TERM'}; |
| 32 | my $UseColor = (defined $TERM and $TERM eq 'xterm-color' and -t STDOUT |
| 33 | and defined $ENV{'SCAN_BUILD_COLOR'}); |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 34 | |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 35 | my $UserName = HtmlEscape(getpwuid($<) || 'unknown'); |
| 36 | my $HostName = HtmlEscape(hostname() || 'unknown'); |
| 37 | my $CurrentDir = HtmlEscape(getcwd()); |
| 38 | my $CurrentDirSuffix = basename($CurrentDir); |
| 39 | |
| 40 | my $CmdArgs; |
| 41 | |
| 42 | my $HtmlTitle; |
| 43 | |
| 44 | my $Date = localtime(); |
| 45 | |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 46 | ##----------------------------------------------------------------------------## |
| 47 | # Diagnostics |
| 48 | ##----------------------------------------------------------------------------## |
| 49 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 50 | sub Diag { |
| 51 | if ($UseColor) { |
| 52 | print BOLD, MAGENTA "$Prog: @_"; |
| 53 | print RESET; |
| 54 | } |
| 55 | else { |
| 56 | print "$Prog: @_"; |
| 57 | } |
| 58 | } |
| 59 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 60 | sub DiagCrashes { |
| 61 | my $Dir = shift; |
| 62 | Diag ("The analyzer crashed on some source files.\n"); |
Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 63 | Diag ("Preprocessed versions of crashed files were deposited in '$Dir/crashes'.\n"); |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 64 | Diag ("Please consider submitting a bug report using these files:\n"); |
| 65 | Diag (" http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs\n") |
| 66 | } |
| 67 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 68 | sub 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 Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 80 | ##----------------------------------------------------------------------------## |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 81 | # Some initial preprocessing of Clang options. |
| 82 | ##----------------------------------------------------------------------------## |
| 83 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 84 | my $ClangSB = Cwd::realpath("$RealBin/clang"); |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 85 | my $Clang = $ClangSB; |
| 86 | |
| 87 | if (! -x $ClangSB) { |
| 88 | $Clang = "clang"; |
| 89 | } |
| 90 | |
| 91 | my %AvailableAnalyses; |
| 92 | |
| 93 | # Query clang for analysis options. |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 94 | open(PIPE, "-|", $Clang, "--help") or |
Ted Kremenek | 445fa77 | 2008-10-10 00:17:08 +0000 | [diff] [blame] | 95 | DieDiag("Cannot execute '$Clang'\n"); |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 96 | |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 97 | my $FoundAnalysis = 0; |
| 98 | |
| 99 | while(<PIPE>) { |
| 100 | if ($FoundAnalysis == 0) { |
Ted Kremenek | ce1448b | 2008-10-24 15:11:58 +0000 | [diff] [blame] | 101 | if (/SCA Checks\/Analyses/) { |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 102 | $FoundAnalysis = 1; |
| 103 | } |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 104 | |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 105 | next; |
| 106 | } |
| 107 | |
| 108 | if (/^\s\s\s\s([^\s]+)\s(.+)$/) { |
| 109 | next if ($1 =~ /-dump/ or $1 =~ /-view/ |
| 110 | or $1 =~ /-checker-simple/ or $1 =~ /-warn-uninit/); |
| 111 | |
| 112 | $AvailableAnalyses{$1} = $2; |
| 113 | next; |
| 114 | } |
| 115 | |
| 116 | last; |
| 117 | } |
| 118 | |
| 119 | close (PIPE); |
| 120 | |
| 121 | my %AnalysesDefaultEnabled = ( |
| 122 | '-warn-dead-stores' => 1, |
| 123 | '-checker-cfref' => 1, |
Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 124 | '-warn-objc-methodsigs' => 1, |
Ted Kremenek | bde3a05 | 2008-07-25 20:35:01 +0000 | [diff] [blame] | 125 | '-warn-objc-missing-dealloc' => 1, |
Ted Kremenek | 5d44349 | 2008-09-18 06:34:16 +0000 | [diff] [blame] | 126 | '-warn-objc-unused-ivars' => 1, |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 127 | ); |
| 128 | |
| 129 | ##----------------------------------------------------------------------------## |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 130 | # GetHTMLRunDir - Construct an HTML directory name for the current sub-run. |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 131 | ##----------------------------------------------------------------------------## |
| 132 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 133 | sub GetHTMLRunDir { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 134 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 135 | die "Not enough arguments." if (@_ == 0); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 136 | my $Dir = shift @_; |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 137 | |
| 138 | my $TmpMode = 0; |
| 139 | if (!defined $Dir) { |
Ted Kremenek | ffda0b4 | 2008-10-31 05:48:42 +0000 | [diff] [blame] | 140 | if (`uname` =~ /Darwin/) { |
| 141 | $Dir = $ENV{'TMPDIR'}; |
| 142 | if (!defined $Dir) { $Dir = "/tmp"; } |
| 143 | } |
| 144 | else { |
| 145 | $Dir = "/tmp"; |
| 146 | } |
| 147 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 148 | $TmpMode = 1; |
| 149 | } |
| 150 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 151 | # Get current date and time. |
| 152 | |
| 153 | my @CurrentTime = localtime(); |
| 154 | |
| 155 | my $year = $CurrentTime[5] + 1900; |
| 156 | my $day = $CurrentTime[3]; |
| 157 | my $month = $CurrentTime[4] + 1; |
| 158 | |
Ted Kremenek | 9d7405f | 2008-05-14 17:23:56 +0000 | [diff] [blame] | 159 | my $DateString = sprintf("%d-%02d-%02d", $year, $month, $day); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 160 | |
| 161 | # Determine the run number. |
| 162 | |
| 163 | my $RunNumber; |
| 164 | |
| 165 | if (-d $Dir) { |
| 166 | |
| 167 | if (! -r $Dir) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 168 | DieDiag("directory '$Dir' exists but is not readable.\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | # Iterate over all files in the specified directory. |
| 172 | |
| 173 | my $max = 0; |
| 174 | |
| 175 | opendir(DIR, $Dir); |
Ted Kremenek | 29da6c5 | 2008-08-07 17:57:34 +0000 | [diff] [blame] | 176 | my @FILES = grep { -d "$Dir/$_" } readdir(DIR); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 177 | closedir(DIR); |
| 178 | |
| 179 | foreach my $f (@FILES) { |
| 180 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 181 | # Strip the prefix '$Prog-' if we are dumping files to /tmp. |
| 182 | if ($TmpMode) { |
| 183 | next if (!($f =~ /^$Prog-(.+)/)); |
| 184 | $f = $1; |
| 185 | } |
| 186 | |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 187 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 188 | my @x = split/-/, $f; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 189 | next if (scalar(@x) != 4); |
| 190 | next if ($x[0] != $year); |
| 191 | next if ($x[1] != $month); |
| 192 | next if ($x[2] != $day); |
| 193 | |
| 194 | if ($x[3] > $max) { |
| 195 | $max = $x[3]; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | $RunNumber = $max + 1; |
| 200 | } |
| 201 | else { |
| 202 | |
| 203 | if (-x $Dir) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 204 | DieDiag("'$Dir' exists but is not a directory.\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 205 | } |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 206 | |
| 207 | if ($TmpMode) { |
Ted Kremenek | 445fa77 | 2008-10-10 00:17:08 +0000 | [diff] [blame] | 208 | DieDiag("The directory '/tmp' does not exist or cannot be accessed.\n"); |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 211 | # $Dir does not exist. It will be automatically created by the |
| 212 | # clang driver. Set the run number to 1. |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 213 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 214 | $RunNumber = 1; |
| 215 | } |
| 216 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 217 | die "RunNumber must be defined!" if (!defined $RunNumber); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 218 | |
| 219 | # Append the run number. |
Ted Kremenek | fc0898a | 2008-09-04 23:56:36 +0000 | [diff] [blame] | 220 | my $NewDir; |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 221 | if ($TmpMode) { |
Ted Kremenek | fc0898a | 2008-09-04 23:56:36 +0000 | [diff] [blame] | 222 | $NewDir = "$Dir/$Prog-$DateString-$RunNumber"; |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 223 | } |
| 224 | else { |
Ted Kremenek | fc0898a | 2008-09-04 23:56:36 +0000 | [diff] [blame] | 225 | $NewDir = "$Dir/$DateString-$RunNumber"; |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 226 | } |
Ted Kremenek | fc0898a | 2008-09-04 23:56:36 +0000 | [diff] [blame] | 227 | system 'mkdir','-p',$NewDir; |
| 228 | return $NewDir; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 231 | sub SetHtmlEnv { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 232 | |
| 233 | die "Wrong number of arguments." if (scalar(@_) != 2); |
| 234 | |
| 235 | my $Args = shift; |
| 236 | my $Dir = shift; |
| 237 | |
| 238 | die "No build command." if (scalar(@$Args) == 0); |
| 239 | |
| 240 | my $Cmd = $$Args[0]; |
| 241 | |
| 242 | if ($Cmd =~ /configure/) { |
| 243 | return; |
| 244 | } |
| 245 | |
| 246 | if ($Verbose) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 247 | Diag("Emitting reports for this run to '$Dir'.\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | $ENV{'CCC_ANALYZER_HTML'} = $Dir; |
| 251 | } |
| 252 | |
| 253 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 254 | # ComputeDigest - Compute a digest of the specified file. |
| 255 | ##----------------------------------------------------------------------------## |
| 256 | |
| 257 | sub ComputeDigest { |
| 258 | my $FName = shift; |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 259 | DieDiag("Cannot read $FName to compute Digest.\n") if (! -r $FName); |
Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 260 | |
| 261 | # Use Digest::MD5. We don't have to be cryptographically secure. We're |
Ted Kremenek | 7ea02e6 | 2008-04-19 18:07:44 +0000 | [diff] [blame] | 262 | # just looking for duplicate files that come from a non-malicious source. |
| 263 | # We use Digest::MD5 because it is a standard Perl module that should |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 264 | # come bundled on most systems. |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 265 | open(FILE, $FName) or DieDiag("Cannot open $FName when computing Digest.\n"); |
Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 266 | binmode FILE; |
| 267 | my $Result = Digest::MD5->new->addfile(*FILE)->hexdigest; |
| 268 | close(FILE); |
| 269 | |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 270 | # Return the digest. |
Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 271 | return $Result; |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 275 | # UpdatePrefix - Compute the common prefix of files. |
| 276 | ##----------------------------------------------------------------------------## |
| 277 | |
| 278 | my $Prefix; |
| 279 | |
| 280 | sub UpdatePrefix { |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 281 | my $x = shift; |
| 282 | my $y = basename($x); |
| 283 | $x =~ s/\Q$y\E$//; |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 284 | |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 285 | if (!defined $Prefix) { |
| 286 | $Prefix = $x; |
| 287 | return; |
| 288 | } |
| 289 | |
Ted Kremenek | 20b2bae | 2008-09-11 21:15:10 +0000 | [diff] [blame] | 290 | chop $Prefix while (!($x =~ /^\Q$Prefix/)); |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | sub GetPrefix { |
| 294 | return $Prefix; |
| 295 | } |
| 296 | |
| 297 | ##----------------------------------------------------------------------------## |
| 298 | # UpdateInFilePath - Update the path in the report file. |
| 299 | ##----------------------------------------------------------------------------## |
| 300 | |
| 301 | sub UpdateInFilePath { |
| 302 | my $fname = shift; |
| 303 | my $regex = shift; |
| 304 | my $newtext = shift; |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 305 | |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 306 | open (RIN, $fname) or die "cannot open $fname"; |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 307 | open (ROUT, ">", "$fname.tmp") or die "cannot open $fname.tmp"; |
| 308 | |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 309 | while (<RIN>) { |
| 310 | s/$regex/$newtext/; |
| 311 | print ROUT $_; |
| 312 | } |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 313 | |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 314 | close (ROUT); |
| 315 | close (RIN); |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 316 | system("mv", "$fname.tmp", $fname); |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 320 | # ScanFile - Scan a report file for various identifying attributes. |
| 321 | ##----------------------------------------------------------------------------## |
| 322 | |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 323 | # Sometimes a source file is scanned more than once, and thus produces |
| 324 | # multiple error reports. We use a cache to solve this problem. |
| 325 | |
| 326 | my %AlreadyScanned; |
| 327 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 328 | sub ScanFile { |
| 329 | |
| 330 | my $Index = shift; |
| 331 | my $Dir = shift; |
| 332 | my $FName = shift; |
| 333 | |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 334 | # Compute a digest for the report file. Determine if we have already |
| 335 | # scanned a file that looks just like it. |
| 336 | |
| 337 | my $digest = ComputeDigest("$Dir/$FName"); |
| 338 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 339 | if (defined $AlreadyScanned{$digest}) { |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 340 | # Redundant file. Remove it. |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 341 | system ("rm", "-f", "$Dir/$FName"); |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 342 | return; |
| 343 | } |
| 344 | |
| 345 | $AlreadyScanned{$digest} = 1; |
| 346 | |
Ted Kremenek | 809709f | 2008-04-18 16:58:34 +0000 | [diff] [blame] | 347 | # At this point the report file is not world readable. Make it happen. |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 348 | system ("chmod", "644", "$Dir/$FName"); |
Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 349 | |
| 350 | # Scan the report file for tags. |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 351 | open(IN, "$Dir/$FName") or DieDiag("Cannot open '$Dir/$FName'\n"); |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 352 | |
| 353 | my $BugDesc = ""; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 354 | my $BugFile = ""; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 355 | my $BugCategory; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 356 | my $BugPathLength = 1; |
| 357 | my $BugLine = 0; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 358 | my $found = 0; |
| 359 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 360 | while (<IN>) { |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 361 | |
| 362 | last if ($found == 5); |
| 363 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 364 | if (/<!-- BUGDESC (.*) -->$/) { |
| 365 | $BugDesc = $1; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 366 | ++$found; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 367 | } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 368 | elsif (/<!-- BUGFILE (.*) -->$/) { |
Ted Kremenek | 990c2f4 | 2008-12-03 19:19:23 +0000 | [diff] [blame^] | 369 | $BugFile = abs_path($1); |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 370 | UpdatePrefix($BugFile); |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 371 | ++$found; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 372 | } |
| 373 | elsif (/<!-- BUGPATHLENGTH (.*) -->$/) { |
| 374 | $BugPathLength = $1; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 375 | ++$found; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 376 | } |
| 377 | elsif (/<!-- BUGLINE (.*) -->$/) { |
| 378 | $BugLine = $1; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 379 | ++$found; |
| 380 | } |
| 381 | elsif (/<!-- BUGCATEGORY (.*) -->$/) { |
| 382 | $BugCategory = $1; |
| 383 | ++$found; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 384 | } |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | close(IN); |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 388 | |
| 389 | if (!defined $BugCategory) { |
| 390 | $BugCategory = "Other"; |
| 391 | } |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 392 | |
Ted Kremenek | 8198311 | 2008-09-28 04:13:09 +0000 | [diff] [blame] | 393 | push @$Index,[ $FName, $BugCategory, $BugDesc, $BugFile, $BugLine, |
| 394 | $BugPathLength ]; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 398 | # CopyFiles - Copy resource files to target directory. |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 399 | ##----------------------------------------------------------------------------## |
| 400 | |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 401 | sub CopyFiles { |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 402 | |
| 403 | my $Dir = shift; |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 404 | |
| 405 | my $JS = Cwd::realpath("$RealBin/sorttable.js"); |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 406 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 407 | DieDiag("Cannot find 'sorttable.js'.\n") |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 408 | if (! -r $JS); |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 409 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 410 | system ("cp", $JS, "$Dir"); |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 411 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 412 | DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n") |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 413 | if (! -r "$Dir/sorttable.js"); |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 414 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 415 | my $CSS = Cwd::realpath("$RealBin/scanview.css"); |
| 416 | |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 417 | DieDiag("Cannot find 'scanview.css'.\n") |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 418 | if (! -r $CSS); |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 419 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 420 | system ("cp", $CSS, "$Dir"); |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 421 | |
| 422 | DieDiag("Could not copy 'scanview.css' to '$Dir'.\n") |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 423 | if (! -r $CSS); |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 427 | # Postprocess - Postprocess the results of an analysis scan. |
| 428 | ##----------------------------------------------------------------------------## |
| 429 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 430 | sub Postprocess { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 431 | |
| 432 | my $Dir = shift; |
Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 433 | my $BaseDir = shift; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 434 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 435 | die "No directory specified." if (!defined $Dir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 436 | |
| 437 | if (! -d $Dir) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 438 | Diag("No bugs found.\n"); |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 439 | return 0; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | opendir(DIR, $Dir); |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 443 | my $Crashes = 0; |
| 444 | my @files = grep { if ($_ eq "crashes") { $Crashes++; } |
| 445 | /^report-.*\.html$/; } readdir(DIR); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 446 | closedir(DIR); |
| 447 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 448 | if (scalar(@files) == 0 and $Crashes == 0) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 449 | Diag("Removing directory '$Dir' because it contains no reports.\n"); |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 450 | system ("rm", "-fR", $Dir); |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 451 | return 0; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 452 | } |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 453 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 454 | # Scan each report file and build an index. |
| 455 | my @Index; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 456 | foreach my $file (@files) { ScanFile(\@Index, $Dir, $file); } |
| 457 | |
Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 458 | # Scan the crashes directory and use the information in the .info files |
| 459 | # to update the common prefix directory. |
| 460 | if (-d "$Dir/crashes") { |
| 461 | opendir(DIR, "$Dir/crashes"); |
Ted Kremenek | 82a1253 | 2008-09-25 00:25:16 +0000 | [diff] [blame] | 462 | my @files = grep { /[.]info.txt$/; } readdir(DIR); |
Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 463 | closedir(DIR); |
| 464 | foreach my $file (@files) { |
| 465 | open IN, "$Dir/crashes/$file" or DieDiag("cannot open $file\n"); |
| 466 | my $Path = <IN>; |
| 467 | if (defined $Path) { UpdatePrefix($Path); } |
| 468 | close IN; |
| 469 | } |
| 470 | } |
| 471 | |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 472 | # Generate an index.html file. |
| 473 | my $FName = "$Dir/index.html"; |
| 474 | open(OUT, ">", $FName) or DieDiag("Cannot create file '$FName'\n"); |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 475 | |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 476 | # Print out the header. |
| 477 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 478 | print OUT <<ENDTEXT; |
| 479 | <html> |
| 480 | <head> |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 481 | <title>${HtmlTitle}</title> |
Ted Kremenek | f143545 | 2008-09-23 22:34:51 +0000 | [diff] [blame] | 482 | <link type="text/css" rel="stylesheet" href="scanview.css"/> |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 483 | <script src="sorttable.js"></script> |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 484 | <script language='javascript' type="text/javascript"> |
| 485 | function SetDisplay(RowClass, DisplayVal) |
| 486 | { |
| 487 | var Rows = document.getElementsByTagName("tr"); |
| 488 | for ( var i = 0 ; i < Rows.length; ++i ) { |
| 489 | if (Rows[i].className == RowClass) { |
| 490 | Rows[i].style.display = DisplayVal; |
| 491 | } |
| 492 | } |
| 493 | } |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 494 | |
Ted Kremenek | 2350a46 | 2008-10-28 19:56:52 +0000 | [diff] [blame] | 495 | function CopyCheckedStateToCheckButtons(SummaryCheckButton) { |
| 496 | var Inputs = document.getElementsByTagName("input"); |
| 497 | for ( var i = 0 ; i < Inputs.length; ++i ) { |
| 498 | if (Inputs[i].type == "checkbox") { |
| 499 | if(Inputs[i] != SummaryCheckButton) { |
| 500 | Inputs[i].checked = SummaryCheckButton.checked; |
| 501 | Inputs[i].onclick(); |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | |
Ted Kremenek | 999e120 | 2008-10-28 20:09:57 +0000 | [diff] [blame] | 507 | function returnObjById( id ) { |
| 508 | if (document.getElementById) |
| 509 | var returnVar = document.getElementById(id); |
| 510 | else if (document.all) |
| 511 | var returnVar = document.all[id]; |
| 512 | else if (document.layers) |
| 513 | var returnVar = document.layers[id]; |
| 514 | return returnVar; |
| 515 | } |
| 516 | |
| 517 | var NumUnchecked = 0; |
| 518 | |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 519 | function ToggleDisplay(CheckButton, ClassName) { |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 520 | if (CheckButton.checked) { |
| 521 | SetDisplay(ClassName, ""); |
Ted Kremenek | 999e120 | 2008-10-28 20:09:57 +0000 | [diff] [blame] | 522 | if (--NumUnchecked == 0) { |
| 523 | returnObjById("AllBugsCheck").checked = true; |
| 524 | } |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 525 | } |
| 526 | else { |
| 527 | SetDisplay(ClassName, "none"); |
Ted Kremenek | 999e120 | 2008-10-28 20:09:57 +0000 | [diff] [blame] | 528 | NumUnchecked++; |
| 529 | returnObjById("AllBugsCheck").checked = false; |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | </script> |
Ted Kremenek | 1d1abb1 | 2008-09-22 17:52:58 +0000 | [diff] [blame] | 533 | <!-- SUMMARYENDHEAD --> |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 534 | </head> |
| 535 | <body> |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 536 | <h1>${HtmlTitle}</h1> |
| 537 | |
| 538 | <table> |
| 539 | <tr><th>User:</th><td>${UserName}\@${HostName}</td></tr> |
| 540 | <tr><th>Working Directory:</th><td>${CurrentDir}</td></tr> |
| 541 | <tr><th>Command Line:</th><td>${CmdArgs}</td></tr> |
| 542 | <tr><th>Date:</th><td>${Date}</td></tr> |
| 543 | ENDTEXT |
| 544 | |
| 545 | print OUT "<tr><th>Version:</th><td>${BuildName} (${BuildDate})</td></tr>\n" |
| 546 | if (defined($BuildName) && defined($BuildDate)); |
| 547 | |
| 548 | print OUT <<ENDTEXT; |
| 549 | </table> |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 550 | ENDTEXT |
| 551 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 552 | if (scalar(@files)) { |
| 553 | # Print out the summary table. |
| 554 | my %Totals; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 555 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 556 | for my $row ( @Index ) { |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 557 | my $bug_type = ($row->[2]); |
| 558 | my $bug_category = ($row->[1]); |
| 559 | my $key = "$bug_category:$bug_type"; |
| 560 | |
| 561 | if (!defined $Totals{$key}) { $Totals{$key} = [1,$bug_category,$bug_type]; } |
| 562 | else { $Totals{$key}->[0]++; } |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 563 | } |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 564 | |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 565 | print OUT "<h2>Bug Summary</h2>"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 566 | |
| 567 | if (defined $BuildName) { |
| 568 | print OUT "\n<p>Results in this analysis run are based on analyzer build <b>$BuildName</b>.</p>\n" |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 569 | } |
Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 570 | |
Ted Kremenek | 2350a46 | 2008-10-28 19:56:52 +0000 | [diff] [blame] | 571 | |
| 572 | my $TotalBugs = scalar(@Index); |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 573 | print OUT <<ENDTEXT; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 574 | <table> |
| 575 | <thead><tr><td>Bug Type</td><td>Quantity</td><td class="sorttable_nosort">Display?</td></tr></thead> |
Ted Kremenek | 999e120 | 2008-10-28 20:09:57 +0000 | [diff] [blame] | 576 | <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 Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 577 | ENDTEXT |
| 578 | |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 579 | my $last_category; |
| 580 | |
| 581 | for my $key ( |
| 582 | sort { |
| 583 | my $x = $Totals{$a}; |
| 584 | my $y = $Totals{$b}; |
| 585 | my $res = $x->[1] cmp $y->[1]; |
| 586 | $res = $x->[2] cmp $y->[2] if ($res == 0); |
| 587 | $res |
| 588 | } keys %Totals ) |
| 589 | { |
| 590 | my $val = $Totals{$key}; |
| 591 | my $category = $val->[1]; |
| 592 | if (!defined $last_category or $last_category ne $category) { |
| 593 | $last_category = $category; |
| 594 | print OUT "<tr><th>$category</th><th colspan=2></th></tr>\n"; |
| 595 | } |
| 596 | my $x = lc $key; |
| 597 | $x =~ s/[ ,'":\/()]+/_/g; |
| 598 | print OUT "<tr><td class=\"SUMM_DESC\">"; |
| 599 | print OUT $val->[2]; |
Ted Kremenek | 2350a46 | 2008-10-28 19:56:52 +0000 | [diff] [blame] | 600 | print OUT "</td><td class=\"Q\">"; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 601 | print OUT $val->[0]; |
| 602 | print OUT "</td><td><center><input type=\"checkbox\" onClick=\"ToggleDisplay(this,'bt_$x');\" checked/></center></td></tr>\n"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 603 | } |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 604 | |
| 605 | # Print out the table of errors. |
| 606 | |
| 607 | print OUT <<ENDTEXT; |
| 608 | </table> |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 609 | <h2>Reports</h2> |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 610 | |
| 611 | <table class="sortable" style="table-layout:automatic"> |
| 612 | <thead><tr> |
| 613 | <td>Bug Group</td> |
| 614 | <td class="sorttable_sorted">Bug Type<span id="sorttable_sortfwdind"> ▾</span></td> |
Ted Kremenek | bba1cf5 | 2008-04-03 05:50:51 +0000 | [diff] [blame] | 615 | <td>File</td> |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 616 | <td class="Q">Line</td> |
Ted Kremenek | 8198311 | 2008-09-28 04:13:09 +0000 | [diff] [blame] | 617 | <td class="Q">Path Length</td> |
Ted Kremenek | 2645c77 | 2008-07-07 16:58:44 +0000 | [diff] [blame] | 618 | <td class="sorttable_nosort"></td> |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 619 | <!-- REPORTBUGCOL --> |
| 620 | </tr></thead> |
| 621 | <tbody> |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 622 | ENDTEXT |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 623 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 624 | my $prefix = GetPrefix(); |
| 625 | my $regex; |
| 626 | my $InFileRegex; |
| 627 | my $InFilePrefix = "File:</td><td>"; |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 628 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 629 | if (defined $prefix) { |
| 630 | $regex = qr/^\Q$prefix\E/is; |
| 631 | $InFileRegex = qr/\Q$InFilePrefix$prefix\E/is; |
| 632 | } |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 633 | |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 634 | for my $row ( sort { $a->[2] cmp $b->[2] } @Index ) { |
| 635 | my $x = "$row->[1]:$row->[2]"; |
| 636 | $x = lc $x; |
| 637 | $x =~ s/[ ,'":\/()]+/_/g; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 638 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 639 | my $ReportFile = $row->[0]; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 640 | |
| 641 | print OUT "<tr class=\"bt_$x\">"; |
| 642 | print OUT "<td class=\"DESC\">"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 643 | print OUT $row->[1]; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 644 | print OUT "</td>"; |
| 645 | print OUT "<td class=\"DESC\">"; |
| 646 | print OUT $row->[2]; |
| 647 | print OUT "</td>"; |
| 648 | |
| 649 | # Update the file prefix. |
| 650 | my $fname = $row->[3]; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 651 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 652 | if (defined $regex) { |
| 653 | $fname =~ s/$regex//; |
| 654 | UpdateInFilePath("$Dir/$ReportFile", $InFileRegex, $InFilePrefix) |
| 655 | } |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 656 | |
Ted Kremenek | 91639ef | 2008-09-22 17:42:31 +0000 | [diff] [blame] | 657 | print OUT "<td>"; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 658 | my @fname = split /\//,$fname; |
| 659 | if ($#fname > 0) { |
| 660 | while ($#fname >= 0) { |
| 661 | my $x = shift @fname; |
| 662 | print OUT $x; |
| 663 | if ($#fname >= 0) { |
| 664 | print OUT "<span class=\"W\"> </span>/"; |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | else { |
| 669 | print OUT $fname; |
Ted Kremenek | 91639ef | 2008-09-22 17:42:31 +0000 | [diff] [blame] | 670 | } |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 671 | print OUT "</td>"; |
| 672 | |
| 673 | # Print out the quantities. |
Ted Kremenek | 8198311 | 2008-09-28 04:13:09 +0000 | [diff] [blame] | 674 | for my $j ( 4 .. 5 ) { |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 675 | print OUT "<td class=\"Q\">$row->[$j]</td>"; |
| 676 | } |
| 677 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 678 | # Print the rest of the columns. |
Ted Kremenek | 8198311 | 2008-09-28 04:13:09 +0000 | [diff] [blame] | 679 | for (my $j = 6; $j <= $#{$row}; ++$j) { |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 680 | print OUT "<td>$row->[$j]</td>" |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 681 | } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 682 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 683 | # Emit the "View" link. |
Ted Kremenek | 68005dd | 2008-09-22 17:39:18 +0000 | [diff] [blame] | 684 | print OUT "<td><a href=\"$ReportFile#EndPath\">View Report</a></td>"; |
Ted Kremenek | 3cea9ee | 2008-07-30 17:58:08 +0000 | [diff] [blame] | 685 | |
Daniel Dunbar | e43038e | 2008-09-19 23:18:44 +0000 | [diff] [blame] | 686 | # Emit REPORTBUG markers. |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 687 | print OUT "\n<!-- REPORTBUG id=\"$ReportFile\" -->\n"; |
Daniel Dunbar | e43038e | 2008-09-19 23:18:44 +0000 | [diff] [blame] | 688 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 689 | # End the row. |
| 690 | print OUT "</tr>\n"; |
| 691 | } |
| 692 | |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 693 | print OUT "</tbody>\n</table>\n\n"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | if ($Crashes) { |
| 697 | # Read the crash directory for files. |
| 698 | opendir(DIR, "$Dir/crashes"); |
Ted Kremenek | 82a1253 | 2008-09-25 00:25:16 +0000 | [diff] [blame] | 699 | my @files = grep { /[.]info.txt$/ } readdir(DIR); |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 700 | closedir(DIR); |
| 701 | |
| 702 | if (scalar(@files)) { |
| 703 | print OUT <<ENDTEXT; |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 704 | <h2>Analyzer Failures</h2> |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 705 | |
Ted Kremenek | 5d31f83 | 2008-08-18 18:38:29 +0000 | [diff] [blame] | 706 | <p>The analyzer had problems processing the following files:</p> |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 707 | |
| 708 | <table> |
Ted Kremenek | 9f9b1fd | 2008-09-12 22:49:36 +0000 | [diff] [blame] | 709 | <thead><tr><td>Problem</td><td>Source File</td><td>Preprocessed File</td><td>STDERR Output</td></tr></thead> |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 710 | ENDTEXT |
| 711 | |
| 712 | foreach my $file (sort @files) { |
Ted Kremenek | 82a1253 | 2008-09-25 00:25:16 +0000 | [diff] [blame] | 713 | $file =~ /(.+).info.txt$/; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 714 | # Get the preprocessed file. |
| 715 | my $ppfile = $1; |
| 716 | # Open the info file and get the name of the source file. |
| 717 | open (INFO, "$Dir/crashes/$file") or |
| 718 | die "Cannot open $Dir/crashes/$file\n"; |
| 719 | my $srcfile = <INFO>; |
Ted Kremenek | 5d31f83 | 2008-08-18 18:38:29 +0000 | [diff] [blame] | 720 | chomp $srcfile; |
| 721 | my $problem = <INFO>; |
| 722 | chomp $problem; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 723 | close (INFO); |
| 724 | # Print the information in the table. |
Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 725 | my $prefix = GetPrefix(); |
Ted Kremenek | 9f9b1fd | 2008-09-12 22:49:36 +0000 | [diff] [blame] | 726 | if (defined $prefix) { $srcfile =~ s/^\Q$prefix//; } |
| 727 | print OUT "<tr><td>$problem</td><td>$srcfile</td><td><a href=\"crashes/$ppfile\">$ppfile</a></td><td><a href=\"crashes/$ppfile.stderr.txt\">$ppfile.stderr.txt</a></td></tr>\n"; |
Daniel Dunbar | ce723ce | 2008-09-25 01:10:50 +0000 | [diff] [blame] | 728 | my $ppfile_clang = $ppfile; |
| 729 | $ppfile_clang =~ s/[.](.+)$/.clang.$1/; |
Daniel Dunbar | 7ebe0ed | 2008-09-25 06:05:31 +0000 | [diff] [blame] | 730 | print OUT " <!-- REPORTPROBLEM src=\"$srcfile\" file=\"crashes/$ppfile\" clangfile=\"crashes/$ppfile_clang\" stderr=\"crashes/$ppfile.stderr.txt\" info=\"crashes/$ppfile.info.txt\" -->\n"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | print OUT <<ENDTEXT; |
| 734 | </table> |
Daniel Dunbar | ce723ce | 2008-09-25 01:10:50 +0000 | [diff] [blame] | 735 | <p>Please consider submitting preprocessed files as <a href="http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs">bug reports</a>. <!-- REPORTCRASHES --> </p> |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 736 | ENDTEXT |
| 737 | } |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 740 | print OUT "</body></html>\n"; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 741 | close(OUT); |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 742 | CopyFiles($Dir); |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 743 | |
| 744 | # Make sure $Dir and $BaseDir are world readable/executable. |
| 745 | system("chmod", "755", $Dir); |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 746 | if (defined $BaseDir) { system("chmod", "755", $BaseDir); } |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 747 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 748 | my $Num = scalar(@Index); |
Ted Kremenek | 150c212 | 2008-07-11 19:15:05 +0000 | [diff] [blame] | 749 | Diag("$Num bugs found.\n"); |
| 750 | if ($Num > 0 && -r "$Dir/index.html") { |
Ted Kremenek | 5950b3f | 2008-09-22 06:47:01 +0000 | [diff] [blame] | 751 | Diag("Run 'scan-view $Dir' to examine bug reports.\n"); |
Ted Kremenek | 150c212 | 2008-07-11 19:15:05 +0000 | [diff] [blame] | 752 | } |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 753 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 754 | DiagCrashes($Dir) if ($Crashes); |
| 755 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 756 | return $Num; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | ##----------------------------------------------------------------------------## |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 760 | # RunBuildCommand - Run the build command. |
| 761 | ##----------------------------------------------------------------------------## |
| 762 | |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 763 | sub AddIfNotPresent { |
| 764 | my $Args = shift; |
| 765 | my $Arg = shift; |
| 766 | my $found = 0; |
| 767 | |
| 768 | foreach my $k (@$Args) { |
| 769 | if ($k eq $Arg) { |
| 770 | $found = 1; |
| 771 | last; |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | if ($found == 0) { |
| 776 | push @$Args, $Arg; |
| 777 | } |
| 778 | } |
| 779 | |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 780 | sub RunBuildCommand { |
| 781 | |
| 782 | my $Args = shift; |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 783 | my $IgnoreErrors = shift; |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 784 | my $Cmd = $Args->[0]; |
Ted Kremenek | 6195c37 | 2008-06-02 21:52:47 +0000 | [diff] [blame] | 785 | my $CCAnalyzer = shift; |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 786 | |
Ted Kremenek | 3301cb1 | 2008-06-30 18:18:16 +0000 | [diff] [blame] | 787 | # Get only the part of the command after the last '/'. |
| 788 | if ($Cmd =~ /\/([^\/]+)$/) { |
| 789 | $Cmd = $1; |
| 790 | } |
| 791 | |
Ted Kremenek | 92548fe | 2008-11-19 01:46:21 +0000 | [diff] [blame] | 792 | if ($Cmd =~ /(.*\/?gcc[^\/]*$)/ or |
| 793 | $Cmd =~ /(.*\/?cc[^\/]*$)/ or |
| 794 | $Cmd =~ /(.*\/?llvm-gcc[^\/]*$)/ or |
| 795 | $Cmd =~ /(.*\/?ccc-analyzer[^\/]*$)/) { |
| 796 | |
| 797 | if (!($Cmd =~ /ccc-analyzer/) and !defined $ENV{"CCC_CC"}) { |
| 798 | $ENV{"CCC_CC"} = $1; |
| 799 | } |
| 800 | |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 801 | shift @$Args; |
Ted Kremenek | 6195c37 | 2008-06-02 21:52:47 +0000 | [diff] [blame] | 802 | unshift @$Args, $CCAnalyzer; |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 803 | } |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 804 | elsif ($IgnoreErrors) { |
| 805 | if ($Cmd eq "make" or $Cmd eq "gmake") { |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 806 | AddIfNotPresent($Args,"-k"); |
Ted Kremenek | 8912b54 | 2008-05-13 21:28:02 +0000 | [diff] [blame] | 807 | AddIfNotPresent($Args,"-i"); |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 808 | } |
| 809 | elsif ($Cmd eq "xcodebuild") { |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 810 | AddIfNotPresent($Args,"-PBXBuildsContinueAfterErrors=YES"); |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 811 | } |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 812 | } |
| 813 | |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 814 | if ($Cmd eq "xcodebuild") { |
Ted Kremenek | cfd4c7b | 2008-05-23 22:18:16 +0000 | [diff] [blame] | 815 | # Disable distributed builds for xcodebuild. |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 816 | AddIfNotPresent($Args,"-nodistribute"); |
Ted Kremenek | cfd4c7b | 2008-05-23 22:18:16 +0000 | [diff] [blame] | 817 | |
| 818 | # Disable PCH files until clang supports them. |
| 819 | AddIfNotPresent($Args,"GCC_PRECOMPILE_PREFIX_HEADER=NO"); |
Ted Kremenek | 915e972 | 2008-05-27 23:18:07 +0000 | [diff] [blame] | 820 | |
| 821 | # When 'CC' is set, xcodebuild uses it to do all linking, even if we are |
| 822 | # linking C++ object files. Set 'LDPLUSPLUS' so that xcodebuild uses 'g++' |
| 823 | # when linking such files. |
Ted Kremenek | 95aa105 | 2008-09-04 17:52:41 +0000 | [diff] [blame] | 824 | die if (!defined $CXX); |
| 825 | my $LDPLUSPLUS = `which $CXX`; |
Ted Kremenek | 915e972 | 2008-05-27 23:18:07 +0000 | [diff] [blame] | 826 | $LDPLUSPLUS =~ s/\015?\012//; # strip newlines |
| 827 | $ENV{'LDPLUSPLUS'} = $LDPLUSPLUS; |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 828 | } |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 829 | |
Ted Kremenek | 5a4ddaf | 2008-08-25 20:10:45 +0000 | [diff] [blame] | 830 | return (system(@$Args) >> 8); |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 831 | } |
| 832 | |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 833 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 834 | # DisplayHelp - Utility function to display all help options. |
| 835 | ##----------------------------------------------------------------------------## |
| 836 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 837 | sub DisplayHelp { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 838 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 839 | print <<ENDTEXT; |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 840 | USAGE: $Prog [options] <build command> [build options] |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 841 | |
Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 842 | ENDTEXT |
| 843 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 844 | if (defined $BuildName) { |
Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 845 | print "ANALYZER BUILD: $BuildName ($BuildDate)\n\n"; |
| 846 | } |
| 847 | |
| 848 | print <<ENDTEXT; |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 849 | OPTIONS: |
| 850 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 851 | -analyze-headers - Also analyze functions in #included files. |
| 852 | |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 853 | -store [model] - Specify the store model used by the analyzer. By default, |
| 854 | the 'basic' store model is used. 'region' specifies a field- |
| 855 | sensitive store model. Be warned that the 'region' model |
| 856 | is still in very early testing phase and may often crash. |
| 857 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 858 | -o - Target directory for HTML report files. Subdirectories |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 859 | will be created as needed to represent separate "runs" of |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 860 | the analyzer. If this option is not specified, a directory |
Ted Kremenek | ffda0b4 | 2008-10-31 05:48:42 +0000 | [diff] [blame] | 861 | is created in /tmp (TMPDIR on Mac OS X) to store the reports. |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 862 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 863 | -h - Display this message. |
| 864 | --help |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 865 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 866 | -k - Add a "keep on going" option to the specified build command. |
| 867 | --keep-going This option currently supports make and xcodebuild. |
Ted Kremenek | f02e8db | 2008-04-02 16:41:25 +0000 | [diff] [blame] | 868 | This is a convenience option; one can specify this |
| 869 | behavior directly using build options. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 870 | |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 871 | --html-title [title] - Specify the title used on generated HTML pages. |
| 872 | --html-title=[title] If not specified, a default title will be used. |
| 873 | |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 874 | -plist - By default the output of scan-build is a set of HTML files. |
| 875 | This option outputs the results as a set of .plist files. |
| 876 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 877 | --status-bugs - By default, the exit status of $Prog is the same as the |
| 878 | executed build command. Specifying this option causes the |
| 879 | exit status of $Prog to be 1 if it found potential bugs |
| 880 | and 0 otherwise. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 881 | |
Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 882 | --use-cc [compiler path] - By default, $Prog uses 'gcc' to compile and link |
| 883 | --use-cc=[compiler path] your C and Objective-C code. Use this option |
| 884 | to specify an alternate compiler. |
| 885 | |
| 886 | --use-c++ [compiler path] - By default, $Prog uses 'g++' to compile and link |
| 887 | --use-c++=[compiler path] your C++ and Objective-C++ code. Use this option |
| 888 | to specify an alternate compiler. |
Ted Kremenek | f17ef3c | 2008-08-21 21:47:09 +0000 | [diff] [blame] | 889 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 890 | -v - Verbose output from $Prog and the analyzer. |
Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 891 | A second and third '-v' increases verbosity. |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 892 | |
| 893 | -V - View analysis results in a web browser when the build |
| 894 | --view completes. |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 895 | |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 896 | |
Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 897 | AVAILABLE ANALYSES (multiple analyses may be specified): |
Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 898 | |
| 899 | ENDTEXT |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 900 | |
| 901 | foreach my $Analysis (sort keys %AvailableAnalyses) { |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 902 | if (defined $AnalysesDefaultEnabled{$Analysis}) { |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 903 | print " (+)"; |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 904 | } |
| 905 | else { |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 906 | print " "; |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | print " $Analysis $AvailableAnalyses{$Analysis}\n"; |
| 910 | } |
| 911 | |
| 912 | print <<ENDTEXT |
| 913 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 914 | NOTE: "(+)" indicates that an analysis is enabled by default unless one |
| 915 | or more analysis options are specified |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 916 | |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 917 | BUILD OPTIONS |
| 918 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 919 | You can specify any build option acceptable to the build command. |
Ted Kremenek | 39eefde | 2008-04-02 16:47:27 +0000 | [diff] [blame] | 920 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 921 | EXAMPLE |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 922 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 923 | $Prog -o /tmp/myhtmldir make -j4 |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 924 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 925 | The above example causes analysis reports to be deposited into |
| 926 | a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option. |
| 927 | A different subdirectory is created each time $Prog analyzes a project. |
| 928 | The analyzer should support most parallel builds, but not distributed builds. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 929 | |
| 930 | ENDTEXT |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 934 | # HtmlEscape - HTML entity encode characters that are special in HTML |
| 935 | ##----------------------------------------------------------------------------## |
| 936 | |
| 937 | sub HtmlEscape { |
| 938 | # copy argument to new variable so we don't clobber the original |
| 939 | my $arg = shift || ''; |
| 940 | my $tmp = $arg; |
Ted Kremenek | 87f8de7 | 2008-11-03 07:44:16 +0000 | [diff] [blame] | 941 | $tmp =~ s/&/&/g; |
| 942 | $tmp =~ s/</</g; |
| 943 | $tmp =~ s/>/>/g; |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 944 | return $tmp; |
| 945 | } |
| 946 | |
| 947 | ##----------------------------------------------------------------------------## |
| 948 | # ShellEscape - backslash escape characters that are special to the shell |
| 949 | ##----------------------------------------------------------------------------## |
| 950 | |
| 951 | sub ShellEscape { |
| 952 | # copy argument to new variable so we don't clobber the original |
| 953 | my $arg = shift || ''; |
Ted Kremenek | 87f8de7 | 2008-11-03 07:44:16 +0000 | [diff] [blame] | 954 | if ($arg =~ /["\s]/) { return "'" . $arg . "'"; } |
| 955 | return $arg; |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 959 | # Process command-line arguments. |
| 960 | ##----------------------------------------------------------------------------## |
| 961 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 962 | my $AnalyzeHeaders = 0; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 963 | my $HtmlDir; # Parent directory to store HTML files. |
| 964 | my $IgnoreErrors = 0; # Ignore build errors. |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 965 | my $ViewResults = 0; # View results when the build terminates. |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 966 | my $ExitStatusFoundBugs = 0; # Exit status reflects whether bugs were found |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 967 | my @AnalysesToRun; |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 968 | my $StoreModel; |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 969 | my $OutputFormat; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 970 | |
| 971 | if (!@ARGV) { |
| 972 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 973 | exit 1; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | while (@ARGV) { |
| 977 | |
| 978 | # Scan for options we recognize. |
| 979 | |
| 980 | my $arg = $ARGV[0]; |
| 981 | |
Sam Bishop | 2f2418e | 2008-04-03 14:29:47 +0000 | [diff] [blame] | 982 | if ($arg eq "-h" or $arg eq "--help") { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 983 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 984 | exit 0; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 985 | } |
| 986 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 987 | if ($arg eq '-analyze-headers') { |
| 988 | shift @ARGV; |
| 989 | $AnalyzeHeaders = 1; |
| 990 | next; |
| 991 | } |
| 992 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 993 | if (defined $AvailableAnalyses{$arg}) { |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 994 | shift @ARGV; |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 995 | push @AnalysesToRun, $arg; |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 996 | next; |
| 997 | } |
| 998 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 999 | if ($arg eq "-o") { |
| 1000 | shift @ARGV; |
| 1001 | |
| 1002 | if (!@ARGV) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 1003 | DieDiag("'-o' option requires a target directory name.\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | $HtmlDir = shift @ARGV; |
| 1007 | next; |
| 1008 | } |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 1009 | |
| 1010 | if ($arg =~ /^--html-title(=(.+))?$/) { |
| 1011 | shift @ARGV; |
| 1012 | |
| 1013 | if ($2 eq '') { |
| 1014 | if (!@ARGV) { |
| 1015 | DieDiag("'--html-title' option requires a string.\n"); |
| 1016 | } |
| 1017 | |
| 1018 | $HtmlTitle = shift @ARGV; |
| 1019 | } else { |
| 1020 | $HtmlTitle = $2; |
| 1021 | } |
| 1022 | |
| 1023 | next; |
| 1024 | } |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1025 | |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 1026 | if ($arg eq "-k" or $arg eq "--keep-going") { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1027 | shift @ARGV; |
| 1028 | $IgnoreErrors = 1; |
| 1029 | next; |
| 1030 | } |
| 1031 | |
Ted Kremenek | f17ef3c | 2008-08-21 21:47:09 +0000 | [diff] [blame] | 1032 | if ($arg =~ /^--use-cc(=(.+))?$/) { |
| 1033 | shift @ARGV; |
| 1034 | my $cc; |
| 1035 | |
| 1036 | if ($2 eq "") { |
| 1037 | if (!@ARGV) { |
| 1038 | DieDiag("'--use-cc' option requires a compiler executable name.\n"); |
| 1039 | } |
| 1040 | $cc = shift @ARGV; |
| 1041 | } |
| 1042 | else { |
| 1043 | $cc = $2; |
| 1044 | } |
| 1045 | |
| 1046 | $ENV{"CCC_CC"} = $cc; |
| 1047 | next; |
| 1048 | } |
| 1049 | |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 1050 | if ($arg =~ /^--use-c\+\+(=(.+))?$/) { |
Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 1051 | shift @ARGV; |
| 1052 | |
| 1053 | if ($2 eq "") { |
| 1054 | if (!@ARGV) { |
| 1055 | DieDiag("'--use-c++' option requires a compiler executable name.\n"); |
| 1056 | } |
| 1057 | $CXX = shift @ARGV; |
| 1058 | } |
| 1059 | else { |
| 1060 | $CXX = $2; |
| 1061 | } |
| 1062 | next; |
| 1063 | } |
| 1064 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1065 | if ($arg eq "-v") { |
| 1066 | shift @ARGV; |
| 1067 | $Verbose++; |
| 1068 | next; |
| 1069 | } |
| 1070 | |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 1071 | if ($arg eq "-V" or $arg eq "--view") { |
| 1072 | shift @ARGV; |
| 1073 | $ViewResults = 1; |
| 1074 | next; |
| 1075 | } |
| 1076 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 1077 | if ($arg eq "--status-bugs") { |
| 1078 | shift @ARGV; |
| 1079 | $ExitStatusFoundBugs = 1; |
| 1080 | next; |
| 1081 | } |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 1082 | |
| 1083 | if ($arg eq "-store") { |
| 1084 | shift @ARGV; |
| 1085 | $StoreModel = '-analyzer-store-' . shift @ARGV; |
| 1086 | next; |
| 1087 | } |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 1088 | |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1089 | if ($arg eq "-plist") { |
| 1090 | shift @ARGV; |
| 1091 | $OutputFormat = "plist"; |
| 1092 | next; |
| 1093 | } |
| 1094 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 1095 | DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/); |
Ted Kremenek | 0062ad4 | 2008-04-02 16:35:01 +0000 | [diff] [blame] | 1096 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1097 | last; |
| 1098 | } |
| 1099 | |
| 1100 | if (!@ARGV) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 1101 | Diag("No build command specified.\n\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1102 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 1103 | exit 1; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 1106 | $CmdArgs = HtmlEscape(join(' ', map(ShellEscape($_), @ARGV))); |
| 1107 | $HtmlTitle = "${CurrentDirSuffix} - scan-build results" |
| 1108 | unless (defined($HtmlTitle)); |
Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 1109 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1110 | # Determine the output directory for the HTML reports. |
Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 1111 | my $BaseDir = $HtmlDir; |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 1112 | $HtmlDir = GetHTMLRunDir($HtmlDir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1113 | |
| 1114 | # Set the appropriate environment variables. |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 1115 | SetHtmlEnv(\@ARGV, $HtmlDir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1116 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 1117 | my $Cmd = Cwd::realpath("$RealBin/ccc-analyzer"); |
Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 1118 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 1119 | DieDiag("Executable 'ccc-analyzer' does not exist at '$Cmd'\n") |
Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 1120 | if (! -x $Cmd); |
Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 1121 | |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 1122 | if (! -x $ClangSB) { |
| 1123 | Diag("'clang' executable not found in '$RealBin'.\n"); |
| 1124 | Diag("Using 'clang' from path.\n"); |
Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 1125 | } |
Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 1126 | |
Ted Kremenek | 95aa105 | 2008-09-04 17:52:41 +0000 | [diff] [blame] | 1127 | if (defined $CXX) { |
| 1128 | $ENV{'CXX'} = $CXX; |
| 1129 | } |
| 1130 | else { |
| 1131 | $CXX = 'g++'; # This variable is used by other parts of scan-build |
| 1132 | # that need to know a default C++ compiler to fall back to. |
| 1133 | } |
| 1134 | |
Ted Kremenek | 4f4b17d | 2008-04-03 20:08:18 +0000 | [diff] [blame] | 1135 | $ENV{'CC'} = $Cmd; |
Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 1136 | $ENV{'CLANG'} = $Clang; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1137 | |
| 1138 | if ($Verbose >= 2) { |
| 1139 | $ENV{'CCC_ANALYZER_VERBOSE'} = 1; |
| 1140 | } |
| 1141 | |
Ted Kremenek | a9525c9 | 2008-05-12 22:07:14 +0000 | [diff] [blame] | 1142 | if ($Verbose >= 3) { |
| 1143 | $ENV{'CCC_ANALYZER_LOG'} = 1; |
| 1144 | } |
| 1145 | |
Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 1146 | if (scalar(@AnalysesToRun) == 0) { |
| 1147 | foreach my $key (keys %AnalysesDefaultEnabled) { |
| 1148 | push @AnalysesToRun,$key; |
| 1149 | } |
Ted Kremenek | 0100678 | 2008-07-02 23:16:10 +0000 | [diff] [blame] | 1150 | } |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 1151 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 1152 | if ($AnalyzeHeaders) { |
| 1153 | push @AnalysesToRun,"-analyzer-opt-analyze-headers"; |
| 1154 | } |
| 1155 | |
Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 1156 | $ENV{'CCC_ANALYZER_ANALYSIS'} = join ' ',@AnalysesToRun; |
| 1157 | |
Zhongxing Xu | 3cab2b1 | 2008-11-02 10:58:16 +0000 | [diff] [blame] | 1158 | if (defined $StoreModel) { |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 1159 | $ENV{'CCC_ANALYZER_STORE_MODEL'} = $StoreModel; |
| 1160 | } |
| 1161 | |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1162 | if (defined $OutputFormat) { |
| 1163 | $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'} = $OutputFormat; |
| 1164 | } |
| 1165 | |
| 1166 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1167 | # Run the build. |
Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 1168 | my $ExitStatus = RunBuildCommand(\@ARGV, $IgnoreErrors, $Cmd); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1169 | |
Ted Kremenek | 655aba7 | 2008-11-04 00:22:12 +0000 | [diff] [blame] | 1170 | if (defined $OutputFormat and $OutputFormat eq "plist") { |
Ted Kremenek | 50534dc | 2008-09-22 17:38:23 +0000 | [diff] [blame] | 1171 | Diag "Analysis run complete.\n"; |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1172 | Diag "Analysis results (plist files) deposited in '$HtmlDir'\n"; |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 1173 | } |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1174 | else { |
| 1175 | # Postprocess the HTML directory. |
| 1176 | my $NumBugs = Postprocess($HtmlDir, $BaseDir); |
Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 1177 | |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1178 | if ($ViewResults and -r "$HtmlDir/index.html") { |
| 1179 | Diag "Analysis run complete.\n"; |
| 1180 | Diag "Viewing analysis results in '$HtmlDir' using scan-view.\n"; |
| 1181 | my $ScanView = Cwd::realpath("$RealBin/scan-view"); |
| 1182 | if (! -x $ScanView) { $ScanView = "scan-view"; } |
| 1183 | exec $ScanView, "$HtmlDir"; |
| 1184 | } |
| 1185 | |
| 1186 | if ($ExitStatusFoundBugs) { |
| 1187 | exit 1 if ($NumBugs > 0); |
| 1188 | exit 0; |
| 1189 | } |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 1192 | exit $ExitStatus; |
| 1193 | |