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