2008-07-19 14:11:04 +08:00
|
|
|
#!/usr/bin/env perl
|
2008-03-26 06:35:32 +08:00
|
|
|
#
|
|
|
|
# The LLVM Compiler Infrastructure
|
|
|
|
#
|
|
|
|
# This file is distributed under the University of Illinois Open Source
|
|
|
|
# License. See LICENSE.TXT for details.
|
|
|
|
#
|
|
|
|
##===----------------------------------------------------------------------===##
|
|
|
|
#
|
2008-07-19 14:11:04 +08:00
|
|
|
# A script designed to interpose between the build system and gcc. It invokes
|
|
|
|
# both gcc and the static analyzer.
|
2008-03-26 06:35:32 +08:00
|
|
|
#
|
|
|
|
##===----------------------------------------------------------------------===##
|
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2008-09-22 03:56:14 +08:00
|
|
|
use Cwd qw/ getcwd abs_path /;
|
2008-08-09 04:46:42 +08:00
|
|
|
use File::Temp qw/ tempfile /;
|
|
|
|
use File::Path qw / mkpath /;
|
2009-01-21 08:42:24 +08:00
|
|
|
use File::Basename;
|
2008-08-26 04:44:31 +08:00
|
|
|
|
|
|
|
my $CC = $ENV{'CCC_CC'};
|
|
|
|
if (!defined $CC) { $CC = "gcc"; }
|
2009-01-21 08:42:24 +08:00
|
|
|
my $CleanupFile;
|
|
|
|
my $ResultFile;
|
|
|
|
|
|
|
|
# Remove any stale files at exit.
|
|
|
|
END {
|
|
|
|
if (defined $CleanupFile && -z $CleanupFile) {
|
|
|
|
`rm -f $CleanupFile`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-09 04:46:42 +08:00
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
# Process Clang Crashes.
|
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
|
|
|
|
sub GetPPExt {
|
|
|
|
my $Lang = shift;
|
|
|
|
if ($Lang =~ /objective-c/) { return ".mi"; }
|
|
|
|
return ".i";
|
|
|
|
}
|
|
|
|
|
2009-01-27 09:19:08 +08:00
|
|
|
my $ParserRejects = "Parser Rejects";
|
|
|
|
|
2008-08-19 02:38:29 +08:00
|
|
|
sub ProcessClangFailure {
|
2008-09-25 08:51:44 +08:00
|
|
|
my ($Clang, $Lang, $file, $Args, $HtmlDir, $ErrorType, $ofile) = @_;
|
2008-08-09 04:46:42 +08:00
|
|
|
my $Dir = "$HtmlDir/crashes";
|
|
|
|
mkpath $Dir;
|
2009-01-27 09:19:08 +08:00
|
|
|
|
|
|
|
my $prefix = "clang_crash";
|
|
|
|
if ($ErrorType == $ParserRejects) { $prefix = "clang_parser_rejects"; }
|
2008-09-25 08:51:44 +08:00
|
|
|
|
|
|
|
# Generate the preprocessed file with cc (i.e., gcc).
|
2009-01-27 09:19:08 +08:00
|
|
|
my ($PPH, $PPFile) = tempfile( $prefix . "_XXXXXX",
|
|
|
|
SUFFIX => GetPPExt($Lang),
|
|
|
|
DIR => $Dir);
|
2008-08-09 04:46:42 +08:00
|
|
|
|
2008-08-26 04:44:31 +08:00
|
|
|
system $CC, @$Args, "-E", "-o", $PPFile;
|
2008-08-09 04:46:42 +08:00
|
|
|
close ($PPH);
|
2008-09-25 08:51:44 +08:00
|
|
|
|
|
|
|
# Generate the preprocessed file with clang.
|
|
|
|
my $PPFile_Clang = $PPFile;
|
|
|
|
$PPFile_Clang =~ s/[.](.+)$/.clang.$1/;
|
|
|
|
system $Clang, @$Args, "-E", "-o", "$PPFile_Clang";
|
|
|
|
|
|
|
|
# Create the info file.
|
2008-09-25 08:25:16 +08:00
|
|
|
open (OUT, ">", "$PPFile.info.txt") or die "Cannot open $PPFile.info.txt\n";
|
2008-09-22 02:04:49 +08:00
|
|
|
print OUT abs_path($file), "\n";
|
2008-08-19 02:38:29 +08:00
|
|
|
print OUT "$ErrorType\n";
|
2008-08-19 04:55:25 +08:00
|
|
|
print OUT "@$Args\n";
|
2008-08-09 04:46:42 +08:00
|
|
|
close OUT;
|
2008-09-25 08:25:16 +08:00
|
|
|
`uname -a >> $PPFile.info.txt 2>&1`;
|
|
|
|
`$CC -v >> $PPFile.info.txt 2>&1`;
|
2008-09-13 06:49:36 +08:00
|
|
|
system 'mv',$ofile,"$PPFile.stderr.txt";
|
2008-08-09 04:46:42 +08:00
|
|
|
}
|
2008-03-26 06:35:32 +08:00
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
# Running the analyzer.
|
|
|
|
##----------------------------------------------------------------------------##
|
2008-03-26 06:35:32 +08:00
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
sub Analyze {
|
|
|
|
my ($Clang, $Args, $Lang, $Output, $Verbose, $HtmlDir, $file, $Analyses) = @_;
|
2008-04-04 19:02:21 +08:00
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
# Skip anything related to C++.
|
|
|
|
return if ($Lang =~ /c[+][+]/);
|
2008-08-19 02:38:29 +08:00
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
my $RunAnalyzer = 0;
|
|
|
|
my $Cmd;
|
|
|
|
my @CmdArgs;
|
2008-08-09 04:46:42 +08:00
|
|
|
my @CmdArgsSansAnalyses;
|
2008-07-19 14:11:04 +08:00
|
|
|
|
|
|
|
if ($Lang =~ /header/) {
|
|
|
|
exit 0 if (!defined ($Output));
|
|
|
|
$Cmd = 'cp';
|
|
|
|
push @CmdArgs,$file;
|
|
|
|
# Remove the PCH extension.
|
|
|
|
$Output =~ s/[.]gch$//;
|
|
|
|
push @CmdArgs,$Output;
|
2008-08-09 04:46:42 +08:00
|
|
|
@CmdArgsSansAnalyses = @CmdArgs;
|
2008-07-19 14:11:04 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$Cmd = $Clang;
|
|
|
|
push @CmdArgs,'-DIBOutlet=__attribute__((iboutlet))';
|
|
|
|
push @CmdArgs,@$Args;
|
2008-08-09 04:46:42 +08:00
|
|
|
@CmdArgsSansAnalyses = @CmdArgs;
|
2009-01-21 07:17:32 +08:00
|
|
|
push @CmdArgs,'--analyze';
|
2009-01-24 04:52:26 +08:00
|
|
|
push @CmdArgs,"--analyzer-display-progress";
|
2008-08-09 04:46:42 +08:00
|
|
|
push @CmdArgs,(split /\s/,$Analyses);
|
2008-07-19 14:11:04 +08:00
|
|
|
$RunAnalyzer = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
my @PrintArgs;
|
|
|
|
my $dir;
|
2008-05-24 23:58:54 +08:00
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
if ($Verbose) {
|
|
|
|
$dir = getcwd();
|
|
|
|
print STDERR "\n[LOCATION]: $dir\n";
|
|
|
|
push @PrintArgs,"'$Cmd'";
|
|
|
|
foreach my $arg (@CmdArgs) { push @PrintArgs,"\'$arg\'"; }
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($Verbose == 1) {
|
2008-05-24 23:58:54 +08:00
|
|
|
# We MUST print to stderr. Some clients use the stdout output of
|
|
|
|
# gcc for various purposes.
|
2008-07-19 14:11:04 +08:00
|
|
|
print STDERR join(' ',@PrintArgs);
|
|
|
|
print STDERR "\n";
|
|
|
|
}
|
|
|
|
elsif ($Verbose == 2) {
|
|
|
|
print STDERR "#SHELL (cd '$dir' && @PrintArgs)\n";
|
|
|
|
}
|
2008-05-24 23:58:54 +08:00
|
|
|
|
2009-01-21 08:42:24 +08:00
|
|
|
if ($RunAnalyzer) {
|
|
|
|
if (defined $ResultFile) {
|
|
|
|
push @CmdArgs,'-o';
|
|
|
|
push @CmdArgs, $ResultFile;
|
|
|
|
}
|
|
|
|
elsif (defined $HtmlDir) {
|
|
|
|
push @CmdArgs,'-o';
|
|
|
|
push @CmdArgs, $HtmlDir;
|
|
|
|
}
|
2008-07-19 14:11:04 +08:00
|
|
|
}
|
2008-08-28 06:30:34 +08:00
|
|
|
|
|
|
|
if (defined $ENV{'CCC_UBI'}) {
|
|
|
|
push @CmdArgs,"--analyzer-viz-egraph-ubigraph";
|
|
|
|
}
|
2008-08-09 04:46:42 +08:00
|
|
|
|
2008-09-04 08:02:34 +08:00
|
|
|
# Capture the STDERR of clang and send it to a temporary file.
|
|
|
|
# Capture the STDOUT of clang and reroute it to ccc-analyzer's STDERR.
|
|
|
|
# We save the output file in the 'crashes' directory if clang encounters
|
|
|
|
# any problems with the file.
|
2008-09-12 07:05:26 +08:00
|
|
|
pipe (FROM_CHILD, TO_PARENT);
|
2008-09-04 08:02:34 +08:00
|
|
|
my $pid = fork();
|
|
|
|
if ($pid == 0) {
|
2008-09-12 07:05:26 +08:00
|
|
|
close FROM_CHILD;
|
|
|
|
open(STDOUT,">&", \*TO_PARENT);
|
|
|
|
open(STDERR,">&", \*TO_PARENT);
|
2008-09-04 08:02:34 +08:00
|
|
|
exec $Cmd, @CmdArgs;
|
|
|
|
}
|
2008-09-12 07:05:26 +08:00
|
|
|
|
|
|
|
close TO_PARENT;
|
|
|
|
my ($ofh, $ofile) = tempfile("clang_output_XXXXXX", DIR => $HtmlDir);
|
|
|
|
|
|
|
|
while (<FROM_CHILD>) {
|
|
|
|
print $ofh $_;
|
|
|
|
print STDERR $_;
|
|
|
|
}
|
|
|
|
|
|
|
|
waitpid($pid,0);
|
2008-09-04 08:02:34 +08:00
|
|
|
my $Result = $?;
|
|
|
|
|
|
|
|
# Did the command die because of a signal?
|
|
|
|
if ($Result & 127 and $Cmd eq $Clang and defined $HtmlDir) {
|
2008-09-25 08:51:44 +08:00
|
|
|
ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses, $HtmlDir,
|
2008-09-04 08:02:34 +08:00
|
|
|
"Crash", $ofile);
|
|
|
|
}
|
|
|
|
elsif ($Result) {
|
2008-09-25 08:51:44 +08:00
|
|
|
ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses, $HtmlDir,
|
2009-01-27 09:19:08 +08:00
|
|
|
$ParserRejects, $ofile);
|
2008-09-04 08:02:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
`rm -f $ofile`;
|
2008-07-19 14:11:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
# Lookup tables.
|
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
|
|
|
|
my %CompileOptionMap = (
|
|
|
|
'-nostdinc' => 0,
|
2008-12-20 04:56:23 +08:00
|
|
|
'-fblocks' => 0,
|
2008-07-19 14:11:04 +08:00
|
|
|
'-fobjc-gc-only' => 0,
|
|
|
|
'-fobjc-gc' => 0,
|
|
|
|
'-include' => 1,
|
|
|
|
'-idirafter' => 1,
|
|
|
|
'-iprefix' => 1,
|
|
|
|
'-iquote' => 1,
|
|
|
|
'-isystem' => 1,
|
|
|
|
'-iwithprefix' => 1,
|
|
|
|
'-iwithprefixbefore' => 1
|
|
|
|
);
|
|
|
|
|
|
|
|
my %LinkerOptionMap = (
|
|
|
|
'-framework' => 1
|
|
|
|
);
|
|
|
|
|
|
|
|
my %CompilerLinkerOptionMap = (
|
|
|
|
'-isysroot' => 1,
|
|
|
|
'-arch' => 1,
|
2008-09-30 06:45:28 +08:00
|
|
|
'-v' => 0,
|
2008-10-01 07:40:25 +08:00
|
|
|
'-fpascal-strings' => 0,
|
|
|
|
'-mmacosx-version-min' => 0 # This is really a 1 argument, but always has '='
|
2008-07-19 14:11:04 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
my %IgnoredOptionMap = (
|
2008-07-24 11:52:21 +08:00
|
|
|
'-MT' => 1, # Ignore these preprocessor options.
|
|
|
|
'-MF' => 1,
|
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
'-fsyntax-only' => 0,
|
|
|
|
'-save-temps' => 0,
|
|
|
|
'-install_name' => 1,
|
|
|
|
'-exported_symbols_list' => 1,
|
|
|
|
'-current_version' => 1,
|
|
|
|
'-compatibility_version' => 1,
|
|
|
|
'-init' => 1,
|
|
|
|
'-e' => 1,
|
|
|
|
'-seg1addr' => 1,
|
|
|
|
'-bundle_loader' => 1,
|
|
|
|
'-multiply_defined' => 1,
|
|
|
|
'-sectorder' => 3,
|
|
|
|
'--param' => 1,
|
|
|
|
'-u' => 1
|
|
|
|
);
|
|
|
|
|
|
|
|
my %LangMap = (
|
|
|
|
'c' => 'c',
|
|
|
|
'cpp' => 'c++',
|
|
|
|
'cc' => 'c++',
|
|
|
|
'i' => 'c-cpp-output',
|
|
|
|
'm' => 'objective-c',
|
|
|
|
'mi' => 'objective-c-cpp-output'
|
|
|
|
);
|
|
|
|
|
2008-09-30 00:15:20 +08:00
|
|
|
my %UniqueOptions = (
|
|
|
|
'-isysroot' => 0
|
|
|
|
);
|
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
# Main Logic.
|
|
|
|
##----------------------------------------------------------------------------##
|
|
|
|
|
|
|
|
my $Action = 'link';
|
|
|
|
my @CompileOpts;
|
|
|
|
my @LinkOpts;
|
|
|
|
my @Files;
|
|
|
|
my $Lang;
|
|
|
|
my $Output;
|
2008-09-30 00:15:20 +08:00
|
|
|
my %Uniqued;
|
2008-07-19 14:11:04 +08:00
|
|
|
|
|
|
|
# Forward arguments to gcc.
|
2008-08-22 05:47:09 +08:00
|
|
|
my $Status = system($CC,@ARGV);
|
2008-08-28 09:18:44 +08:00
|
|
|
if ($Status) { exit($Status >> 8); }
|
2008-07-19 14:11:04 +08:00
|
|
|
|
|
|
|
# Get the analysis options.
|
|
|
|
my $Analyses = $ENV{'CCC_ANALYZER_ANALYSIS'};
|
|
|
|
if (!defined($Analyses)) { $Analyses = '-checker-cfref'; }
|
|
|
|
|
2008-10-27 22:26:32 +08:00
|
|
|
# Get the store model.
|
|
|
|
my $StoreModel = $ENV{'CCC_ANALYZER_STORE_MODEL'};
|
|
|
|
|
2008-11-04 08:02:53 +08:00
|
|
|
# Get the output format.
|
|
|
|
my $OutputFormat = $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'};
|
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
# Determine the level of verbosity.
|
|
|
|
my $Verbose = 0;
|
|
|
|
if (defined $ENV{CCC_ANALYZER_VERBOSE}) { $Verbose = 1; }
|
|
|
|
if (defined $ENV{CCC_ANALYZER_LOG}) { $Verbose = 2; }
|
|
|
|
|
|
|
|
# Determine what clang executable to use.
|
|
|
|
my $Clang = $ENV{'CLANG'};
|
|
|
|
if (!defined $Clang) { $Clang = 'clang'; }
|
|
|
|
|
|
|
|
# Get the HTML output directory.
|
|
|
|
my $HtmlDir = $ENV{'CCC_ANALYZER_HTML'};
|
|
|
|
|
2008-09-26 04:17:57 +08:00
|
|
|
my %ArchsSeen;
|
2008-07-19 14:11:04 +08:00
|
|
|
|
|
|
|
# Process the arguments.
|
|
|
|
foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
|
2008-10-19 14:42:38 +08:00
|
|
|
my $Arg = $ARGV[$i];
|
|
|
|
my ($ArgKey) = split /=/,$Arg,2;
|
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
# Modes ccc-analyzer supports
|
|
|
|
if ($Arg eq '-E') { $Action = 'preprocess'; }
|
|
|
|
elsif ($Arg eq '-c') { $Action = 'compile'; }
|
|
|
|
elsif ($Arg =~ /^-print-prog-name/) { exit 0; }
|
2008-09-26 04:17:57 +08:00
|
|
|
|
|
|
|
# Specially handle duplicate cases of -arch
|
|
|
|
if ($Arg eq "-arch") {
|
|
|
|
my $arch = $ARGV[$i+1];
|
|
|
|
$ArchsSeen{$arch} = 1;
|
|
|
|
++$i;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
# Options with possible arguments that should pass through to compiler.
|
2008-10-19 14:42:38 +08:00
|
|
|
if (defined $CompileOptionMap{$ArgKey}) {
|
|
|
|
my $Cnt = $CompileOptionMap{$ArgKey};
|
2008-07-19 14:11:04 +08:00
|
|
|
push @CompileOpts,$Arg;
|
|
|
|
while ($Cnt > 0) { ++$i; --$Cnt; push @CompileOpts, $ARGV[$i]; }
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Options with possible arguments that should pass through to linker.
|
2008-10-19 14:42:38 +08:00
|
|
|
if (defined $LinkerOptionMap{$ArgKey}) {
|
|
|
|
my $Cnt = $LinkerOptionMap{$ArgKey};
|
2008-07-19 14:11:04 +08:00
|
|
|
push @LinkOpts,$Arg;
|
|
|
|
while ($Cnt > 0) { ++$i; --$Cnt; push @LinkOpts, $ARGV[$i]; }
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Options with possible arguments that should pass through to both compiler
|
|
|
|
# and the linker.
|
2008-10-19 14:42:38 +08:00
|
|
|
if (defined $CompilerLinkerOptionMap{$ArgKey}) {
|
|
|
|
my $Cnt = $CompilerLinkerOptionMap{$ArgKey};
|
2008-09-30 07:06:09 +08:00
|
|
|
|
2008-09-30 00:15:20 +08:00
|
|
|
# Check if this is an option that should have a unique value, and if so
|
|
|
|
# determine if the value was checked before.
|
|
|
|
if ($UniqueOptions{$Arg}) {
|
|
|
|
if (defined $Uniqued{$Arg}) {
|
|
|
|
$i += $Cnt;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$Uniqued{$Arg} = 1;
|
|
|
|
}
|
|
|
|
|
2008-09-30 07:06:09 +08:00
|
|
|
push @CompileOpts,$Arg;
|
|
|
|
push @LinkOpts,$Arg;
|
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
while ($Cnt > 0) {
|
|
|
|
++$i; --$Cnt;
|
|
|
|
push @CompileOpts, $ARGV[$i];
|
|
|
|
push @LinkOpts, $ARGV[$i];
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2008-05-24 23:58:54 +08:00
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
# Ignored options.
|
2008-10-19 14:42:38 +08:00
|
|
|
if (defined $IgnoredOptionMap{$ArgKey}) {
|
|
|
|
my $Cnt = $IgnoredOptionMap{$ArgKey};
|
2008-07-19 14:11:04 +08:00
|
|
|
while ($Cnt > 0) {
|
|
|
|
++$i; --$Cnt;
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2008-05-24 23:58:54 +08:00
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
# Compile mode flags.
|
|
|
|
if ($Arg =~ /^-[D,I,U](.*)$/) {
|
|
|
|
my $Tmp = $Arg;
|
|
|
|
if ($1 eq '') {
|
|
|
|
# FIXME: Check if we are going off the end.
|
|
|
|
++$i;
|
|
|
|
$Tmp = $Arg . $ARGV[$i];
|
|
|
|
}
|
|
|
|
push @CompileOpts,$Tmp;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Language.
|
|
|
|
if ($Arg eq '-x') {
|
|
|
|
$Lang = $ARGV[$i+1];
|
|
|
|
++$i; next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Output file.
|
|
|
|
if ($Arg eq '-o') {
|
|
|
|
++$i;
|
|
|
|
$Output = $ARGV[$i];
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get the link mode.
|
|
|
|
if ($Arg =~ /^-[l,L,O]/) {
|
|
|
|
if ($Arg eq '-O') { push @LinkOpts,'-O1'; }
|
|
|
|
elsif ($Arg eq '-Os') { push @LinkOpts,'-O2'; }
|
|
|
|
else { push @LinkOpts,$Arg; }
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($Arg =~ /^-std=/) {
|
|
|
|
push @CompileOpts,$Arg;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# if ($Arg =~ /^-f/) {
|
|
|
|
# # FIXME: Not sure if the remaining -fxxxx options have no arguments.
|
|
|
|
# push @CompileOpts,$Arg;
|
|
|
|
# push @LinkOpts,$Arg; # FIXME: Not sure if these are link opts.
|
|
|
|
# }
|
|
|
|
|
|
|
|
# Get the compiler/link mode.
|
|
|
|
if ($Arg =~ /^-F(.+)$/) {
|
|
|
|
my $Tmp = $Arg;
|
|
|
|
if ($1 eq '') {
|
|
|
|
# FIXME: Check if we are going off the end.
|
|
|
|
++$i;
|
|
|
|
$Tmp = $Arg . $ARGV[$i];
|
|
|
|
}
|
|
|
|
push @CompileOpts,$Tmp;
|
|
|
|
push @LinkOpts,$Tmp;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Input files.
|
|
|
|
if ($Arg eq '-filelist') {
|
|
|
|
# FIXME: Make sure we aren't walking off the end.
|
|
|
|
open(IN, $ARGV[$i+1]);
|
|
|
|
while (<IN>) { s/\015?\012//; push @Files,$_; }
|
|
|
|
close(IN);
|
|
|
|
++$i; next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!($Arg =~ /^-/)) {
|
|
|
|
push @Files,$Arg; next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($Action eq 'compile' or $Action eq 'link') {
|
|
|
|
foreach my $file (@Files) {
|
|
|
|
# Determine the language for the file.
|
|
|
|
my $FileLang = $Lang;
|
|
|
|
|
|
|
|
if (!defined($FileLang)) {
|
|
|
|
# Infer the language from the extension.
|
|
|
|
if ($file =~ /[.]([^.]+)$/) {
|
|
|
|
$FileLang = $LangMap{$1};
|
|
|
|
}
|
|
|
|
}
|
2008-05-15 04:26:52 +08:00
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
next if (!defined $FileLang);
|
|
|
|
|
|
|
|
my @AnalyzeArgs;
|
|
|
|
|
|
|
|
if ($FileLang ne 'unknown') {
|
|
|
|
push @AnalyzeArgs,'-x';
|
|
|
|
push @AnalyzeArgs,$FileLang;
|
|
|
|
}
|
2008-05-24 23:58:54 +08:00
|
|
|
|
2008-10-27 22:26:32 +08:00
|
|
|
if (defined $StoreModel) {
|
|
|
|
push @AnalyzeArgs, $StoreModel;
|
|
|
|
}
|
2008-11-04 08:02:53 +08:00
|
|
|
|
|
|
|
if (defined $OutputFormat) {
|
|
|
|
push @AnalyzeArgs, "-analyzer-output-" . $OutputFormat;
|
2009-01-21 08:42:24 +08:00
|
|
|
if ($OutputFormat eq "plist") {
|
|
|
|
# Change "Output" to be a file.
|
|
|
|
my ($h, $f) = tempfile("report-XXXXXX", SUFFIX => ".plist",
|
|
|
|
DIR => $HtmlDir);
|
|
|
|
$ResultFile = $f;
|
|
|
|
$CleanupFile = $f;
|
|
|
|
}
|
|
|
|
|
2008-11-04 08:02:53 +08:00
|
|
|
}
|
2008-10-27 22:26:32 +08:00
|
|
|
|
2008-07-19 14:11:04 +08:00
|
|
|
push @AnalyzeArgs,@CompileOpts;
|
|
|
|
push @AnalyzeArgs,$file;
|
2008-10-27 22:26:32 +08:00
|
|
|
|
2008-09-26 04:17:57 +08:00
|
|
|
my @Archs = keys %ArchsSeen;
|
|
|
|
if (scalar @Archs) {
|
|
|
|
foreach my $arch (@Archs) {
|
|
|
|
my @NewArgs;
|
|
|
|
push @NewArgs, '-arch';
|
|
|
|
push @NewArgs, $arch;
|
|
|
|
push @NewArgs, @AnalyzeArgs;
|
|
|
|
Analyze($Clang, \@NewArgs, $FileLang, $Output,
|
|
|
|
$Verbose, $HtmlDir, $file, $Analyses);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Analyze($Clang, \@AnalyzeArgs, $FileLang, $Output,
|
|
|
|
$Verbose, $HtmlDir, $file, $Analyses);
|
|
|
|
}
|
2008-07-19 14:11:04 +08:00
|
|
|
}
|
|
|
|
}
|
2008-03-26 06:35:32 +08:00
|
|
|
|
2008-08-28 06:30:34 +08:00
|
|
|
exit($Status >> 8);
|
|
|
|
|