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 | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 19 | |
| 20 | my $Verbose = 0; # Verbose output from this script. |
| 21 | my $Prog = "scan-build"; |
| 22 | |
| 23 | ##----------------------------------------------------------------------------## |
| 24 | # GetHTMLRunDir - Construct an HTML directory name for the current run. |
| 25 | ##----------------------------------------------------------------------------## |
| 26 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 27 | sub GetHTMLRunDir { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 28 | |
| 29 | die "Not enough arguments." if (@_ == 0); |
| 30 | |
| 31 | my $Dir = shift @_; |
| 32 | |
| 33 | # Get current date and time. |
| 34 | |
| 35 | my @CurrentTime = localtime(); |
| 36 | |
| 37 | my $year = $CurrentTime[5] + 1900; |
| 38 | my $day = $CurrentTime[3]; |
| 39 | my $month = $CurrentTime[4] + 1; |
| 40 | |
| 41 | my $DateString = "$year-$month-$day"; |
| 42 | |
| 43 | # Determine the run number. |
| 44 | |
| 45 | my $RunNumber; |
| 46 | |
| 47 | if (-d $Dir) { |
| 48 | |
| 49 | if (! -r $Dir) { |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 50 | die "error: '$Dir' exists but is not readable.\n"; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | # Iterate over all files in the specified directory. |
| 54 | |
| 55 | my $max = 0; |
| 56 | |
| 57 | opendir(DIR, $Dir); |
| 58 | my @FILES= readdir(DIR); |
| 59 | closedir(DIR); |
| 60 | |
| 61 | foreach my $f (@FILES) { |
| 62 | |
| 63 | my @x = split/-/, $f; |
| 64 | |
| 65 | next if (scalar(@x) != 4); |
| 66 | next if ($x[0] != $year); |
| 67 | next if ($x[1] != $month); |
| 68 | next if ($x[2] != $day); |
| 69 | |
| 70 | if ($x[3] > $max) { |
| 71 | $max = $x[3]; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | $RunNumber = $max + 1; |
| 76 | } |
| 77 | else { |
| 78 | |
| 79 | if (-x $Dir) { |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 80 | die "error: '$Dir' exists but is not a directory.\n"; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | # $Dir does not exist. It will be automatically created by the |
| 84 | # clang driver. Set the run number to 1. |
| 85 | |
| 86 | $RunNumber = 1; |
| 87 | } |
| 88 | |
| 89 | die "RunNumber must be defined!" if (!defined($RunNumber)); |
| 90 | |
| 91 | # Append the run number. |
| 92 | |
| 93 | return "$Dir/$DateString-$RunNumber"; |
| 94 | } |
| 95 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 96 | sub SetHtmlEnv { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 97 | |
| 98 | die "Wrong number of arguments." if (scalar(@_) != 2); |
| 99 | |
| 100 | my $Args = shift; |
| 101 | my $Dir = shift; |
| 102 | |
| 103 | die "No build command." if (scalar(@$Args) == 0); |
| 104 | |
| 105 | my $Cmd = $$Args[0]; |
| 106 | |
| 107 | if ($Cmd =~ /configure/) { |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | if ($Verbose) { |
| 112 | print "$Prog: Emitting reports for this run to '$Dir'.\n"; |
| 113 | } |
| 114 | |
| 115 | $ENV{'CCC_ANALYZER_HTML'} = $Dir; |
| 116 | } |
| 117 | |
| 118 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame^] | 119 | # ComputeDigest - Compute a digest of the specified file. |
| 120 | ##----------------------------------------------------------------------------## |
| 121 | |
| 122 | sub ComputeDigest { |
| 123 | my $FName = shift; |
| 124 | die "Cannot read $FName" if (! -r $FName); |
| 125 | my $Result = `sha1sum -b $FName`; |
| 126 | my @Output = split /\s+/,$Result; |
| 127 | die "Bad output from sha1sum" if (scalar(@Output) != 2); |
| 128 | return $Output[0]; |
| 129 | } |
| 130 | |
| 131 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 132 | # ScanFile - Scan a report file for various identifying attributes. |
| 133 | ##----------------------------------------------------------------------------## |
| 134 | |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame^] | 135 | # Sometimes a source file is scanned more than once, and thus produces |
| 136 | # multiple error reports. We use a cache to solve this problem. |
| 137 | |
| 138 | my %AlreadyScanned; |
| 139 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 140 | sub ScanFile { |
| 141 | |
| 142 | my $Index = shift; |
| 143 | my $Dir = shift; |
| 144 | my $FName = shift; |
| 145 | |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame^] | 146 | # Compute a digest for the report file. Determine if we have already |
| 147 | # scanned a file that looks just like it. |
| 148 | |
| 149 | my $digest = ComputeDigest("$Dir/$FName"); |
| 150 | |
| 151 | if (defined($AlreadyScanned{$digest})) { |
| 152 | # Redundant file. Remove it. |
| 153 | `rm -f $Dir/$FName`; |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | $AlreadyScanned{$digest} = 1; |
| 158 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 159 | open(IN, "$Dir/$FName") or die "$Prog: Cannot open '$Dir/$FName'\n"; |
| 160 | |
| 161 | my $BugDesc = ""; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 162 | my $BugFile = ""; |
| 163 | my $BugPathLength = 1; |
| 164 | my $BugLine = 0; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 165 | |
| 166 | while (<IN>) { |
| 167 | |
| 168 | if (/<!-- BUGDESC (.*) -->$/) { |
| 169 | $BugDesc = $1; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 170 | } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 171 | elsif (/<!-- BUGFILE (.*) -->$/) { |
| 172 | $BugFile = $1; |
| 173 | } |
| 174 | elsif (/<!-- BUGPATHLENGTH (.*) -->$/) { |
| 175 | $BugPathLength = $1; |
| 176 | } |
| 177 | elsif (/<!-- BUGLINE (.*) -->$/) { |
| 178 | $BugLine = $1; |
| 179 | } |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | close(IN); |
| 183 | |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 184 | push @$Index,[ $FName, $BugDesc, $BugFile, $BugLine, $BugPathLength ]; |
| 185 | } |
| 186 | |
| 187 | ##----------------------------------------------------------------------------## |
| 188 | # CopyJS - Copy JavaScript code to target directory. |
| 189 | ##----------------------------------------------------------------------------## |
| 190 | |
| 191 | sub CopyJS { |
| 192 | |
| 193 | my $Dir = shift; |
| 194 | |
| 195 | die "$Prog: Cannot find 'sorttable.js'.\n" |
| 196 | if (! -r "$RealBin/sorttable.js"); |
| 197 | |
| 198 | `cp $RealBin/sorttable.js $Dir`; |
| 199 | |
| 200 | die "$Prog: Could not copy 'sorttable.js' to '$Dir'." |
| 201 | if (! -r "$Dir/sorttable.js"); |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 205 | # Postprocess - Postprocess the results of an analysis scan. |
| 206 | ##----------------------------------------------------------------------------## |
| 207 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 208 | sub Postprocess { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 209 | |
| 210 | my $Dir = shift; |
| 211 | |
| 212 | die "No directory specified." if (!defined($Dir)); |
| 213 | |
| 214 | if (! -d $Dir) { |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | opendir(DIR, $Dir); |
| 219 | my @files = grep(/^report-.*\.html$/,readdir(DIR)); |
| 220 | closedir(DIR); |
| 221 | |
| 222 | if (scalar(@files) == 0) { |
Ted Kremenek | 0249378 | 2008-04-02 07:05:07 +0000 | [diff] [blame] | 223 | print "$Prog: Removing directory '$Dir' because it contains no reports.\n"; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 224 | `rm -fR $Dir`; |
| 225 | return; |
| 226 | } |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 227 | |
| 228 | # Scan each report file and build an index. |
| 229 | |
| 230 | my @Index; |
| 231 | |
| 232 | foreach my $file (@files) { ScanFile(\@Index, $Dir, $file); } |
| 233 | |
| 234 | # Generate an index.html file. |
| 235 | |
| 236 | my $FName = "$Dir/index.html"; |
| 237 | |
| 238 | open(OUT, ">$FName") or die "$Prog: Cannot create file '$FName'\n"; |
| 239 | |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 240 | # Print out the header. |
| 241 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 242 | print OUT <<ENDTEXT; |
| 243 | <html> |
| 244 | <head> |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 245 | <style type="text/css"> |
| 246 | body { color:#000000; background-color:#ffffff } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 247 | body { font-family: Helvetica, sans-serif; font-size:9pt } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 248 | h1 { font-size:12pt } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 249 | table.sortable thead { |
| 250 | background-color:#eee; color:#666666; |
| 251 | font-weight: bold; cursor: default; |
Ted Kremenek | bba1cf5 | 2008-04-03 05:50:51 +0000 | [diff] [blame] | 252 | text-align:center; |
| 253 | border-top: 2px solid #000000; |
| 254 | border-bottom: 2px solid #000000; |
| 255 | font-weight: bold; font-family: Verdana |
| 256 | } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 257 | table.sortable { border: 1px #000000 solid } |
| 258 | table.sortable { border-collapse: collapse; border-spacing: 0px } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 259 | td { border-bottom: 1px #000000 dotted } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 260 | td { padding:5px; padding-left:8px; padding-right:8px } |
Ted Kremenek | d8c6d0c | 2008-04-07 23:50:07 +0000 | [diff] [blame] | 261 | td { text-align:left; font-size:9pt } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 262 | td.View { padding-left: 10px } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 263 | </style> |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 264 | <script src="sorttable.js"></script> |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 265 | <script language='javascript' type="text/javascript"> |
| 266 | function SetDisplay(RowClass, DisplayVal) |
| 267 | { |
| 268 | var Rows = document.getElementsByTagName("tr"); |
| 269 | for ( var i = 0 ; i < Rows.length; ++i ) { |
| 270 | if (Rows[i].className == RowClass) { |
| 271 | Rows[i].style.display = DisplayVal; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | function ToggleDisplay(CheckButton, ClassName) { |
| 277 | window.console.log("writing"); |
| 278 | if (CheckButton.checked) { |
| 279 | SetDisplay(ClassName, ""); |
| 280 | } |
| 281 | else { |
| 282 | SetDisplay(ClassName, "none"); |
| 283 | } |
| 284 | } |
| 285 | </script> |
| 286 | </head> |
| 287 | <body> |
| 288 | ENDTEXT |
| 289 | |
| 290 | # Print out the summary table. |
| 291 | |
| 292 | my %Totals; |
| 293 | |
| 294 | for my $row ( @Index ) { |
| 295 | |
| 296 | my $bug_type = lc($row->[1]); |
| 297 | |
| 298 | if (!defined($Totals{$bug_type})) { |
| 299 | $Totals{$bug_type} = 1; |
| 300 | } |
| 301 | else { |
| 302 | $Totals{$bug_type}++; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | print OUT <<ENDTEXT; |
| 307 | <h3>Summary</h3> |
| 308 | <table class="sortable"> |
| 309 | <tr> |
| 310 | <td>Bug Type</td> |
| 311 | <td>Quantity</td> |
| 312 | <td "sorttable_nosort">Display?</td> |
| 313 | </tr> |
| 314 | ENDTEXT |
| 315 | |
| 316 | for my $key ( sort { $a cmp $b } keys %Totals ) { |
| 317 | my $x = $key; |
| 318 | $x =~ s/\s/_/g; |
| 319 | print OUT "<tr><td>$key</td><td>$Totals{$key}</td><td><input type=\"checkbox\" onClick=\"ToggleDisplay(this,'bt_$x');\" checked/></td></tr>\n"; |
| 320 | } |
| 321 | |
| 322 | # Print out the table of errors. |
| 323 | |
| 324 | print OUT <<ENDTEXT; |
| 325 | </table> |
| 326 | <h3>Reports</h3> |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 327 | <table class="sortable"> |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 328 | <tr> |
Ted Kremenek | bba1cf5 | 2008-04-03 05:50:51 +0000 | [diff] [blame] | 329 | <td>Bug Type</td> |
| 330 | <td>File</td> |
| 331 | <td>Line</td> |
| 332 | <td>Path Length</td> |
| 333 | <td "sorttable_nosort"></td> |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 334 | </tr> |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 335 | ENDTEXT |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 336 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 337 | for my $row ( sort { $a->[1] cmp $b->[1] } @Index ) { |
| 338 | |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 339 | my $x = lc($row->[1]); |
| 340 | $x =~ s/\s/_/g; |
| 341 | |
| 342 | print OUT "<tr class=\"bt_$x\">\n"; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 343 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 344 | my $ReportFile = $row->[0]; |
| 345 | |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 346 | print OUT " <td class=\"DESC\">"; |
| 347 | print OUT lc($row->[1]); |
| 348 | print OUT "</td>\n"; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 349 | |
| 350 | for my $j ( 2 .. $#{$row} ) { |
| 351 | print OUT "<td>$row->[$j]</td>\n" |
| 352 | } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 353 | |
| 354 | # Emit the "View" link. |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 355 | |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 356 | 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] | 357 | |
| 358 | # End the row. |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 359 | print OUT "</tr>\n"; |
| 360 | } |
| 361 | |
| 362 | print OUT "</table>\n</body></html>\n"; |
| 363 | close(OUT); |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 364 | |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 365 | CopyJS($Dir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | ##----------------------------------------------------------------------------## |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 369 | # RunBuildCommand - Run the build command. |
| 370 | ##----------------------------------------------------------------------------## |
| 371 | |
| 372 | sub RunBuildCommand { |
| 373 | |
| 374 | my $Args = shift; |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 375 | my $IgnoreErrors = shift; |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 376 | my $Cmd = $Args->[0]; |
| 377 | |
Ted Kremenek | 6a43ba9 | 2008-04-02 15:34:12 +0000 | [diff] [blame] | 378 | 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] | 379 | shift @$Args; |
| 380 | unshift @$Args, "ccc-analyzer" |
| 381 | } |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 382 | elsif ($IgnoreErrors) { |
| 383 | if ($Cmd eq "make" or $Cmd eq "gmake") { |
| 384 | push @$Args, "-k"; |
| 385 | } |
| 386 | elsif ($Cmd eq "xcodebuild") { |
| 387 | push @$Args, "-PBXBuildsContinueAfterErrors=YES"; |
| 388 | } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 389 | } |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 390 | |
| 391 | system(@$Args); |
| 392 | } |
| 393 | |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 394 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 395 | # DisplayHelp - Utility function to display all help options. |
| 396 | ##----------------------------------------------------------------------------## |
| 397 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 398 | sub DisplayHelp { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 399 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 400 | print <<ENDTEXT; |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 401 | USAGE: $Prog [options] <build command> [build options] |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 402 | |
| 403 | OPTIONS: |
| 404 | |
| 405 | -o - Target directory for HTML report files. Subdirectories |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 406 | will be created as needed to represent separate "runs" of |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 407 | the analyzer. If this option is not specified, a directory |
| 408 | is created in /tmp to store the reports. |
| 409 | |
Ted Kremenek | 10f883f | 2008-04-03 07:11:44 +0000 | [diff] [blame] | 410 | -h - Display this message. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 411 | --help |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 412 | |
Ted Kremenek | af08f64 | 2008-04-02 16:31:58 +0000 | [diff] [blame] | 413 | -k - Add a "keep on going" option to the specified build command. |
Ted Kremenek | f02e8db | 2008-04-02 16:41:25 +0000 | [diff] [blame] | 414 | --keep-going This option currently supports make and xcodebuild. |
| 415 | This is a convenience option; one can specify this |
| 416 | behavior directly using build options. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 417 | |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 418 | -v - Verbose output from $Prog and the analyzer. |
| 419 | A second "-v" increases verbosity. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 420 | |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 421 | -V - View analysis results in a web browser when the build |
| 422 | --view completes. |
| 423 | |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 424 | BUILD OPTIONS |
| 425 | |
Ted Kremenek | 39eefde | 2008-04-02 16:47:27 +0000 | [diff] [blame] | 426 | You can specify any build option acceptable to the build command. |
| 427 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 428 | EXAMPLE |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 429 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 430 | $Prog -o /tmp/myhtmldir make -j4 |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 431 | |
Ted Kremenek | 39eefde | 2008-04-02 16:47:27 +0000 | [diff] [blame] | 432 | The above example causes analysis reports to be deposited into |
| 433 | a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option. |
| 434 | A different subdirectory is created each time $Prog analyzes a project. |
| 435 | The analyzer should support most parallel builds, but not distributed builds. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 436 | |
| 437 | ENDTEXT |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | ##----------------------------------------------------------------------------## |
| 441 | # Process command-line arguments. |
| 442 | ##----------------------------------------------------------------------------## |
| 443 | |
| 444 | my $HtmlDir; # Parent directory to store HTML files. |
| 445 | my $IgnoreErrors = 0; # Ignore build errors. |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 446 | my $ViewResults = 0; # View results when the build terminates. |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 447 | |
| 448 | if (!@ARGV) { |
| 449 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 450 | exit 1; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | while (@ARGV) { |
| 454 | |
| 455 | # Scan for options we recognize. |
| 456 | |
| 457 | my $arg = $ARGV[0]; |
| 458 | |
Sam Bishop | 2f2418e | 2008-04-03 14:29:47 +0000 | [diff] [blame] | 459 | if ($arg eq "-h" or $arg eq "--help") { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 460 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 461 | exit 0; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | if ($arg eq "-o") { |
| 465 | shift @ARGV; |
| 466 | |
| 467 | if (!@ARGV) { |
Ted Kremenek | 0062ad4 | 2008-04-02 16:35:01 +0000 | [diff] [blame] | 468 | die "$Prog: '-o' option requires a target directory name.\n"; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | $HtmlDir = shift @ARGV; |
| 472 | next; |
| 473 | } |
| 474 | |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 475 | if ($arg eq "-k" or $arg eq "--keep-going") { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 476 | shift @ARGV; |
| 477 | $IgnoreErrors = 1; |
| 478 | next; |
| 479 | } |
| 480 | |
| 481 | if ($arg eq "-v") { |
| 482 | shift @ARGV; |
| 483 | $Verbose++; |
| 484 | next; |
| 485 | } |
| 486 | |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 487 | if ($arg eq "-V" or $arg eq "--view") { |
| 488 | shift @ARGV; |
| 489 | $ViewResults = 1; |
| 490 | next; |
| 491 | } |
| 492 | |
Ted Kremenek | 0062ad4 | 2008-04-02 16:35:01 +0000 | [diff] [blame] | 493 | die "$Prog: unrecognized option '$arg'\n" if ($arg =~ /^-/); |
| 494 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 495 | last; |
| 496 | } |
| 497 | |
| 498 | if (!@ARGV) { |
| 499 | print STDERR "$Prog: No build command specified.\n\n"; |
| 500 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 501 | exit 1; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | # Determine the output directory for the HTML reports. |
| 505 | |
| 506 | if (!defined($HtmlDir)) { |
| 507 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 508 | $HtmlDir = mkdtemp("/tmp/$Prog-XXXXXX"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 509 | |
| 510 | if (!defined($HtmlDir)) { |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 511 | die "error: Cannot create HTML directory in /tmp.\n"; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | if (!$Verbose) { |
| 515 | print "$Prog: Using '$HtmlDir' as base HTML report directory.\n"; |
| 516 | } |
| 517 | } |
| 518 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 519 | $HtmlDir = GetHTMLRunDir($HtmlDir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 520 | |
| 521 | # Set the appropriate environment variables. |
| 522 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 523 | SetHtmlEnv(\@ARGV, $HtmlDir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 524 | |
Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 525 | my $Cmd = "$RealBin/ccc-analyzer"; |
| 526 | |
| 527 | die "$Prog: Executable 'ccc-analyzer' does not exist at '$Cmd'\n" |
| 528 | if (! -x $Cmd); |
| 529 | |
Ted Kremenek | 4f4b17d | 2008-04-03 20:08:18 +0000 | [diff] [blame] | 530 | $ENV{'CC'} = $Cmd; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 531 | |
| 532 | if ($Verbose >= 2) { |
| 533 | $ENV{'CCC_ANALYZER_VERBOSE'} = 1; |
| 534 | } |
| 535 | |
| 536 | # Run the build. |
| 537 | |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 538 | RunBuildCommand(\@ARGV, $IgnoreErrors); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 539 | |
| 540 | # Postprocess the HTML directory. |
| 541 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 542 | Postprocess($HtmlDir); |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 543 | |
| 544 | if ($ViewResults and -r "$HtmlDir/index.html") { |
| 545 | # Only works on Mac OS X (for now). |
| 546 | print "Viewing analysis results: '$HtmlDir/index.html'\n"; |
| 547 | `open $HtmlDir/index.html` |
| 548 | } |