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