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