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