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 | |
| 209 | print OUT <<ENDTEXT; |
| 210 | <html> |
| 211 | <head> |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 212 | <style type="text/css"> |
| 213 | body { color:#000000; background-color:#ffffff } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame^] | 214 | body { font-family: Helvetica, sans-serif; font-size:9pt } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 215 | h1 { font-size:12pt } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame^] | 216 | table.sortable thead { |
| 217 | background-color:#eee; color:#666666; |
| 218 | font-weight: bold; cursor: default; |
| 219 | } |
| 220 | table.sortable { border: 1px #000000 solid } |
| 221 | table.sortable { border-collapse: collapse; border-spacing: 0px } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 222 | td { border-bottom: 1px #000000 dotted } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame^] | 223 | td { padding:5px; padding-left:8px; padding-right:8px } |
| 224 | td { text-align:right; font-size:9pt } |
| 225 | td.header { text-align:center} |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 226 | td.header { border-top: 2px solid #000000; } |
| 227 | td.header { border-bottom: 2px solid #000000; } |
| 228 | td.header { font-weight: bold; font-family: Verdana } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame^] | 229 | td.View { padding-left: 10px } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 230 | </style> |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame^] | 231 | <script src="sorttable.js"></script> |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 232 | </head>\n<body> |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame^] | 233 | <table class="sortable"> |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 234 | <tr> |
| 235 | <td class="header">Bug Type</td> |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame^] | 236 | <td class="header">File</td> |
| 237 | <td class="header">Line</td> |
| 238 | <td class="header">Path Length</td> |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 239 | <td class="header"></td> |
| 240 | </tr> |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 241 | ENDTEXT |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 242 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 243 | for my $row ( sort { $a->[1] cmp $b->[1] } @Index ) { |
| 244 | |
| 245 | print OUT "<tr>\n"; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 246 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 247 | my $ReportFile = $row->[0]; |
| 248 | |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame^] | 249 | print OUT " <td class=\"DESC\">"; |
| 250 | print OUT lc($row->[1]); |
| 251 | print OUT "</td>\n"; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 252 | |
| 253 | for my $j ( 2 .. $#{$row} ) { |
| 254 | print OUT "<td>$row->[$j]</td>\n" |
| 255 | } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 256 | |
| 257 | # Emit the "View" link. |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 258 | |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame^] | 259 | 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] | 260 | |
| 261 | # End the row. |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 262 | print OUT "</tr>\n"; |
| 263 | } |
| 264 | |
| 265 | print OUT "</table>\n</body></html>\n"; |
| 266 | close(OUT); |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame^] | 267 | |
| 268 | print "$RealBin\n"; |
| 269 | |
| 270 | CopyJS($Dir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | ##----------------------------------------------------------------------------## |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 274 | # RunBuildCommand - Run the build command. |
| 275 | ##----------------------------------------------------------------------------## |
| 276 | |
| 277 | sub RunBuildCommand { |
| 278 | |
| 279 | my $Args = shift; |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 280 | my $IgnoreErrors = shift; |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 281 | my $Cmd = $Args->[0]; |
| 282 | |
Ted Kremenek | 6a43ba9 | 2008-04-02 15:34:12 +0000 | [diff] [blame] | 283 | 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] | 284 | shift @$Args; |
| 285 | unshift @$Args, "ccc-analyzer" |
| 286 | } |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 287 | elsif ($IgnoreErrors) { |
| 288 | if ($Cmd eq "make" or $Cmd eq "gmake") { |
| 289 | push @$Args, "-k"; |
| 290 | } |
| 291 | elsif ($Cmd eq "xcodebuild") { |
| 292 | push @$Args, "-PBXBuildsContinueAfterErrors=YES"; |
| 293 | } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame^] | 294 | } |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 295 | |
| 296 | system(@$Args); |
| 297 | } |
| 298 | |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 299 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 300 | # DisplayHelp - Utility function to display all help options. |
| 301 | ##----------------------------------------------------------------------------## |
| 302 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 303 | sub DisplayHelp { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 304 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 305 | print <<ENDTEXT; |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 306 | USAGE: $Prog [options] <build command> [build options] |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 307 | |
| 308 | OPTIONS: |
| 309 | |
| 310 | -o - Target directory for HTML report files. Subdirectories |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 311 | will be created as needed to represent separate "runs" of |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 312 | the analyzer. If this option is not specified, a directory |
| 313 | is created in /tmp to store the reports. |
| 314 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 315 | -?, -h - Display this message. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 316 | --help |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 317 | |
Ted Kremenek | af08f64 | 2008-04-02 16:31:58 +0000 | [diff] [blame] | 318 | -k - Add a "keep on going" option to the specified build command. |
Ted Kremenek | f02e8db | 2008-04-02 16:41:25 +0000 | [diff] [blame] | 319 | --keep-going This option currently supports make and xcodebuild. |
| 320 | This is a convenience option; one can specify this |
| 321 | behavior directly using build options. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 322 | |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 323 | -v - Verbose output from $Prog and the analyzer. |
| 324 | A second "-v" increases verbosity. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 325 | |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 326 | -V - View analysis results in a web browser when the build |
| 327 | --view completes. |
| 328 | |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 329 | BUILD OPTIONS |
| 330 | |
Ted Kremenek | 39eefde | 2008-04-02 16:47:27 +0000 | [diff] [blame] | 331 | You can specify any build option acceptable to the build command. |
| 332 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 333 | EXAMPLE |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 334 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 335 | $Prog -o /tmp/myhtmldir make -j4 |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 336 | |
Ted Kremenek | 39eefde | 2008-04-02 16:47:27 +0000 | [diff] [blame] | 337 | The above example causes analysis reports to be deposited into |
| 338 | a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option. |
| 339 | A different subdirectory is created each time $Prog analyzes a project. |
| 340 | The analyzer should support most parallel builds, but not distributed builds. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 341 | |
| 342 | ENDTEXT |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | ##----------------------------------------------------------------------------## |
| 346 | # Process command-line arguments. |
| 347 | ##----------------------------------------------------------------------------## |
| 348 | |
| 349 | my $HtmlDir; # Parent directory to store HTML files. |
| 350 | my $IgnoreErrors = 0; # Ignore build errors. |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 351 | my $ViewResults = 0; # View results when the build terminates. |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 352 | |
| 353 | if (!@ARGV) { |
| 354 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 355 | exit 1; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | while (@ARGV) { |
| 359 | |
| 360 | # Scan for options we recognize. |
| 361 | |
| 362 | my $arg = $ARGV[0]; |
| 363 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 364 | if ($arg eq "-?" or $arg eq "-h" or $arg eq "--help") { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 365 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 366 | exit 0; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | if ($arg eq "-o") { |
| 370 | shift @ARGV; |
| 371 | |
| 372 | if (!@ARGV) { |
Ted Kremenek | 0062ad4 | 2008-04-02 16:35:01 +0000 | [diff] [blame] | 373 | die "$Prog: '-o' option requires a target directory name.\n"; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | $HtmlDir = shift @ARGV; |
| 377 | next; |
| 378 | } |
| 379 | |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 380 | if ($arg eq "-k" or $arg eq "--keep-going") { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 381 | shift @ARGV; |
| 382 | $IgnoreErrors = 1; |
| 383 | next; |
| 384 | } |
| 385 | |
| 386 | if ($arg eq "-v") { |
| 387 | shift @ARGV; |
| 388 | $Verbose++; |
| 389 | next; |
| 390 | } |
| 391 | |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 392 | if ($arg eq "-V" or $arg eq "--view") { |
| 393 | shift @ARGV; |
| 394 | $ViewResults = 1; |
| 395 | next; |
| 396 | } |
| 397 | |
Ted Kremenek | 0062ad4 | 2008-04-02 16:35:01 +0000 | [diff] [blame] | 398 | die "$Prog: unrecognized option '$arg'\n" if ($arg =~ /^-/); |
| 399 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 400 | last; |
| 401 | } |
| 402 | |
| 403 | if (!@ARGV) { |
| 404 | print STDERR "$Prog: No build command specified.\n\n"; |
| 405 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 406 | exit 1; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | # Determine the output directory for the HTML reports. |
| 410 | |
| 411 | if (!defined($HtmlDir)) { |
| 412 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 413 | $HtmlDir = mkdtemp("/tmp/$Prog-XXXXXX"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 414 | |
| 415 | if (!defined($HtmlDir)) { |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 416 | die "error: Cannot create HTML directory in /tmp.\n"; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | if (!$Verbose) { |
| 420 | print "$Prog: Using '$HtmlDir' as base HTML report directory.\n"; |
| 421 | } |
| 422 | } |
| 423 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 424 | $HtmlDir = GetHTMLRunDir($HtmlDir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 425 | |
| 426 | # Set the appropriate environment variables. |
| 427 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 428 | SetHtmlEnv(\@ARGV, $HtmlDir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 429 | |
| 430 | $ENV{'CC'} = "ccc-analyzer"; |
| 431 | |
| 432 | if ($Verbose >= 2) { |
| 433 | $ENV{'CCC_ANALYZER_VERBOSE'} = 1; |
| 434 | } |
| 435 | |
| 436 | # Run the build. |
| 437 | |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 438 | RunBuildCommand(\@ARGV, $IgnoreErrors); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 439 | |
| 440 | # Postprocess the HTML directory. |
| 441 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 442 | Postprocess($HtmlDir); |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 443 | |
| 444 | if ($ViewResults and -r "$HtmlDir/index.html") { |
| 445 | # Only works on Mac OS X (for now). |
| 446 | print "Viewing analysis results: '$HtmlDir/index.html'\n"; |
| 447 | `open $HtmlDir/index.html` |
| 448 | } |