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