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