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