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