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