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