blob: 88728bdf6f178ae63de1e92ad110010d6d188694 [file] [log] [blame]
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +00001#!/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
15use strict;
16use warnings;
Ted Kremenek22d6a632008-04-02 20:43:36 +000017use FindBin qw($RealBin);
Ted Kremeneka6e24812008-04-19 18:05:48 +000018use Digest::MD5;
Ted Kremenek7a4648d2008-05-02 22:04:53 +000019use File::Basename;
Ted Kremenek23cfca32008-06-16 22:40:14 +000020use Term::ANSIColor;
21use Term::ANSIColor qw(:constants);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +000022
23my $Verbose = 0; # Verbose output from this script.
24my $Prog = "scan-build";
Ted Kremenekf4cdf412008-05-23 18:17:05 +000025my $BuildName;
26my $BuildDate;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +000027
Ted Kremenekf2f8d6c2008-06-17 03:06:59 +000028my $UseColor = ((($ENV{'TERM'} eq 'xterm-color') and -t STDOUT)
29 and defined($ENV{'SCAN_BUILD_COLOR'}));
Ted Kremenek23cfca32008-06-16 22:40:14 +000030
Ted Kremenekb7770c02008-07-15 17:06:13 +000031##----------------------------------------------------------------------------##
32# Diagnostics
33##----------------------------------------------------------------------------##
34
Ted Kremenek23cfca32008-06-16 22:40:14 +000035sub Diag {
36 if ($UseColor) {
37 print BOLD, MAGENTA "$Prog: @_";
38 print RESET;
39 }
40 else {
41 print "$Prog: @_";
42 }
43}
44
Ted Kremenek991c54b2008-08-08 20:46:42 +000045sub DiagCrashes {
46 my $Dir = shift;
47 Diag ("The analyzer crashed on some source files.\n");
48 Diag ("Preprocessed versions of crashed files were depositied in '$Dir/crashes'.\n");
49 Diag ("Please consider submitting a bug report using these files:\n");
50 Diag (" http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs\n")
51}
52
Ted Kremenek23cfca32008-06-16 22:40:14 +000053sub DieDiag {
54 if ($UseColor) {
55 print BOLD, RED "$Prog: ";
56 print RESET, RED @_;
57 print RESET;
58 }
59 else {
60 print "$Prog: ", @_;
61 }
62 exit(0);
63}
64
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +000065##----------------------------------------------------------------------------##
Ted Kremenekb7770c02008-07-15 17:06:13 +000066# Some initial preprocessing of Clang options.
67##----------------------------------------------------------------------------##
68
69my $ClangSB = "$RealBin/clang";
70my $Clang = $ClangSB;
71
72if (! -x $ClangSB) {
73 $Clang = "clang";
74}
75
76my %AvailableAnalyses;
77
78# Query clang for analysis options.
Ted Kremenek63c20172008-08-04 17:34:06 +000079open(PIPE, "-|", $Clang, "--help") or
Ted Kremenekb7770c02008-07-15 17:06:13 +000080 DieDiag("Cannot execute '$Clang'");
Ted Kremenek63c20172008-08-04 17:34:06 +000081
Ted Kremenekb7770c02008-07-15 17:06:13 +000082my $FoundAnalysis = 0;
83
84while(<PIPE>) {
85 if ($FoundAnalysis == 0) {
86 if (/Available Source Code Analyses/) {
87 $FoundAnalysis = 1;
88 }
Ted Kremenek991c54b2008-08-08 20:46:42 +000089
Ted Kremenekb7770c02008-07-15 17:06:13 +000090 next;
91 }
92
93 if (/^\s\s\s\s([^\s]+)\s(.+)$/) {
94 next if ($1 =~ /-dump/ or $1 =~ /-view/
95 or $1 =~ /-checker-simple/ or $1 =~ /-warn-uninit/);
96
97 $AvailableAnalyses{$1} = $2;
98 next;
99 }
100
101 last;
102}
103
104close (PIPE);
105
106my %AnalysesDefaultEnabled = (
107 '-warn-dead-stores' => 1,
108 '-checker-cfref' => 1,
Ted Kremenek90125992008-07-15 23:41:32 +0000109 '-warn-objc-methodsigs' => 1,
Ted Kremenekbde3a052008-07-25 20:35:01 +0000110 '-warn-objc-missing-dealloc' => 1,
111 '-warn-objc-unused-ivars' => 1
Ted Kremenekb7770c02008-07-15 17:06:13 +0000112);
113
114##----------------------------------------------------------------------------##
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000115# GetHTMLRunDir - Construct an HTML directory name for the current sub-run.
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000116##----------------------------------------------------------------------------##
117
Sam Bishopa0e22662008-04-02 03:35:43 +0000118sub GetHTMLRunDir {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000119
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000120 die "Not enough arguments." if (@_ == 0);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000121 my $Dir = shift @_;
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000122
123 my $TmpMode = 0;
124 if (!defined $Dir) {
125 $Dir = "/tmp";
126 $TmpMode = 1;
127 }
128
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000129 # Get current date and time.
130
131 my @CurrentTime = localtime();
132
133 my $year = $CurrentTime[5] + 1900;
134 my $day = $CurrentTime[3];
135 my $month = $CurrentTime[4] + 1;
136
Ted Kremenek9d7405f2008-05-14 17:23:56 +0000137 my $DateString = sprintf("%d-%02d-%02d", $year, $month, $day);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000138
139 # Determine the run number.
140
141 my $RunNumber;
142
143 if (-d $Dir) {
144
145 if (! -r $Dir) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000146 DieDiag("directory '$Dir' exists but is not readable.\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000147 }
148
149 # Iterate over all files in the specified directory.
150
151 my $max = 0;
152
153 opendir(DIR, $Dir);
Ted Kremenek29da6c52008-08-07 17:57:34 +0000154 my @FILES = grep { -d "$Dir/$_" } readdir(DIR);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000155 closedir(DIR);
156
157 foreach my $f (@FILES) {
158
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000159 # Strip the prefix '$Prog-' if we are dumping files to /tmp.
160 if ($TmpMode) {
161 next if (!($f =~ /^$Prog-(.+)/));
162 $f = $1;
163 }
164
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000165 my @x = split/-/, $f;
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000166
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000167 next if (scalar(@x) != 4);
168 next if ($x[0] != $year);
169 next if ($x[1] != $month);
170 next if ($x[2] != $day);
171
172 if ($x[3] > $max) {
173 $max = $x[3];
174 }
175 }
176
177 $RunNumber = $max + 1;
178 }
179 else {
180
181 if (-x $Dir) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000182 DieDiag("'$Dir' exists but is not a directory.\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000183 }
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000184
185 if ($TmpMode) {
186 DieDiag("The directory '/tmp' does not exist or cannot be accessed.");
187 }
188
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000189 # $Dir does not exist. It will be automatically created by the
190 # clang driver. Set the run number to 1.
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000191
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000192 $RunNumber = 1;
193 }
194
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000195 die "RunNumber must be defined!" if (!defined $RunNumber);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000196
197 # Append the run number.
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000198 if ($TmpMode) {
199 my $NewDir = "$Dir/$Prog-$DateString-$RunNumber";
200 mkdir $NewDir;
201 return $NewDir;
202 }
203 else {
204 return "$Dir/$DateString-$RunNumber";
205 }
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000206}
207
Sam Bishopa0e22662008-04-02 03:35:43 +0000208sub SetHtmlEnv {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000209
210 die "Wrong number of arguments." if (scalar(@_) != 2);
211
212 my $Args = shift;
213 my $Dir = shift;
214
215 die "No build command." if (scalar(@$Args) == 0);
216
217 my $Cmd = $$Args[0];
218
219 if ($Cmd =~ /configure/) {
220 return;
221 }
222
223 if ($Verbose) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000224 Diag("Emitting reports for this run to '$Dir'.\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000225 }
226
227 $ENV{'CCC_ANALYZER_HTML'} = $Dir;
228}
229
230##----------------------------------------------------------------------------##
Ted Kremenek57cf4462008-04-18 15:09:30 +0000231# ComputeDigest - Compute a digest of the specified file.
232##----------------------------------------------------------------------------##
233
234sub ComputeDigest {
235 my $FName = shift;
Ted Kremenek23cfca32008-06-16 22:40:14 +0000236 DieDiag("Cannot read $FName to compute Digest.\n") if (! -r $FName);
Ted Kremeneka6e24812008-04-19 18:05:48 +0000237
238 # Use Digest::MD5. We don't have to be cryptographically secure. We're
Ted Kremenek7ea02e62008-04-19 18:07:44 +0000239 # just looking for duplicate files that come from a non-malicious source.
240 # We use Digest::MD5 because it is a standard Perl module that should
Ted Kremenek63c20172008-08-04 17:34:06 +0000241 # come bundled on most systems.
Ted Kremenek23cfca32008-06-16 22:40:14 +0000242 open(FILE, $FName) or DieDiag("Cannot open $FName when computing Digest.\n");
Ted Kremeneka6e24812008-04-19 18:05:48 +0000243 binmode FILE;
244 my $Result = Digest::MD5->new->addfile(*FILE)->hexdigest;
245 close(FILE);
246
Ted Kremenek63c20172008-08-04 17:34:06 +0000247 # Return the digest.
Ted Kremeneka6e24812008-04-19 18:05:48 +0000248 return $Result;
Ted Kremenek57cf4462008-04-18 15:09:30 +0000249}
250
251##----------------------------------------------------------------------------##
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000252# UpdatePrefix - Compute the common prefix of files.
253##----------------------------------------------------------------------------##
254
255my $Prefix;
256
257sub UpdatePrefix {
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000258 my $x = shift;
259 my $y = basename($x);
260 $x =~ s/\Q$y\E$//;
261
262 # Ignore /usr, /Library, /System, /Developer
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000263 return if ( $x =~ /^\/usr/ or $x =~ /^\/Library/
264 or $x =~ /^\/System/ or $x =~ /^\/Developer/);
265
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000266 if (!defined $Prefix) {
267 $Prefix = $x;
268 return;
269 }
270
271 chop $Prefix while (!($x =~ /^$Prefix/));
272}
273
274sub GetPrefix {
275 return $Prefix;
276}
277
278##----------------------------------------------------------------------------##
279# UpdateInFilePath - Update the path in the report file.
280##----------------------------------------------------------------------------##
281
282sub UpdateInFilePath {
283 my $fname = shift;
284 my $regex = shift;
285 my $newtext = shift;
Ted Kremenek63c20172008-08-04 17:34:06 +0000286
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000287 open (RIN, $fname) or die "cannot open $fname";
Ted Kremenek63c20172008-08-04 17:34:06 +0000288 open (ROUT, ">", "$fname.tmp") or die "cannot open $fname.tmp";
289
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000290 while (<RIN>) {
291 s/$regex/$newtext/;
292 print ROUT $_;
293 }
Ted Kremenek63c20172008-08-04 17:34:06 +0000294
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000295 close (ROUT);
296 close (RIN);
Ted Kremenek20161e92008-07-15 20:18:21 +0000297 system("mv", "$fname.tmp", $fname);
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000298}
299
300##----------------------------------------------------------------------------##
Ted Kremenek5744dc22008-04-02 18:03:36 +0000301# ScanFile - Scan a report file for various identifying attributes.
302##----------------------------------------------------------------------------##
303
Ted Kremenek57cf4462008-04-18 15:09:30 +0000304# Sometimes a source file is scanned more than once, and thus produces
305# multiple error reports. We use a cache to solve this problem.
306
307my %AlreadyScanned;
308
Ted Kremenek5744dc22008-04-02 18:03:36 +0000309sub ScanFile {
310
311 my $Index = shift;
312 my $Dir = shift;
313 my $FName = shift;
314
Ted Kremenek57cf4462008-04-18 15:09:30 +0000315 # Compute a digest for the report file. Determine if we have already
316 # scanned a file that looks just like it.
317
318 my $digest = ComputeDigest("$Dir/$FName");
319
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000320 if (defined $AlreadyScanned{$digest}) {
Ted Kremenek57cf4462008-04-18 15:09:30 +0000321 # Redundant file. Remove it.
Ted Kremenek20161e92008-07-15 20:18:21 +0000322 system ("rm", "-f", "$Dir/$FName");
Ted Kremenek57cf4462008-04-18 15:09:30 +0000323 return;
324 }
325
326 $AlreadyScanned{$digest} = 1;
327
Ted Kremenek809709f2008-04-18 16:58:34 +0000328 # At this point the report file is not world readable. Make it happen.
Ted Kremenek20161e92008-07-15 20:18:21 +0000329 system ("chmod", "644", "$Dir/$FName");
Ted Kremenek684bb092008-04-18 15:18:20 +0000330
331 # Scan the report file for tags.
Ted Kremenek23cfca32008-06-16 22:40:14 +0000332 open(IN, "$Dir/$FName") or DieDiag("Cannot open '$Dir/$FName'\n");
Ted Kremenek5744dc22008-04-02 18:03:36 +0000333
334 my $BugDesc = "";
Ted Kremenek22d6a632008-04-02 20:43:36 +0000335 my $BugFile = "";
336 my $BugPathLength = 1;
337 my $BugLine = 0;
Ted Kremenek5744dc22008-04-02 18:03:36 +0000338
339 while (<IN>) {
340
341 if (/<!-- BUGDESC (.*) -->$/) {
342 $BugDesc = $1;
Ted Kremenek5744dc22008-04-02 18:03:36 +0000343 }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000344 elsif (/<!-- BUGFILE (.*) -->$/) {
345 $BugFile = $1;
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000346 UpdatePrefix($BugFile);
Ted Kremenek22d6a632008-04-02 20:43:36 +0000347 }
348 elsif (/<!-- BUGPATHLENGTH (.*) -->$/) {
349 $BugPathLength = $1;
350 }
351 elsif (/<!-- BUGLINE (.*) -->$/) {
352 $BugLine = $1;
353 }
Ted Kremenek5744dc22008-04-02 18:03:36 +0000354 }
355
356 close(IN);
357
Ted Kremenek22d6a632008-04-02 20:43:36 +0000358 push @$Index,[ $FName, $BugDesc, $BugFile, $BugLine, $BugPathLength ];
359}
360
361##----------------------------------------------------------------------------##
362# CopyJS - Copy JavaScript code to target directory.
363##----------------------------------------------------------------------------##
364
365sub CopyJS {
366
367 my $Dir = shift;
368
Ted Kremenek23cfca32008-06-16 22:40:14 +0000369 DieDiag("Cannot find 'sorttable.js'.\n")
Ted Kremenek22d6a632008-04-02 20:43:36 +0000370 if (! -r "$RealBin/sorttable.js");
371
Ted Kremenek20161e92008-07-15 20:18:21 +0000372 system ("cp", "$RealBin/sorttable.js", "$Dir");
Ted Kremenek22d6a632008-04-02 20:43:36 +0000373
Ted Kremenek23cfca32008-06-16 22:40:14 +0000374 DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n")
Ted Kremenek22d6a632008-04-02 20:43:36 +0000375 if (! -r "$Dir/sorttable.js");
Ted Kremenek5744dc22008-04-02 18:03:36 +0000376}
377
378##----------------------------------------------------------------------------##
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000379# Postprocess - Postprocess the results of an analysis scan.
380##----------------------------------------------------------------------------##
381
Sam Bishopa0e22662008-04-02 03:35:43 +0000382sub Postprocess {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000383
384 my $Dir = shift;
Ted Kremenek684bb092008-04-18 15:18:20 +0000385 my $BaseDir = shift;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000386
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000387 die "No directory specified." if (!defined $Dir);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000388
389 if (! -d $Dir) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000390 Diag("No bugs found.\n");
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000391 return 0;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000392 }
393
394 opendir(DIR, $Dir);
Ted Kremenek991c54b2008-08-08 20:46:42 +0000395 my $Crashes = 0;
396 my @files = grep { if ($_ eq "crashes") { $Crashes++; }
397 /^report-.*\.html$/; } readdir(DIR);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000398 closedir(DIR);
399
Ted Kremenek991c54b2008-08-08 20:46:42 +0000400 if (scalar(@files) == 0 and $Crashes == 0) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000401 Diag("Removing directory '$Dir' because it contains no reports.\n");
Ted Kremenek20161e92008-07-15 20:18:21 +0000402 system ("rm", "-fR", $Dir);
Ted Kremenek23cfca32008-06-16 22:40:14 +0000403 # Remove the base directory if it contains no files (don't use '-R').
Ted Kremenek991c54b2008-08-08 20:46:42 +0000404 system ("rm", "-f", $BaseDir) if (defined $BaseDir);
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000405 return 0;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000406 }
Ted Kremenek5744dc22008-04-02 18:03:36 +0000407
Ted Kremenek991c54b2008-08-08 20:46:42 +0000408 # Scan each report file and build an index.
409 my @Index;
Ted Kremenek5744dc22008-04-02 18:03:36 +0000410 foreach my $file (@files) { ScanFile(\@Index, $Dir, $file); }
411
Ted Kremenekd52e4252008-08-25 20:45:07 +0000412 # Scan the crashes directory and use the information in the .info files
413 # to update the common prefix directory.
414 if (-d "$Dir/crashes") {
415 opendir(DIR, "$Dir/crashes");
416 my @files = grep { /[.]info$/; } readdir(DIR);
417 closedir(DIR);
418 foreach my $file (@files) {
419 open IN, "$Dir/crashes/$file" or DieDiag("cannot open $file\n");
420 my $Path = <IN>;
421 if (defined $Path) { UpdatePrefix($Path); }
422 close IN;
423 }
424 }
425
Ted Kremenek63c20172008-08-04 17:34:06 +0000426 # Generate an index.html file.
427 my $FName = "$Dir/index.html";
428 open(OUT, ">", $FName) or DieDiag("Cannot create file '$FName'\n");
Ted Kremenek5744dc22008-04-02 18:03:36 +0000429
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000430 # Print out the header.
431
Ted Kremenek5744dc22008-04-02 18:03:36 +0000432print OUT <<ENDTEXT;
433<html>
434<head>
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000435<style type="text/css">
436 body { color:#000000; background-color:#ffffff }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000437 body { font-family: Helvetica, sans-serif; font-size:9pt }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000438 h1 { font-size:12pt }
Ted Kremenek991c54b2008-08-08 20:46:42 +0000439 table thead {
Ted Kremenek22d6a632008-04-02 20:43:36 +0000440 background-color:#eee; color:#666666;
441 font-weight: bold; cursor: default;
Ted Kremenekbba1cf52008-04-03 05:50:51 +0000442 text-align:center;
443 border-top: 2px solid #000000;
444 border-bottom: 2px solid #000000;
445 font-weight: bold; font-family: Verdana
446 }
Ted Kremenek991c54b2008-08-08 20:46:42 +0000447 table { border: 1px #000000 solid }
448 table { border-collapse: collapse; border-spacing: 0px }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000449 td { border-bottom: 1px #000000 dotted }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000450 td { padding:5px; padding-left:8px; padding-right:8px }
Ted Kremenekd8c6d0c2008-04-07 23:50:07 +0000451 td { text-align:left; font-size:9pt }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000452 td.View { padding-left: 10px }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000453</style>
Ted Kremenek22d6a632008-04-02 20:43:36 +0000454<script src="sorttable.js"></script>
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000455<script language='javascript' type="text/javascript">
456function SetDisplay(RowClass, DisplayVal)
457{
458 var Rows = document.getElementsByTagName("tr");
459 for ( var i = 0 ; i < Rows.length; ++i ) {
460 if (Rows[i].className == RowClass) {
461 Rows[i].style.display = DisplayVal;
462 }
463 }
464}
465
466function ToggleDisplay(CheckButton, ClassName) {
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000467 if (CheckButton.checked) {
468 SetDisplay(ClassName, "");
469 }
470 else {
471 SetDisplay(ClassName, "none");
472 }
473}
474</script>
475</head>
476<body>
477ENDTEXT
478
Ted Kremenek991c54b2008-08-08 20:46:42 +0000479 if (scalar(@files)) {
480 # Print out the summary table.
481 my %Totals;
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000482
Ted Kremenek991c54b2008-08-08 20:46:42 +0000483 for my $row ( @Index ) {
484 #my $bug_type = lc($row->[1]);
485 my $bug_type = ($row->[1]);
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000486
Ted Kremenek991c54b2008-08-08 20:46:42 +0000487 if (!defined $Totals{$bug_type}) { $Totals{$bug_type} = 1; }
488 else { $Totals{$bug_type}++; }
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000489 }
Ted Kremenek991c54b2008-08-08 20:46:42 +0000490
491 print OUT "<h3>Bug Summary</h3>";
492
493 if (defined $BuildName) {
494 print OUT "\n<p>Results in this analysis run are based on analyzer build <b>$BuildName</b>.</p>\n"
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000495 }
Ted Kremenekf4cdf412008-05-23 18:17:05 +0000496
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000497print OUT <<ENDTEXT;
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000498<table class="sortable">
499<tr>
500 <td>Bug Type</td>
501 <td>Quantity</td>
Ted Kremenek2645c772008-07-07 16:58:44 +0000502 <td class="sorttable_nosort">Display?</td>
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000503</tr>
504ENDTEXT
505
Ted Kremenek991c54b2008-08-08 20:46:42 +0000506 for my $key ( sort { $a cmp $b } keys %Totals ) {
507 my $x = lc($key);
508 $x =~ s/[ ,'"]+/_/g;
509 print OUT "<tr><td>$key</td><td>$Totals{$key}</td><td><input type=\"checkbox\" onClick=\"ToggleDisplay(this,'bt_$x');\" checked/></td></tr>\n";
510 }
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000511
512 # Print out the table of errors.
513
514print OUT <<ENDTEXT;
515</table>
516<h3>Reports</h3>
Ted Kremenek22d6a632008-04-02 20:43:36 +0000517<table class="sortable">
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000518<tr>
Ted Kremenek88a96d62008-07-07 17:23:32 +0000519 <td class="sorttable_sorted">Bug Type<span id="sorttable_sortfwdind">&nbsp;&#x25BE;</span>
Ted Kremenekbba1cf52008-04-03 05:50:51 +0000520 <td>File</td>
521 <td>Line</td>
522 <td>Path Length</td>
Ted Kremenek2645c772008-07-07 16:58:44 +0000523 <td class="sorttable_nosort"></td>
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000524</tr>
Ted Kremenek5744dc22008-04-02 18:03:36 +0000525ENDTEXT
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000526
Ted Kremenek991c54b2008-08-08 20:46:42 +0000527 my $prefix = GetPrefix();
528 my $regex;
529 my $InFileRegex;
530 my $InFilePrefix = "File:</td><td>";
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000531
Ted Kremenek991c54b2008-08-08 20:46:42 +0000532 if (defined $prefix) {
533 $regex = qr/^\Q$prefix\E/is;
534 $InFileRegex = qr/\Q$InFilePrefix$prefix\E/is;
535 }
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000536
Ted Kremenek991c54b2008-08-08 20:46:42 +0000537 for my $row ( sort { $a->[1] cmp $b->[1] } @Index ) {
Ted Kremenek5744dc22008-04-02 18:03:36 +0000538
Ted Kremenek991c54b2008-08-08 20:46:42 +0000539 my $x = lc($row->[1]);
540 $x =~ s/[ ,'"]+/_/g;
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000541
Ted Kremenek991c54b2008-08-08 20:46:42 +0000542 print OUT "<tr class=\"bt_$x\">\n";
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000543
Ted Kremenek991c54b2008-08-08 20:46:42 +0000544 my $ReportFile = $row->[0];
Ted Kremenek5744dc22008-04-02 18:03:36 +0000545
Ted Kremenek991c54b2008-08-08 20:46:42 +0000546 print OUT " <td class=\"DESC\">";
547 #print OUT lc($row->[1]);
548 print OUT $row->[1];
549 print OUT "</td>\n";
Ted Kremenek5744dc22008-04-02 18:03:36 +0000550
Ted Kremenek991c54b2008-08-08 20:46:42 +0000551 # Update the file prefix.
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000552
Ted Kremenek991c54b2008-08-08 20:46:42 +0000553 my $fname = $row->[2];
554 if (defined $regex) {
555 $fname =~ s/$regex//;
556 UpdateInFilePath("$Dir/$ReportFile", $InFileRegex, $InFilePrefix)
557 }
Ted Kremenek3e56e0b2008-05-02 23:40:49 +0000558
Ted Kremenek991c54b2008-08-08 20:46:42 +0000559 print OUT "<td>$fname</td>\n";
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000560
Ted Kremenek991c54b2008-08-08 20:46:42 +0000561 # Print the rest of the columns.
562 for my $j ( 3 .. $#{$row} ) {
563 print OUT "<td>$row->[$j]</td>\n"
564 }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000565
Ted Kremenek991c54b2008-08-08 20:46:42 +0000566 # Emit the "View" link.
567 print OUT " <td class=\"View\"><a href=\"$ReportFile#EndPath\">View</a></td>\n";
Ted Kremenek3cea9ee2008-07-30 17:58:08 +0000568
Ted Kremenek991c54b2008-08-08 20:46:42 +0000569 # End the row.
570 print OUT "</tr>\n";
571 }
572
573 print OUT "</table>\n";
574 }
575
576 if ($Crashes) {
577 # Read the crash directory for files.
578 opendir(DIR, "$Dir/crashes");
579 my @files = grep { /[.]info$/ } readdir(DIR);
580 closedir(DIR);
581
582 if (scalar(@files)) {
583 print OUT <<ENDTEXT;
Ted Kremenek5d31f832008-08-18 18:38:29 +0000584<h3>Analyzer Failures</h3>
Ted Kremenek991c54b2008-08-08 20:46:42 +0000585
Ted Kremenek5d31f832008-08-18 18:38:29 +0000586<p>The analyzer had problems processing the following files:</p>
Ted Kremenek991c54b2008-08-08 20:46:42 +0000587
588<table>
Ted Kremenek5d31f832008-08-18 18:38:29 +0000589<thead><tr><td>Problem</td><td>Source File</td><td>Preprocessed File</td></tr></thead>
Ted Kremenek991c54b2008-08-08 20:46:42 +0000590ENDTEXT
591
592 foreach my $file (sort @files) {
593 $file =~ /(.+).info$/;
594 # Get the preprocessed file.
595 my $ppfile = $1;
596 # Open the info file and get the name of the source file.
597 open (INFO, "$Dir/crashes/$file") or
598 die "Cannot open $Dir/crashes/$file\n";
599 my $srcfile = <INFO>;
Ted Kremenek5d31f832008-08-18 18:38:29 +0000600 chomp $srcfile;
601 my $problem = <INFO>;
602 chomp $problem;
Ted Kremenek991c54b2008-08-08 20:46:42 +0000603 close (INFO);
604 # Print the information in the table.
Ted Kremenekd52e4252008-08-25 20:45:07 +0000605 my $prefix = GetPrefix();
606 if (defined $prefix) { $srcfile =~ s/^$prefix//; }
Ted Kremenek5d31f832008-08-18 18:38:29 +0000607 print OUT "<tr><td>$problem</td><td>$srcfile</td><td class=\"View\"><a href=\"crashes/$ppfile\">View</a></td></tr>\n";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000608 }
609
610 print OUT <<ENDTEXT;
611</table>
612<p>Please consider submitting preprocessed files as <a href="http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs">bug reports</a>.</p>
613ENDTEXT
614 }
Ted Kremenek5744dc22008-04-02 18:03:36 +0000615 }
616
Ted Kremenek991c54b2008-08-08 20:46:42 +0000617 print OUT "</body></html>\n";
Ted Kremenek5744dc22008-04-02 18:03:36 +0000618 close(OUT);
Ted Kremenek22d6a632008-04-02 20:43:36 +0000619 CopyJS($Dir);
Ted Kremenek20161e92008-07-15 20:18:21 +0000620
621 # Make sure $Dir and $BaseDir are world readable/executable.
622 system("chmod", "755", $Dir);
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000623 if (defined $BaseDir) { system("chmod", "755", $BaseDir); }
Ted Kremenek20161e92008-07-15 20:18:21 +0000624
Ted Kremenek23cfca32008-06-16 22:40:14 +0000625 my $Num = scalar(@Index);
Ted Kremenek150c2122008-07-11 19:15:05 +0000626 Diag("$Num bugs found.\n");
627 if ($Num > 0 && -r "$Dir/index.html") {
628 Diag("Open '$Dir/index.html' to examine bug reports.\n");
629 }
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000630
Ted Kremenek991c54b2008-08-08 20:46:42 +0000631 DiagCrashes($Dir) if ($Crashes);
632
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000633 return $Num;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000634}
635
636##----------------------------------------------------------------------------##
Ted Kremenekdab11102008-04-02 04:43:42 +0000637# RunBuildCommand - Run the build command.
638##----------------------------------------------------------------------------##
639
Ted Kremenek6b628982008-04-30 23:47:12 +0000640sub AddIfNotPresent {
641 my $Args = shift;
642 my $Arg = shift;
643 my $found = 0;
644
645 foreach my $k (@$Args) {
646 if ($k eq $Arg) {
647 $found = 1;
648 last;
649 }
650 }
651
652 if ($found == 0) {
653 push @$Args, $Arg;
654 }
655}
656
Ted Kremenekdab11102008-04-02 04:43:42 +0000657sub RunBuildCommand {
658
659 my $Args = shift;
Ted Kremenek7442ca62008-04-02 16:04:51 +0000660 my $IgnoreErrors = shift;
Ted Kremenekdab11102008-04-02 04:43:42 +0000661 my $Cmd = $Args->[0];
Ted Kremenek6195c372008-06-02 21:52:47 +0000662 my $CCAnalyzer = shift;
Ted Kremenekdab11102008-04-02 04:43:42 +0000663
Ted Kremenek3301cb12008-06-30 18:18:16 +0000664 # Get only the part of the command after the last '/'.
665 if ($Cmd =~ /\/([^\/]+)$/) {
666 $Cmd = $1;
667 }
668
Ted Kremenek63c20172008-08-04 17:34:06 +0000669 if ($Cmd eq "gcc" or $Cmd eq "cc" or $Cmd eq "llvm-gcc"
670 or $Cmd eq "ccc-analyzer") {
Ted Kremenekdab11102008-04-02 04:43:42 +0000671 shift @$Args;
Ted Kremenek6195c372008-06-02 21:52:47 +0000672 unshift @$Args, $CCAnalyzer;
Ted Kremenekdab11102008-04-02 04:43:42 +0000673 }
Ted Kremenek7442ca62008-04-02 16:04:51 +0000674 elsif ($IgnoreErrors) {
675 if ($Cmd eq "make" or $Cmd eq "gmake") {
Ted Kremenek6b628982008-04-30 23:47:12 +0000676 AddIfNotPresent($Args,"-k");
Ted Kremenek8912b542008-05-13 21:28:02 +0000677 AddIfNotPresent($Args,"-i");
Ted Kremenek7442ca62008-04-02 16:04:51 +0000678 }
679 elsif ($Cmd eq "xcodebuild") {
Ted Kremenek6b628982008-04-30 23:47:12 +0000680 AddIfNotPresent($Args,"-PBXBuildsContinueAfterErrors=YES");
Ted Kremenek7442ca62008-04-02 16:04:51 +0000681 }
Ted Kremenek6b628982008-04-30 23:47:12 +0000682 }
683
Ted Kremenek6b628982008-04-30 23:47:12 +0000684 if ($Cmd eq "xcodebuild") {
Ted Kremenekcfd4c7b2008-05-23 22:18:16 +0000685 # Disable distributed builds for xcodebuild.
Ted Kremenek6b628982008-04-30 23:47:12 +0000686 AddIfNotPresent($Args,"-nodistribute");
Ted Kremenekcfd4c7b2008-05-23 22:18:16 +0000687
688 # Disable PCH files until clang supports them.
689 AddIfNotPresent($Args,"GCC_PRECOMPILE_PREFIX_HEADER=NO");
Ted Kremenek915e9722008-05-27 23:18:07 +0000690
691 # When 'CC' is set, xcodebuild uses it to do all linking, even if we are
692 # linking C++ object files. Set 'LDPLUSPLUS' so that xcodebuild uses 'g++'
693 # when linking such files.
694 my $LDPLUSPLUS = `which g++`;
695 $LDPLUSPLUS =~ s/\015?\012//; # strip newlines
696 $ENV{'LDPLUSPLUS'} = $LDPLUSPLUS;
Ted Kremenek6b628982008-04-30 23:47:12 +0000697 }
Ted Kremenekdab11102008-04-02 04:43:42 +0000698
Ted Kremenek5a4ddaf2008-08-25 20:10:45 +0000699 return (system(@$Args) >> 8);
Ted Kremenekdab11102008-04-02 04:43:42 +0000700}
701
Ted Kremenekdab11102008-04-02 04:43:42 +0000702##----------------------------------------------------------------------------##
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000703# DisplayHelp - Utility function to display all help options.
704##----------------------------------------------------------------------------##
705
Sam Bishopa0e22662008-04-02 03:35:43 +0000706sub DisplayHelp {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000707
Ted Kremenek5744dc22008-04-02 18:03:36 +0000708print <<ENDTEXT;
Sam Bishopa0e22662008-04-02 03:35:43 +0000709USAGE: $Prog [options] <build command> [build options]
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000710
Ted Kremenekf4cdf412008-05-23 18:17:05 +0000711ENDTEXT
712
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000713 if (defined $BuildName) {
Ted Kremenekf4cdf412008-05-23 18:17:05 +0000714 print "ANALYZER BUILD: $BuildName ($BuildDate)\n\n";
715 }
716
717print <<ENDTEXT;
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000718OPTIONS:
719
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000720 -o - Target directory for HTML report files. Subdirectories
Sam Bishopa0e22662008-04-02 03:35:43 +0000721 will be created as needed to represent separate "runs" of
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000722 the analyzer. If this option is not specified, a directory
723 is created in /tmp to store the reports.
Ted Kremenek1262fc42008-05-14 20:10:33 +0000724
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000725 -h - Display this message.
726 --help
Ted Kremenek1262fc42008-05-14 20:10:33 +0000727
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000728 -k - Add a "keep on going" option to the specified build command.
729 --keep-going This option currently supports make and xcodebuild.
Ted Kremenekf02e8db2008-04-02 16:41:25 +0000730 This is a convenience option; one can specify this
731 behavior directly using build options.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000732
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000733 --status-bugs - By default, the exit status of $Prog is the same as the
734 executed build command. Specifying this option causes the
735 exit status of $Prog to be 1 if it found potential bugs
736 and 0 otherwise.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000737
Ted Kremenekf17ef3c2008-08-21 21:47:09 +0000738 --use-cc [compiler path] - By default, $Prog uses 'gcc' to compile
739 --use-cc=[compiler path] your code. This option specifies what compiler
740 to use for regular code compilation.
741
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000742 -v - Verbose output from $Prog and the analyzer.
743 A second and third "-v" increases verbosity.
744
745 -V - View analysis results in a web browser when the build
746 --view completes.
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000747
Ted Kremenekb7770c02008-07-15 17:06:13 +0000748
Ted Kremenekd52e4252008-08-25 20:45:07 +0000749 Available Source Code Analyses (multiple analyses may be specified):
750
751ENDTEXT
Ted Kremenekb7770c02008-07-15 17:06:13 +0000752
753 foreach my $Analysis (sort keys %AvailableAnalyses) {
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000754 if (defined $AnalysesDefaultEnabled{$Analysis}) {
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000755 print " (+)";
Ted Kremenekb7770c02008-07-15 17:06:13 +0000756 }
757 else {
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000758 print " ";
Ted Kremenekb7770c02008-07-15 17:06:13 +0000759 }
760
761 print " $Analysis $AvailableAnalyses{$Analysis}\n";
762 }
763
764print <<ENDTEXT
765
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000766 NOTE: "(+)" indicates that an analysis is enabled by default unless one
767 or more analysis options are specified
Ted Kremenekb7770c02008-07-15 17:06:13 +0000768
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000769BUILD OPTIONS
770
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000771 You can specify any build option acceptable to the build command.
Ted Kremenek39eefde2008-04-02 16:47:27 +0000772
Ted Kremenek5744dc22008-04-02 18:03:36 +0000773EXAMPLE
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000774
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000775 $Prog -o /tmp/myhtmldir make -j4
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000776
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000777 The above example causes analysis reports to be deposited into
778 a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option.
779 A different subdirectory is created each time $Prog analyzes a project.
780 The analyzer should support most parallel builds, but not distributed builds.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000781
782ENDTEXT
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000783}
784
785##----------------------------------------------------------------------------##
786# Process command-line arguments.
787##----------------------------------------------------------------------------##
788
789my $HtmlDir; # Parent directory to store HTML files.
790my $IgnoreErrors = 0; # Ignore build errors.
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000791my $ViewResults = 0; # View results when the build terminates.
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000792my $ExitStatusFoundBugs = 0; # Exit status reflects whether bugs were found
Ted Kremenekb7770c02008-07-15 17:06:13 +0000793my @AnalysesToRun;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000794
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000795
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000796if (!@ARGV) {
797 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +0000798 exit 1;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000799}
800
801while (@ARGV) {
802
803 # Scan for options we recognize.
804
805 my $arg = $ARGV[0];
806
Sam Bishop2f2418e2008-04-03 14:29:47 +0000807 if ($arg eq "-h" or $arg eq "--help") {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000808 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +0000809 exit 0;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000810 }
811
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000812 if (defined $AvailableAnalyses{$arg}) {
Ted Kremenek1262fc42008-05-14 20:10:33 +0000813 shift @ARGV;
Ted Kremenekb7770c02008-07-15 17:06:13 +0000814 push @AnalysesToRun, $arg;
Ted Kremenek1262fc42008-05-14 20:10:33 +0000815 next;
816 }
817
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000818 if ($arg eq "-o") {
819 shift @ARGV;
820
821 if (!@ARGV) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000822 DieDiag("'-o' option requires a target directory name.\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000823 }
824
825 $HtmlDir = shift @ARGV;
826 next;
827 }
828
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000829 if ($arg eq "-k" or $arg eq "--keep-going") {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000830 shift @ARGV;
831 $IgnoreErrors = 1;
832 next;
833 }
834
Ted Kremenekf17ef3c2008-08-21 21:47:09 +0000835 if ($arg =~ /^--use-cc(=(.+))?$/) {
836 shift @ARGV;
837 my $cc;
838
839 if ($2 eq "") {
840 if (!@ARGV) {
841 DieDiag("'--use-cc' option requires a compiler executable name.\n");
842 }
843 $cc = shift @ARGV;
844 }
845 else {
846 $cc = $2;
847 }
848
849 $ENV{"CCC_CC"} = $cc;
850 next;
851 }
852
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000853 if ($arg eq "-v") {
854 shift @ARGV;
855 $Verbose++;
856 next;
857 }
858
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000859 if ($arg eq "-V" or $arg eq "--view") {
860 shift @ARGV;
861 $ViewResults = 1;
862 next;
863 }
864
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000865 if ($arg eq "--status-bugs") {
866 shift @ARGV;
867 $ExitStatusFoundBugs = 1;
868 next;
869 }
870
Ted Kremenek23cfca32008-06-16 22:40:14 +0000871 DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/);
Ted Kremenek0062ad42008-04-02 16:35:01 +0000872
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000873 last;
874}
875
876if (!@ARGV) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000877 Diag("No build command specified.\n\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000878 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +0000879 exit 1;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000880}
881
882# Determine the output directory for the HTML reports.
Ted Kremenek684bb092008-04-18 15:18:20 +0000883my $BaseDir = $HtmlDir;
Sam Bishopa0e22662008-04-02 03:35:43 +0000884$HtmlDir = GetHTMLRunDir($HtmlDir);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000885
886# Set the appropriate environment variables.
Sam Bishopa0e22662008-04-02 03:35:43 +0000887SetHtmlEnv(\@ARGV, $HtmlDir);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000888
Ted Kremenek0b6c1532008-04-08 20:22:12 +0000889my $Cmd = "$RealBin/ccc-analyzer";
890
Ted Kremenek23cfca32008-06-16 22:40:14 +0000891DieDiag("Executable 'ccc-analyzer' does not exist at '$Cmd'\n")
Ted Kremenek0b6c1532008-04-08 20:22:12 +0000892 if (! -x $Cmd);
Ted Kremenekf22eacb2008-04-18 22:00:56 +0000893
Ted Kremenekb7770c02008-07-15 17:06:13 +0000894if (! -x $ClangSB) {
895 Diag("'clang' executable not found in '$RealBin'.\n");
896 Diag("Using 'clang' from path.\n");
Ted Kremenekf22eacb2008-04-18 22:00:56 +0000897}
Ted Kremenek0b6c1532008-04-08 20:22:12 +0000898
Ted Kremenek4f4b17d2008-04-03 20:08:18 +0000899$ENV{'CC'} = $Cmd;
Ted Kremenekf22eacb2008-04-18 22:00:56 +0000900$ENV{'CLANG'} = $Clang;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000901
902if ($Verbose >= 2) {
903 $ENV{'CCC_ANALYZER_VERBOSE'} = 1;
904}
905
Ted Kremeneka9525c92008-05-12 22:07:14 +0000906if ($Verbose >= 3) {
907 $ENV{'CCC_ANALYZER_LOG'} = 1;
908}
909
Ted Kremenek90125992008-07-15 23:41:32 +0000910if (scalar(@AnalysesToRun) == 0) {
911 foreach my $key (keys %AnalysesDefaultEnabled) {
912 push @AnalysesToRun,$key;
913 }
Ted Kremenek01006782008-07-02 23:16:10 +0000914}
Ted Kremenek1262fc42008-05-14 20:10:33 +0000915
Ted Kremenek90125992008-07-15 23:41:32 +0000916$ENV{'CCC_ANALYZER_ANALYSIS'} = join ' ',@AnalysesToRun;
917
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000918# Run the build.
Ted Kremenek5656a982008-07-15 17:09:28 +0000919my $ExitStatus = RunBuildCommand(\@ARGV, $IgnoreErrors, $Cmd);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000920
921# Postprocess the HTML directory.
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000922my $NumBugs = Postprocess($HtmlDir, $BaseDir);
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000923
924if ($ViewResults and -r "$HtmlDir/index.html") {
925 # Only works on Mac OS X (for now).
926 print "Viewing analysis results: '$HtmlDir/index.html'\n";
Ted Kremenek20161e92008-07-15 20:18:21 +0000927 system("open", "$HtmlDir/index.html");
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000928}
Ted Kremenek5656a982008-07-15 17:09:28 +0000929
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000930if ($ExitStatusFoundBugs) {
931 exit 1 if ($NumBugs > 0);
932 exit 0;
933}
934
Ted Kremenek5656a982008-07-15 17:09:28 +0000935exit $ExitStatus;
936