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; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 17 | use FindBin qw($RealBin); |
Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 18 | use Digest::MD5; |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 19 | use File::Basename; |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 20 | use Term::ANSIColor; |
| 21 | use Term::ANSIColor qw(:constants); |
Ted Kremenek | cd25c13 | 2008-12-03 19:50:37 +0000 | [diff] [blame] | 22 | use Cwd qw/ getcwd abs_path /; |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 23 | use Sys::Hostname; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 24 | |
| 25 | my $Verbose = 0; # Verbose output from this script. |
| 26 | my $Prog = "scan-build"; |
Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 27 | my $BuildName; |
| 28 | my $BuildDate; |
Ted Kremenek | 95aa105 | 2008-09-04 17:52:41 +0000 | [diff] [blame] | 29 | my $CXX; # Leave undefined initially. |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 30 | |
Ted Kremenek | 0e68938 | 2008-09-11 18:17:51 +0000 | [diff] [blame] | 31 | my $TERM = $ENV{'TERM'}; |
| 32 | my $UseColor = (defined $TERM and $TERM eq 'xterm-color' and -t STDOUT |
| 33 | and defined $ENV{'SCAN_BUILD_COLOR'}); |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 34 | |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 35 | my $UserName = HtmlEscape(getpwuid($<) || 'unknown'); |
| 36 | my $HostName = HtmlEscape(hostname() || 'unknown'); |
| 37 | my $CurrentDir = HtmlEscape(getcwd()); |
| 38 | my $CurrentDirSuffix = basename($CurrentDir); |
| 39 | |
| 40 | my $CmdArgs; |
| 41 | |
| 42 | my $HtmlTitle; |
| 43 | |
| 44 | my $Date = localtime(); |
| 45 | |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 46 | ##----------------------------------------------------------------------------## |
| 47 | # Diagnostics |
| 48 | ##----------------------------------------------------------------------------## |
| 49 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 50 | sub Diag { |
| 51 | if ($UseColor) { |
| 52 | print BOLD, MAGENTA "$Prog: @_"; |
| 53 | print RESET; |
| 54 | } |
| 55 | else { |
| 56 | print "$Prog: @_"; |
| 57 | } |
| 58 | } |
| 59 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 60 | sub DiagCrashes { |
| 61 | my $Dir = shift; |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 62 | Diag ("The analyzer encountered problems on some source files.\n"); |
| 63 | Diag ("Preprocessed versions of these sources were deposited in '$Dir/failures'.\n"); |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 64 | Diag ("Please consider submitting a bug report using these files:\n"); |
| 65 | Diag (" http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs\n") |
| 66 | } |
| 67 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 68 | sub DieDiag { |
| 69 | if ($UseColor) { |
| 70 | print BOLD, RED "$Prog: "; |
| 71 | print RESET, RED @_; |
| 72 | print RESET; |
| 73 | } |
| 74 | else { |
| 75 | print "$Prog: ", @_; |
| 76 | } |
| 77 | exit(0); |
| 78 | } |
| 79 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 80 | ##----------------------------------------------------------------------------## |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 81 | # Some initial preprocessing of Clang options. |
| 82 | ##----------------------------------------------------------------------------## |
| 83 | |
Ted Kremenek | 2d62ab1 | 2009-02-23 23:01:06 +0000 | [diff] [blame] | 84 | my $ClangSB = Cwd::realpath("$RealBin/bin/clang"); |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 85 | my $Clang = $ClangSB; |
| 86 | |
Ted Kremenek | 8d10cdd | 2009-02-20 04:34:29 +0000 | [diff] [blame] | 87 | if (!defined $ClangSB || ! -x $ClangSB) { |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 88 | $Clang = "clang"; |
| 89 | } |
| 90 | |
| 91 | my %AvailableAnalyses; |
| 92 | |
| 93 | # Query clang for analysis options. |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 94 | open(PIPE, "-|", $Clang, "--help") or |
Ted Kremenek | 445fa77 | 2008-10-10 00:17:08 +0000 | [diff] [blame] | 95 | DieDiag("Cannot execute '$Clang'\n"); |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 96 | |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 97 | my $FoundAnalysis = 0; |
| 98 | |
| 99 | while(<PIPE>) { |
| 100 | if ($FoundAnalysis == 0) { |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 101 | if (/Checks and Analyses/) { |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 102 | $FoundAnalysis = 1; |
| 103 | } |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 104 | next; |
| 105 | } |
| 106 | |
| 107 | if (/^\s\s\s\s([^\s]+)\s(.+)$/) { |
| 108 | next if ($1 =~ /-dump/ or $1 =~ /-view/ |
| 109 | or $1 =~ /-checker-simple/ or $1 =~ /-warn-uninit/); |
| 110 | |
| 111 | $AvailableAnalyses{$1} = $2; |
| 112 | next; |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 113 | } |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 114 | last; |
| 115 | } |
| 116 | |
| 117 | close (PIPE); |
| 118 | |
| 119 | my %AnalysesDefaultEnabled = ( |
| 120 | '-warn-dead-stores' => 1, |
| 121 | '-checker-cfref' => 1, |
Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 122 | '-warn-objc-methodsigs' => 1, |
Ted Kremenek | bde3a05 | 2008-07-25 20:35:01 +0000 | [diff] [blame] | 123 | '-warn-objc-missing-dealloc' => 1, |
Ted Kremenek | 5d44349 | 2008-09-18 06:34:16 +0000 | [diff] [blame] | 124 | '-warn-objc-unused-ivars' => 1, |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 125 | ); |
| 126 | |
| 127 | ##----------------------------------------------------------------------------## |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 128 | # GetHTMLRunDir - Construct an HTML directory name for the current sub-run. |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 129 | ##----------------------------------------------------------------------------## |
| 130 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 131 | sub GetHTMLRunDir { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 132 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 133 | die "Not enough arguments." if (@_ == 0); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 134 | my $Dir = shift @_; |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 135 | |
| 136 | my $TmpMode = 0; |
| 137 | if (!defined $Dir) { |
Ted Kremenek | ffda0b4 | 2008-10-31 05:48:42 +0000 | [diff] [blame] | 138 | if (`uname` =~ /Darwin/) { |
| 139 | $Dir = $ENV{'TMPDIR'}; |
| 140 | if (!defined $Dir) { $Dir = "/tmp"; } |
| 141 | } |
| 142 | else { |
| 143 | $Dir = "/tmp"; |
| 144 | } |
| 145 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 146 | $TmpMode = 1; |
| 147 | } |
Ted Kremenek | bf762c9 | 2009-02-24 02:38:02 +0000 | [diff] [blame^] | 148 | |
| 149 | # Chop off any trailing '/' characters. |
| 150 | while ($Dir =~ /\/$/) { chop $Dir; } |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 151 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 152 | # Get current date and time. |
| 153 | |
| 154 | my @CurrentTime = localtime(); |
| 155 | |
| 156 | my $year = $CurrentTime[5] + 1900; |
| 157 | my $day = $CurrentTime[3]; |
| 158 | my $month = $CurrentTime[4] + 1; |
| 159 | |
Ted Kremenek | 9d7405f | 2008-05-14 17:23:56 +0000 | [diff] [blame] | 160 | my $DateString = sprintf("%d-%02d-%02d", $year, $month, $day); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 161 | |
| 162 | # Determine the run number. |
| 163 | |
| 164 | my $RunNumber; |
| 165 | |
| 166 | if (-d $Dir) { |
| 167 | |
| 168 | if (! -r $Dir) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 169 | DieDiag("directory '$Dir' exists but is not readable.\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | # Iterate over all files in the specified directory. |
| 173 | |
| 174 | my $max = 0; |
| 175 | |
| 176 | opendir(DIR, $Dir); |
Ted Kremenek | 29da6c5 | 2008-08-07 17:57:34 +0000 | [diff] [blame] | 177 | my @FILES = grep { -d "$Dir/$_" } readdir(DIR); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 178 | closedir(DIR); |
| 179 | |
| 180 | foreach my $f (@FILES) { |
| 181 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 182 | # Strip the prefix '$Prog-' if we are dumping files to /tmp. |
| 183 | if ($TmpMode) { |
| 184 | next if (!($f =~ /^$Prog-(.+)/)); |
| 185 | $f = $1; |
| 186 | } |
| 187 | |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 188 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 189 | my @x = split/-/, $f; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 190 | next if (scalar(@x) != 4); |
| 191 | next if ($x[0] != $year); |
| 192 | next if ($x[1] != $month); |
| 193 | next if ($x[2] != $day); |
| 194 | |
| 195 | if ($x[3] > $max) { |
| 196 | $max = $x[3]; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | $RunNumber = $max + 1; |
| 201 | } |
| 202 | else { |
| 203 | |
| 204 | if (-x $Dir) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 205 | DieDiag("'$Dir' exists but is not a directory.\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 206 | } |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 207 | |
| 208 | if ($TmpMode) { |
Ted Kremenek | 445fa77 | 2008-10-10 00:17:08 +0000 | [diff] [blame] | 209 | DieDiag("The directory '/tmp' does not exist or cannot be accessed.\n"); |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 212 | # $Dir does not exist. It will be automatically created by the |
| 213 | # clang driver. Set the run number to 1. |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 214 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 215 | $RunNumber = 1; |
| 216 | } |
| 217 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 218 | die "RunNumber must be defined!" if (!defined $RunNumber); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 219 | |
| 220 | # Append the run number. |
Ted Kremenek | fc0898a | 2008-09-04 23:56:36 +0000 | [diff] [blame] | 221 | my $NewDir; |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 222 | if ($TmpMode) { |
Ted Kremenek | fc0898a | 2008-09-04 23:56:36 +0000 | [diff] [blame] | 223 | $NewDir = "$Dir/$Prog-$DateString-$RunNumber"; |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 224 | } |
| 225 | else { |
Ted Kremenek | fc0898a | 2008-09-04 23:56:36 +0000 | [diff] [blame] | 226 | $NewDir = "$Dir/$DateString-$RunNumber"; |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 227 | } |
Ted Kremenek | fc0898a | 2008-09-04 23:56:36 +0000 | [diff] [blame] | 228 | system 'mkdir','-p',$NewDir; |
| 229 | return $NewDir; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 232 | sub SetHtmlEnv { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 233 | |
| 234 | die "Wrong number of arguments." if (scalar(@_) != 2); |
| 235 | |
| 236 | my $Args = shift; |
| 237 | my $Dir = shift; |
| 238 | |
| 239 | die "No build command." if (scalar(@$Args) == 0); |
| 240 | |
| 241 | my $Cmd = $$Args[0]; |
| 242 | |
| 243 | if ($Cmd =~ /configure/) { |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | if ($Verbose) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 248 | Diag("Emitting reports for this run to '$Dir'.\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | $ENV{'CCC_ANALYZER_HTML'} = $Dir; |
| 252 | } |
| 253 | |
| 254 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 255 | # ComputeDigest - Compute a digest of the specified file. |
| 256 | ##----------------------------------------------------------------------------## |
| 257 | |
| 258 | sub ComputeDigest { |
| 259 | my $FName = shift; |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 260 | DieDiag("Cannot read $FName to compute Digest.\n") if (! -r $FName); |
Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 261 | |
| 262 | # 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] | 263 | # just looking for duplicate files that come from a non-malicious source. |
| 264 | # We use Digest::MD5 because it is a standard Perl module that should |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 265 | # come bundled on most systems. |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 266 | open(FILE, $FName) or DieDiag("Cannot open $FName when computing Digest.\n"); |
Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 267 | binmode FILE; |
| 268 | my $Result = Digest::MD5->new->addfile(*FILE)->hexdigest; |
| 269 | close(FILE); |
| 270 | |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 271 | # Return the digest. |
Ted Kremenek | a6e2481 | 2008-04-19 18:05:48 +0000 | [diff] [blame] | 272 | return $Result; |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 276 | # UpdatePrefix - Compute the common prefix of files. |
| 277 | ##----------------------------------------------------------------------------## |
| 278 | |
| 279 | my $Prefix; |
| 280 | |
| 281 | sub UpdatePrefix { |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 282 | my $x = shift; |
| 283 | my $y = basename($x); |
| 284 | $x =~ s/\Q$y\E$//; |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 285 | |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 286 | if (!defined $Prefix) { |
| 287 | $Prefix = $x; |
| 288 | return; |
| 289 | } |
| 290 | |
Ted Kremenek | 20b2bae | 2008-09-11 21:15:10 +0000 | [diff] [blame] | 291 | chop $Prefix while (!($x =~ /^\Q$Prefix/)); |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | sub GetPrefix { |
| 295 | return $Prefix; |
| 296 | } |
| 297 | |
| 298 | ##----------------------------------------------------------------------------## |
| 299 | # UpdateInFilePath - Update the path in the report file. |
| 300 | ##----------------------------------------------------------------------------## |
| 301 | |
| 302 | sub UpdateInFilePath { |
| 303 | my $fname = shift; |
| 304 | my $regex = shift; |
| 305 | my $newtext = shift; |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 306 | |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 307 | open (RIN, $fname) or die "cannot open $fname"; |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 308 | open (ROUT, ">", "$fname.tmp") or die "cannot open $fname.tmp"; |
| 309 | |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 310 | while (<RIN>) { |
| 311 | s/$regex/$newtext/; |
| 312 | print ROUT $_; |
| 313 | } |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 314 | |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 315 | close (ROUT); |
| 316 | close (RIN); |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 317 | system("mv", "$fname.tmp", $fname); |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 321 | # ScanFile - Scan a report file for various identifying attributes. |
| 322 | ##----------------------------------------------------------------------------## |
| 323 | |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 324 | # Sometimes a source file is scanned more than once, and thus produces |
| 325 | # multiple error reports. We use a cache to solve this problem. |
| 326 | |
| 327 | my %AlreadyScanned; |
| 328 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 329 | sub ScanFile { |
| 330 | |
| 331 | my $Index = shift; |
| 332 | my $Dir = shift; |
| 333 | my $FName = shift; |
| 334 | |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 335 | # Compute a digest for the report file. Determine if we have already |
| 336 | # scanned a file that looks just like it. |
| 337 | |
| 338 | my $digest = ComputeDigest("$Dir/$FName"); |
| 339 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 340 | if (defined $AlreadyScanned{$digest}) { |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 341 | # Redundant file. Remove it. |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 342 | system ("rm", "-f", "$Dir/$FName"); |
Ted Kremenek | 57cf446 | 2008-04-18 15:09:30 +0000 | [diff] [blame] | 343 | return; |
| 344 | } |
| 345 | |
| 346 | $AlreadyScanned{$digest} = 1; |
| 347 | |
Ted Kremenek | 809709f | 2008-04-18 16:58:34 +0000 | [diff] [blame] | 348 | # At this point the report file is not world readable. Make it happen. |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 349 | system ("chmod", "644", "$Dir/$FName"); |
Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 350 | |
| 351 | # Scan the report file for tags. |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 352 | open(IN, "$Dir/$FName") or DieDiag("Cannot open '$Dir/$FName'\n"); |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 353 | |
Ted Kremenek | a26ddab | 2009-01-27 01:53:39 +0000 | [diff] [blame] | 354 | my $BugType = ""; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 355 | my $BugFile = ""; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 356 | my $BugCategory; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 357 | my $BugPathLength = 1; |
| 358 | my $BugLine = 0; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 359 | my $found = 0; |
| 360 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 361 | while (<IN>) { |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 362 | |
| 363 | last if ($found == 5); |
| 364 | |
Ted Kremenek | a26ddab | 2009-01-27 01:53:39 +0000 | [diff] [blame] | 365 | if (/<!-- BUGTYPE (.*) -->$/) { |
| 366 | $BugType = $1; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 367 | ++$found; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 368 | } |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 369 | elsif (/<!-- BUGFILE (.*) -->$/) { |
Ted Kremenek | 990c2f4 | 2008-12-03 19:19:23 +0000 | [diff] [blame] | 370 | $BugFile = abs_path($1); |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 371 | UpdatePrefix($BugFile); |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 372 | ++$found; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 373 | } |
| 374 | elsif (/<!-- BUGPATHLENGTH (.*) -->$/) { |
| 375 | $BugPathLength = $1; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 376 | ++$found; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 377 | } |
| 378 | elsif (/<!-- BUGLINE (.*) -->$/) { |
| 379 | $BugLine = $1; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 380 | ++$found; |
| 381 | } |
| 382 | elsif (/<!-- BUGCATEGORY (.*) -->$/) { |
| 383 | $BugCategory = $1; |
| 384 | ++$found; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 385 | } |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | close(IN); |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 389 | |
| 390 | if (!defined $BugCategory) { |
| 391 | $BugCategory = "Other"; |
| 392 | } |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 393 | |
Ted Kremenek | a26ddab | 2009-01-27 01:53:39 +0000 | [diff] [blame] | 394 | push @$Index,[ $FName, $BugCategory, $BugType, $BugFile, $BugLine, |
Ted Kremenek | 8198311 | 2008-09-28 04:13:09 +0000 | [diff] [blame] | 395 | $BugPathLength ]; |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 399 | # CopyFiles - Copy resource files to target directory. |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 400 | ##----------------------------------------------------------------------------## |
| 401 | |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 402 | sub CopyFiles { |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 403 | |
| 404 | my $Dir = shift; |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 405 | |
| 406 | my $JS = Cwd::realpath("$RealBin/sorttable.js"); |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 407 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 408 | DieDiag("Cannot find 'sorttable.js'.\n") |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 409 | if (! -r $JS); |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 410 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 411 | system ("cp", $JS, "$Dir"); |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 412 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 413 | DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n") |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 414 | if (! -r "$Dir/sorttable.js"); |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 415 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 416 | my $CSS = Cwd::realpath("$RealBin/scanview.css"); |
| 417 | |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 418 | DieDiag("Cannot find 'scanview.css'.\n") |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 419 | if (! -r $CSS); |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 420 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 421 | system ("cp", $CSS, "$Dir"); |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 422 | |
| 423 | DieDiag("Could not copy 'scanview.css' to '$Dir'.\n") |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 424 | if (! -r $CSS); |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 428 | # Postprocess - Postprocess the results of an analysis scan. |
| 429 | ##----------------------------------------------------------------------------## |
| 430 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 431 | sub Postprocess { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 432 | |
| 433 | my $Dir = shift; |
Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 434 | my $BaseDir = shift; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 435 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 436 | die "No directory specified." if (!defined $Dir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 437 | |
| 438 | if (! -d $Dir) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 439 | Diag("No bugs found.\n"); |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 440 | return 0; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | opendir(DIR, $Dir); |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 444 | my @files = grep { /^report-.*\.html$/ } readdir(DIR); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 445 | closedir(DIR); |
| 446 | |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 447 | if (scalar(@files) == 0 and ! -e "$Dir/failures") { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 448 | Diag("Removing directory '$Dir' because it contains no reports.\n"); |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 449 | system ("rm", "-fR", $Dir); |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 450 | return 0; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 451 | } |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 452 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 453 | # Scan each report file and build an index. |
| 454 | my @Index; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 455 | foreach my $file (@files) { ScanFile(\@Index, $Dir, $file); } |
| 456 | |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 457 | # Scan the failures directory and use the information in the .info files |
Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 458 | # to update the common prefix directory. |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 459 | my @failures; |
| 460 | my @attributes_ignored; |
| 461 | if (-d "$Dir/failures") { |
| 462 | opendir(DIR, "$Dir/failures"); |
| 463 | @failures = grep { /[.]info.txt$/ && !/attribute_ignored/; } readdir(DIR); |
Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 464 | closedir(DIR); |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 465 | opendir(DIR, "$Dir/failures"); |
| 466 | @attributes_ignored = grep { /^attribute_ignored/; } readdir(DIR); |
| 467 | closedir(DIR); |
| 468 | foreach my $file (@failures) { |
| 469 | open IN, "$Dir/failures/$file" or DieDiag("cannot open $file\n"); |
Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 470 | my $Path = <IN>; |
| 471 | if (defined $Path) { UpdatePrefix($Path); } |
| 472 | close IN; |
| 473 | } |
| 474 | } |
| 475 | |
Ted Kremenek | 63c2017 | 2008-08-04 17:34:06 +0000 | [diff] [blame] | 476 | # Generate an index.html file. |
| 477 | my $FName = "$Dir/index.html"; |
| 478 | open(OUT, ">", $FName) or DieDiag("Cannot create file '$FName'\n"); |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 479 | |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 480 | # Print out the header. |
| 481 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 482 | print OUT <<ENDTEXT; |
| 483 | <html> |
| 484 | <head> |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 485 | <title>${HtmlTitle}</title> |
Ted Kremenek | f143545 | 2008-09-23 22:34:51 +0000 | [diff] [blame] | 486 | <link type="text/css" rel="stylesheet" href="scanview.css"/> |
Ted Kremenek | 22d6a63 | 2008-04-02 20:43:36 +0000 | [diff] [blame] | 487 | <script src="sorttable.js"></script> |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 488 | <script language='javascript' type="text/javascript"> |
| 489 | function SetDisplay(RowClass, DisplayVal) |
| 490 | { |
| 491 | var Rows = document.getElementsByTagName("tr"); |
| 492 | for ( var i = 0 ; i < Rows.length; ++i ) { |
| 493 | if (Rows[i].className == RowClass) { |
| 494 | Rows[i].style.display = DisplayVal; |
| 495 | } |
| 496 | } |
| 497 | } |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 498 | |
Ted Kremenek | 2350a46 | 2008-10-28 19:56:52 +0000 | [diff] [blame] | 499 | function CopyCheckedStateToCheckButtons(SummaryCheckButton) { |
| 500 | var Inputs = document.getElementsByTagName("input"); |
| 501 | for ( var i = 0 ; i < Inputs.length; ++i ) { |
| 502 | if (Inputs[i].type == "checkbox") { |
| 503 | if(Inputs[i] != SummaryCheckButton) { |
| 504 | Inputs[i].checked = SummaryCheckButton.checked; |
| 505 | Inputs[i].onclick(); |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
Ted Kremenek | 999e120 | 2008-10-28 20:09:57 +0000 | [diff] [blame] | 511 | function returnObjById( id ) { |
| 512 | if (document.getElementById) |
| 513 | var returnVar = document.getElementById(id); |
| 514 | else if (document.all) |
| 515 | var returnVar = document.all[id]; |
| 516 | else if (document.layers) |
| 517 | var returnVar = document.layers[id]; |
| 518 | return returnVar; |
| 519 | } |
| 520 | |
| 521 | var NumUnchecked = 0; |
| 522 | |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 523 | function ToggleDisplay(CheckButton, ClassName) { |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 524 | if (CheckButton.checked) { |
| 525 | SetDisplay(ClassName, ""); |
Ted Kremenek | 999e120 | 2008-10-28 20:09:57 +0000 | [diff] [blame] | 526 | if (--NumUnchecked == 0) { |
| 527 | returnObjById("AllBugsCheck").checked = true; |
| 528 | } |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 529 | } |
| 530 | else { |
| 531 | SetDisplay(ClassName, "none"); |
Ted Kremenek | 999e120 | 2008-10-28 20:09:57 +0000 | [diff] [blame] | 532 | NumUnchecked++; |
| 533 | returnObjById("AllBugsCheck").checked = false; |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | </script> |
Ted Kremenek | 1d1abb1 | 2008-09-22 17:52:58 +0000 | [diff] [blame] | 537 | <!-- SUMMARYENDHEAD --> |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 538 | </head> |
| 539 | <body> |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 540 | <h1>${HtmlTitle}</h1> |
| 541 | |
| 542 | <table> |
| 543 | <tr><th>User:</th><td>${UserName}\@${HostName}</td></tr> |
| 544 | <tr><th>Working Directory:</th><td>${CurrentDir}</td></tr> |
| 545 | <tr><th>Command Line:</th><td>${CmdArgs}</td></tr> |
| 546 | <tr><th>Date:</th><td>${Date}</td></tr> |
| 547 | ENDTEXT |
| 548 | |
| 549 | print OUT "<tr><th>Version:</th><td>${BuildName} (${BuildDate})</td></tr>\n" |
| 550 | if (defined($BuildName) && defined($BuildDate)); |
| 551 | |
| 552 | print OUT <<ENDTEXT; |
| 553 | </table> |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 554 | ENDTEXT |
| 555 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 556 | if (scalar(@files)) { |
| 557 | # Print out the summary table. |
| 558 | my %Totals; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 559 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 560 | for my $row ( @Index ) { |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 561 | my $bug_type = ($row->[2]); |
| 562 | my $bug_category = ($row->[1]); |
| 563 | my $key = "$bug_category:$bug_type"; |
| 564 | |
| 565 | if (!defined $Totals{$key}) { $Totals{$key} = [1,$bug_category,$bug_type]; } |
| 566 | else { $Totals{$key}->[0]++; } |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 567 | } |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 568 | |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 569 | print OUT "<h2>Bug Summary</h2>"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 570 | |
| 571 | if (defined $BuildName) { |
| 572 | print OUT "\n<p>Results in this analysis run are based on analyzer build <b>$BuildName</b>.</p>\n" |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 573 | } |
Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 574 | |
Ted Kremenek | 2350a46 | 2008-10-28 19:56:52 +0000 | [diff] [blame] | 575 | my $TotalBugs = scalar(@Index); |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 576 | print OUT <<ENDTEXT; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 577 | <table> |
| 578 | <thead><tr><td>Bug Type</td><td>Quantity</td><td class="sorttable_nosort">Display?</td></tr></thead> |
Ted Kremenek | 999e120 | 2008-10-28 20:09:57 +0000 | [diff] [blame] | 579 | <tr style="font-weight:bold"><td class="SUMM_DESC">All Bugs</td><td class="Q">$TotalBugs</td><td><center><input type="checkbox" id="AllBugsCheck" onClick="CopyCheckedStateToCheckButtons(this);" checked/></center></td></tr> |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 580 | ENDTEXT |
| 581 | |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 582 | my $last_category; |
| 583 | |
| 584 | for my $key ( |
| 585 | sort { |
| 586 | my $x = $Totals{$a}; |
| 587 | my $y = $Totals{$b}; |
| 588 | my $res = $x->[1] cmp $y->[1]; |
| 589 | $res = $x->[2] cmp $y->[2] if ($res == 0); |
| 590 | $res |
| 591 | } keys %Totals ) |
| 592 | { |
| 593 | my $val = $Totals{$key}; |
| 594 | my $category = $val->[1]; |
| 595 | if (!defined $last_category or $last_category ne $category) { |
| 596 | $last_category = $category; |
| 597 | print OUT "<tr><th>$category</th><th colspan=2></th></tr>\n"; |
| 598 | } |
| 599 | my $x = lc $key; |
| 600 | $x =~ s/[ ,'":\/()]+/_/g; |
| 601 | print OUT "<tr><td class=\"SUMM_DESC\">"; |
| 602 | print OUT $val->[2]; |
Ted Kremenek | 2350a46 | 2008-10-28 19:56:52 +0000 | [diff] [blame] | 603 | print OUT "</td><td class=\"Q\">"; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 604 | print OUT $val->[0]; |
| 605 | print OUT "</td><td><center><input type=\"checkbox\" onClick=\"ToggleDisplay(this,'bt_$x');\" checked/></center></td></tr>\n"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 606 | } |
Ted Kremenek | 6e6eff7 | 2008-04-15 20:47:02 +0000 | [diff] [blame] | 607 | |
| 608 | # Print out the table of errors. |
| 609 | |
| 610 | print OUT <<ENDTEXT; |
| 611 | </table> |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 612 | <h2>Reports</h2> |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 613 | |
| 614 | <table class="sortable" style="table-layout:automatic"> |
| 615 | <thead><tr> |
| 616 | <td>Bug Group</td> |
| 617 | <td class="sorttable_sorted">Bug Type<span id="sorttable_sortfwdind"> ▾</span></td> |
Ted Kremenek | bba1cf5 | 2008-04-03 05:50:51 +0000 | [diff] [blame] | 618 | <td>File</td> |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 619 | <td class="Q">Line</td> |
Ted Kremenek | 8198311 | 2008-09-28 04:13:09 +0000 | [diff] [blame] | 620 | <td class="Q">Path Length</td> |
Ted Kremenek | 2645c77 | 2008-07-07 16:58:44 +0000 | [diff] [blame] | 621 | <td class="sorttable_nosort"></td> |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 622 | <!-- REPORTBUGCOL --> |
| 623 | </tr></thead> |
| 624 | <tbody> |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 625 | ENDTEXT |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 626 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 627 | my $prefix = GetPrefix(); |
| 628 | my $regex; |
| 629 | my $InFileRegex; |
| 630 | my $InFilePrefix = "File:</td><td>"; |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 631 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 632 | if (defined $prefix) { |
| 633 | $regex = qr/^\Q$prefix\E/is; |
| 634 | $InFileRegex = qr/\Q$InFilePrefix$prefix\E/is; |
| 635 | } |
Ted Kremenek | 7a4648d | 2008-05-02 22:04:53 +0000 | [diff] [blame] | 636 | |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 637 | for my $row ( sort { $a->[2] cmp $b->[2] } @Index ) { |
| 638 | my $x = "$row->[1]:$row->[2]"; |
| 639 | $x = lc $x; |
| 640 | $x =~ s/[ ,'":\/()]+/_/g; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 641 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 642 | my $ReportFile = $row->[0]; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 643 | |
| 644 | print OUT "<tr class=\"bt_$x\">"; |
| 645 | print OUT "<td class=\"DESC\">"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 646 | print OUT $row->[1]; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 647 | print OUT "</td>"; |
| 648 | print OUT "<td class=\"DESC\">"; |
| 649 | print OUT $row->[2]; |
| 650 | print OUT "</td>"; |
| 651 | |
| 652 | # Update the file prefix. |
| 653 | my $fname = $row->[3]; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 654 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 655 | if (defined $regex) { |
| 656 | $fname =~ s/$regex//; |
| 657 | UpdateInFilePath("$Dir/$ReportFile", $InFileRegex, $InFilePrefix) |
| 658 | } |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 659 | |
Ted Kremenek | 91639ef | 2008-09-22 17:42:31 +0000 | [diff] [blame] | 660 | print OUT "<td>"; |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 661 | my @fname = split /\//,$fname; |
| 662 | if ($#fname > 0) { |
| 663 | while ($#fname >= 0) { |
| 664 | my $x = shift @fname; |
| 665 | print OUT $x; |
| 666 | if ($#fname >= 0) { |
| 667 | print OUT "<span class=\"W\"> </span>/"; |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | else { |
| 672 | print OUT $fname; |
Ted Kremenek | 91639ef | 2008-09-22 17:42:31 +0000 | [diff] [blame] | 673 | } |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 674 | print OUT "</td>"; |
| 675 | |
| 676 | # Print out the quantities. |
Ted Kremenek | 8198311 | 2008-09-28 04:13:09 +0000 | [diff] [blame] | 677 | for my $j ( 4 .. 5 ) { |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 678 | print OUT "<td class=\"Q\">$row->[$j]</td>"; |
| 679 | } |
| 680 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 681 | # Print the rest of the columns. |
Ted Kremenek | 8198311 | 2008-09-28 04:13:09 +0000 | [diff] [blame] | 682 | for (my $j = 6; $j <= $#{$row}; ++$j) { |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 683 | print OUT "<td>$row->[$j]</td>" |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 684 | } |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 685 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 686 | # Emit the "View" link. |
Ted Kremenek | 68005dd | 2008-09-22 17:39:18 +0000 | [diff] [blame] | 687 | print OUT "<td><a href=\"$ReportFile#EndPath\">View Report</a></td>"; |
Ted Kremenek | 3cea9ee | 2008-07-30 17:58:08 +0000 | [diff] [blame] | 688 | |
Daniel Dunbar | e43038e | 2008-09-19 23:18:44 +0000 | [diff] [blame] | 689 | # Emit REPORTBUG markers. |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 690 | print OUT "\n<!-- REPORTBUG id=\"$ReportFile\" -->\n"; |
Daniel Dunbar | e43038e | 2008-09-19 23:18:44 +0000 | [diff] [blame] | 691 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 692 | # End the row. |
| 693 | print OUT "</tr>\n"; |
| 694 | } |
| 695 | |
Ted Kremenek | ebb7413 | 2008-09-21 06:58:09 +0000 | [diff] [blame] | 696 | print OUT "</tbody>\n</table>\n\n"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 699 | if (scalar (@failures) || scalar(@attributes_ignored)) { |
| 700 | print OUT "<h2>Analyzer Failures</h2>\n"; |
| 701 | |
| 702 | if (scalar @attributes_ignored) { |
| 703 | print OUT "The analyzer's parser ignored the following attributes:<p>\n"; |
| 704 | print OUT "<table>\n"; |
| 705 | print OUT "<thead><tr><td>Attribute</td><td>Source File</td><td>Preprocessed File</td><td>STDERR Output</td></tr></thead>\n"; |
| 706 | foreach my $file (sort @attributes_ignored) { |
| 707 | die "cannot demangle attribute name\n" if (! ($file =~ /^attribute_ignored_(.+).txt/)); |
| 708 | my $attribute = $1; |
| 709 | # Open the attribute file to get the first file that failed. |
| 710 | next if (!open (ATTR, "$Dir/failures/$file")); |
| 711 | my $ppfile = <ATTR>; |
| 712 | chomp $ppfile; |
| 713 | close ATTR; |
| 714 | next if (! -e "$Dir/failures/$ppfile"); |
| 715 | # Open the info file and get the name of the source file. |
| 716 | open (INFO, "$Dir/failures/$ppfile.info.txt") or |
| 717 | die "Cannot open $Dir/failures/$ppfile.info.txt\n"; |
| 718 | my $srcfile = <INFO>; |
| 719 | chomp $srcfile; |
| 720 | close (INFO); |
| 721 | # Print the information in the table. |
| 722 | my $prefix = GetPrefix(); |
| 723 | if (defined $prefix) { $srcfile =~ s/^\Q$prefix//; } |
| 724 | print OUT "<tr><td>$attribute</td><td>$srcfile</td><td><a href=\"failures/$ppfile\">$ppfile</a></td><td><a href=\"failures/$ppfile.stderr.txt\">$ppfile.stderr.txt</a></td></tr>\n"; |
| 725 | my $ppfile_clang = $ppfile; |
| 726 | $ppfile_clang =~ s/[.](.+)$/.clang.$1/; |
| 727 | print OUT " <!-- REPORTPROBLEM src=\"$srcfile\" file=\"failures/$ppfile\" clangfile=\"failures/$ppfile_clang\" stderr=\"failures/$ppfile.stderr.txt\" info=\"failures/$ppfile.info.txt\" -->\n"; |
| 728 | } |
| 729 | print OUT "</table>\n"; |
| 730 | } |
| 731 | |
| 732 | if (scalar @failures) { |
| 733 | print OUT "<p>The analyzer had problems processing the following files:</p>\n"; |
| 734 | print OUT "<table>\n"; |
| 735 | print OUT "<thead><tr><td>Problem</td><td>Source File</td><td>Preprocessed File</td><td>STDERR Output</td></tr></thead>\n"; |
| 736 | foreach my $file (sort @failures) { |
Ted Kremenek | 82a1253 | 2008-09-25 00:25:16 +0000 | [diff] [blame] | 737 | $file =~ /(.+).info.txt$/; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 738 | # Get the preprocessed file. |
| 739 | my $ppfile = $1; |
| 740 | # Open the info file and get the name of the source file. |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 741 | open (INFO, "$Dir/failures/$file") or |
| 742 | die "Cannot open $Dir/failures/$file\n"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 743 | my $srcfile = <INFO>; |
Ted Kremenek | 5d31f83 | 2008-08-18 18:38:29 +0000 | [diff] [blame] | 744 | chomp $srcfile; |
| 745 | my $problem = <INFO>; |
| 746 | chomp $problem; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 747 | close (INFO); |
| 748 | # Print the information in the table. |
Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 749 | my $prefix = GetPrefix(); |
Ted Kremenek | 9f9b1fd | 2008-09-12 22:49:36 +0000 | [diff] [blame] | 750 | if (defined $prefix) { $srcfile =~ s/^\Q$prefix//; } |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 751 | print OUT "<tr><td>$problem</td><td>$srcfile</td><td><a href=\"failures/$ppfile\">$ppfile</a></td><td><a href=\"failures/$ppfile.stderr.txt\">$ppfile.stderr.txt</a></td></tr>\n"; |
Daniel Dunbar | ce723ce | 2008-09-25 01:10:50 +0000 | [diff] [blame] | 752 | my $ppfile_clang = $ppfile; |
| 753 | $ppfile_clang =~ s/[.](.+)$/.clang.$1/; |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 754 | print OUT " <!-- REPORTPROBLEM src=\"$srcfile\" file=\"failures/$ppfile\" clangfile=\"failures/$ppfile_clang\" stderr=\"failures/$ppfile.stderr.txt\" info=\"failures/$ppfile.info.txt\" -->\n"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 755 | } |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 756 | print OUT "</table>\n"; |
| 757 | } |
| 758 | print OUT "<p>Please consider submitting preprocessed files as <a href=\"http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs\">bug reports</a>. <!-- REPORTCRASHES --> </p>\n"; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 761 | print OUT "</body></html>\n"; |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 762 | close(OUT); |
Ted Kremenek | 3ce1207 | 2008-09-22 17:50:47 +0000 | [diff] [blame] | 763 | CopyFiles($Dir); |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 764 | |
| 765 | # Make sure $Dir and $BaseDir are world readable/executable. |
| 766 | system("chmod", "755", $Dir); |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 767 | if (defined $BaseDir) { system("chmod", "755", $BaseDir); } |
Ted Kremenek | 20161e9 | 2008-07-15 20:18:21 +0000 | [diff] [blame] | 768 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 769 | my $Num = scalar(@Index); |
Ted Kremenek | 150c212 | 2008-07-11 19:15:05 +0000 | [diff] [blame] | 770 | Diag("$Num bugs found.\n"); |
| 771 | if ($Num > 0 && -r "$Dir/index.html") { |
Ted Kremenek | 5950b3f | 2008-09-22 06:47:01 +0000 | [diff] [blame] | 772 | Diag("Run 'scan-view $Dir' to examine bug reports.\n"); |
Ted Kremenek | 150c212 | 2008-07-11 19:15:05 +0000 | [diff] [blame] | 773 | } |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 774 | |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 775 | DiagCrashes($Dir) if (scalar @failures || scalar @attributes_ignored); |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 776 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 777 | return $Num; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | ##----------------------------------------------------------------------------## |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 781 | # RunBuildCommand - Run the build command. |
| 782 | ##----------------------------------------------------------------------------## |
| 783 | |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 784 | sub AddIfNotPresent { |
| 785 | my $Args = shift; |
| 786 | my $Arg = shift; |
| 787 | my $found = 0; |
| 788 | |
| 789 | foreach my $k (@$Args) { |
| 790 | if ($k eq $Arg) { |
| 791 | $found = 1; |
| 792 | last; |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | if ($found == 0) { |
| 797 | push @$Args, $Arg; |
| 798 | } |
| 799 | } |
| 800 | |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 801 | sub RunBuildCommand { |
| 802 | |
| 803 | my $Args = shift; |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 804 | my $IgnoreErrors = shift; |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 805 | my $Cmd = $Args->[0]; |
Ted Kremenek | 6195c37 | 2008-06-02 21:52:47 +0000 | [diff] [blame] | 806 | my $CCAnalyzer = shift; |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 807 | |
Ted Kremenek | 3301cb1 | 2008-06-30 18:18:16 +0000 | [diff] [blame] | 808 | # Get only the part of the command after the last '/'. |
| 809 | if ($Cmd =~ /\/([^\/]+)$/) { |
| 810 | $Cmd = $1; |
| 811 | } |
| 812 | |
Ted Kremenek | 92548fe | 2008-11-19 01:46:21 +0000 | [diff] [blame] | 813 | if ($Cmd =~ /(.*\/?gcc[^\/]*$)/ or |
| 814 | $Cmd =~ /(.*\/?cc[^\/]*$)/ or |
| 815 | $Cmd =~ /(.*\/?llvm-gcc[^\/]*$)/ or |
| 816 | $Cmd =~ /(.*\/?ccc-analyzer[^\/]*$)/) { |
| 817 | |
| 818 | if (!($Cmd =~ /ccc-analyzer/) and !defined $ENV{"CCC_CC"}) { |
| 819 | $ENV{"CCC_CC"} = $1; |
| 820 | } |
| 821 | |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 822 | shift @$Args; |
Ted Kremenek | 6195c37 | 2008-06-02 21:52:47 +0000 | [diff] [blame] | 823 | unshift @$Args, $CCAnalyzer; |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 824 | } |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 825 | elsif ($IgnoreErrors) { |
| 826 | if ($Cmd eq "make" or $Cmd eq "gmake") { |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 827 | AddIfNotPresent($Args,"-k"); |
Ted Kremenek | 8912b54 | 2008-05-13 21:28:02 +0000 | [diff] [blame] | 828 | AddIfNotPresent($Args,"-i"); |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 829 | } |
| 830 | elsif ($Cmd eq "xcodebuild") { |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 831 | AddIfNotPresent($Args,"-PBXBuildsContinueAfterErrors=YES"); |
Ted Kremenek | 7442ca6 | 2008-04-02 16:04:51 +0000 | [diff] [blame] | 832 | } |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 833 | } |
| 834 | |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 835 | if ($Cmd eq "xcodebuild") { |
Ted Kremenek | cfd4c7b | 2008-05-23 22:18:16 +0000 | [diff] [blame] | 836 | # Disable distributed builds for xcodebuild. |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 837 | AddIfNotPresent($Args,"-nodistribute"); |
Ted Kremenek | cfd4c7b | 2008-05-23 22:18:16 +0000 | [diff] [blame] | 838 | |
| 839 | # Disable PCH files until clang supports them. |
| 840 | AddIfNotPresent($Args,"GCC_PRECOMPILE_PREFIX_HEADER=NO"); |
Ted Kremenek | 915e972 | 2008-05-27 23:18:07 +0000 | [diff] [blame] | 841 | |
| 842 | # When 'CC' is set, xcodebuild uses it to do all linking, even if we are |
| 843 | # linking C++ object files. Set 'LDPLUSPLUS' so that xcodebuild uses 'g++' |
| 844 | # when linking such files. |
Ted Kremenek | 95aa105 | 2008-09-04 17:52:41 +0000 | [diff] [blame] | 845 | die if (!defined $CXX); |
| 846 | my $LDPLUSPLUS = `which $CXX`; |
Ted Kremenek | 915e972 | 2008-05-27 23:18:07 +0000 | [diff] [blame] | 847 | $LDPLUSPLUS =~ s/\015?\012//; # strip newlines |
| 848 | $ENV{'LDPLUSPLUS'} = $LDPLUSPLUS; |
Ted Kremenek | 6b62898 | 2008-04-30 23:47:12 +0000 | [diff] [blame] | 849 | } |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 850 | |
Ted Kremenek | 5a4ddaf | 2008-08-25 20:10:45 +0000 | [diff] [blame] | 851 | return (system(@$Args) >> 8); |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 852 | } |
| 853 | |
Ted Kremenek | dab1110 | 2008-04-02 04:43:42 +0000 | [diff] [blame] | 854 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 855 | # DisplayHelp - Utility function to display all help options. |
| 856 | ##----------------------------------------------------------------------------## |
| 857 | |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 858 | sub DisplayHelp { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 859 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 860 | print <<ENDTEXT; |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 861 | USAGE: $Prog [options] <build command> [build options] |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 862 | |
Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 863 | ENDTEXT |
| 864 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 865 | if (defined $BuildName) { |
Ted Kremenek | f4cdf41 | 2008-05-23 18:17:05 +0000 | [diff] [blame] | 866 | print "ANALYZER BUILD: $BuildName ($BuildDate)\n\n"; |
| 867 | } |
| 868 | |
| 869 | print <<ENDTEXT; |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 870 | OPTIONS: |
| 871 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 872 | -analyze-headers - Also analyze functions in #included files. |
| 873 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 874 | -o - Target directory for HTML report files. Subdirectories |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 875 | will be created as needed to represent separate "runs" of |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 876 | the analyzer. If this option is not specified, a directory |
Ted Kremenek | ffda0b4 | 2008-10-31 05:48:42 +0000 | [diff] [blame] | 877 | is created in /tmp (TMPDIR on Mac OS X) to store the reports. |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 878 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 879 | -h - Display this message. |
| 880 | --help |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 881 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 882 | -k - Add a "keep on going" option to the specified build command. |
| 883 | --keep-going This option currently supports make and xcodebuild. |
Ted Kremenek | f02e8db | 2008-04-02 16:41:25 +0000 | [diff] [blame] | 884 | This is a convenience option; one can specify this |
| 885 | behavior directly using build options. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 886 | |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 887 | --html-title [title] - Specify the title used on generated HTML pages. |
| 888 | --html-title=[title] If not specified, a default title will be used. |
| 889 | |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 890 | -plist - By default the output of scan-build is a set of HTML files. |
| 891 | This option outputs the results as a set of .plist files. |
| 892 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 893 | --status-bugs - By default, the exit status of $Prog is the same as the |
| 894 | executed build command. Specifying this option causes the |
| 895 | exit status of $Prog to be 1 if it found potential bugs |
| 896 | and 0 otherwise. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 897 | |
Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 898 | --use-cc [compiler path] - By default, $Prog uses 'gcc' to compile and link |
| 899 | --use-cc=[compiler path] your C and Objective-C code. Use this option |
| 900 | to specify an alternate compiler. |
| 901 | |
| 902 | --use-c++ [compiler path] - By default, $Prog uses 'g++' to compile and link |
| 903 | --use-c++=[compiler path] your C++ and Objective-C++ code. Use this option |
| 904 | to specify an alternate compiler. |
Ted Kremenek | f17ef3c | 2008-08-21 21:47:09 +0000 | [diff] [blame] | 905 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 906 | -v - Verbose output from $Prog and the analyzer. |
Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 907 | A second and third '-v' increases verbosity. |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 908 | |
| 909 | -V - View analysis results in a web browser when the build |
| 910 | --view completes. |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 911 | |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 912 | ADVANCED OPTIONS: |
| 913 | |
Ted Kremenek | 9f4ecb3 | 2009-02-20 21:49:22 +0000 | [diff] [blame] | 914 | -constraints [model] - Specify the contraint engine used by the analyzer. |
| 915 | By default the 'range' model is used. Specifying |
| 916 | 'basic' uses a simpler, less powerful constraint model |
Ted Kremenek | d4c7684 | 2009-02-21 04:46:41 +0000 | [diff] [blame] | 917 | used by checker-0.160 and earlier. |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 918 | |
| 919 | -store [model] - Specify the store model used by the analyzer. By default, |
| 920 | the 'basic' store model is used. 'region' specifies a field- |
| 921 | sensitive store model. Be warned that the 'region' model |
| 922 | is still in very early testing phase and may often crash. |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 923 | |
Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 924 | AVAILABLE ANALYSES (multiple analyses may be specified): |
Ted Kremenek | d52e425 | 2008-08-25 20:45:07 +0000 | [diff] [blame] | 925 | |
| 926 | ENDTEXT |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 927 | |
| 928 | foreach my $Analysis (sort keys %AvailableAnalyses) { |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 929 | if (defined $AnalysesDefaultEnabled{$Analysis}) { |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 930 | print " (+)"; |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 931 | } |
| 932 | else { |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 933 | print " "; |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | print " $Analysis $AvailableAnalyses{$Analysis}\n"; |
| 937 | } |
| 938 | |
| 939 | print <<ENDTEXT |
| 940 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 941 | NOTE: "(+)" indicates that an analysis is enabled by default unless one |
| 942 | or more analysis options are specified |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 943 | |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 944 | BUILD OPTIONS |
| 945 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 946 | You can specify any build option acceptable to the build command. |
Ted Kremenek | 39eefde | 2008-04-02 16:47:27 +0000 | [diff] [blame] | 947 | |
Ted Kremenek | 5744dc2 | 2008-04-02 18:03:36 +0000 | [diff] [blame] | 948 | EXAMPLE |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 949 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 950 | $Prog -o /tmp/myhtmldir make -j4 |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 951 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 952 | The above example causes analysis reports to be deposited into |
| 953 | a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option. |
| 954 | A different subdirectory is created each time $Prog analyzes a project. |
| 955 | The analyzer should support most parallel builds, but not distributed builds. |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 956 | |
| 957 | ENDTEXT |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 961 | # HtmlEscape - HTML entity encode characters that are special in HTML |
| 962 | ##----------------------------------------------------------------------------## |
| 963 | |
| 964 | sub HtmlEscape { |
| 965 | # copy argument to new variable so we don't clobber the original |
| 966 | my $arg = shift || ''; |
| 967 | my $tmp = $arg; |
Ted Kremenek | 87f8de7 | 2008-11-03 07:44:16 +0000 | [diff] [blame] | 968 | $tmp =~ s/&/&/g; |
| 969 | $tmp =~ s/</</g; |
| 970 | $tmp =~ s/>/>/g; |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 971 | return $tmp; |
| 972 | } |
| 973 | |
| 974 | ##----------------------------------------------------------------------------## |
| 975 | # ShellEscape - backslash escape characters that are special to the shell |
| 976 | ##----------------------------------------------------------------------------## |
| 977 | |
| 978 | sub ShellEscape { |
| 979 | # copy argument to new variable so we don't clobber the original |
| 980 | my $arg = shift || ''; |
Ted Kremenek | 87f8de7 | 2008-11-03 07:44:16 +0000 | [diff] [blame] | 981 | if ($arg =~ /["\s]/) { return "'" . $arg . "'"; } |
| 982 | return $arg; |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | ##----------------------------------------------------------------------------## |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 986 | # Process command-line arguments. |
| 987 | ##----------------------------------------------------------------------------## |
| 988 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 989 | my $AnalyzeHeaders = 0; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 990 | my $HtmlDir; # Parent directory to store HTML files. |
| 991 | my $IgnoreErrors = 0; # Ignore build errors. |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 992 | my $ViewResults = 0; # View results when the build terminates. |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 993 | my $ExitStatusFoundBugs = 0; # Exit status reflects whether bugs were found |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 994 | my @AnalysesToRun; |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 995 | my $StoreModel; |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 996 | my $ConstraintsModel; |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 997 | my $OutputFormat; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 998 | |
| 999 | if (!@ARGV) { |
| 1000 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 1001 | exit 1; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | while (@ARGV) { |
| 1005 | |
| 1006 | # Scan for options we recognize. |
| 1007 | |
| 1008 | my $arg = $ARGV[0]; |
| 1009 | |
Sam Bishop | 2f2418e | 2008-04-03 14:29:47 +0000 | [diff] [blame] | 1010 | if ($arg eq "-h" or $arg eq "--help") { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1011 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 1012 | exit 0; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 1015 | if ($arg eq '-analyze-headers') { |
| 1016 | shift @ARGV; |
| 1017 | $AnalyzeHeaders = 1; |
| 1018 | next; |
| 1019 | } |
| 1020 | |
Ted Kremenek | fc1d340 | 2008-08-04 18:15:26 +0000 | [diff] [blame] | 1021 | if (defined $AvailableAnalyses{$arg}) { |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 1022 | shift @ARGV; |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 1023 | push @AnalysesToRun, $arg; |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 1024 | next; |
| 1025 | } |
| 1026 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1027 | if ($arg eq "-o") { |
| 1028 | shift @ARGV; |
| 1029 | |
| 1030 | if (!@ARGV) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 1031 | DieDiag("'-o' option requires a target directory name.\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | $HtmlDir = shift @ARGV; |
| 1035 | next; |
| 1036 | } |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 1037 | |
| 1038 | if ($arg =~ /^--html-title(=(.+))?$/) { |
| 1039 | shift @ARGV; |
| 1040 | |
| 1041 | if ($2 eq '') { |
| 1042 | if (!@ARGV) { |
| 1043 | DieDiag("'--html-title' option requires a string.\n"); |
| 1044 | } |
| 1045 | |
| 1046 | $HtmlTitle = shift @ARGV; |
| 1047 | } else { |
| 1048 | $HtmlTitle = $2; |
| 1049 | } |
| 1050 | |
| 1051 | next; |
| 1052 | } |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1053 | |
Ted Kremenek | 2b74ab6 | 2008-04-01 21:22:03 +0000 | [diff] [blame] | 1054 | if ($arg eq "-k" or $arg eq "--keep-going") { |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1055 | shift @ARGV; |
| 1056 | $IgnoreErrors = 1; |
| 1057 | next; |
| 1058 | } |
| 1059 | |
Ted Kremenek | f17ef3c | 2008-08-21 21:47:09 +0000 | [diff] [blame] | 1060 | if ($arg =~ /^--use-cc(=(.+))?$/) { |
| 1061 | shift @ARGV; |
| 1062 | my $cc; |
| 1063 | |
| 1064 | if ($2 eq "") { |
| 1065 | if (!@ARGV) { |
| 1066 | DieDiag("'--use-cc' option requires a compiler executable name.\n"); |
| 1067 | } |
| 1068 | $cc = shift @ARGV; |
| 1069 | } |
| 1070 | else { |
| 1071 | $cc = $2; |
| 1072 | } |
| 1073 | |
| 1074 | $ENV{"CCC_CC"} = $cc; |
| 1075 | next; |
| 1076 | } |
| 1077 | |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 1078 | if ($arg =~ /^--use-c\+\+(=(.+))?$/) { |
Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 1079 | shift @ARGV; |
| 1080 | |
| 1081 | if ($2 eq "") { |
| 1082 | if (!@ARGV) { |
| 1083 | DieDiag("'--use-c++' option requires a compiler executable name.\n"); |
| 1084 | } |
| 1085 | $CXX = shift @ARGV; |
| 1086 | } |
| 1087 | else { |
| 1088 | $CXX = $2; |
| 1089 | } |
| 1090 | next; |
| 1091 | } |
| 1092 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1093 | if ($arg eq "-v") { |
| 1094 | shift @ARGV; |
| 1095 | $Verbose++; |
| 1096 | next; |
| 1097 | } |
| 1098 | |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 1099 | if ($arg eq "-V" or $arg eq "--view") { |
| 1100 | shift @ARGV; |
| 1101 | $ViewResults = 1; |
| 1102 | next; |
| 1103 | } |
| 1104 | |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 1105 | if ($arg eq "--status-bugs") { |
| 1106 | shift @ARGV; |
| 1107 | $ExitStatusFoundBugs = 1; |
| 1108 | next; |
| 1109 | } |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 1110 | |
| 1111 | if ($arg eq "-store") { |
| 1112 | shift @ARGV; |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 1113 | $StoreModel = shift @ARGV; |
| 1114 | next; |
| 1115 | } |
| 1116 | |
| 1117 | if ($arg eq "-constraints") { |
| 1118 | shift @ARGV; |
| 1119 | $ConstraintsModel = shift @ARGV; |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 1120 | next; |
| 1121 | } |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 1122 | |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1123 | if ($arg eq "-plist") { |
| 1124 | shift @ARGV; |
| 1125 | $OutputFormat = "plist"; |
| 1126 | next; |
| 1127 | } |
| 1128 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 1129 | DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/); |
Ted Kremenek | 0062ad4 | 2008-04-02 16:35:01 +0000 | [diff] [blame] | 1130 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1131 | last; |
| 1132 | } |
| 1133 | |
| 1134 | if (!@ARGV) { |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 1135 | Diag("No build command specified.\n\n"); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1136 | DisplayHelp(); |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 1137 | exit 1; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
Ted Kremenek | 7cba112 | 2008-09-22 01:35:58 +0000 | [diff] [blame] | 1140 | $CmdArgs = HtmlEscape(join(' ', map(ShellEscape($_), @ARGV))); |
| 1141 | $HtmlTitle = "${CurrentDirSuffix} - scan-build results" |
| 1142 | unless (defined($HtmlTitle)); |
Ted Kremenek | 386c693 | 2008-09-03 17:59:35 +0000 | [diff] [blame] | 1143 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1144 | # Determine the output directory for the HTML reports. |
Ted Kremenek | 684bb09 | 2008-04-18 15:18:20 +0000 | [diff] [blame] | 1145 | my $BaseDir = $HtmlDir; |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 1146 | $HtmlDir = GetHTMLRunDir($HtmlDir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1147 | |
| 1148 | # Set the appropriate environment variables. |
Sam Bishop | a0e2266 | 2008-04-02 03:35:43 +0000 | [diff] [blame] | 1149 | SetHtmlEnv(\@ARGV, $HtmlDir); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1150 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 1151 | my $Cmd = Cwd::realpath("$RealBin/ccc-analyzer"); |
Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 1152 | |
Ted Kremenek | 23cfca3 | 2008-06-16 22:40:14 +0000 | [diff] [blame] | 1153 | DieDiag("Executable 'ccc-analyzer' does not exist at '$Cmd'\n") |
Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 1154 | if (! -x $Cmd); |
Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 1155 | |
Ted Kremenek | 2d62ab1 | 2009-02-23 23:01:06 +0000 | [diff] [blame] | 1156 | if (!defined $ClangSB || ! -x $ClangSB) { |
| 1157 | Diag("'clang' executable not found in '$RealBin/bin'.\n"); |
Ted Kremenek | b7770c0 | 2008-07-15 17:06:13 +0000 | [diff] [blame] | 1158 | Diag("Using 'clang' from path.\n"); |
Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 1159 | } |
Ted Kremenek | 0b6c153 | 2008-04-08 20:22:12 +0000 | [diff] [blame] | 1160 | |
Ted Kremenek | 95aa105 | 2008-09-04 17:52:41 +0000 | [diff] [blame] | 1161 | if (defined $CXX) { |
| 1162 | $ENV{'CXX'} = $CXX; |
| 1163 | } |
| 1164 | else { |
| 1165 | $CXX = 'g++'; # This variable is used by other parts of scan-build |
| 1166 | # that need to know a default C++ compiler to fall back to. |
| 1167 | } |
| 1168 | |
Ted Kremenek | 4f4b17d | 2008-04-03 20:08:18 +0000 | [diff] [blame] | 1169 | $ENV{'CC'} = $Cmd; |
Ted Kremenek | f22eacb | 2008-04-18 22:00:56 +0000 | [diff] [blame] | 1170 | $ENV{'CLANG'} = $Clang; |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1171 | |
| 1172 | if ($Verbose >= 2) { |
| 1173 | $ENV{'CCC_ANALYZER_VERBOSE'} = 1; |
| 1174 | } |
| 1175 | |
Ted Kremenek | a9525c9 | 2008-05-12 22:07:14 +0000 | [diff] [blame] | 1176 | if ($Verbose >= 3) { |
| 1177 | $ENV{'CCC_ANALYZER_LOG'} = 1; |
| 1178 | } |
| 1179 | |
Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 1180 | if (scalar(@AnalysesToRun) == 0) { |
| 1181 | foreach my $key (keys %AnalysesDefaultEnabled) { |
| 1182 | push @AnalysesToRun,$key; |
| 1183 | } |
Ted Kremenek | 0100678 | 2008-07-02 23:16:10 +0000 | [diff] [blame] | 1184 | } |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 1185 | |
Ted Kremenek | e15fa27 | 2008-10-13 21:46:42 +0000 | [diff] [blame] | 1186 | if ($AnalyzeHeaders) { |
| 1187 | push @AnalysesToRun,"-analyzer-opt-analyze-headers"; |
| 1188 | } |
| 1189 | |
Ted Kremenek | 9012599 | 2008-07-15 23:41:32 +0000 | [diff] [blame] | 1190 | $ENV{'CCC_ANALYZER_ANALYSIS'} = join ' ',@AnalysesToRun; |
| 1191 | |
Zhongxing Xu | 3cab2b1 | 2008-11-02 10:58:16 +0000 | [diff] [blame] | 1192 | if (defined $StoreModel) { |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 1193 | $ENV{'CCC_ANALYZER_STORE_MODEL'} = $StoreModel; |
| 1194 | } |
| 1195 | |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 1196 | if (defined $ConstraintsModel) { |
| 1197 | $ENV{'CCC_ANALYZER_CONSTRAINTS_MODEL'} = $ConstraintsModel; |
| 1198 | } |
| 1199 | |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1200 | if (defined $OutputFormat) { |
| 1201 | $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'} = $OutputFormat; |
| 1202 | } |
| 1203 | |
| 1204 | |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1205 | # Run the build. |
Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 1206 | my $ExitStatus = RunBuildCommand(\@ARGV, $IgnoreErrors, $Cmd); |
Ted Kremenek | 9cc8c2c | 2008-04-01 20:47:38 +0000 | [diff] [blame] | 1207 | |
Ted Kremenek | 655aba7 | 2008-11-04 00:22:12 +0000 | [diff] [blame] | 1208 | if (defined $OutputFormat and $OutputFormat eq "plist") { |
Ted Kremenek | 50534dc | 2008-09-22 17:38:23 +0000 | [diff] [blame] | 1209 | Diag "Analysis run complete.\n"; |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1210 | Diag "Analysis results (plist files) deposited in '$HtmlDir'\n"; |
Ted Kremenek | 7f8a325 | 2008-04-02 18:42:49 +0000 | [diff] [blame] | 1211 | } |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1212 | else { |
| 1213 | # Postprocess the HTML directory. |
| 1214 | my $NumBugs = Postprocess($HtmlDir, $BaseDir); |
Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 1215 | |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 1216 | if ($ViewResults and -r "$HtmlDir/index.html") { |
| 1217 | Diag "Analysis run complete.\n"; |
| 1218 | Diag "Viewing analysis results in '$HtmlDir' using scan-view.\n"; |
| 1219 | my $ScanView = Cwd::realpath("$RealBin/scan-view"); |
| 1220 | if (! -x $ScanView) { $ScanView = "scan-view"; } |
| 1221 | exec $ScanView, "$HtmlDir"; |
| 1222 | } |
| 1223 | |
| 1224 | if ($ExitStatusFoundBugs) { |
| 1225 | exit 1 if ($NumBugs > 0); |
| 1226 | exit 0; |
| 1227 | } |
Ted Kremenek | 363dc3f | 2008-07-15 22:03:09 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
Ted Kremenek | 5656a98 | 2008-07-15 17:09:28 +0000 | [diff] [blame] | 1230 | exit $ExitStatus; |
| 1231 | |