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 | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 22 | |
| 23 | my $Verbose = 0; # Verbose output from this script. |
| 24 | my $Prog = "scan-build"; |
Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 25 | my $BuildName; |
| 26 | my $BuildDate; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 27 | |
Ted Kremenek | f2f8d6c | 2008-06-17 03:06:59 +0000 | [diff] [blame] | 28 | my $UseColor = ((($ENV{'TERM'} eq 'xterm-color') and -t STDOUT) |
| 29 | and defined($ENV{'SCAN_BUILD_COLOR'})); |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 30 | |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 31 | ##----------------------------------------------------------------------------## |
| 32 | # Diagnostics |
| 33 | ##----------------------------------------------------------------------------## |
| 34 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 35 | sub Diag { |
| 36 | if ($UseColor) { |
| 37 | print BOLD, MAGENTA "$Prog: @_"; |
| 38 | print RESET; |
| 39 | } |
| 40 | else { |
| 41 | print "$Prog: @_"; |
| 42 | } |
| 43 | } |
| 44 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 45 | sub DiagCrashes { |
| 46 | my $Dir = shift; |
| 47 | Diag ("The analyzer crashed on some source files.\n"); |
| 48 | Diag ("Preprocessed versions of crashed files were depositied in '$Dir/crashes'.\n"); |
| 49 | Diag ("Please consider submitting a bug report using these files:\n"); |
| 50 | Diag (" http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs\n") |
| 51 | } |
| 52 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 53 | sub DieDiag { |
| 54 | if ($UseColor) { |
| 55 | print BOLD, RED "$Prog: "; |
| 56 | print RESET, RED @_; |
| 57 | print RESET; |
| 58 | } |
| 59 | else { |
| 60 | print "$Prog: ", @_; |
| 61 | } |
| 62 | exit(0); |
| 63 | } |
| 64 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 65 | ##----------------------------------------------------------------------------## |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 66 | # Some initial preprocessing of Clang options. |
| 67 | ##----------------------------------------------------------------------------## |
| 68 | |
| 69 | my $ClangSB = "$RealBin/clang"; |
| 70 | my $Clang = $ClangSB; |
| 71 | |
| 72 | if (! -x $ClangSB) { |
| 73 | $Clang = "clang"; |
| 74 | } |
| 75 | |
| 76 | my %AvailableAnalyses; |
| 77 | |
| 78 | # Query clang for analysis options. |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 79 | open(PIPE, "-|", $Clang, "--help") or |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 80 | DieDiag("Cannot execute '$Clang'"); |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 81 | |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 82 | my $FoundAnalysis = 0; |
| 83 | |
| 84 | while(<PIPE>) { |
| 85 | if ($FoundAnalysis == 0) { |
| 86 | if (/Available Source Code Analyses/) { |
| 87 | $FoundAnalysis = 1; |
| 88 | } |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 89 | |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 90 | next; |
| 91 | } |
| 92 | |
| 93 | if (/^\s\s\s\s([^\s]+)\s(.+)$/) { |
| 94 | next if ($1 =~ /-dump/ or $1 =~ /-view/ |
| 95 | or $1 =~ /-checker-simple/ or $1 =~ /-warn-uninit/); |
| 96 | |
| 97 | $AvailableAnalyses{$1} = $2; |
| 98 | next; |
| 99 | } |
| 100 | |
| 101 | last; |
| 102 | } |
| 103 | |
| 104 | close (PIPE); |
| 105 | |
| 106 | my %AnalysesDefaultEnabled = ( |
| 107 | '-warn-dead-stores' => 1, |
| 108 | '-checker-cfref' => 1, |
Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 109 | '-warn-objc-methodsigs' => 1, |
Ted Kremenek | bde3a05 | 2008-07-25 20:35:01 +0000 | [diff] [blame] | 110 | '-warn-objc-missing-dealloc' => 1, |
| 111 | '-warn-objc-unused-ivars' => 1 |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 112 | ); |
| 113 | |
| 114 | ##----------------------------------------------------------------------------## |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 115 | # GetHTMLRunDir - Construct an HTML directory name for the current sub-run. |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 116 | ##----------------------------------------------------------------------------## |
| 117 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 118 | sub GetHTMLRunDir { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 119 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 120 | die "Not enough arguments." if (@_ == 0); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 121 | my $Dir = shift @_; |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 122 | |
| 123 | my $TmpMode = 0; |
| 124 | if (!defined $Dir) { |
| 125 | $Dir = "/tmp"; |
| 126 | $TmpMode = 1; |
| 127 | } |
| 128 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 129 | # Get current date and time. |
| 130 | |
| 131 | my @CurrentTime = localtime(); |
| 132 | |
| 133 | my $year = $CurrentTime[5] + 1900; |
| 134 | my $day = $CurrentTime[3]; |
| 135 | my $month = $CurrentTime[4] + 1; |
| 136 | |
Ted Kremenek | 9d7405f | 2008-05-14 17:23:56 +0000 | [diff] [blame] | 137 | my $DateString = sprintf("%d-%02d-%02d", $year, $month, $day); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 138 | |
| 139 | # Determine the run number. |
| 140 | |
| 141 | my $RunNumber; |
| 142 | |
| 143 | if (-d $Dir) { |
| 144 | |
| 145 | if (! -r $Dir) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 146 | DieDiag("directory '$Dir' exists but is not readable.\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | # Iterate over all files in the specified directory. |
| 150 | |
| 151 | my $max = 0; |
| 152 | |
| 153 | opendir(DIR, $Dir); |
Ted Kremenek | 29da6c5 | 2008-08-07 17:57:34 +0000 | [diff] [blame] | 154 | my @FILES = grep { -d "$Dir/$_" } readdir(DIR); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 155 | closedir(DIR); |
| 156 | |
| 157 | foreach my $f (@FILES) { |
| 158 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 159 | # Strip the prefix '$Prog-' if we are dumping files to /tmp. |
| 160 | if ($TmpMode) { |
| 161 | next if (!($f =~ /^$Prog-(.+)/)); |
| 162 | $f = $1; |
| 163 | } |
| 164 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 165 | my @x = split/-/, $f; |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 166 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 167 | next if (scalar(@x) != 4); |
| 168 | next if ($x[0] != $year); |
| 169 | next if ($x[1] != $month); |
| 170 | next if ($x[2] != $day); |
| 171 | |
| 172 | if ($x[3] > $max) { |
| 173 | $max = $x[3]; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | $RunNumber = $max + 1; |
| 178 | } |
| 179 | else { |
| 180 | |
| 181 | if (-x $Dir) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 182 | DieDiag("'$Dir' exists but is not a directory.\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 183 | } |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 184 | |
| 185 | if ($TmpMode) { |
| 186 | DieDiag("The directory '/tmp' does not exist or cannot be accessed."); |
| 187 | } |
| 188 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 189 | # $Dir does not exist. It will be automatically created by the |
| 190 | # clang driver. Set the run number to 1. |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 191 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 192 | $RunNumber = 1; |
| 193 | } |
| 194 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 195 | die "RunNumber must be defined!" if (!defined $RunNumber); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 196 | |
| 197 | # Append the run number. |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 198 | if ($TmpMode) { |
| 199 | my $NewDir = "$Dir/$Prog-$DateString-$RunNumber"; |
| 200 | mkdir $NewDir; |
| 201 | return $NewDir; |
| 202 | } |
| 203 | else { |
| 204 | return "$Dir/$DateString-$RunNumber"; |
| 205 | } |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 208 | sub SetHtmlEnv { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 209 | |
| 210 | die "Wrong number of arguments." if (scalar(@_) != 2); |
| 211 | |
| 212 | my $Args = shift; |
| 213 | my $Dir = shift; |
| 214 | |
| 215 | die "No build command." if (scalar(@$Args) == 0); |
| 216 | |
| 217 | my $Cmd = $$Args[0]; |
| 218 | |
| 219 | if ($Cmd =~ /configure/) { |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | if ($Verbose) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 224 | Diag("Emitting reports for this run to '$Dir'.\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | $ENV{'CCC_ANALYZER_HTML'} = $Dir; |
| 228 | } |
| 229 | |
| 230 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 231 | # ComputeDigest - Compute a digest of the specified file. |
| 232 | ##----------------------------------------------------------------------------## |
| 233 | |
| 234 | sub ComputeDigest { |
| 235 | my $FName = shift; |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 236 | DieDiag("Cannot read $FName to compute Digest.\n") if (! -r $FName); |
Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 237 | |
| 238 | # 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] | 239 | # just looking for duplicate files that come from a non-malicious source. |
| 240 | # 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] | 241 | # come bundled on most systems. |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 242 | open(FILE, $FName) or DieDiag("Cannot open $FName when computing Digest.\n"); |
Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 243 | binmode FILE; |
| 244 | my $Result = Digest::MD5->new->addfile(*FILE)->hexdigest; |
| 245 | close(FILE); |
| 246 | |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 247 | # Return the digest. |
Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 248 | return $Result; |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 252 | # UpdatePrefix - Compute the common prefix of files. |
| 253 | ##----------------------------------------------------------------------------## |
| 254 | |
| 255 | my $Prefix; |
| 256 | |
| 257 | sub UpdatePrefix { |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 258 | my $x = shift; |
| 259 | my $y = basename($x); |
| 260 | $x =~ s/\Q$y\E$//; |
| 261 | |
| 262 | # Ignore /usr, /Library, /System, /Developer |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 263 | return if ( $x =~ /^\/usr/ or $x =~ /^\/Library/ |
| 264 | or $x =~ /^\/System/ or $x =~ /^\/Developer/); |
| 265 | |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 266 | if (!defined $Prefix) { |
| 267 | $Prefix = $x; |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | chop $Prefix while (!($x =~ /^$Prefix/)); |
| 272 | } |
| 273 | |
| 274 | sub GetPrefix { |
| 275 | return $Prefix; |
| 276 | } |
| 277 | |
| 278 | ##----------------------------------------------------------------------------## |
| 279 | # UpdateInFilePath - Update the path in the report file. |
| 280 | ##----------------------------------------------------------------------------## |
| 281 | |
| 282 | sub UpdateInFilePath { |
| 283 | my $fname = shift; |
| 284 | my $regex = shift; |
| 285 | my $newtext = shift; |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 286 | |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 287 | open (RIN, $fname) or die "cannot open $fname"; |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 288 | open (ROUT, ">", "$fname.tmp") or die "cannot open $fname.tmp"; |
| 289 | |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 290 | while (<RIN>) { |
| 291 | s/$regex/$newtext/; |
| 292 | print ROUT $_; |
| 293 | } |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 294 | |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 295 | close (ROUT); |
| 296 | close (RIN); |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 297 | system("mv", "$fname.tmp", $fname); |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 301 | # ScanFile - Scan a report file for various identifying attributes. |
| 302 | ##----------------------------------------------------------------------------## |
| 303 | |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 304 | # Sometimes a source file is scanned more than once, and thus produces |
| 305 | # multiple error reports. We use a cache to solve this problem. |
| 306 | |
| 307 | my %AlreadyScanned; |
| 308 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 309 | sub ScanFile { |
| 310 | |
| 311 | my $Index = shift; |
| 312 | my $Dir = shift; |
| 313 | my $FName = shift; |
| 314 | |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 315 | # Compute a digest for the report file. Determine if we have already |
| 316 | # scanned a file that looks just like it. |
| 317 | |
| 318 | my $digest = ComputeDigest("$Dir/$FName"); |
| 319 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 320 | if (defined $AlreadyScanned{$digest}) { |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 321 | # Redundant file. Remove it. |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 322 | system ("rm", "-f", "$Dir/$FName"); |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 323 | return; |
| 324 | } |
| 325 | |
| 326 | $AlreadyScanned{$digest} = 1; |
| 327 | |
Ted Kremenek | 809709f | 2008-04-18 16:58:34 +0000 | [diff] [blame] | 328 | # 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] | 329 | system ("chmod", "644", "$Dir/$FName"); |
Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 330 | |
| 331 | # Scan the report file for tags. |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 332 | open(IN, "$Dir/$FName") or DieDiag("Cannot open '$Dir/$FName'\n"); |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 333 | |
| 334 | my $BugDesc = ""; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 335 | my $BugFile = ""; |
| 336 | my $BugPathLength = 1; |
| 337 | my $BugLine = 0; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 338 | |
| 339 | while (<IN>) { |
| 340 | |
| 341 | if (/<!-- BUGDESC (.*) -->$/) { |
| 342 | $BugDesc = $1; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 343 | } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 344 | elsif (/<!-- BUGFILE (.*) -->$/) { |
| 345 | $BugFile = $1; |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 346 | UpdatePrefix($BugFile); |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 347 | } |
| 348 | elsif (/<!-- BUGPATHLENGTH (.*) -->$/) { |
| 349 | $BugPathLength = $1; |
| 350 | } |
| 351 | elsif (/<!-- BUGLINE (.*) -->$/) { |
| 352 | $BugLine = $1; |
| 353 | } |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | close(IN); |
| 357 | |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 358 | push @$Index,[ $FName, $BugDesc, $BugFile, $BugLine, $BugPathLength ]; |
| 359 | } |
| 360 | |
| 361 | ##----------------------------------------------------------------------------## |
| 362 | # CopyJS - Copy JavaScript code to target directory. |
| 363 | ##----------------------------------------------------------------------------## |
| 364 | |
| 365 | sub CopyJS { |
| 366 | |
| 367 | my $Dir = shift; |
| 368 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 369 | DieDiag("Cannot find 'sorttable.js'.\n") |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 370 | if (! -r "$RealBin/sorttable.js"); |
| 371 | |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 372 | system ("cp", "$RealBin/sorttable.js", "$Dir"); |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 373 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 374 | DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n") |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 375 | if (! -r "$Dir/sorttable.js"); |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 379 | # Postprocess - Postprocess the results of an analysis scan. |
| 380 | ##----------------------------------------------------------------------------## |
| 381 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 382 | sub Postprocess { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 383 | |
| 384 | my $Dir = shift; |
Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 385 | my $BaseDir = shift; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 386 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 387 | die "No directory specified." if (!defined $Dir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 388 | |
| 389 | if (! -d $Dir) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 390 | Diag("No bugs found.\n"); |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 391 | return 0; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | opendir(DIR, $Dir); |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 395 | my $Crashes = 0; |
| 396 | my @files = grep { if ($_ eq "crashes") { $Crashes++; } |
| 397 | /^report-.*\.html$/; } readdir(DIR); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 398 | closedir(DIR); |
| 399 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 400 | if (scalar(@files) == 0 and $Crashes == 0) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 401 | Diag("Removing directory '$Dir' because it contains no reports.\n"); |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 402 | system ("rm", "-fR", $Dir); |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 403 | # Remove the base directory if it contains no files (don't use '-R'). |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 404 | system ("rm", "-f", $BaseDir) if (defined $BaseDir); |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 405 | return 0; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 406 | } |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 407 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 408 | # Scan each report file and build an index. |
| 409 | my @Index; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 410 | foreach my $file (@files) { ScanFile(\@Index, $Dir, $file); } |
| 411 | |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 412 | # Generate an index.html file. |
| 413 | my $FName = "$Dir/index.html"; |
| 414 | open(OUT, ">", $FName) or DieDiag("Cannot create file '$FName'\n"); |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 415 | |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 416 | # Print out the header. |
| 417 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 418 | print OUT <<ENDTEXT; |
| 419 | <html> |
| 420 | <head> |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 421 | <style type="text/css"> |
| 422 | body { color:#000000; background-color:#ffffff } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 423 | body { font-family: Helvetica, sans-serif; font-size:9pt } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 424 | h1 { font-size:12pt } |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 425 | table thead { |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 426 | background-color:#eee; color:#666666; |
| 427 | font-weight: bold; cursor: default; |
Ted Kremenek | bba1cf5 | 2008-04-03 05:50:51 +0000 | [diff] [blame] | 428 | text-align:center; |
| 429 | border-top: 2px solid #000000; |
| 430 | border-bottom: 2px solid #000000; |
| 431 | font-weight: bold; font-family: Verdana |
| 432 | } |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 433 | table { border: 1px #000000 solid } |
| 434 | table { border-collapse: collapse; border-spacing: 0px } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 435 | td { border-bottom: 1px #000000 dotted } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 436 | td { padding:5px; padding-left:8px; padding-right:8px } |
Ted Kremenek | d8c6d0c | 2008-04-07 23:50:07 +0000 | [diff] [blame] | 437 | td { text-align:left; font-size:9pt } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 438 | td.View { padding-left: 10px } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 439 | </style> |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 440 | <script src="sorttable.js"></script> |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 441 | <script language='javascript' type="text/javascript"> |
| 442 | function SetDisplay(RowClass, DisplayVal) |
| 443 | { |
| 444 | var Rows = document.getElementsByTagName("tr"); |
| 445 | for ( var i = 0 ; i < Rows.length; ++i ) { |
| 446 | if (Rows[i].className == RowClass) { |
| 447 | Rows[i].style.display = DisplayVal; |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | function ToggleDisplay(CheckButton, ClassName) { |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 453 | if (CheckButton.checked) { |
| 454 | SetDisplay(ClassName, ""); |
| 455 | } |
| 456 | else { |
| 457 | SetDisplay(ClassName, "none"); |
| 458 | } |
| 459 | } |
| 460 | </script> |
| 461 | </head> |
| 462 | <body> |
| 463 | ENDTEXT |
| 464 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 465 | if (scalar(@files)) { |
| 466 | # Print out the summary table. |
| 467 | my %Totals; |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 468 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 469 | for my $row ( @Index ) { |
| 470 | #my $bug_type = lc($row->[1]); |
| 471 | my $bug_type = ($row->[1]); |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 472 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 473 | if (!defined $Totals{$bug_type}) { $Totals{$bug_type} = 1; } |
| 474 | else { $Totals{$bug_type}++; } |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 475 | } |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 476 | |
| 477 | print OUT "<h3>Bug Summary</h3>"; |
| 478 | |
| 479 | if (defined $BuildName) { |
| 480 | 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] | 481 | } |
Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 482 | |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 483 | print OUT <<ENDTEXT; |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 484 | <table class="sortable"> |
| 485 | <tr> |
| 486 | <td>Bug Type</td> |
| 487 | <td>Quantity</td> |
Ted Kremenek | 2645c77 | 2008-07-07 16:58:44 +0000 | [diff] [blame] | 488 | <td class="sorttable_nosort">Display?</td> |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 489 | </tr> |
| 490 | ENDTEXT |
| 491 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 492 | for my $key ( sort { $a cmp $b } keys %Totals ) { |
| 493 | my $x = lc($key); |
| 494 | $x =~ s/[ ,'"]+/_/g; |
| 495 | print OUT "<tr><td>$key</td><td>$Totals{$key}</td><td><input type=\"checkbox\" onClick=\"ToggleDisplay(this,'bt_$x');\" checked/></td></tr>\n"; |
| 496 | } |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 497 | |
| 498 | # Print out the table of errors. |
| 499 | |
| 500 | print OUT <<ENDTEXT; |
| 501 | </table> |
| 502 | <h3>Reports</h3> |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 503 | <table class="sortable"> |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 504 | <tr> |
Ted Kremenek | 88a96d6 | 2008-07-07 17:23:32 +0000 | [diff] [blame] | 505 | <td class="sorttable_sorted">Bug Type<span id="sorttable_sortfwdind"> ▾</span> |
Ted Kremenek | bba1cf5 | 2008-04-03 05:50:51 +0000 | [diff] [blame] | 506 | <td>File</td> |
| 507 | <td>Line</td> |
| 508 | <td>Path Length</td> |
Ted Kremenek | 2645c77 | 2008-07-07 16:58:44 +0000 | [diff] [blame] | 509 | <td class="sorttable_nosort"></td> |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 510 | </tr> |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 511 | ENDTEXT |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 512 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 513 | my $prefix = GetPrefix(); |
| 514 | my $regex; |
| 515 | my $InFileRegex; |
| 516 | my $InFilePrefix = "File:</td><td>"; |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 517 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 518 | if (defined $prefix) { |
| 519 | $regex = qr/^\Q$prefix\E/is; |
| 520 | $InFileRegex = qr/\Q$InFilePrefix$prefix\E/is; |
| 521 | } |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 522 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 523 | for my $row ( sort { $a->[1] cmp $b->[1] } @Index ) { |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 524 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 525 | my $x = lc($row->[1]); |
| 526 | $x =~ s/[ ,'"]+/_/g; |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 527 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 528 | print OUT "<tr class=\"bt_$x\">\n"; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 529 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 530 | my $ReportFile = $row->[0]; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 531 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 532 | print OUT " <td class=\"DESC\">"; |
| 533 | #print OUT lc($row->[1]); |
| 534 | print OUT $row->[1]; |
| 535 | print OUT "</td>\n"; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 536 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 537 | # Update the file prefix. |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 538 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 539 | my $fname = $row->[2]; |
| 540 | if (defined $regex) { |
| 541 | $fname =~ s/$regex//; |
| 542 | UpdateInFilePath("$Dir/$ReportFile", $InFileRegex, $InFilePrefix) |
| 543 | } |
Ted Kremenek | 3e56e0b | 2008-05-02 23:40:49 +0000 | [diff] [blame] | 544 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 545 | print OUT "<td>$fname</td>\n"; |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 546 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 547 | # Print the rest of the columns. |
| 548 | for my $j ( 3 .. $#{$row} ) { |
| 549 | print OUT "<td>$row->[$j]</td>\n" |
| 550 | } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 551 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 552 | # Emit the "View" link. |
| 553 | print OUT " <td class=\"View\"><a href=\"$ReportFile#EndPath\">View</a></td>\n"; |
Ted Kremenek | 3cea9ee | 2008-07-30 17:58:08 +0000 | [diff] [blame] | 554 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 555 | # End the row. |
| 556 | print OUT "</tr>\n"; |
| 557 | } |
| 558 | |
| 559 | print OUT "</table>\n"; |
| 560 | } |
| 561 | |
| 562 | if ($Crashes) { |
| 563 | # Read the crash directory for files. |
| 564 | opendir(DIR, "$Dir/crashes"); |
| 565 | my @files = grep { /[.]info$/ } readdir(DIR); |
| 566 | closedir(DIR); |
| 567 | |
| 568 | if (scalar(@files)) { |
| 569 | print OUT <<ENDTEXT; |
Ted Kremenek | 5d31f83 | 2008-08-18 18:38:29 +0000 | [diff] [blame] | 570 | <h3>Analyzer Failures</h3> |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 571 | |
Ted Kremenek | 5d31f83 | 2008-08-18 18:38:29 +0000 | [diff] [blame] | 572 | <p>The analyzer had problems processing the following files:</p> |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 573 | |
| 574 | <table> |
Ted Kremenek | 5d31f83 | 2008-08-18 18:38:29 +0000 | [diff] [blame] | 575 | <thead><tr><td>Problem</td><td>Source File</td><td>Preprocessed File</td></tr></thead> |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 576 | ENDTEXT |
| 577 | |
| 578 | foreach my $file (sort @files) { |
| 579 | $file =~ /(.+).info$/; |
| 580 | # Get the preprocessed file. |
| 581 | my $ppfile = $1; |
| 582 | # Open the info file and get the name of the source file. |
| 583 | open (INFO, "$Dir/crashes/$file") or |
| 584 | die "Cannot open $Dir/crashes/$file\n"; |
| 585 | my $srcfile = <INFO>; |
Ted Kremenek | 5d31f83 | 2008-08-18 18:38:29 +0000 | [diff] [blame] | 586 | chomp $srcfile; |
| 587 | my $problem = <INFO>; |
| 588 | chomp $problem; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 589 | close (INFO); |
| 590 | # Print the information in the table. |
Ted Kremenek | 5d31f83 | 2008-08-18 18:38:29 +0000 | [diff] [blame] | 591 | print OUT "<tr><td>$problem</td><td>$srcfile</td><td class=\"View\"><a href=\"crashes/$ppfile\">View</a></td></tr>\n"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | print OUT <<ENDTEXT; |
| 595 | </table> |
| 596 | <p>Please consider submitting preprocessed files as <a href="http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs">bug reports</a>.</p> |
| 597 | ENDTEXT |
| 598 | } |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 601 | print OUT "</body></html>\n"; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 602 | close(OUT); |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 603 | CopyJS($Dir); |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 604 | |
| 605 | # Make sure $Dir and $BaseDir are world readable/executable. |
| 606 | system("chmod", "755", $Dir); |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 607 | if (defined $BaseDir) { system("chmod", "755", $BaseDir); } |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 608 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 609 | my $Num = scalar(@Index); |
Ted Kremenek | 150c212 | 2008-07-11 19:15:05 +0000 | [diff] [blame] | 610 | Diag("$Num bugs found.\n"); |
| 611 | if ($Num > 0 && -r "$Dir/index.html") { |
| 612 | Diag("Open '$Dir/index.html' to examine bug reports.\n"); |
| 613 | } |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 614 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 615 | DiagCrashes($Dir) if ($Crashes); |
| 616 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 617 | return $Num; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | ##----------------------------------------------------------------------------## |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 621 | # RunBuildCommand - Run the build command. |
| 622 | ##----------------------------------------------------------------------------## |
| 623 | |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 624 | sub AddIfNotPresent { |
| 625 | my $Args = shift; |
| 626 | my $Arg = shift; |
| 627 | my $found = 0; |
| 628 | |
| 629 | foreach my $k (@$Args) { |
| 630 | if ($k eq $Arg) { |
| 631 | $found = 1; |
| 632 | last; |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | if ($found == 0) { |
| 637 | push @$Args, $Arg; |
| 638 | } |
| 639 | } |
| 640 | |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 641 | sub RunBuildCommand { |
| 642 | |
| 643 | my $Args = shift; |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 644 | my $IgnoreErrors = shift; |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 645 | my $Cmd = $Args->[0]; |
Ted Kremenek | 6195c37 | 2008-06-02 21:52:47 +0000 | [diff] [blame] | 646 | my $CCAnalyzer = shift; |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 647 | |
Ted Kremenek | 3301cb1 | 2008-06-30 18:18:16 +0000 | [diff] [blame] | 648 | # Get only the part of the command after the last '/'. |
| 649 | if ($Cmd =~ /\/([^\/]+)$/) { |
| 650 | $Cmd = $1; |
| 651 | } |
| 652 | |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 653 | if ($Cmd eq "gcc" or $Cmd eq "cc" or $Cmd eq "llvm-gcc" |
| 654 | or $Cmd eq "ccc-analyzer") { |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 655 | shift @$Args; |
Ted Kremenek | 6195c37 | 2008-06-02 21:52:47 +0000 | [diff] [blame] | 656 | unshift @$Args, $CCAnalyzer; |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 657 | } |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 658 | elsif ($IgnoreErrors) { |
| 659 | if ($Cmd eq "make" or $Cmd eq "gmake") { |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 660 | AddIfNotPresent($Args,"-k"); |
Ted Kremenek | 8912b54 | 2008-05-13 21:28:02 +0000 | [diff] [blame] | 661 | AddIfNotPresent($Args,"-i"); |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 662 | } |
| 663 | elsif ($Cmd eq "xcodebuild") { |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 664 | AddIfNotPresent($Args,"-PBXBuildsContinueAfterErrors=YES"); |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 665 | } |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 666 | } |
| 667 | |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 668 | if ($Cmd eq "xcodebuild") { |
Ted Kremenek | cfd4c7b | 2008-05-23 22:18:16 +0000 | [diff] [blame] | 669 | # Disable distributed builds for xcodebuild. |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 670 | AddIfNotPresent($Args,"-nodistribute"); |
Ted Kremenek | cfd4c7b | 2008-05-23 22:18:16 +0000 | [diff] [blame] | 671 | |
| 672 | # Disable PCH files until clang supports them. |
| 673 | AddIfNotPresent($Args,"GCC_PRECOMPILE_PREFIX_HEADER=NO"); |
Ted Kremenek | 915e972 | 2008-05-27 23:18:07 +0000 | [diff] [blame] | 674 | |
| 675 | # When 'CC' is set, xcodebuild uses it to do all linking, even if we are |
| 676 | # linking C++ object files. Set 'LDPLUSPLUS' so that xcodebuild uses 'g++' |
| 677 | # when linking such files. |
| 678 | my $LDPLUSPLUS = `which g++`; |
| 679 | $LDPLUSPLUS =~ s/\015?\012//; # strip newlines |
| 680 | $ENV{'LDPLUSPLUS'} = $LDPLUSPLUS; |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 681 | } |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 682 | |
Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 683 | return system(@$Args); |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 684 | } |
| 685 | |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 686 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 687 | # DisplayHelp - Utility function to display all help options. |
| 688 | ##----------------------------------------------------------------------------## |
| 689 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 690 | sub DisplayHelp { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 691 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 692 | print <<ENDTEXT; |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 693 | USAGE: $Prog [options] <build command> [build options] |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 694 | |
Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 695 | ENDTEXT |
| 696 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 697 | if (defined $BuildName) { |
Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 698 | print "ANALYZER BUILD: $BuildName ($BuildDate)\n\n"; |
| 699 | } |
| 700 | |
| 701 | print <<ENDTEXT; |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 702 | OPTIONS: |
| 703 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 704 | -o - Target directory for HTML report files. Subdirectories |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 705 | will be created as needed to represent separate "runs" of |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 706 | the analyzer. If this option is not specified, a directory |
| 707 | is created in /tmp to store the reports. |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 708 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 709 | -h - Display this message. |
| 710 | --help |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 711 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 712 | -k - Add a "keep on going" option to the specified build command. |
| 713 | --keep-going This option currently supports make and xcodebuild. |
Ted Kremenek | f02e8db | 2008-04-02 16:41:25 +0000 | [diff] [blame] | 714 | This is a convenience option; one can specify this |
| 715 | behavior directly using build options. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 716 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 717 | --status-bugs - By default, the exit status of $Prog is the same as the |
| 718 | executed build command. Specifying this option causes the |
| 719 | exit status of $Prog to be 1 if it found potential bugs |
| 720 | and 0 otherwise. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 721 | |
Ted Kremenek | f17ef3c | 2008-08-21 21:47:09 +0000 | [diff] [blame^] | 722 | --use-cc [compiler path] - By default, $Prog uses 'gcc' to compile |
| 723 | --use-cc=[compiler path] your code. This option specifies what compiler |
| 724 | to use for regular code compilation. |
| 725 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 726 | -v - Verbose output from $Prog and the analyzer. |
| 727 | A second and third "-v" increases verbosity. |
| 728 | |
| 729 | -V - View analysis results in a web browser when the build |
| 730 | --view completes. |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 731 | |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 732 | ENDTEXT |
| 733 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 734 | print " Available Source Code Analyses (multiple analyses may be specified):\n\n"; |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 735 | |
| 736 | foreach my $Analysis (sort keys %AvailableAnalyses) { |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 737 | if (defined $AnalysesDefaultEnabled{$Analysis}) { |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 738 | print " (+)"; |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 739 | } |
| 740 | else { |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 741 | print " "; |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | print " $Analysis $AvailableAnalyses{$Analysis}\n"; |
| 745 | } |
| 746 | |
| 747 | print <<ENDTEXT |
| 748 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 749 | NOTE: "(+)" indicates that an analysis is enabled by default unless one |
| 750 | or more analysis options are specified |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 751 | |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 752 | BUILD OPTIONS |
| 753 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 754 | You can specify any build option acceptable to the build command. |
Ted Kremenek | 39eefde | 2008-04-02 16:47:27 +0000 | [diff] [blame] | 755 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 756 | EXAMPLE |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 757 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 758 | $Prog -o /tmp/myhtmldir make -j4 |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 759 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 760 | The above example causes analysis reports to be deposited into |
| 761 | a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option. |
| 762 | A different subdirectory is created each time $Prog analyzes a project. |
| 763 | The analyzer should support most parallel builds, but not distributed builds. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 764 | |
| 765 | ENDTEXT |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | ##----------------------------------------------------------------------------## |
| 769 | # Process command-line arguments. |
| 770 | ##----------------------------------------------------------------------------## |
| 771 | |
| 772 | my $HtmlDir; # Parent directory to store HTML files. |
| 773 | my $IgnoreErrors = 0; # Ignore build errors. |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 774 | my $ViewResults = 0; # View results when the build terminates. |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 775 | my $ExitStatusFoundBugs = 0; # Exit status reflects whether bugs were found |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 776 | my @AnalysesToRun; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 777 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 778 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 779 | if (!@ARGV) { |
| 780 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 781 | exit 1; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | while (@ARGV) { |
| 785 | |
| 786 | # Scan for options we recognize. |
| 787 | |
| 788 | my $arg = $ARGV[0]; |
| 789 | |
Sam Bishop | 2f2418e | 2008-04-03 14:29:47 +0000 | [diff] [blame] | 790 | if ($arg eq "-h" or $arg eq "--help") { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 791 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 792 | exit 0; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 795 | if (defined $AvailableAnalyses{$arg}) { |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 796 | shift @ARGV; |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 797 | push @AnalysesToRun, $arg; |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 798 | next; |
| 799 | } |
| 800 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 801 | if ($arg eq "-o") { |
| 802 | shift @ARGV; |
| 803 | |
| 804 | if (!@ARGV) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 805 | DieDiag("'-o' option requires a target directory name.\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | $HtmlDir = shift @ARGV; |
| 809 | next; |
| 810 | } |
| 811 | |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 812 | if ($arg eq "-k" or $arg eq "--keep-going") { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 813 | shift @ARGV; |
| 814 | $IgnoreErrors = 1; |
| 815 | next; |
| 816 | } |
| 817 | |
Ted Kremenek | f17ef3c | 2008-08-21 21:47:09 +0000 | [diff] [blame^] | 818 | if ($arg =~ /^--use-cc(=(.+))?$/) { |
| 819 | shift @ARGV; |
| 820 | my $cc; |
| 821 | |
| 822 | if ($2 eq "") { |
| 823 | if (!@ARGV) { |
| 824 | DieDiag("'--use-cc' option requires a compiler executable name.\n"); |
| 825 | } |
| 826 | $cc = shift @ARGV; |
| 827 | } |
| 828 | else { |
| 829 | $cc = $2; |
| 830 | } |
| 831 | |
| 832 | $ENV{"CCC_CC"} = $cc; |
| 833 | next; |
| 834 | } |
| 835 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 836 | if ($arg eq "-v") { |
| 837 | shift @ARGV; |
| 838 | $Verbose++; |
| 839 | next; |
| 840 | } |
| 841 | |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 842 | if ($arg eq "-V" or $arg eq "--view") { |
| 843 | shift @ARGV; |
| 844 | $ViewResults = 1; |
| 845 | next; |
| 846 | } |
| 847 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 848 | if ($arg eq "--status-bugs") { |
| 849 | shift @ARGV; |
| 850 | $ExitStatusFoundBugs = 1; |
| 851 | next; |
| 852 | } |
| 853 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 854 | DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/); |
Ted Kremenek | 0062ad4 | 2008-04-02 16:35:01 +0000 | [diff] [blame] | 855 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 856 | last; |
| 857 | } |
| 858 | |
| 859 | if (!@ARGV) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 860 | Diag("No build command specified.\n\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 861 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 862 | exit 1; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | # Determine the output directory for the HTML reports. |
Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 866 | my $BaseDir = $HtmlDir; |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 867 | $HtmlDir = GetHTMLRunDir($HtmlDir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 868 | |
| 869 | # Set the appropriate environment variables. |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 870 | SetHtmlEnv(\@ARGV, $HtmlDir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 871 | |
Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 872 | my $Cmd = "$RealBin/ccc-analyzer"; |
| 873 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 874 | DieDiag("Executable 'ccc-analyzer' does not exist at '$Cmd'\n") |
Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 875 | if (! -x $Cmd); |
Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 876 | |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 877 | if (! -x $ClangSB) { |
| 878 | Diag("'clang' executable not found in '$RealBin'.\n"); |
| 879 | Diag("Using 'clang' from path.\n"); |
Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 880 | } |
Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 881 | |
Ted Kremenek | 4f4b17d | 2008-04-03 20:08:18 +0000 | [diff] [blame] | 882 | $ENV{'CC'} = $Cmd; |
Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 883 | $ENV{'CLANG'} = $Clang; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 884 | |
| 885 | if ($Verbose >= 2) { |
| 886 | $ENV{'CCC_ANALYZER_VERBOSE'} = 1; |
| 887 | } |
| 888 | |
Ted Kremenek | a9525c9 | 2008-05-12 22:07:14 +0000 | [diff] [blame] | 889 | if ($Verbose >= 3) { |
| 890 | $ENV{'CCC_ANALYZER_LOG'} = 1; |
| 891 | } |
| 892 | |
Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 893 | if (scalar(@AnalysesToRun) == 0) { |
| 894 | foreach my $key (keys %AnalysesDefaultEnabled) { |
| 895 | push @AnalysesToRun,$key; |
| 896 | } |
Ted Kremenek | 0100678 | 2008-07-02 23:16:10 +0000 | [diff] [blame] | 897 | } |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 898 | |
Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 899 | $ENV{'CCC_ANALYZER_ANALYSIS'} = join ' ',@AnalysesToRun; |
| 900 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 901 | # Run the build. |
Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 902 | my $ExitStatus = RunBuildCommand(\@ARGV, $IgnoreErrors, $Cmd); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 903 | |
| 904 | # Postprocess the HTML directory. |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 905 | my $NumBugs = Postprocess($HtmlDir, $BaseDir); |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 906 | |
| 907 | if ($ViewResults and -r "$HtmlDir/index.html") { |
| 908 | # Only works on Mac OS X (for now). |
| 909 | print "Viewing analysis results: '$HtmlDir/index.html'\n"; |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 910 | system("open", "$HtmlDir/index.html"); |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 911 | } |
Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 912 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 913 | if ($ExitStatusFoundBugs) { |
| 914 | exit 1 if ($NumBugs > 0); |
| 915 | exit 0; |
| 916 | } |
| 917 | |
Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 918 | exit $ExitStatus; |
| 919 | |