blob: 0024c8ec366bc53ddfeefe56ed0a8544a08db011 [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;
17use File::Temp qw/ :mktemp /;
Ted Kremenek22d6a632008-04-02 20:43:36 +000018use FindBin qw($RealBin);
Ted Kremeneka6e24812008-04-19 18:05:48 +000019use Digest::MD5;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +000020
21my $Verbose = 0; # Verbose output from this script.
22my $Prog = "scan-build";
23
24##----------------------------------------------------------------------------##
25# GetHTMLRunDir - Construct an HTML directory name for the current run.
26##----------------------------------------------------------------------------##
27
Sam Bishopa0e22662008-04-02 03:35:43 +000028sub GetHTMLRunDir {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +000029
30 die "Not enough arguments." if (@_ == 0);
31
32 my $Dir = shift @_;
33
34 # Get current date and time.
35
36 my @CurrentTime = localtime();
37
38 my $year = $CurrentTime[5] + 1900;
39 my $day = $CurrentTime[3];
40 my $month = $CurrentTime[4] + 1;
41
42 my $DateString = "$year-$month-$day";
43
44 # Determine the run number.
45
46 my $RunNumber;
47
48 if (-d $Dir) {
49
50 if (! -r $Dir) {
Sam Bishopa0e22662008-04-02 03:35:43 +000051 die "error: '$Dir' exists but is not readable.\n";
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +000052 }
53
54 # Iterate over all files in the specified directory.
55
56 my $max = 0;
57
58 opendir(DIR, $Dir);
59 my @FILES= readdir(DIR);
60 closedir(DIR);
61
62 foreach my $f (@FILES) {
63
64 my @x = split/-/, $f;
65
66 next if (scalar(@x) != 4);
67 next if ($x[0] != $year);
68 next if ($x[1] != $month);
69 next if ($x[2] != $day);
70
71 if ($x[3] > $max) {
72 $max = $x[3];
73 }
74 }
75
76 $RunNumber = $max + 1;
77 }
78 else {
79
80 if (-x $Dir) {
Sam Bishopa0e22662008-04-02 03:35:43 +000081 die "error: '$Dir' exists but is not a directory.\n";
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +000082 }
83
84 # $Dir does not exist. It will be automatically created by the
85 # clang driver. Set the run number to 1.
86
87 $RunNumber = 1;
88 }
89
90 die "RunNumber must be defined!" if (!defined($RunNumber));
91
92 # Append the run number.
93
94 return "$Dir/$DateString-$RunNumber";
95}
96
Sam Bishopa0e22662008-04-02 03:35:43 +000097sub SetHtmlEnv {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +000098
99 die "Wrong number of arguments." if (scalar(@_) != 2);
100
101 my $Args = shift;
102 my $Dir = shift;
103
104 die "No build command." if (scalar(@$Args) == 0);
105
106 my $Cmd = $$Args[0];
107
108 if ($Cmd =~ /configure/) {
109 return;
110 }
111
112 if ($Verbose) {
113 print "$Prog: Emitting reports for this run to '$Dir'.\n";
114 }
115
116 $ENV{'CCC_ANALYZER_HTML'} = $Dir;
117}
118
119##----------------------------------------------------------------------------##
Ted Kremenek57cf4462008-04-18 15:09:30 +0000120# ComputeDigest - Compute a digest of the specified file.
121##----------------------------------------------------------------------------##
122
123sub ComputeDigest {
124 my $FName = shift;
125 die "Cannot read $FName" if (! -r $FName);
Ted Kremeneka6e24812008-04-19 18:05:48 +0000126
127 # Use Digest::MD5. We don't have to be cryptographically secure. We're
Ted Kremenek7ea02e62008-04-19 18:07:44 +0000128 # just looking for duplicate files that come from a non-malicious source.
129 # We use Digest::MD5 because it is a standard Perl module that should
Ted Kremeneka6e24812008-04-19 18:05:48 +0000130 # come bundled on most systems.
131
132 open(FILE, $FName) or die "Cannot open $FName.";
133 binmode FILE;
134 my $Result = Digest::MD5->new->addfile(*FILE)->hexdigest;
135 close(FILE);
136
137 # Return the digest.
138
139 return $Result;
Ted Kremenek57cf4462008-04-18 15:09:30 +0000140}
141
142##----------------------------------------------------------------------------##
Ted Kremenek5744dc22008-04-02 18:03:36 +0000143# ScanFile - Scan a report file for various identifying attributes.
144##----------------------------------------------------------------------------##
145
Ted Kremenek57cf4462008-04-18 15:09:30 +0000146# Sometimes a source file is scanned more than once, and thus produces
147# multiple error reports. We use a cache to solve this problem.
148
149my %AlreadyScanned;
150
Ted Kremenek5744dc22008-04-02 18:03:36 +0000151sub ScanFile {
152
153 my $Index = shift;
154 my $Dir = shift;
155 my $FName = shift;
156
Ted Kremenek57cf4462008-04-18 15:09:30 +0000157 # Compute a digest for the report file. Determine if we have already
158 # scanned a file that looks just like it.
159
160 my $digest = ComputeDigest("$Dir/$FName");
161
162 if (defined($AlreadyScanned{$digest})) {
163 # Redundant file. Remove it.
164 `rm -f $Dir/$FName`;
165 return;
166 }
167
168 $AlreadyScanned{$digest} = 1;
169
Ted Kremenek809709f2008-04-18 16:58:34 +0000170 # At this point the report file is not world readable. Make it happen.
Ted Kremenek684bb092008-04-18 15:18:20 +0000171 `chmod 644 $Dir/$FName`;
172
173 # Scan the report file for tags.
Ted Kremenek5744dc22008-04-02 18:03:36 +0000174 open(IN, "$Dir/$FName") or die "$Prog: Cannot open '$Dir/$FName'\n";
175
176 my $BugDesc = "";
Ted Kremenek22d6a632008-04-02 20:43:36 +0000177 my $BugFile = "";
178 my $BugPathLength = 1;
179 my $BugLine = 0;
Ted Kremenek5744dc22008-04-02 18:03:36 +0000180
181 while (<IN>) {
182
183 if (/<!-- BUGDESC (.*) -->$/) {
184 $BugDesc = $1;
Ted Kremenek5744dc22008-04-02 18:03:36 +0000185 }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000186 elsif (/<!-- BUGFILE (.*) -->$/) {
187 $BugFile = $1;
188 }
189 elsif (/<!-- BUGPATHLENGTH (.*) -->$/) {
190 $BugPathLength = $1;
191 }
192 elsif (/<!-- BUGLINE (.*) -->$/) {
193 $BugLine = $1;
194 }
Ted Kremenek5744dc22008-04-02 18:03:36 +0000195 }
196
197 close(IN);
198
Ted Kremenek22d6a632008-04-02 20:43:36 +0000199 push @$Index,[ $FName, $BugDesc, $BugFile, $BugLine, $BugPathLength ];
200}
201
202##----------------------------------------------------------------------------##
203# CopyJS - Copy JavaScript code to target directory.
204##----------------------------------------------------------------------------##
205
206sub CopyJS {
207
208 my $Dir = shift;
209
210 die "$Prog: Cannot find 'sorttable.js'.\n"
211 if (! -r "$RealBin/sorttable.js");
212
213 `cp $RealBin/sorttable.js $Dir`;
214
215 die "$Prog: Could not copy 'sorttable.js' to '$Dir'."
216 if (! -r "$Dir/sorttable.js");
Ted Kremenek5744dc22008-04-02 18:03:36 +0000217}
218
219##----------------------------------------------------------------------------##
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000220# Postprocess - Postprocess the results of an analysis scan.
221##----------------------------------------------------------------------------##
222
Sam Bishopa0e22662008-04-02 03:35:43 +0000223sub Postprocess {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000224
225 my $Dir = shift;
Ted Kremenek684bb092008-04-18 15:18:20 +0000226 my $BaseDir = shift;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000227
228 die "No directory specified." if (!defined($Dir));
Ted Kremenek684bb092008-04-18 15:18:20 +0000229 die "No base directory specified." if (!defined($BaseDir));
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000230
231 if (! -d $Dir) {
232 return;
233 }
234
235 opendir(DIR, $Dir);
236 my @files = grep(/^report-.*\.html$/,readdir(DIR));
237 closedir(DIR);
238
239 if (scalar(@files) == 0) {
Ted Kremenek02493782008-04-02 07:05:07 +0000240 print "$Prog: Removing directory '$Dir' because it contains no reports.\n";
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000241 `rm -fR $Dir`;
242 return;
243 }
Ted Kremenek5744dc22008-04-02 18:03:36 +0000244
245 # Scan each report file and build an index.
246
247 my @Index;
248
249 foreach my $file (@files) { ScanFile(\@Index, $Dir, $file); }
250
251 # Generate an index.html file.
252
253 my $FName = "$Dir/index.html";
254
255 open(OUT, ">$FName") or die "$Prog: Cannot create file '$FName'\n";
256
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000257 # Print out the header.
258
Ted Kremenek5744dc22008-04-02 18:03:36 +0000259print OUT <<ENDTEXT;
260<html>
261<head>
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000262<style type="text/css">
263 body { color:#000000; background-color:#ffffff }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000264 body { font-family: Helvetica, sans-serif; font-size:9pt }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000265 h1 { font-size:12pt }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000266 table.sortable thead {
267 background-color:#eee; color:#666666;
268 font-weight: bold; cursor: default;
Ted Kremenekbba1cf52008-04-03 05:50:51 +0000269 text-align:center;
270 border-top: 2px solid #000000;
271 border-bottom: 2px solid #000000;
272 font-weight: bold; font-family: Verdana
273 }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000274 table.sortable { border: 1px #000000 solid }
275 table.sortable { border-collapse: collapse; border-spacing: 0px }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000276 td { border-bottom: 1px #000000 dotted }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000277 td { padding:5px; padding-left:8px; padding-right:8px }
Ted Kremenekd8c6d0c2008-04-07 23:50:07 +0000278 td { text-align:left; font-size:9pt }
Ted Kremenek22d6a632008-04-02 20:43:36 +0000279 td.View { padding-left: 10px }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000280</style>
Ted Kremenek22d6a632008-04-02 20:43:36 +0000281<script src="sorttable.js"></script>
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000282<script language='javascript' type="text/javascript">
283function SetDisplay(RowClass, DisplayVal)
284{
285 var Rows = document.getElementsByTagName("tr");
286 for ( var i = 0 ; i < Rows.length; ++i ) {
287 if (Rows[i].className == RowClass) {
288 Rows[i].style.display = DisplayVal;
289 }
290 }
291}
292
293function ToggleDisplay(CheckButton, ClassName) {
294 window.console.log("writing");
295 if (CheckButton.checked) {
296 SetDisplay(ClassName, "");
297 }
298 else {
299 SetDisplay(ClassName, "none");
300 }
301}
302</script>
303</head>
304<body>
305ENDTEXT
306
307 # Print out the summary table.
308
309 my %Totals;
310
311 for my $row ( @Index ) {
312
313 my $bug_type = lc($row->[1]);
314
315 if (!defined($Totals{$bug_type})) {
316 $Totals{$bug_type} = 1;
317 }
318 else {
319 $Totals{$bug_type}++;
320 }
321 }
322
323print OUT <<ENDTEXT;
324<h3>Summary</h3>
325<table class="sortable">
326<tr>
327 <td>Bug Type</td>
328 <td>Quantity</td>
329 <td "sorttable_nosort">Display?</td>
330</tr>
331ENDTEXT
332
333 for my $key ( sort { $a cmp $b } keys %Totals ) {
334 my $x = $key;
335 $x =~ s/\s/_/g;
336 print OUT "<tr><td>$key</td><td>$Totals{$key}</td><td><input type=\"checkbox\" onClick=\"ToggleDisplay(this,'bt_$x');\" checked/></td></tr>\n";
337 }
338
339 # Print out the table of errors.
340
341print OUT <<ENDTEXT;
342</table>
343<h3>Reports</h3>
Ted Kremenek22d6a632008-04-02 20:43:36 +0000344<table class="sortable">
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000345<tr>
Ted Kremenekbba1cf52008-04-03 05:50:51 +0000346 <td>Bug Type</td>
347 <td>File</td>
348 <td>Line</td>
349 <td>Path Length</td>
350 <td "sorttable_nosort"></td>
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000351</tr>
Ted Kremenek5744dc22008-04-02 18:03:36 +0000352ENDTEXT
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000353
Ted Kremenek5744dc22008-04-02 18:03:36 +0000354 for my $row ( sort { $a->[1] cmp $b->[1] } @Index ) {
355
Ted Kremenek6e6eff72008-04-15 20:47:02 +0000356 my $x = lc($row->[1]);
357 $x =~ s/\s/_/g;
358
359 print OUT "<tr class=\"bt_$x\">\n";
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000360
Ted Kremenek5744dc22008-04-02 18:03:36 +0000361 my $ReportFile = $row->[0];
362
Ted Kremenek22d6a632008-04-02 20:43:36 +0000363 print OUT " <td class=\"DESC\">";
364 print OUT lc($row->[1]);
365 print OUT "</td>\n";
Ted Kremenek5744dc22008-04-02 18:03:36 +0000366
367 for my $j ( 2 .. $#{$row} ) {
368 print OUT "<td>$row->[$j]</td>\n"
369 }
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000370
371 # Emit the "View" link.
Ted Kremenek5744dc22008-04-02 18:03:36 +0000372
Ted Kremenek22d6a632008-04-02 20:43:36 +0000373 print OUT " <td class=\"View\"><a href=\"$ReportFile#EndPath\">View</a></td>\n";
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000374
375 # End the row.
Ted Kremenek5744dc22008-04-02 18:03:36 +0000376 print OUT "</tr>\n";
377 }
378
379 print OUT "</table>\n</body></html>\n";
380 close(OUT);
Ted Kremenek22d6a632008-04-02 20:43:36 +0000381
Ted Kremenek22d6a632008-04-02 20:43:36 +0000382 CopyJS($Dir);
Ted Kremenek684bb092008-04-18 15:18:20 +0000383
384 # Make sure $Dir and $BaseDir is world readable/executable.
385 `chmod 755 $Dir`;
386 `chmod 755 $BaseDir`;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000387}
388
389##----------------------------------------------------------------------------##
Ted Kremenekdab11102008-04-02 04:43:42 +0000390# RunBuildCommand - Run the build command.
391##----------------------------------------------------------------------------##
392
Ted Kremenek6b628982008-04-30 23:47:12 +0000393sub AddIfNotPresent {
394 my $Args = shift;
395 my $Arg = shift;
396 my $found = 0;
397
398 foreach my $k (@$Args) {
399 if ($k eq $Arg) {
400 $found = 1;
401 last;
402 }
403 }
404
405 if ($found == 0) {
406 push @$Args, $Arg;
407 }
408}
409
Ted Kremenekdab11102008-04-02 04:43:42 +0000410sub RunBuildCommand {
411
412 my $Args = shift;
Ted Kremenek7442ca62008-04-02 16:04:51 +0000413 my $IgnoreErrors = shift;
Ted Kremenekdab11102008-04-02 04:43:42 +0000414 my $Cmd = $Args->[0];
415
Ted Kremenek6a43ba92008-04-02 15:34:12 +0000416 if ($Cmd eq "gcc" or $Cmd eq "cc" or $Cmd eq "llvm-gcc") {
Ted Kremenekdab11102008-04-02 04:43:42 +0000417 shift @$Args;
418 unshift @$Args, "ccc-analyzer"
419 }
Ted Kremenek7442ca62008-04-02 16:04:51 +0000420 elsif ($IgnoreErrors) {
421 if ($Cmd eq "make" or $Cmd eq "gmake") {
Ted Kremenek6b628982008-04-30 23:47:12 +0000422 AddIfNotPresent($Args,"-k");
Ted Kremenek7442ca62008-04-02 16:04:51 +0000423 }
424 elsif ($Cmd eq "xcodebuild") {
Ted Kremenek6b628982008-04-30 23:47:12 +0000425 AddIfNotPresent($Args,"-PBXBuildsContinueAfterErrors=YES");
Ted Kremenek7442ca62008-04-02 16:04:51 +0000426 }
Ted Kremenek6b628982008-04-30 23:47:12 +0000427 }
428
429 # Disable distributed builds for xcodebuild.
430 if ($Cmd eq "xcodebuild") {
431 AddIfNotPresent($Args,"-nodistribute");
432 }
Ted Kremenekdab11102008-04-02 04:43:42 +0000433
434 system(@$Args);
435}
436
Ted Kremenekdab11102008-04-02 04:43:42 +0000437##----------------------------------------------------------------------------##
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000438# DisplayHelp - Utility function to display all help options.
439##----------------------------------------------------------------------------##
440
Sam Bishopa0e22662008-04-02 03:35:43 +0000441sub DisplayHelp {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000442
Ted Kremenek5744dc22008-04-02 18:03:36 +0000443print <<ENDTEXT;
Sam Bishopa0e22662008-04-02 03:35:43 +0000444USAGE: $Prog [options] <build command> [build options]
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000445
446OPTIONS:
447
448 -o - Target directory for HTML report files. Subdirectories
Sam Bishopa0e22662008-04-02 03:35:43 +0000449 will be created as needed to represent separate "runs" of
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000450 the analyzer. If this option is not specified, a directory
451 is created in /tmp to store the reports.
452
Ted Kremenek10f883f2008-04-03 07:11:44 +0000453 -h - Display this message.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000454 --help
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000455
Ted Kremenekaf08f642008-04-02 16:31:58 +0000456 -k - Add a "keep on going" option to the specified build command.
Ted Kremenekf02e8db2008-04-02 16:41:25 +0000457 --keep-going This option currently supports make and xcodebuild.
458 This is a convenience option; one can specify this
459 behavior directly using build options.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000460
Ted Kremenekdab11102008-04-02 04:43:42 +0000461 -v - Verbose output from $Prog and the analyzer.
462 A second "-v" increases verbosity.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000463
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000464 -V - View analysis results in a web browser when the build
465 --view completes.
466
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000467BUILD OPTIONS
468
Ted Kremenek39eefde2008-04-02 16:47:27 +0000469 You can specify any build option acceptable to the build command.
470
Ted Kremenek5744dc22008-04-02 18:03:36 +0000471EXAMPLE
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000472
Ted Kremenek5744dc22008-04-02 18:03:36 +0000473 $Prog -o /tmp/myhtmldir make -j4
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000474
Ted Kremenek39eefde2008-04-02 16:47:27 +0000475 The above example causes analysis reports to be deposited into
476 a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option.
477 A different subdirectory is created each time $Prog analyzes a project.
478 The analyzer should support most parallel builds, but not distributed builds.
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000479
480ENDTEXT
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000481}
482
483##----------------------------------------------------------------------------##
484# Process command-line arguments.
485##----------------------------------------------------------------------------##
486
487my $HtmlDir; # Parent directory to store HTML files.
488my $IgnoreErrors = 0; # Ignore build errors.
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000489my $ViewResults = 0; # View results when the build terminates.
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000490
491if (!@ARGV) {
492 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +0000493 exit 1;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000494}
495
496while (@ARGV) {
497
498 # Scan for options we recognize.
499
500 my $arg = $ARGV[0];
501
Sam Bishop2f2418e2008-04-03 14:29:47 +0000502 if ($arg eq "-h" or $arg eq "--help") {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000503 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +0000504 exit 0;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000505 }
506
507 if ($arg eq "-o") {
508 shift @ARGV;
509
510 if (!@ARGV) {
Ted Kremenek0062ad42008-04-02 16:35:01 +0000511 die "$Prog: '-o' option requires a target directory name.\n";
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000512 }
513
514 $HtmlDir = shift @ARGV;
515 next;
516 }
517
Ted Kremenek2b74ab62008-04-01 21:22:03 +0000518 if ($arg eq "-k" or $arg eq "--keep-going") {
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000519 shift @ARGV;
520 $IgnoreErrors = 1;
521 next;
522 }
523
524 if ($arg eq "-v") {
525 shift @ARGV;
526 $Verbose++;
527 next;
528 }
529
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000530 if ($arg eq "-V" or $arg eq "--view") {
531 shift @ARGV;
532 $ViewResults = 1;
533 next;
534 }
535
Ted Kremenek0062ad42008-04-02 16:35:01 +0000536 die "$Prog: unrecognized option '$arg'\n" if ($arg =~ /^-/);
537
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000538 last;
539}
540
541if (!@ARGV) {
542 print STDERR "$Prog: No build command specified.\n\n";
543 DisplayHelp();
Sam Bishopa0e22662008-04-02 03:35:43 +0000544 exit 1;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000545}
546
547# Determine the output directory for the HTML reports.
548
549if (!defined($HtmlDir)) {
550
Sam Bishopa0e22662008-04-02 03:35:43 +0000551 $HtmlDir = mkdtemp("/tmp/$Prog-XXXXXX");
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000552
553 if (!defined($HtmlDir)) {
Sam Bishopa0e22662008-04-02 03:35:43 +0000554 die "error: Cannot create HTML directory in /tmp.\n";
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000555 }
556
557 if (!$Verbose) {
558 print "$Prog: Using '$HtmlDir' as base HTML report directory.\n";
559 }
560}
561
Ted Kremenek684bb092008-04-18 15:18:20 +0000562my $BaseDir = $HtmlDir;
Sam Bishopa0e22662008-04-02 03:35:43 +0000563$HtmlDir = GetHTMLRunDir($HtmlDir);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000564
565# Set the appropriate environment variables.
566
Sam Bishopa0e22662008-04-02 03:35:43 +0000567SetHtmlEnv(\@ARGV, $HtmlDir);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000568
Ted Kremenek0b6c1532008-04-08 20:22:12 +0000569my $Cmd = "$RealBin/ccc-analyzer";
570
571die "$Prog: Executable 'ccc-analyzer' does not exist at '$Cmd'\n"
572 if (! -x $Cmd);
Ted Kremenekf22eacb2008-04-18 22:00:56 +0000573
574my $Clang = "$RealBin/clang";
575
576if (! -x $Clang) {
577 print "$Prog: 'clang' executable not found in '$RealBin'. Using 'clang' from path.\n";
578 $Clang = "clang";
579}
Ted Kremenek0b6c1532008-04-08 20:22:12 +0000580
Ted Kremenek4f4b17d2008-04-03 20:08:18 +0000581$ENV{'CC'} = $Cmd;
Ted Kremenekf22eacb2008-04-18 22:00:56 +0000582$ENV{'CLANG'} = $Clang;
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000583
584if ($Verbose >= 2) {
585 $ENV{'CCC_ANALYZER_VERBOSE'} = 1;
586}
587
588# Run the build.
589
Ted Kremenek7442ca62008-04-02 16:04:51 +0000590RunBuildCommand(\@ARGV, $IgnoreErrors);
Ted Kremenek9cc8c2c2008-04-01 20:47:38 +0000591
592# Postprocess the HTML directory.
593
Ted Kremenek684bb092008-04-18 15:18:20 +0000594Postprocess($HtmlDir, $BaseDir);
Ted Kremenek7f8a3252008-04-02 18:42:49 +0000595
596if ($ViewResults and -r "$HtmlDir/index.html") {
597 # Only works on Mac OS X (for now).
598 print "Viewing analysis results: '$HtmlDir/index.html'\n";
599 `open $HtmlDir/index.html`
600}