#!/usr/bin/env perl
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##
#
# A script designed to wrap a build so that all calls to gcc are intercepted
# and piped to the static analyzer.
#
##===----------------------------------------------------------------------===##
use strict;
use warnings;
use FindBin qw($RealBin);
use Digest::MD5;
use File::Basename;
use Term::ANSIColor;
use Term::ANSIColor qw(:constants);
use Cwd qw/ getcwd abs_path /;
use Sys::Hostname;
my $Verbose = 0; # Verbose output from this script.
my $Prog = "scan-build";
my $BuildName;
my $BuildDate;
my $CXX; # Leave undefined initially.
my $TERM = $ENV{'TERM'};
my $UseColor = (defined $TERM and $TERM eq 'xterm-color' and -t STDOUT
and defined $ENV{'SCAN_BUILD_COLOR'});
my $UserName = HtmlEscape(getpwuid($<) || 'unknown');
my $HostName = HtmlEscape(hostname() || 'unknown');
my $CurrentDir = HtmlEscape(getcwd());
my $CurrentDirSuffix = basename($CurrentDir);
my $CmdArgs;
my $HtmlTitle;
my $Date = localtime();
##----------------------------------------------------------------------------##
# Diagnostics
##----------------------------------------------------------------------------##
sub Diag {
if ($UseColor) {
print BOLD, MAGENTA "$Prog: @_";
print RESET;
}
else {
print "$Prog: @_";
}
}
sub DiagCrashes {
my $Dir = shift;
Diag ("The analyzer encountered problems on some source files.\n");
Diag ("Preprocessed versions of these sources were deposited in '$Dir/failures'.\n");
Diag ("Please consider submitting a bug report using these files:\n");
Diag (" http://clang.llvm.org/StaticAnalysisUsage.html#filingbugs\n")
}
sub DieDiag {
if ($UseColor) {
print BOLD, RED "$Prog: ";
print RESET, RED @_;
print RESET;
}
else {
print "$Prog: ", @_;
}
exit(0);
}
##----------------------------------------------------------------------------##
# Some initial preprocessing of Clang options.
##----------------------------------------------------------------------------##
# First, look for 'clang-cc' in libexec.
my $ClangCCSB = Cwd::realpath("$RealBin/libexec/clang-cc");
# Second, look for 'clang-cc' in the same directory as scan-build.
if (!defined $ClangCCSB || ! -x $ClangCCSB) {
$ClangCCSB = Cwd::realpath("$RealBin/clang-cc");
}
# Third, look for 'clang-cc' in ../libexec
if (!defined $ClangCCSB || ! -x $ClangCCSB) {
$ClangCCSB = Cwd::realpath