| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl | 
|  | 2 | # | 
|  | 3 | #                     The LLVM Compiler Infrastructure | 
|  | 4 | # | 
|  | 5 | # This file is distributed under the University of Illinois Open Source | 
|  | 6 | # License. See LICENSE.TXT for details. | 
|  | 7 | # | 
|  | 8 | ##===----------------------------------------------------------------------===## | 
|  | 9 | # | 
|  | 10 | # A script designed to wrap a build so that all calls to gcc are intercepted | 
|  | 11 | # and piped to the static analyzer. | 
|  | 12 | # | 
|  | 13 | ##===----------------------------------------------------------------------===## | 
|  | 14 |  | 
|  | 15 | use strict; | 
|  | 16 | use warnings; | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 17 | use FindBin qw($RealBin); | 
| Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 18 | use Digest::MD5; | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 19 | use File::Basename; | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 20 | use Term::ANSIColor; | 
|  | 21 | use Term::ANSIColor qw(:constants); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 22 |  | 
|  | 23 | my $Verbose = 0;       # Verbose output from this script. | 
|  | 24 | my $Prog = "scan-build"; | 
| Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 25 | my $BuildName; | 
|  | 26 | my $BuildDate; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 27 |  | 
| Ted Kremenek | f2f8d6c | 2008-06-17 03:06:59 +0000 | [diff] [blame] | 28 | my $UseColor = ((($ENV{'TERM'} eq 'xterm-color') and -t STDOUT) | 
|  | 29 | and defined($ENV{'SCAN_BUILD_COLOR'})); | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 30 |  | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 31 | ##----------------------------------------------------------------------------## | 
|  | 32 | # Diagnostics | 
|  | 33 | ##----------------------------------------------------------------------------## | 
|  | 34 |  | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 35 | sub Diag { | 
|  | 36 | if ($UseColor) { | 
|  | 37 | print BOLD, MAGENTA "$Prog: @_"; | 
|  | 38 | print RESET; | 
|  | 39 | } | 
|  | 40 | else { | 
|  | 41 | print "$Prog: @_"; | 
|  | 42 | } | 
|  | 43 | } | 
|  | 44 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 45 | sub DiagCrashes { | 
|  | 46 | my $Dir = shift; | 
|  | 47 | Diag ("The analyzer crashed on some source files.\n"); | 
|  | 48 | Diag ("Preprocessed versions of crashed files were depositied in '$Dir/crashes'.\n"); | 
|  | 49 | Diag ("Please consider submitting a bug report using these files:\n"); | 
|  | 50 | Diag ("  http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs\n") | 
|  | 51 | } | 
|  | 52 |  | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 53 | sub DieDiag { | 
|  | 54 | if ($UseColor) { | 
|  | 55 | print BOLD, RED "$Prog: "; | 
|  | 56 | print RESET, RED @_; | 
|  | 57 | print RESET; | 
|  | 58 | } | 
|  | 59 | else { | 
|  | 60 | print "$Prog: ", @_; | 
|  | 61 | } | 
|  | 62 | exit(0); | 
|  | 63 | } | 
|  | 64 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 65 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 66 | # Some initial preprocessing of Clang options. | 
|  | 67 | ##----------------------------------------------------------------------------## | 
|  | 68 |  | 
|  | 69 | my $ClangSB = "$RealBin/clang"; | 
|  | 70 | my $Clang = $ClangSB; | 
|  | 71 |  | 
|  | 72 | if (! -x $ClangSB) { | 
|  | 73 | $Clang = "clang"; | 
|  | 74 | } | 
|  | 75 |  | 
|  | 76 | my %AvailableAnalyses; | 
|  | 77 |  | 
|  | 78 | # Query clang for analysis options. | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 79 | open(PIPE, "-|", $Clang, "--help") or | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 80 | DieDiag("Cannot execute '$Clang'"); | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 81 |  | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 82 | my $FoundAnalysis = 0; | 
|  | 83 |  | 
|  | 84 | while(<PIPE>) { | 
|  | 85 | if ($FoundAnalysis == 0) { | 
|  | 86 | if (/Available Source Code Analyses/) { | 
|  | 87 | $FoundAnalysis = 1; | 
|  | 88 | } | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 89 |  | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 90 | next; | 
|  | 91 | } | 
|  | 92 |  | 
|  | 93 | if (/^\s\s\s\s([^\s]+)\s(.+)$/) { | 
|  | 94 | next if ($1 =~ /-dump/ or $1 =~ /-view/ | 
|  | 95 | or $1 =~ /-checker-simple/ or $1 =~ /-warn-uninit/); | 
|  | 96 |  | 
|  | 97 | $AvailableAnalyses{$1} = $2; | 
|  | 98 | next; | 
|  | 99 | } | 
|  | 100 |  | 
|  | 101 | last; | 
|  | 102 | } | 
|  | 103 |  | 
|  | 104 | close (PIPE); | 
|  | 105 |  | 
|  | 106 | my %AnalysesDefaultEnabled = ( | 
|  | 107 | '-warn-dead-stores' => 1, | 
|  | 108 | '-checker-cfref' => 1, | 
| Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 109 | '-warn-objc-methodsigs' => 1, | 
| Ted Kremenek | bde3a05 | 2008-07-25 20:35:01 +0000 | [diff] [blame] | 110 | '-warn-objc-missing-dealloc' => 1, | 
|  | 111 | '-warn-objc-unused-ivars' => 1 | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 112 | ); | 
|  | 113 |  | 
|  | 114 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 115 | # GetHTMLRunDir - Construct an HTML directory name for the current sub-run. | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 116 | ##----------------------------------------------------------------------------## | 
|  | 117 |  | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 118 | sub GetHTMLRunDir { | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 119 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 120 | die "Not enough arguments." if (@_ == 0); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 121 | my $Dir = shift @_; | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 122 |  | 
|  | 123 | my $TmpMode = 0; | 
|  | 124 | if (!defined $Dir) { | 
|  | 125 | $Dir = "/tmp"; | 
|  | 126 | $TmpMode = 1; | 
|  | 127 | } | 
|  | 128 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 129 | # Get current date and time. | 
|  | 130 |  | 
|  | 131 | my @CurrentTime = localtime(); | 
|  | 132 |  | 
|  | 133 | my $year  = $CurrentTime[5] + 1900; | 
|  | 134 | my $day   = $CurrentTime[3]; | 
|  | 135 | my $month = $CurrentTime[4] + 1; | 
|  | 136 |  | 
| Ted Kremenek | 9d7405f | 2008-05-14 17:23:56 +0000 | [diff] [blame] | 137 | my $DateString = sprintf("%d-%02d-%02d", $year, $month, $day); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 138 |  | 
|  | 139 | # Determine the run number. | 
|  | 140 |  | 
|  | 141 | my $RunNumber; | 
|  | 142 |  | 
|  | 143 | if (-d $Dir) { | 
|  | 144 |  | 
|  | 145 | if (! -r $Dir) { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 146 | DieDiag("directory '$Dir' exists but is not readable.\n"); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 147 | } | 
|  | 148 |  | 
|  | 149 | # Iterate over all files in the specified directory. | 
|  | 150 |  | 
|  | 151 | my $max = 0; | 
|  | 152 |  | 
|  | 153 | opendir(DIR, $Dir); | 
| Ted Kremenek | 29da6c5 | 2008-08-07 17:57:34 +0000 | [diff] [blame] | 154 | my @FILES = grep { -d "$Dir/$_" } readdir(DIR); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 155 | closedir(DIR); | 
|  | 156 |  | 
|  | 157 | foreach my $f (@FILES) { | 
|  | 158 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 159 | # Strip the prefix '$Prog-' if we are dumping files to /tmp. | 
|  | 160 | if ($TmpMode) { | 
|  | 161 | next if (!($f =~ /^$Prog-(.+)/)); | 
|  | 162 | $f = $1; | 
|  | 163 | } | 
|  | 164 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 165 | my @x = split/-/, $f; | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 166 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 167 | next if (scalar(@x) != 4); | 
|  | 168 | next if ($x[0] != $year); | 
|  | 169 | next if ($x[1] != $month); | 
|  | 170 | next if ($x[2] != $day); | 
|  | 171 |  | 
|  | 172 | if ($x[3] > $max) { | 
|  | 173 | $max = $x[3]; | 
|  | 174 | } | 
|  | 175 | } | 
|  | 176 |  | 
|  | 177 | $RunNumber = $max + 1; | 
|  | 178 | } | 
|  | 179 | else { | 
|  | 180 |  | 
|  | 181 | if (-x $Dir) { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 182 | DieDiag("'$Dir' exists but is not a directory.\n"); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 183 | } | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 184 |  | 
|  | 185 | if ($TmpMode) { | 
|  | 186 | DieDiag("The directory '/tmp' does not exist or cannot be accessed."); | 
|  | 187 | } | 
|  | 188 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 189 | # $Dir does not exist.  It will be automatically created by the | 
|  | 190 | # clang driver.  Set the run number to 1. | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 191 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 192 | $RunNumber = 1; | 
|  | 193 | } | 
|  | 194 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 195 | die "RunNumber must be defined!" if (!defined $RunNumber); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 196 |  | 
|  | 197 | # Append the run number. | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 198 | if ($TmpMode) { | 
|  | 199 | my $NewDir = "$Dir/$Prog-$DateString-$RunNumber"; | 
|  | 200 | mkdir $NewDir; | 
|  | 201 | return $NewDir; | 
|  | 202 | } | 
|  | 203 | else { | 
|  | 204 | return "$Dir/$DateString-$RunNumber"; | 
|  | 205 | } | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 206 | } | 
|  | 207 |  | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 208 | sub SetHtmlEnv { | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 209 |  | 
|  | 210 | die "Wrong number of arguments." if (scalar(@_) != 2); | 
|  | 211 |  | 
|  | 212 | my $Args = shift; | 
|  | 213 | my $Dir = shift; | 
|  | 214 |  | 
|  | 215 | die "No build command." if (scalar(@$Args) == 0); | 
|  | 216 |  | 
|  | 217 | my $Cmd = $$Args[0]; | 
|  | 218 |  | 
|  | 219 | if ($Cmd =~ /configure/) { | 
|  | 220 | return; | 
|  | 221 | } | 
|  | 222 |  | 
|  | 223 | if ($Verbose) { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 224 | Diag("Emitting reports for this run to '$Dir'.\n"); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 225 | } | 
|  | 226 |  | 
|  | 227 | $ENV{'CCC_ANALYZER_HTML'} = $Dir; | 
|  | 228 | } | 
|  | 229 |  | 
|  | 230 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 231 | # ComputeDigest - Compute a digest of the specified file. | 
|  | 232 | ##----------------------------------------------------------------------------## | 
|  | 233 |  | 
|  | 234 | sub ComputeDigest { | 
|  | 235 | my $FName = shift; | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 236 | DieDiag("Cannot read $FName to compute Digest.\n") if (! -r $FName); | 
| Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 237 |  | 
|  | 238 | # Use Digest::MD5.  We don't have to be cryptographically secure.  We're | 
| Ted Kremenek | 7ea02e6 | 2008-04-19 18:07:44 +0000 | [diff] [blame] | 239 | # just looking for duplicate files that come from a non-malicious source. | 
|  | 240 | # We use Digest::MD5 because it is a standard Perl module that should | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 241 | # come bundled on most systems. | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 242 | open(FILE, $FName) or DieDiag("Cannot open $FName when computing Digest.\n"); | 
| Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 243 | binmode FILE; | 
|  | 244 | my $Result = Digest::MD5->new->addfile(*FILE)->hexdigest; | 
|  | 245 | close(FILE); | 
|  | 246 |  | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 247 | # Return the digest. | 
| Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 248 | return $Result; | 
| Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 249 | } | 
|  | 250 |  | 
|  | 251 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 252 | #  UpdatePrefix - Compute the common prefix of files. | 
|  | 253 | ##----------------------------------------------------------------------------## | 
|  | 254 |  | 
|  | 255 | my $Prefix; | 
|  | 256 |  | 
|  | 257 | sub UpdatePrefix { | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 258 | my $x = shift; | 
|  | 259 | my $y = basename($x); | 
|  | 260 | $x =~ s/\Q$y\E$//; | 
|  | 261 |  | 
|  | 262 | # Ignore /usr, /Library, /System, /Developer | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 263 | return if ( $x =~ /^\/usr/ or $x =~ /^\/Library/ | 
|  | 264 | or $x =~ /^\/System/ or $x =~ /^\/Developer/); | 
|  | 265 |  | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 266 | if (!defined $Prefix) { | 
|  | 267 | $Prefix = $x; | 
|  | 268 | return; | 
|  | 269 | } | 
|  | 270 |  | 
|  | 271 | chop $Prefix while (!($x =~ /^$Prefix/)); | 
|  | 272 | } | 
|  | 273 |  | 
|  | 274 | sub GetPrefix { | 
|  | 275 | return $Prefix; | 
|  | 276 | } | 
|  | 277 |  | 
|  | 278 | ##----------------------------------------------------------------------------## | 
|  | 279 | #  UpdateInFilePath - Update the path in the report file. | 
|  | 280 | ##----------------------------------------------------------------------------## | 
|  | 281 |  | 
|  | 282 | sub UpdateInFilePath { | 
|  | 283 | my $fname = shift; | 
|  | 284 | my $regex = shift; | 
|  | 285 | my $newtext = shift; | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 286 |  | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 287 | open (RIN, $fname) or die "cannot open $fname"; | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 288 | open (ROUT, ">", "$fname.tmp") or die "cannot open $fname.tmp"; | 
|  | 289 |  | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 290 | while (<RIN>) { | 
|  | 291 | s/$regex/$newtext/; | 
|  | 292 | print ROUT $_; | 
|  | 293 | } | 
| Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 294 |  | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 295 | close (ROUT); | 
|  | 296 | close (RIN); | 
| Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 297 | system("mv", "$fname.tmp", $fname); | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 298 | } | 
|  | 299 |  | 
|  | 300 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 301 | # ScanFile - Scan a report file for various identifying attributes. | 
|  | 302 | ##----------------------------------------------------------------------------## | 
|  | 303 |  | 
| Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 304 | # Sometimes a source file is scanned more than once, and thus produces | 
|  | 305 | # multiple error reports.  We use a cache to solve this problem. | 
|  | 306 |  | 
|  | 307 | my %AlreadyScanned; | 
|  | 308 |  | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 309 | sub ScanFile { | 
|  | 310 |  | 
|  | 311 | my $Index = shift; | 
|  | 312 | my $Dir = shift; | 
|  | 313 | my $FName = shift; | 
|  | 314 |  | 
| Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 315 | # Compute a digest for the report file.  Determine if we have already | 
|  | 316 | # scanned a file that looks just like it. | 
|  | 317 |  | 
|  | 318 | my $digest = ComputeDigest("$Dir/$FName"); | 
|  | 319 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 320 | if (defined $AlreadyScanned{$digest}) { | 
| Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 321 | # Redundant file.  Remove it. | 
| Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 322 | system ("rm", "-f", "$Dir/$FName"); | 
| Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 323 | return; | 
|  | 324 | } | 
|  | 325 |  | 
|  | 326 | $AlreadyScanned{$digest} = 1; | 
|  | 327 |  | 
| Ted Kremenek | 809709f | 2008-04-18 16:58:34 +0000 | [diff] [blame] | 328 | # At this point the report file is not world readable.  Make it happen. | 
| Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 329 | system ("chmod", "644", "$Dir/$FName"); | 
| Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 330 |  | 
|  | 331 | # Scan the report file for tags. | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 332 | open(IN, "$Dir/$FName") or DieDiag("Cannot open '$Dir/$FName'\n"); | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 333 |  | 
|  | 334 | my $BugDesc = ""; | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 335 | my $BugFile = ""; | 
|  | 336 | my $BugPathLength = 1; | 
|  | 337 | my $BugLine = 0; | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 338 |  | 
|  | 339 | while (<IN>) { | 
|  | 340 |  | 
|  | 341 | if (/<!-- BUGDESC (.*) -->$/) { | 
|  | 342 | $BugDesc = $1; | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 343 | } | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 344 | elsif (/<!-- BUGFILE (.*) -->$/) { | 
|  | 345 | $BugFile = $1; | 
| Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 346 | UpdatePrefix($BugFile); | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 347 | } | 
|  | 348 | elsif (/<!-- BUGPATHLENGTH (.*) -->$/) { | 
|  | 349 | $BugPathLength = $1; | 
|  | 350 | } | 
|  | 351 | elsif (/<!-- BUGLINE (.*) -->$/) { | 
|  | 352 | $BugLine = $1; | 
|  | 353 | } | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 354 | } | 
|  | 355 |  | 
|  | 356 | close(IN); | 
|  | 357 |  | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 358 | push @$Index,[ $FName, $BugDesc, $BugFile, $BugLine, $BugPathLength ]; | 
|  | 359 | } | 
|  | 360 |  | 
|  | 361 | ##----------------------------------------------------------------------------## | 
|  | 362 | # CopyJS - Copy JavaScript code to target directory. | 
|  | 363 | ##----------------------------------------------------------------------------## | 
|  | 364 |  | 
|  | 365 | sub CopyJS { | 
|  | 366 |  | 
|  | 367 | my $Dir = shift; | 
|  | 368 |  | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 369 | DieDiag("Cannot find 'sorttable.js'.\n") | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 370 | if (! -r "$RealBin/sorttable.js"); | 
|  | 371 |  | 
| Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 372 | system ("cp", "$RealBin/sorttable.js", "$Dir"); | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 373 |  | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 374 | DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n") | 
| Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 375 | if (! -r "$Dir/sorttable.js"); | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 376 | } | 
|  | 377 |  | 
|  | 378 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 379 | # Postprocess - Postprocess the results of an analysis scan. | 
|  | 380 | ##----------------------------------------------------------------------------## | 
|  | 381 |  | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 382 | sub Postprocess { | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 383 |  | 
|  | 384 | my $Dir = shift; | 
| Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 385 | my $BaseDir = shift; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 386 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 387 | die "No directory specified." if (!defined $Dir); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 388 |  | 
|  | 389 | if (! -d $Dir) { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 390 | Diag("No bugs found.\n"); | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 391 | return 0; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 392 | } | 
|  | 393 |  | 
|  | 394 | opendir(DIR, $Dir); | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 395 | my $Crashes = 0; | 
|  | 396 | my @files = grep { if ($_ eq "crashes") { $Crashes++; } | 
|  | 397 | /^report-.*\.html$/; } readdir(DIR); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 398 | closedir(DIR); | 
|  | 399 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 400 | if (scalar(@files) == 0 and $Crashes == 0) { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 401 | Diag("Removing directory '$Dir' because it contains no reports.\n"); | 
| Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 402 | system ("rm", "-fR", $Dir); | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 403 | # Remove the base directory if it contains no files (don't use '-R'). | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 404 | system ("rm", "-f", $BaseDir) if (defined $BaseDir); | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 405 | return 0; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 406 | } | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 407 |  | 
| Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 408 | # Scan each report file and build an index. | 
|  | 409 | my @Index; | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 410 | foreach my $file (@files) { ScanFile(\@Index, $Dir, $file); } | 
|  | 411 |  | 
| Ted Kremenek | 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. | 
|  | 694 | my $LDPLUSPLUS = `which g++`; | 
|  | 695 | $LDPLUSPLUS =~ s/\015?\012//;  # strip newlines | 
|  | 696 | $ENV{'LDPLUSPLUS'} = $LDPLUSPLUS; | 
| Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 697 | } | 
| Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 698 |  | 
| Ted Kremenek | 5a4ddaf | 2008-08-25 20:10:45 +0000 | [diff] [blame] | 699 | return (system(@$Args) >> 8); | 
| Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 700 | } | 
|  | 701 |  | 
| Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 702 | ##----------------------------------------------------------------------------## | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 703 | # DisplayHelp - Utility function to display all help options. | 
|  | 704 | ##----------------------------------------------------------------------------## | 
|  | 705 |  | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 706 | sub DisplayHelp { | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 707 |  | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 708 | print <<ENDTEXT; | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 709 | USAGE: $Prog [options] <build command> [build options] | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 710 |  | 
| Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 711 | ENDTEXT | 
|  | 712 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 713 | if (defined $BuildName) { | 
| Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 714 | print "ANALYZER BUILD: $BuildName ($BuildDate)\n\n"; | 
|  | 715 | } | 
|  | 716 |  | 
|  | 717 | print <<ENDTEXT; | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 718 | OPTIONS: | 
|  | 719 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 720 | -o             - Target directory for HTML report files.  Subdirectories | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 721 | will be created as needed to represent separate "runs" of | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 722 | the analyzer.  If this option is not specified, a directory | 
|  | 723 | is created in /tmp to store the reports. | 
| Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 724 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 725 | -h             - Display this message. | 
|  | 726 | --help | 
| Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 727 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 728 | -k             - Add a "keep on going" option to the specified build command. | 
|  | 729 | --keep-going     This option currently supports make and xcodebuild. | 
| Ted Kremenek | f02e8db | 2008-04-02 16:41:25 +0000 | [diff] [blame] | 730 | This is a convenience option; one can specify this | 
|  | 731 | behavior directly using build options. | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 732 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 733 | --status-bugs  - By default, the exit status of $Prog is the same as the | 
|  | 734 | executed build command.  Specifying this option causes the | 
|  | 735 | exit status of $Prog to be 1 if it found potential bugs | 
|  | 736 | and 0 otherwise. | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 737 |  | 
| Ted Kremenek | f17ef3c | 2008-08-21 21:47:09 +0000 | [diff] [blame] | 738 | --use-cc [compiler path]  - By default, $Prog uses 'gcc' to compile | 
|  | 739 | --use-cc=[compiler path]    your code. This option specifies what compiler | 
|  | 740 | to use for regular code compilation. | 
|  | 741 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 742 | -v             - Verbose output from $Prog and the analyzer. | 
|  | 743 | A second and third "-v" increases verbosity. | 
|  | 744 |  | 
|  | 745 | -V             - View analysis results in a web browser when the build | 
|  | 746 | --view           completes. | 
| Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 747 |  | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 748 |  | 
| Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame^] | 749 | Available Source Code Analyses (multiple analyses may be specified): | 
|  | 750 |  | 
|  | 751 | ENDTEXT | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 752 |  | 
|  | 753 | foreach my $Analysis (sort keys %AvailableAnalyses) { | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 754 | if (defined $AnalysesDefaultEnabled{$Analysis}) { | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 755 | print " (+)"; | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 756 | } | 
|  | 757 | else { | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 758 | print "    "; | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 759 | } | 
|  | 760 |  | 
|  | 761 | print " $Analysis  $AvailableAnalyses{$Analysis}\n"; | 
|  | 762 | } | 
|  | 763 |  | 
|  | 764 | print <<ENDTEXT | 
|  | 765 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 766 | NOTE: "(+)" indicates that an analysis is enabled by default unless one | 
|  | 767 | or more analysis options are specified | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 768 |  | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 769 | BUILD OPTIONS | 
|  | 770 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 771 | You can specify any build option acceptable to the build command. | 
| Ted Kremenek | 39eefde | 2008-04-02 16:47:27 +0000 | [diff] [blame] | 772 |  | 
| Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 773 | EXAMPLE | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 774 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 775 | $Prog -o /tmp/myhtmldir make -j4 | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 776 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 777 | The above example causes analysis reports to be deposited into | 
|  | 778 | a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option. | 
|  | 779 | A different subdirectory is created each time $Prog analyzes a project. | 
|  | 780 | The analyzer should support most parallel builds, but not distributed builds. | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 781 |  | 
|  | 782 | ENDTEXT | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 783 | } | 
|  | 784 |  | 
|  | 785 | ##----------------------------------------------------------------------------## | 
|  | 786 | # Process command-line arguments. | 
|  | 787 | ##----------------------------------------------------------------------------## | 
|  | 788 |  | 
|  | 789 | my $HtmlDir;           # Parent directory to store HTML files. | 
|  | 790 | my $IgnoreErrors = 0;  # Ignore build errors. | 
| Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 791 | my $ViewResults  = 0;  # View results when the build terminates. | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 792 | my $ExitStatusFoundBugs = 0; # Exit status reflects whether bugs were found | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 793 | my @AnalysesToRun; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 794 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 795 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 796 | if (!@ARGV) { | 
|  | 797 | DisplayHelp(); | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 798 | exit 1; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 799 | } | 
|  | 800 |  | 
|  | 801 | while (@ARGV) { | 
|  | 802 |  | 
|  | 803 | # Scan for options we recognize. | 
|  | 804 |  | 
|  | 805 | my $arg = $ARGV[0]; | 
|  | 806 |  | 
| Sam Bishop | 2f2418e | 2008-04-03 14:29:47 +0000 | [diff] [blame] | 807 | if ($arg eq "-h" or $arg eq "--help") { | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 808 | DisplayHelp(); | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 809 | exit 0; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 810 | } | 
|  | 811 |  | 
| Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 812 | if (defined $AvailableAnalyses{$arg}) { | 
| Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 813 | shift @ARGV; | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 814 | push @AnalysesToRun, $arg; | 
| Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 815 | next; | 
|  | 816 | } | 
|  | 817 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 818 | if ($arg eq "-o") { | 
|  | 819 | shift @ARGV; | 
|  | 820 |  | 
|  | 821 | if (!@ARGV) { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 822 | DieDiag("'-o' option requires a target directory name.\n"); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 823 | } | 
|  | 824 |  | 
|  | 825 | $HtmlDir = shift @ARGV; | 
|  | 826 | next; | 
|  | 827 | } | 
|  | 828 |  | 
| Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 829 | if ($arg eq "-k" or $arg eq "--keep-going") { | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 830 | shift @ARGV; | 
|  | 831 | $IgnoreErrors = 1; | 
|  | 832 | next; | 
|  | 833 | } | 
|  | 834 |  | 
| Ted Kremenek | f17ef3c | 2008-08-21 21:47:09 +0000 | [diff] [blame] | 835 | if ($arg =~ /^--use-cc(=(.+))?$/) { | 
|  | 836 | shift @ARGV; | 
|  | 837 | my $cc; | 
|  | 838 |  | 
|  | 839 | if ($2 eq "") { | 
|  | 840 | if (!@ARGV) { | 
|  | 841 | DieDiag("'--use-cc' option requires a compiler executable name.\n"); | 
|  | 842 | } | 
|  | 843 | $cc = shift @ARGV; | 
|  | 844 | } | 
|  | 845 | else { | 
|  | 846 | $cc = $2; | 
|  | 847 | } | 
|  | 848 |  | 
|  | 849 | $ENV{"CCC_CC"} = $cc; | 
|  | 850 | next; | 
|  | 851 | } | 
|  | 852 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 853 | if ($arg eq "-v") { | 
|  | 854 | shift @ARGV; | 
|  | 855 | $Verbose++; | 
|  | 856 | next; | 
|  | 857 | } | 
|  | 858 |  | 
| Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 859 | if ($arg eq "-V" or $arg eq "--view") { | 
|  | 860 | shift @ARGV; | 
|  | 861 | $ViewResults = 1; | 
|  | 862 | next; | 
|  | 863 | } | 
|  | 864 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 865 | if ($arg eq "--status-bugs") { | 
|  | 866 | shift @ARGV; | 
|  | 867 | $ExitStatusFoundBugs = 1; | 
|  | 868 | next; | 
|  | 869 | } | 
|  | 870 |  | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 871 | DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/); | 
| Ted Kremenek | 0062ad4 | 2008-04-02 16:35:01 +0000 | [diff] [blame] | 872 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 873 | last; | 
|  | 874 | } | 
|  | 875 |  | 
|  | 876 | if (!@ARGV) { | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 877 | Diag("No build command specified.\n\n"); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 878 | DisplayHelp(); | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 879 | exit 1; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 880 | } | 
|  | 881 |  | 
|  | 882 | # Determine the output directory for the HTML reports. | 
| Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 883 | my $BaseDir = $HtmlDir; | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 884 | $HtmlDir = GetHTMLRunDir($HtmlDir); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 885 |  | 
|  | 886 | # Set the appropriate environment variables. | 
| Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 887 | SetHtmlEnv(\@ARGV, $HtmlDir); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 888 |  | 
| Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 889 | my $Cmd = "$RealBin/ccc-analyzer"; | 
|  | 890 |  | 
| Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 891 | DieDiag("Executable 'ccc-analyzer' does not exist at '$Cmd'\n") | 
| Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 892 | if (! -x $Cmd); | 
| Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 893 |  | 
| Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 894 | if (! -x $ClangSB) { | 
|  | 895 | Diag("'clang' executable not found in '$RealBin'.\n"); | 
|  | 896 | Diag("Using 'clang' from path.\n"); | 
| Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 897 | } | 
| Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 898 |  | 
| Ted Kremenek | 4f4b17d | 2008-04-03 20:08:18 +0000 | [diff] [blame] | 899 | $ENV{'CC'} = $Cmd; | 
| Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 900 | $ENV{'CLANG'} = $Clang; | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 901 |  | 
|  | 902 | if ($Verbose >= 2) { | 
|  | 903 | $ENV{'CCC_ANALYZER_VERBOSE'} = 1; | 
|  | 904 | } | 
|  | 905 |  | 
| Ted Kremenek | a9525c9 | 2008-05-12 22:07:14 +0000 | [diff] [blame] | 906 | if ($Verbose >= 3) { | 
|  | 907 | $ENV{'CCC_ANALYZER_LOG'} = 1; | 
|  | 908 | } | 
|  | 909 |  | 
| Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 910 | if (scalar(@AnalysesToRun) == 0) { | 
|  | 911 | foreach my $key (keys %AnalysesDefaultEnabled) { | 
|  | 912 | push @AnalysesToRun,$key; | 
|  | 913 | } | 
| Ted Kremenek | 0100678 | 2008-07-02 23:16:10 +0000 | [diff] [blame] | 914 | } | 
| Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 915 |  | 
| Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 916 | $ENV{'CCC_ANALYZER_ANALYSIS'} = join ' ',@AnalysesToRun; | 
|  | 917 |  | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 918 | # Run the build. | 
| Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 919 | my $ExitStatus = RunBuildCommand(\@ARGV, $IgnoreErrors, $Cmd); | 
| Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 920 |  | 
|  | 921 | # Postprocess the HTML directory. | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 922 | my $NumBugs = Postprocess($HtmlDir, $BaseDir); | 
| Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 923 |  | 
|  | 924 | if ($ViewResults and -r "$HtmlDir/index.html") { | 
|  | 925 | # Only works on Mac OS X (for now). | 
|  | 926 | print "Viewing analysis results: '$HtmlDir/index.html'\n"; | 
| Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 927 | system("open", "$HtmlDir/index.html"); | 
| Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 928 | } | 
| Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 929 |  | 
| Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 930 | if ($ExitStatusFoundBugs) { | 
|  | 931 | exit 1 if ($NumBugs > 0); | 
|  | 932 | exit 0; | 
|  | 933 | } | 
|  | 934 |  | 
| Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 935 | exit $ExitStatus; | 
|  | 936 |  |