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