blob: d04c2897e9df135104ec17681a969598c6b2c35b [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 Kremenek63c20172008-08-04 17:34:06 +0000412 # Generate an index.html file.
413 my $FName = "$Dir/index.html";
414 open(OUT, ">", $FName) or DieDiag("Cannot create file '$FName'\n");
Ted Kremenek5744dc22008-04-02 18:03:36 +0000415
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000416 # Print out the header.
417
Ted Kremenek5744dc22008-04-02 18:03:36 +0000418print OUT <<ENDTEXT;
419<html>
420<head>
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000421<style type="text/css">
422 body { color:#000000; background-color:#ffffff }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000423 body { font-family: Helvetica, sans-serif; font-size:9pt }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000424 h1 { font-size:12pt }
Ted Kremenek991c54b2008-08-08 20:46:42 +0000425 table thead {
Ted Kremenek22d6a632008-04-02 20:43:36 +0000426 background-color:#eee; color:#666666;
427 font-weight: bold; cursor: default;
Ted Kremenekbba1cf52008-04-03 05:50:51 +0000428 text-align:center;
429 border-top: 2px solid #000000;
430 border-bottom: 2px solid #000000;
431 font-weight: bold; font-family: Verdana
432 }
Ted Kremenek991c54b2008-08-08 20:46:42 +0000433 table { border: 1px #000000 solid }
434 table { border-collapse: collapse; border-spacing: 0px }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000435 td { border-bottom: 1px #000000 dotted }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000436 td { padding:5px; padding-left:8px; padding-right:8px }
Ted Kremenekd8c6d0c2008-04-07 23:50:07 +0000437 td { text-align:left; font-size:9pt }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000438 td.View { padding-left: 10px }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000439</style>
Ted Kremenek22d6a632008-04-02 20:43:36 +0000440<script src="sorttable.js"></script>
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000441<script language='javascript' type="text/javascript">
442function SetDisplay(RowClass, DisplayVal)
443{
444 var Rows = document.getElementsByTagName("tr");
445 for ( var i = 0 ; i < Rows.length; ++i ) {
446 if (Rows[i].className == RowClass) {
447 Rows[i].style.display = DisplayVal;
448 }
449 }
450}
451
452function ToggleDisplay(CheckButton, ClassName) {
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000453 if (CheckButton.checked) {
454 SetDisplay(ClassName, "");
455 }
456 else {
457 SetDisplay(ClassName, "none");
458 }
459}
460</script>
461</head>
462<body>
463ENDTEXT
464
Ted Kremenek991c54b2008-08-08 20:46:42 +0000465 if (scalar(@files)) {
466 # Print out the summary table.
467 my %Totals;
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000468
Ted Kremenek991c54b2008-08-08 20:46:42 +0000469 for my $row ( @Index ) {
470 #my $bug_type = lc($row->[1]);
471 my $bug_type = ($row->[1]);
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000472
Ted Kremenek991c54b2008-08-08 20:46:42 +0000473 if (!defined $Totals{$bug_type}) { $Totals{$bug_type} = 1; }
474 else { $Totals{$bug_type}++; }
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000475 }
Ted Kremenek991c54b2008-08-08 20:46:42 +0000476
477 print OUT "<h3>Bug Summary</h3>";
478
479 if (defined $BuildName) {
480 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 +0000481 }
Ted Kremenekf4cdf412008-05-23 18:17:05 +0000482
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000483print OUT <<ENDTEXT;
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000484<table class="sortable">
485<tr>
486 <td>Bug Type</td>
487 <td>Quantity</td>
Ted Kremenek2645c772008-07-07 16:58:44 +0000488 <td class="sorttable_nosort">Display?</td>
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000489</tr>
490ENDTEXT
491
Ted Kremenek991c54b2008-08-08 20:46:42 +0000492 for my $key ( sort { $a cmp $b } keys %Totals ) {
493 my $x = lc($key);
494 $x =~ s/[ ,'"]+/_/g;
495 print OUT "<tr><td>$key</td><td>$Totals{$key}</td><td><input type=\"checkbox\" onClick=\"ToggleDisplay(this,'bt_$x');\" checked/></td></tr>\n";
496 }
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000497
498 # Print out the table of errors.
499
500print OUT <<ENDTEXT;
501</table>
502<h3>Reports</h3>
Ted Kremenek22d6a632008-04-02 20:43:36 +0000503<table class="sortable">
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000504<tr>
Ted Kremenek88a96d62008-07-07 17:23:32 +0000505 <td class="sorttable_sorted">Bug Type<span id="sorttable_sortfwdind">&nbsp;&#x25BE;</span>
Ted Kremenekbba1cf52008-04-03 05:50:51 +0000506 <td>File</td>
507 <td>Line</td>
508 <td>Path Length</td>
Ted Kremenek2645c772008-07-07 16:58:44 +0000509 <td class="sorttable_nosort"></td>
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000510</tr>
Ted Kremenek5744dc22008-04-02 18:03:36 +0000511ENDTEXT
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000512
Ted Kremenek991c54b2008-08-08 20:46:42 +0000513 my $prefix = GetPrefix();
514 my $regex;
515 my $InFileRegex;
516 my $InFilePrefix = "File:</td><td>";
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000517
Ted Kremenek991c54b2008-08-08 20:46:42 +0000518 if (defined $prefix) {
519 $regex = qr/^\Q$prefix\E/is;
520 $InFileRegex = qr/\Q$InFilePrefix$prefix\E/is;
521 }
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000522
Ted Kremenek991c54b2008-08-08 20:46:42 +0000523 for my $row ( sort { $a->[1] cmp $b->[1] } @Index ) {
Ted Kremenek5744dc22008-04-02 18:03:36 +0000524
Ted Kremenek991c54b2008-08-08 20:46:42 +0000525 my $x = lc($row->[1]);
526 $x =~ s/[ ,'"]+/_/g;
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000527
Ted Kremenek991c54b2008-08-08 20:46:42 +0000528 print OUT "<tr class=\"bt_$x\">\n";
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000529
Ted Kremenek991c54b2008-08-08 20:46:42 +0000530 my $ReportFile = $row->[0];
Ted Kremenek5744dc22008-04-02 18:03:36 +0000531
Ted Kremenek991c54b2008-08-08 20:46:42 +0000532 print OUT " <td class=\"DESC\">";
533 #print OUT lc($row->[1]);
534 print OUT $row->[1];
535 print OUT "</td>\n";
Ted Kremenek5744dc22008-04-02 18:03:36 +0000536
Ted Kremenek991c54b2008-08-08 20:46:42 +0000537 # Update the file prefix.
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000538
Ted Kremenek991c54b2008-08-08 20:46:42 +0000539 my $fname = $row->[2];
540 if (defined $regex) {
541 $fname =~ s/$regex//;
542 UpdateInFilePath("$Dir/$ReportFile", $InFileRegex, $InFilePrefix)
543 }
Ted Kremenek3e56e0b2008-05-02 23:40:49 +0000544
Ted Kremenek991c54b2008-08-08 20:46:42 +0000545 print OUT "<td>$fname</td>\n";
Ted Kremenek7a4648d2008-05-02 22:04:53 +0000546
Ted Kremenek991c54b2008-08-08 20:46:42 +0000547 # Print the rest of the columns.
548 for my $j ( 3 .. $#{$row} ) {
549 print OUT "<td>$row->[$j]</td>\n"
550 }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000551
Ted Kremenek991c54b2008-08-08 20:46:42 +0000552 # Emit the "View" link.
553 print OUT " <td class=\"View\"><a href=\"$ReportFile#EndPath\">View</a></td>\n";
Ted Kremenek3cea9ee2008-07-30 17:58:08 +0000554
Ted Kremenek991c54b2008-08-08 20:46:42 +0000555 # End the row.
556 print OUT "</tr>\n";
557 }
558
559 print OUT "</table>\n";
560 }
561
562 if ($Crashes) {
563 # Read the crash directory for files.
564 opendir(DIR, "$Dir/crashes");
565 my @files = grep { /[.]info$/ } readdir(DIR);
566 closedir(DIR);
567
568 if (scalar(@files)) {
569 print OUT <<ENDTEXT;
Ted Kremenek5d31f832008-08-18 18:38:29 +0000570<h3>Analyzer Failures</h3>
Ted Kremenek991c54b2008-08-08 20:46:42 +0000571
Ted Kremenek5d31f832008-08-18 18:38:29 +0000572<p>The analyzer had problems processing the following files:</p>
Ted Kremenek991c54b2008-08-08 20:46:42 +0000573
574<table>
Ted Kremenek5d31f832008-08-18 18:38:29 +0000575<thead><tr><td>Problem</td><td>Source File</td><td>Preprocessed File</td></tr></thead>
Ted Kremenek991c54b2008-08-08 20:46:42 +0000576ENDTEXT
577
578 foreach my $file (sort @files) {
579 $file =~ /(.+).info$/;
580 # Get the preprocessed file.
581 my $ppfile = $1;
582 # Open the info file and get the name of the source file.
583 open (INFO, "$Dir/crashes/$file") or
584 die "Cannot open $Dir/crashes/$file\n";
585 my $srcfile = <INFO>;
Ted Kremenek5d31f832008-08-18 18:38:29 +0000586 chomp $srcfile;
587 my $problem = <INFO>;
588 chomp $problem;
Ted Kremenek991c54b2008-08-08 20:46:42 +0000589 close (INFO);
590 # Print the information in the table.
Ted Kremenek5d31f832008-08-18 18:38:29 +0000591 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 +0000592 }
593
594 print OUT <<ENDTEXT;
595</table>
596<p>Please consider submitting preprocessed files as <a href="http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs">bug reports</a>.</p>
597ENDTEXT
598 }
Ted Kremenek5744dc22008-04-02 18:03:36 +0000599 }
600
Ted Kremenek991c54b2008-08-08 20:46:42 +0000601 print OUT "</body></html>\n";
Ted Kremenek5744dc22008-04-02 18:03:36 +0000602 close(OUT);
Ted Kremenek22d6a632008-04-02 20:43:36 +0000603 CopyJS($Dir);
Ted Kremenek20161e92008-07-15 20:18:21 +0000604
605 # Make sure $Dir and $BaseDir are world readable/executable.
606 system("chmod", "755", $Dir);
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000607 if (defined $BaseDir) { system("chmod", "755", $BaseDir); }
Ted Kremenek20161e92008-07-15 20:18:21 +0000608
Ted Kremenek23cfca32008-06-16 22:40:14 +0000609 my $Num = scalar(@Index);
Ted Kremenek150c2122008-07-11 19:15:05 +0000610 Diag("$Num bugs found.\n");
611 if ($Num > 0 && -r "$Dir/index.html") {
612 Diag("Open '$Dir/index.html' to examine bug reports.\n");
613 }
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000614
Ted Kremenek991c54b2008-08-08 20:46:42 +0000615 DiagCrashes($Dir) if ($Crashes);
616
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000617 return $Num;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000618}
619
620##----------------------------------------------------------------------------##
Ted Kremenekdab11102008-04-02 04:43:42 +0000621# RunBuildCommand - Run the build command.
622##----------------------------------------------------------------------------##
623
Ted Kremenek6b628982008-04-30 23:47:12 +0000624sub AddIfNotPresent {
625 my $Args = shift;
626 my $Arg = shift;
627 my $found = 0;
628
629 foreach my $k (@$Args) {
630 if ($k eq $Arg) {
631 $found = 1;
632 last;
633 }
634 }
635
636 if ($found == 0) {
637 push @$Args, $Arg;
638 }
639}
640
Ted Kremenekdab11102008-04-02 04:43:42 +0000641sub RunBuildCommand {
642
643 my $Args = shift;
Ted Kremenek7442ca62008-04-02 16:04:51 +0000644 my $IgnoreErrors = shift;
Ted Kremenekdab11102008-04-02 04:43:42 +0000645 my $Cmd = $Args->[0];
Ted Kremenek6195c372008-06-02 21:52:47 +0000646 my $CCAnalyzer = shift;
Ted Kremenekdab11102008-04-02 04:43:42 +0000647
Ted Kremenek3301cb12008-06-30 18:18:16 +0000648 # Get only the part of the command after the last '/'.
649 if ($Cmd =~ /\/([^\/]+)$/) {
650 $Cmd = $1;
651 }
652
Ted Kremenek63c20172008-08-04 17:34:06 +0000653 if ($Cmd eq "gcc" or $Cmd eq "cc" or $Cmd eq "llvm-gcc"
654 or $Cmd eq "ccc-analyzer") {
Ted Kremenekdab11102008-04-02 04:43:42 +0000655 shift @$Args;
Ted Kremenek6195c372008-06-02 21:52:47 +0000656 unshift @$Args, $CCAnalyzer;
Ted Kremenekdab11102008-04-02 04:43:42 +0000657 }
Ted Kremenek7442ca62008-04-02 16:04:51 +0000658 elsif ($IgnoreErrors) {
659 if ($Cmd eq "make" or $Cmd eq "gmake") {
Ted Kremenek6b628982008-04-30 23:47:12 +0000660 AddIfNotPresent($Args,"-k");
Ted Kremenek8912b542008-05-13 21:28:02 +0000661 AddIfNotPresent($Args,"-i");
Ted Kremenek7442ca62008-04-02 16:04:51 +0000662 }
663 elsif ($Cmd eq "xcodebuild") {
Ted Kremenek6b628982008-04-30 23:47:12 +0000664 AddIfNotPresent($Args,"-PBXBuildsContinueAfterErrors=YES");
Ted Kremenek7442ca62008-04-02 16:04:51 +0000665 }
Ted Kremenek6b628982008-04-30 23:47:12 +0000666 }
667
Ted Kremenek6b628982008-04-30 23:47:12 +0000668 if ($Cmd eq "xcodebuild") {
Ted Kremenekcfd4c7b2008-05-23 22:18:16 +0000669 # Disable distributed builds for xcodebuild.
Ted Kremenek6b628982008-04-30 23:47:12 +0000670 AddIfNotPresent($Args,"-nodistribute");
Ted Kremenekcfd4c7b2008-05-23 22:18:16 +0000671
672 # Disable PCH files until clang supports them.
673 AddIfNotPresent($Args,"GCC_PRECOMPILE_PREFIX_HEADER=NO");
Ted Kremenek915e9722008-05-27 23:18:07 +0000674
675 # When 'CC' is set, xcodebuild uses it to do all linking, even if we are
676 # linking C++ object files. Set 'LDPLUSPLUS' so that xcodebuild uses 'g++'
677 # when linking such files.
678 my $LDPLUSPLUS = `which g++`;
679 $LDPLUSPLUS =~ s/\015?\012//; # strip newlines
680 $ENV{'LDPLUSPLUS'} = $LDPLUSPLUS;
Ted Kremenek6b628982008-04-30 23:47:12 +0000681 }
Ted Kremenekdab11102008-04-02 04:43:42 +0000682
Ted Kremenek5656a982008-07-15 17:09:28 +0000683 return system(@$Args);
Ted Kremenekdab11102008-04-02 04:43:42 +0000684}
685
Ted Kremenekdab11102008-04-02 04:43:42 +0000686##----------------------------------------------------------------------------##
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000687# DisplayHelp - Utility function to display all help options.
688##----------------------------------------------------------------------------##
689
Sam Bishopa0e22662008-04-02 03:35:43 +0000690sub DisplayHelp {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000691
Ted Kremenek5744dc22008-04-02 18:03:36 +0000692print <<ENDTEXT;
Sam Bishopa0e22662008-04-02 03:35:43 +0000693USAGE: $Prog [options] <build command> [build options]
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000694
Ted Kremenekf4cdf412008-05-23 18:17:05 +0000695ENDTEXT
696
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000697 if (defined $BuildName) {
Ted Kremenekf4cdf412008-05-23 18:17:05 +0000698 print "ANALYZER BUILD: $BuildName ($BuildDate)\n\n";
699 }
700
701print <<ENDTEXT;
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000702OPTIONS:
703
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000704 -o - Target directory for HTML report files. Subdirectories
Sam Bishopa0e22662008-04-02 03:35:43 +0000705 will be created as needed to represent separate "runs" of
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000706 the analyzer. If this option is not specified, a directory
707 is created in /tmp to store the reports.
Ted Kremenek1262fc42008-05-14 20:10:33 +0000708
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000709 -h - Display this message.
710 --help
Ted Kremenek1262fc42008-05-14 20:10:33 +0000711
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000712 -k - Add a "keep on going" option to the specified build command.
713 --keep-going This option currently supports make and xcodebuild.
Ted Kremenekf02e8db2008-04-02 16:41:25 +0000714 This is a convenience option; one can specify this
715 behavior directly using build options.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000716
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000717 --status-bugs - By default, the exit status of $Prog is the same as the
718 executed build command. Specifying this option causes the
719 exit status of $Prog to be 1 if it found potential bugs
720 and 0 otherwise.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000721
Ted Kremenekf17ef3c2008-08-21 21:47:09 +0000722 --use-cc [compiler path] - By default, $Prog uses 'gcc' to compile
723 --use-cc=[compiler path] your code. This option specifies what compiler
724 to use for regular code compilation.
725
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000726 -v - Verbose output from $Prog and the analyzer.
727 A second and third "-v" increases verbosity.
728
729 -V - View analysis results in a web browser when the build
730 --view completes.
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000731
Ted Kremenekb7770c02008-07-15 17:06:13 +0000732ENDTEXT
733
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000734 print " Available Source Code Analyses (multiple analyses may be specified):\n\n";
Ted Kremenekb7770c02008-07-15 17:06:13 +0000735
736 foreach my $Analysis (sort keys %AvailableAnalyses) {
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000737 if (defined $AnalysesDefaultEnabled{$Analysis}) {
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000738 print " (+)";
Ted Kremenekb7770c02008-07-15 17:06:13 +0000739 }
740 else {
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000741 print " ";
Ted Kremenekb7770c02008-07-15 17:06:13 +0000742 }
743
744 print " $Analysis $AvailableAnalyses{$Analysis}\n";
745 }
746
747print <<ENDTEXT
748
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000749 NOTE: "(+)" indicates that an analysis is enabled by default unless one
750 or more analysis options are specified
Ted Kremenekb7770c02008-07-15 17:06:13 +0000751
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000752BUILD OPTIONS
753
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000754 You can specify any build option acceptable to the build command.
Ted Kremenek39eefde2008-04-02 16:47:27 +0000755
Ted Kremenek5744dc22008-04-02 18:03:36 +0000756EXAMPLE
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000757
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000758 $Prog -o /tmp/myhtmldir make -j4
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000759
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000760 The above example causes analysis reports to be deposited into
761 a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option.
762 A different subdirectory is created each time $Prog analyzes a project.
763 The analyzer should support most parallel builds, but not distributed builds.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000764
765ENDTEXT
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000766}
767
768##----------------------------------------------------------------------------##
769# Process command-line arguments.
770##----------------------------------------------------------------------------##
771
772my $HtmlDir; # Parent directory to store HTML files.
773my $IgnoreErrors = 0; # Ignore build errors.
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000774my $ViewResults = 0; # View results when the build terminates.
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000775my $ExitStatusFoundBugs = 0; # Exit status reflects whether bugs were found
Ted Kremenekb7770c02008-07-15 17:06:13 +0000776my @AnalysesToRun;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000777
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000778
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000779if (!@ARGV) {
780 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +0000781 exit 1;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000782}
783
784while (@ARGV) {
785
786 # Scan for options we recognize.
787
788 my $arg = $ARGV[0];
789
Sam Bishop2f2418e2008-04-03 14:29:47 +0000790 if ($arg eq "-h" or $arg eq "--help") {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000791 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +0000792 exit 0;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000793 }
794
Ted Kremenekfc1d3402008-08-04 18:15:26 +0000795 if (defined $AvailableAnalyses{$arg}) {
Ted Kremenek1262fc42008-05-14 20:10:33 +0000796 shift @ARGV;
Ted Kremenekb7770c02008-07-15 17:06:13 +0000797 push @AnalysesToRun, $arg;
Ted Kremenek1262fc42008-05-14 20:10:33 +0000798 next;
799 }
800
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000801 if ($arg eq "-o") {
802 shift @ARGV;
803
804 if (!@ARGV) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000805 DieDiag("'-o' option requires a target directory name.\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000806 }
807
808 $HtmlDir = shift @ARGV;
809 next;
810 }
811
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000812 if ($arg eq "-k" or $arg eq "--keep-going") {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000813 shift @ARGV;
814 $IgnoreErrors = 1;
815 next;
816 }
817
Ted Kremenekf17ef3c2008-08-21 21:47:09 +0000818 if ($arg =~ /^--use-cc(=(.+))?$/) {
819 shift @ARGV;
820 my $cc;
821
822 if ($2 eq "") {
823 if (!@ARGV) {
824 DieDiag("'--use-cc' option requires a compiler executable name.\n");
825 }
826 $cc = shift @ARGV;
827 }
828 else {
829 $cc = $2;
830 }
831
832 $ENV{"CCC_CC"} = $cc;
833 next;
834 }
835
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000836 if ($arg eq "-v") {
837 shift @ARGV;
838 $Verbose++;
839 next;
840 }
841
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000842 if ($arg eq "-V" or $arg eq "--view") {
843 shift @ARGV;
844 $ViewResults = 1;
845 next;
846 }
847
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000848 if ($arg eq "--status-bugs") {
849 shift @ARGV;
850 $ExitStatusFoundBugs = 1;
851 next;
852 }
853
Ted Kremenek23cfca32008-06-16 22:40:14 +0000854 DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/);
Ted Kremenek0062ad42008-04-02 16:35:01 +0000855
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000856 last;
857}
858
859if (!@ARGV) {
Ted Kremenek23cfca32008-06-16 22:40:14 +0000860 Diag("No build command specified.\n\n");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000861 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +0000862 exit 1;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000863}
864
865# Determine the output directory for the HTML reports.
Ted Kremenek684bb092008-04-18 15:18:20 +0000866my $BaseDir = $HtmlDir;
Sam Bishopa0e22662008-04-02 03:35:43 +0000867$HtmlDir = GetHTMLRunDir($HtmlDir);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000868
869# Set the appropriate environment variables.
Sam Bishopa0e22662008-04-02 03:35:43 +0000870SetHtmlEnv(\@ARGV, $HtmlDir);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000871
Ted Kremenek0b6c1532008-04-08 20:22:12 +0000872my $Cmd = "$RealBin/ccc-analyzer";
873
Ted Kremenek23cfca32008-06-16 22:40:14 +0000874DieDiag("Executable 'ccc-analyzer' does not exist at '$Cmd'\n")
Ted Kremenek0b6c1532008-04-08 20:22:12 +0000875 if (! -x $Cmd);
Ted Kremenekf22eacb2008-04-18 22:00:56 +0000876
Ted Kremenekb7770c02008-07-15 17:06:13 +0000877if (! -x $ClangSB) {
878 Diag("'clang' executable not found in '$RealBin'.\n");
879 Diag("Using 'clang' from path.\n");
Ted Kremenekf22eacb2008-04-18 22:00:56 +0000880}
Ted Kremenek0b6c1532008-04-08 20:22:12 +0000881
Ted Kremenek4f4b17d2008-04-03 20:08:18 +0000882$ENV{'CC'} = $Cmd;
Ted Kremenekf22eacb2008-04-18 22:00:56 +0000883$ENV{'CLANG'} = $Clang;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000884
885if ($Verbose >= 2) {
886 $ENV{'CCC_ANALYZER_VERBOSE'} = 1;
887}
888
Ted Kremeneka9525c92008-05-12 22:07:14 +0000889if ($Verbose >= 3) {
890 $ENV{'CCC_ANALYZER_LOG'} = 1;
891}
892
Ted Kremenek90125992008-07-15 23:41:32 +0000893if (scalar(@AnalysesToRun) == 0) {
894 foreach my $key (keys %AnalysesDefaultEnabled) {
895 push @AnalysesToRun,$key;
896 }
Ted Kremenek01006782008-07-02 23:16:10 +0000897}
Ted Kremenek1262fc42008-05-14 20:10:33 +0000898
Ted Kremenek90125992008-07-15 23:41:32 +0000899$ENV{'CCC_ANALYZER_ANALYSIS'} = join ' ',@AnalysesToRun;
900
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000901# Run the build.
Ted Kremenek5656a982008-07-15 17:09:28 +0000902my $ExitStatus = RunBuildCommand(\@ARGV, $IgnoreErrors, $Cmd);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000903
904# Postprocess the HTML directory.
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000905my $NumBugs = Postprocess($HtmlDir, $BaseDir);
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000906
907if ($ViewResults and -r "$HtmlDir/index.html") {
908 # Only works on Mac OS X (for now).
909 print "Viewing analysis results: '$HtmlDir/index.html'\n";
Ted Kremenek20161e92008-07-15 20:18:21 +0000910 system("open", "$HtmlDir/index.html");
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000911}
Ted Kremenek5656a982008-07-15 17:09:28 +0000912
Ted Kremenek363dc3f2008-07-15 22:03:09 +0000913if ($ExitStatusFoundBugs) {
914 exit 1 if ($NumBugs > 0);
915 exit 0;
916}
917
Ted Kremenek5656a982008-07-15 17:09:28 +0000918exit $ExitStatus;
919