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