blob: 920ba47c0bb6d58a62f054542fbb021eeb50e0bc [file] [log] [blame]
Ted Kremenekc9d8fde2008-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 Kremenekd5d43622008-04-02 20:43:36 +000018use FindBin qw($RealBin);
Ted Kremenek422b0ac2008-04-19 18:05:48 +000019use Digest::MD5;
Ted Kremenekc9d8fde2008-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 Bishop479982e2008-04-02 03:35:43 +000028sub GetHTMLRunDir {
Ted Kremenekc9d8fde2008-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 Bishop479982e2008-04-02 03:35:43 +000051 die "error: '$Dir' exists but is not readable.\n";
Ted Kremenekc9d8fde2008-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 Bishop479982e2008-04-02 03:35:43 +000081 die "error: '$Dir' exists but is not a directory.\n";
Ted Kremenekc9d8fde2008-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 Bishop479982e2008-04-02 03:35:43 +000097sub SetHtmlEnv {
Ted Kremenekc9d8fde2008-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 Kremenekf0a08a52008-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 Kremenek422b0ac2008-04-19 18:05:48 +0000126
127 # Use Digest::MD5. We don't have to be cryptographically secure. We're
128 # just looking for duplicate files that come from a non-maliciious source.
129 # We use Digest::MD5 becomes it is a standard Perl module that should
130 # 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 Kremenekf0a08a52008-04-18 15:09:30 +0000140}
141
142##----------------------------------------------------------------------------##
Ted Kremeneked757e02008-04-02 18:03:36 +0000143# ScanFile - Scan a report file for various identifying attributes.
144##----------------------------------------------------------------------------##
145
Ted Kremenekf0a08a52008-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 Kremeneked757e02008-04-02 18:03:36 +0000151sub ScanFile {
152
153 my $Index = shift;
154 my $Dir = shift;
155 my $FName = shift;
156
Ted Kremenekf0a08a52008-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 Kremenekebd0bb72008-04-18 16:58:34 +0000170 # At this point the report file is not world readable. Make it happen.
Ted Kremenekc5b38202008-04-18 15:18:20 +0000171 `chmod 644 $Dir/$FName`;
172
173 # Scan the report file for tags.
Ted Kremeneked757e02008-04-02 18:03:36 +0000174 open(IN, "$Dir/$FName") or die "$Prog: Cannot open '$Dir/$FName'\n";
175
176 my $BugDesc = "";
Ted Kremenekd5d43622008-04-02 20:43:36 +0000177 my $BugFile = "";
178 my $BugPathLength = 1;
179 my $BugLine = 0;
Ted Kremeneked757e02008-04-02 18:03:36 +0000180
181 while (<IN>) {
182
183 if (/<!-- BUGDESC (.*) -->$/) {
184 $BugDesc = $1;
Ted Kremeneked757e02008-04-02 18:03:36 +0000185 }
Ted Kremenekd5d43622008-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 Kremeneked757e02008-04-02 18:03:36 +0000195 }
196
197 close(IN);
198
Ted Kremenekd5d43622008-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 Kremeneked757e02008-04-02 18:03:36 +0000217}
218
219##----------------------------------------------------------------------------##
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000220# Postprocess - Postprocess the results of an analysis scan.
221##----------------------------------------------------------------------------##
222
Sam Bishop479982e2008-04-02 03:35:43 +0000223sub Postprocess {
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000224
225 my $Dir = shift;
Ted Kremenekc5b38202008-04-18 15:18:20 +0000226 my $BaseDir = shift;
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000227
228 die "No directory specified." if (!defined($Dir));
Ted Kremenekc5b38202008-04-18 15:18:20 +0000229 die "No base directory specified." if (!defined($BaseDir));
Ted Kremenekc9d8fde2008-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 Kremenek4efca192008-04-02 07:05:07 +0000240 print "$Prog: Removing directory '$Dir' because it contains no reports.\n";
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000241 `rm -fR $Dir`;
242 return;
243 }
Ted Kremeneked757e02008-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 Kremenek4de0c562008-04-15 20:47:02 +0000257 # Print out the header.
258
Ted Kremeneked757e02008-04-02 18:03:36 +0000259print OUT <<ENDTEXT;
260<html>
261<head>
Ted Kremenekb59b7542008-04-02 18:42:49 +0000262<style type="text/css">
263 body { color:#000000; background-color:#ffffff }
Ted Kremenekd5d43622008-04-02 20:43:36 +0000264 body { font-family: Helvetica, sans-serif; font-size:9pt }
Ted Kremenekb59b7542008-04-02 18:42:49 +0000265 h1 { font-size:12pt }
Ted Kremenekd5d43622008-04-02 20:43:36 +0000266 table.sortable thead {
267 background-color:#eee; color:#666666;
268 font-weight: bold; cursor: default;
Ted Kremenek38471832008-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 Kremenekd5d43622008-04-02 20:43:36 +0000274 table.sortable { border: 1px #000000 solid }
275 table.sortable { border-collapse: collapse; border-spacing: 0px }
Ted Kremenekb59b7542008-04-02 18:42:49 +0000276 td { border-bottom: 1px #000000 dotted }
Ted Kremenekd5d43622008-04-02 20:43:36 +0000277 td { padding:5px; padding-left:8px; padding-right:8px }
Ted Kremenek756515f2008-04-07 23:50:07 +0000278 td { text-align:left; font-size:9pt }
Ted Kremenekd5d43622008-04-02 20:43:36 +0000279 td.View { padding-left: 10px }
Ted Kremenekb59b7542008-04-02 18:42:49 +0000280</style>
Ted Kremenekd5d43622008-04-02 20:43:36 +0000281<script src="sorttable.js"></script>
Ted Kremenek4de0c562008-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 Kremenekd5d43622008-04-02 20:43:36 +0000344<table class="sortable">
Ted Kremenekb59b7542008-04-02 18:42:49 +0000345<tr>
Ted Kremenek38471832008-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 Kremenekb59b7542008-04-02 18:42:49 +0000351</tr>
Ted Kremeneked757e02008-04-02 18:03:36 +0000352ENDTEXT
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000353
Ted Kremeneked757e02008-04-02 18:03:36 +0000354 for my $row ( sort { $a->[1] cmp $b->[1] } @Index ) {
355
Ted Kremenek4de0c562008-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 Kremenekc9d8fde2008-04-01 20:47:38 +0000360
Ted Kremeneked757e02008-04-02 18:03:36 +0000361 my $ReportFile = $row->[0];
362
Ted Kremenekd5d43622008-04-02 20:43:36 +0000363 print OUT " <td class=\"DESC\">";
364 print OUT lc($row->[1]);
365 print OUT "</td>\n";
Ted Kremeneked757e02008-04-02 18:03:36 +0000366
367 for my $j ( 2 .. $#{$row} ) {
368 print OUT "<td>$row->[$j]</td>\n"
369 }
Ted Kremenekb59b7542008-04-02 18:42:49 +0000370
371 # Emit the "View" link.
Ted Kremeneked757e02008-04-02 18:03:36 +0000372
Ted Kremenekd5d43622008-04-02 20:43:36 +0000373 print OUT " <td class=\"View\"><a href=\"$ReportFile#EndPath\">View</a></td>\n";
Ted Kremenekb59b7542008-04-02 18:42:49 +0000374
375 # End the row.
Ted Kremeneked757e02008-04-02 18:03:36 +0000376 print OUT "</tr>\n";
377 }
378
379 print OUT "</table>\n</body></html>\n";
380 close(OUT);
Ted Kremenekd5d43622008-04-02 20:43:36 +0000381
Ted Kremenekd5d43622008-04-02 20:43:36 +0000382 CopyJS($Dir);
Ted Kremenekc5b38202008-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 Kremenekc9d8fde2008-04-01 20:47:38 +0000387}
388
389##----------------------------------------------------------------------------##
Ted Kremenekd6c03a82008-04-02 04:43:42 +0000390# RunBuildCommand - Run the build command.
391##----------------------------------------------------------------------------##
392
393sub RunBuildCommand {
394
395 my $Args = shift;
Ted Kremenek091f9372008-04-02 16:04:51 +0000396 my $IgnoreErrors = shift;
Ted Kremenekd6c03a82008-04-02 04:43:42 +0000397 my $Cmd = $Args->[0];
398
Ted Kremenek404cb262008-04-02 15:34:12 +0000399 if ($Cmd eq "gcc" or $Cmd eq "cc" or $Cmd eq "llvm-gcc") {
Ted Kremenekd6c03a82008-04-02 04:43:42 +0000400 shift @$Args;
401 unshift @$Args, "ccc-analyzer"
402 }
Ted Kremenek091f9372008-04-02 16:04:51 +0000403 elsif ($IgnoreErrors) {
404 if ($Cmd eq "make" or $Cmd eq "gmake") {
405 push @$Args, "-k";
406 }
407 elsif ($Cmd eq "xcodebuild") {
408 push @$Args, "-PBXBuildsContinueAfterErrors=YES";
409 }
Ted Kremenekd5d43622008-04-02 20:43:36 +0000410 }
Ted Kremenekd6c03a82008-04-02 04:43:42 +0000411
412 system(@$Args);
413}
414
Ted Kremenekd6c03a82008-04-02 04:43:42 +0000415##----------------------------------------------------------------------------##
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000416# DisplayHelp - Utility function to display all help options.
417##----------------------------------------------------------------------------##
418
Sam Bishop479982e2008-04-02 03:35:43 +0000419sub DisplayHelp {
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000420
Ted Kremeneked757e02008-04-02 18:03:36 +0000421print <<ENDTEXT;
Sam Bishop479982e2008-04-02 03:35:43 +0000422USAGE: $Prog [options] <build command> [build options]
Ted Kremenekb9177df2008-04-01 21:22:03 +0000423
424OPTIONS:
425
426 -o - Target directory for HTML report files. Subdirectories
Sam Bishop479982e2008-04-02 03:35:43 +0000427 will be created as needed to represent separate "runs" of
Ted Kremenekb9177df2008-04-01 21:22:03 +0000428 the analyzer. If this option is not specified, a directory
429 is created in /tmp to store the reports.
430
Ted Kremeneke9c91a82008-04-03 07:11:44 +0000431 -h - Display this message.
Ted Kremenekb9177df2008-04-01 21:22:03 +0000432 --help
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000433
Ted Kremenekd1843772008-04-02 16:31:58 +0000434 -k - Add a "keep on going" option to the specified build command.
Ted Kremenek707a9ad2008-04-02 16:41:25 +0000435 --keep-going This option currently supports make and xcodebuild.
436 This is a convenience option; one can specify this
437 behavior directly using build options.
Ted Kremenekb9177df2008-04-01 21:22:03 +0000438
Ted Kremenekd6c03a82008-04-02 04:43:42 +0000439 -v - Verbose output from $Prog and the analyzer.
440 A second "-v" increases verbosity.
Ted Kremenekb9177df2008-04-01 21:22:03 +0000441
Ted Kremenekb59b7542008-04-02 18:42:49 +0000442 -V - View analysis results in a web browser when the build
443 --view completes.
444
Ted Kremenekb9177df2008-04-01 21:22:03 +0000445BUILD OPTIONS
446
Ted Kremenekf76812d2008-04-02 16:47:27 +0000447 You can specify any build option acceptable to the build command.
448
Ted Kremeneked757e02008-04-02 18:03:36 +0000449EXAMPLE
Ted Kremenekb9177df2008-04-01 21:22:03 +0000450
Ted Kremeneked757e02008-04-02 18:03:36 +0000451 $Prog -o /tmp/myhtmldir make -j4
Ted Kremenekb9177df2008-04-01 21:22:03 +0000452
Ted Kremenekf76812d2008-04-02 16:47:27 +0000453 The above example causes analysis reports to be deposited into
454 a subdirectory of "/tmp/myhtmldir" and to run "make" with the "-j4" option.
455 A different subdirectory is created each time $Prog analyzes a project.
456 The analyzer should support most parallel builds, but not distributed builds.
Ted Kremenekb9177df2008-04-01 21:22:03 +0000457
458ENDTEXT
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000459}
460
461##----------------------------------------------------------------------------##
462# Process command-line arguments.
463##----------------------------------------------------------------------------##
464
465my $HtmlDir; # Parent directory to store HTML files.
466my $IgnoreErrors = 0; # Ignore build errors.
Ted Kremenekb59b7542008-04-02 18:42:49 +0000467my $ViewResults = 0; # View results when the build terminates.
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000468
469if (!@ARGV) {
470 DisplayHelp();
Sam Bishop479982e2008-04-02 03:35:43 +0000471 exit 1;
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000472}
473
474while (@ARGV) {
475
476 # Scan for options we recognize.
477
478 my $arg = $ARGV[0];
479
Sam Bishopa3281512008-04-03 14:29:47 +0000480 if ($arg eq "-h" or $arg eq "--help") {
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000481 DisplayHelp();
Sam Bishop479982e2008-04-02 03:35:43 +0000482 exit 0;
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000483 }
484
485 if ($arg eq "-o") {
486 shift @ARGV;
487
488 if (!@ARGV) {
Ted Kremenek78965de2008-04-02 16:35:01 +0000489 die "$Prog: '-o' option requires a target directory name.\n";
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000490 }
491
492 $HtmlDir = shift @ARGV;
493 next;
494 }
495
Ted Kremenekb9177df2008-04-01 21:22:03 +0000496 if ($arg eq "-k" or $arg eq "--keep-going") {
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000497 shift @ARGV;
498 $IgnoreErrors = 1;
499 next;
500 }
501
502 if ($arg eq "-v") {
503 shift @ARGV;
504 $Verbose++;
505 next;
506 }
507
Ted Kremenekb59b7542008-04-02 18:42:49 +0000508 if ($arg eq "-V" or $arg eq "--view") {
509 shift @ARGV;
510 $ViewResults = 1;
511 next;
512 }
513
Ted Kremenek78965de2008-04-02 16:35:01 +0000514 die "$Prog: unrecognized option '$arg'\n" if ($arg =~ /^-/);
515
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000516 last;
517}
518
519if (!@ARGV) {
520 print STDERR "$Prog: No build command specified.\n\n";
521 DisplayHelp();
Sam Bishop479982e2008-04-02 03:35:43 +0000522 exit 1;
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000523}
524
525# Determine the output directory for the HTML reports.
526
527if (!defined($HtmlDir)) {
528
Sam Bishop479982e2008-04-02 03:35:43 +0000529 $HtmlDir = mkdtemp("/tmp/$Prog-XXXXXX");
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000530
531 if (!defined($HtmlDir)) {
Sam Bishop479982e2008-04-02 03:35:43 +0000532 die "error: Cannot create HTML directory in /tmp.\n";
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000533 }
534
535 if (!$Verbose) {
536 print "$Prog: Using '$HtmlDir' as base HTML report directory.\n";
537 }
538}
539
Ted Kremenekc5b38202008-04-18 15:18:20 +0000540my $BaseDir = $HtmlDir;
Sam Bishop479982e2008-04-02 03:35:43 +0000541$HtmlDir = GetHTMLRunDir($HtmlDir);
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000542
543# Set the appropriate environment variables.
544
Sam Bishop479982e2008-04-02 03:35:43 +0000545SetHtmlEnv(\@ARGV, $HtmlDir);
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000546
Ted Kremenekfc0f1c22008-04-08 20:22:12 +0000547my $Cmd = "$RealBin/ccc-analyzer";
548
549die "$Prog: Executable 'ccc-analyzer' does not exist at '$Cmd'\n"
550 if (! -x $Cmd);
Ted Kremenek056171b2008-04-18 22:00:56 +0000551
552my $Clang = "$RealBin/clang";
553
554if (! -x $Clang) {
555 print "$Prog: 'clang' executable not found in '$RealBin'. Using 'clang' from path.\n";
556 $Clang = "clang";
557}
Ted Kremenekfc0f1c22008-04-08 20:22:12 +0000558
Ted Kremenek47bf3892008-04-03 20:08:18 +0000559$ENV{'CC'} = $Cmd;
Ted Kremenek056171b2008-04-18 22:00:56 +0000560$ENV{'CLANG'} = $Clang;
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000561
562if ($Verbose >= 2) {
563 $ENV{'CCC_ANALYZER_VERBOSE'} = 1;
564}
565
566# Run the build.
567
Ted Kremenek091f9372008-04-02 16:04:51 +0000568RunBuildCommand(\@ARGV, $IgnoreErrors);
Ted Kremenekc9d8fde2008-04-01 20:47:38 +0000569
570# Postprocess the HTML directory.
571
Ted Kremenekc5b38202008-04-18 15:18:20 +0000572Postprocess($HtmlDir, $BaseDir);
Ted Kremenekb59b7542008-04-02 18:42:49 +0000573
574if ($ViewResults and -r "$HtmlDir/index.html") {
575 # Only works on Mac OS X (for now).
576 print "Viewing analysis results: '$HtmlDir/index.html'\n";
577 `open $HtmlDir/index.html`
578}