my $UseColor = ((($ENV{'TERM'} eq 'xterm-color') and -t STDOUT)
and defined($ENV{'SCAN_BUILD_COLOR'}));
+##----------------------------------------------------------------------------##
+# Diagnostics
+##----------------------------------------------------------------------------##
+
sub Diag {
if ($UseColor) {
print BOLD, MAGENTA "$Prog: @_";
exit(0);
}
+##----------------------------------------------------------------------------##
+# Some initial preprocessing of Clang options.
+##----------------------------------------------------------------------------##
+
+my $ClangSB = "$RealBin/clang";
+my $Clang = $ClangSB;
+
+if (! -x $ClangSB) {
+ $Clang = "clang";
+}
+
+my %AvailableAnalyses;
+
+# Query clang for analysis options.
+open(PIPE, "$Clang --help |") or
+ DieDiag("Cannot execute '$Clang'");
+
+my $FoundAnalysis = 0;
+
+while(<PIPE>) {
+ if ($FoundAnalysis == 0) {
+ if (/Available Source Code Analyses/) {
+ $FoundAnalysis = 1;
+ }
+
+ next;
+ }
+
+ if (/^\s\s\s\s([^\s]+)\s(.+)$/) {
+ next if ($1 =~ /-dump/ or $1 =~ /-view/
+ or $1 =~ /-checker-simple/ or $1 =~ /-warn-uninit/);
+
+ $AvailableAnalyses{$1} = $2;
+ next;
+ }
+
+ last;
+}
+
+close (PIPE);
+
+my %AnalysesDefaultEnabled = (
+ '-warn-dead-stores' => 1,
+ '-checker-cfref' => 1,
+ '-warn-objc-methodsigs' => 1
+);
+
##----------------------------------------------------------------------------##
# GetHTMLRunDir - Construct an HTML directory name for the current run.
##----------------------------------------------------------------------------##
print <<ENDTEXT;
OPTIONS:
- -a - The analysis to run. The default is 'checker-cfref'.
- Valid options are: 'checker-cfref', 'fsyntax-only'
-
-o - Target directory for HTML report files. Subdirectories
will be created as needed to represent separate "runs" of
the analyzer. If this option is not specified, a directory
-V - View analysis results in a web browser when the build
--view completes.
+ENDTEXT
+
+ print " Available Source Code Analyses (multiple analyses may be specified):\n\n";
+
+ foreach my $Analysis (sort keys %AvailableAnalyses) {
+ if (defined($AnalysesDefaultEnabled{$Analysis})) {
+ print " (+)";
+ }
+ else {
+ print " ";
+ }
+
+ print " $Analysis $AvailableAnalyses{$Analysis}\n";
+ }
+
+print <<ENDTEXT
+
+ (+) == analysis enabled by default unless one
+ or more analysis options are specified
+
BUILD OPTIONS
You can specify any build option acceptable to the build command.
my $HtmlDir; # Parent directory to store HTML files.
my $IgnoreErrors = 0; # Ignore build errors.
my $ViewResults = 0; # View results when the build terminates.
-my $Analysis;
+my @AnalysesToRun;
if (!@ARGV) {
DisplayHelp();
exit 0;
}
- if ($arg eq "-a") {
+ if (defined($AvailableAnalyses{$arg})) {
shift @ARGV;
-
- if (!@ARGV) {
- DieDiag("'-a' option requires an analysis type.\n");
- }
-
- $Analysis = shift @ARGV;
-
- if (!($Analysis eq "checker-cfref" or $Analysis eq "fsyntax-only")) {
- DieDiag("Invalid argument '$Analysis' to -a.\n");
- }
-
+ push @AnalysesToRun, $arg;
next;
}
DieDiag("Executable 'ccc-analyzer' does not exist at '$Cmd'\n")
if (! -x $Cmd);
-
-my $Clang = "$RealBin/clang";
-if (! -x $Clang) {
- Diag("'clang' executable not found in '$RealBin'. Using 'clang' from path.\n");
- $Clang = "clang";
+if (! -x $ClangSB) {
+ Diag("'clang' executable not found in '$RealBin'.\n");
+ Diag("Using 'clang' from path.\n");
}
$ENV{'CC'} = $Cmd;
$ENV{'CCC_ANALYZER_LOG'} = 1;
}
-if (defined($Analysis)) {
- $ENV{'CCC_ANALYZER_ANALYSIS'} = $Analysis;
+if (scalar(@AnalysesToRun)) {
+ $ENV{'CCC_ANALYZER_ANALYSIS'} = join ' ',@AnalysesToRun;
}
# Run the build.