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