1f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#!/usr/bin/env perl
2f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#
3f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#                     The LLVM Compiler Infrastructure
4f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#
5f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# This file is distributed under the University of Illinois Open Source
6f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# License. See LICENSE.TXT for details.
7f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#
8f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##===----------------------------------------------------------------------===##
9f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#
10f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# A script designed to wrap a build so that all calls to gcc are intercepted
11f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# and piped to the static analyzer.
12f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#
13f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##===----------------------------------------------------------------------===##
14f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
15f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotuse strict;
16f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotuse warnings;
17f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotuse FindBin qw($RealBin);
18f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotuse Digest::MD5;
19f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotuse File::Basename;
20f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotuse File::Find;
21f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotuse File::Copy qw(copy);
22f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotuse File::Path qw( rmtree mkpath );
23f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotuse Term::ANSIColor;
24f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotuse Term::ANSIColor qw(:constants);
25f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotuse Cwd qw/ getcwd abs_path /;
26f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotuse Sys::Hostname;
27f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotuse Hash::Util qw(lock_keys);
28f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
29f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $Prog = "scan-build";
30f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $BuildName;
31f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $BuildDate;
32f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
33f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $TERM = $ENV{'TERM'};
34f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $UseColor = (defined $TERM and $TERM =~ 'xterm-.*color' and -t STDOUT
35f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                and defined $ENV{'SCAN_BUILD_COLOR'});
36f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
37f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Portability: getpwuid is not implemented for Win32 (see Perl language
38f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# reference, perlport), use getlogin instead.
39f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $UserName = HtmlEscape(getlogin() || getpwuid($<) || 'unknown');
40f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $HostName = HtmlEscape(hostname() || 'unknown');
41f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $CurrentDir = HtmlEscape(getcwd());
42f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
43f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $CmdArgs;
44f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
45f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $Date = localtime();
46f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
47f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Command-line/config arguments.
48f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy %Options = (
49f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Verbose => 0,              # Verbose output from this script.
50f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  AnalyzeHeaders => 0,
51f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  OutputDir => undef,        # Parent directory to store HTML files.
52f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  HtmlTitle => basename($CurrentDir)." - scan-build results",
53f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IgnoreErrors => 0,         # Ignore build errors.
54f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ViewResults => 0,          # View results when the build terminates.
55f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ExitStatusFoundBugs => 0,  # Exit status reflects whether bugs were found
56f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ShowDescription => 0,      # Display the description of the defect in the list
57f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  KeepEmpty => 0,            # Don't remove output directory even with 0 results.
58f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  EnableCheckers => {},
59f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DisableCheckers => {},
60f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  UseCC => undef,            # C compiler to use for compilation.
61f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  UseCXX => undef,           # C++ compiler to use for compilation.
62f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  AnalyzerTarget => undef,
63f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  StoreModel => undef,
64f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ConstraintsModel => undef,
65f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  InternalStats => undef,
66f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  OutputFormat => "html",
67f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ConfigOptions => [],       # Options to pass through to the analyzer's -analyzer-config flag.
68f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ReportFailures => undef,
69f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  AnalyzerStats => 0,
70f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  MaxLoop => 0,
71f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  PluginsToLoad => [],
72f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  AnalyzerDiscoveryMethod => undef,
73f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  OverrideCompiler => 0,      # The flag corresponding to the --override-compiler command line option.
74f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ForceAnalyzeDebugCode => 0
75f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot);
76f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotlock_keys(%Options);
77f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
78f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
79f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Diagnostics
80f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
81f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
82f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub Diag {
83f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($UseColor) {
84f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print BOLD, MAGENTA "$Prog: @_";
85f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print RESET;
86f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
87f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  else {
88f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print "$Prog: @_";
89f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
90f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
91f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
92f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub ErrorDiag {
93f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($UseColor) {
94f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print STDERR BOLD, RED "$Prog: ";
95f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print STDERR RESET, RED @_;
96f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print STDERR RESET;
97f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  } else {
98f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print STDERR "$Prog: @_";
99f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
100f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
101f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
102f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub DiagCrashes {
103f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Dir = shift;
104f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Diag ("The analyzer encountered problems on some source files.\n");
105f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Diag ("Preprocessed versions of these sources were deposited in '$Dir/failures'.\n");
106f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Diag ("Please consider submitting a bug report using these files:\n");
107f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Diag ("  http://clang-analyzer.llvm.org/filing_bugs.html\n")
108f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
109f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
110f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub DieDiag {
111f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($UseColor) {
112f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print STDERR BOLD, RED "$Prog: ";
113f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print STDERR RESET, RED @_;
114f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print STDERR RESET;
115f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
116f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  else {
117f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print STDERR "$Prog: ", @_;
118f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
119f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  exit 1;
120f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
121f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
122f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
123f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Print default checker names
124f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
125f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
126f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotif (grep /^--help-checkers$/, @ARGV) {
127f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my @options = qx($0 -h);
128f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    foreach (@options) {
129f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    next unless /^ \+/;
130f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    s/^\s*//;
131f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my ($sign, $name, @text) = split ' ', $_;
132f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print $name, $/ if $sign eq '+';
133f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
134f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    exit 0;
135f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
136f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
137f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
138f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Declaration of Clang options.  Populated later.
139f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
140f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
141f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $Clang;
142f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $ClangSB;
143f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $ClangCXX;
144f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $ClangVersion;
145f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
146f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
147f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# GetHTMLRunDir - Construct an HTML directory name for the current sub-run.
148f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
149f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
150f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub GetHTMLRunDir {
151f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  die "Not enough arguments." if (@_ == 0);
152f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Dir = shift @_;
153f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $TmpMode = 0;
154f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (!defined $Dir) {
155f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $Dir = $ENV{'TMPDIR'} || $ENV{'TEMP'} || $ENV{'TMP'} || "/tmp";
156f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $TmpMode = 1;
157f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
158f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
159f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Chop off any trailing '/' characters.
160f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  while ($Dir =~ /\/$/) { chop $Dir; }
161f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
162f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Get current date and time.
163f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my @CurrentTime = localtime();
164f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $year  = $CurrentTime[5] + 1900;
165f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $day   = $CurrentTime[3];
166f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $month = $CurrentTime[4] + 1;
167f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $hour =  $CurrentTime[2];
168f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $min =   $CurrentTime[1];
169f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $sec =   $CurrentTime[0];
170f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
171f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $TimeString = sprintf("%02d%02d%02d", $hour, $min, $sec);
172f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $DateString = sprintf("%d-%02d-%02d-%s-$$",
173f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                           $year, $month, $day, $TimeString);
174f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
175f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Determine the run number.
176f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $RunNumber;
177f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
178f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (-d $Dir) {
179f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (! -r $Dir) {
180f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DieDiag("directory '$Dir' exists but is not readable.\n");
181f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
182f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    # Iterate over all files in the specified directory.
183f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $max = 0;
184f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    opendir(DIR, $Dir);
185f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my @FILES = grep { -d "$Dir/$_" } readdir(DIR);
186f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    closedir(DIR);
187f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
188f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    foreach my $f (@FILES) {
189f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      # Strip the prefix '$Prog-' if we are dumping files to /tmp.
190f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if ($TmpMode) {
191f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        next if (!($f =~ /^$Prog-(.+)/));
192f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $f = $1;
193f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
194f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
195f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my @x = split/-/, $f;
196f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next if (scalar(@x) != 4);
197f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next if ($x[0] != $year);
198f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next if ($x[1] != $month);
199f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next if ($x[2] != $day);
200f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next if ($x[3] != $TimeString);
201f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next if ($x[4] != $$);
202f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
203f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if ($x[5] > $max) {
204f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $max = $x[5];
205f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
206f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
207f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
208f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $RunNumber = $max + 1;
209f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
210f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  else {
211f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
212f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (-x $Dir) {
213f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DieDiag("'$Dir' exists but is not a directory.\n");
214f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
215f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
216f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($TmpMode) {
217f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DieDiag("The directory '/tmp' does not exist or cannot be accessed.\n");
218f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
219f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
220f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    # $Dir does not exist.  It will be automatically created by the
221f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    # clang driver.  Set the run number to 1.
222f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
223f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $RunNumber = 1;
224f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
225f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
226f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  die "RunNumber must be defined!" if (!defined $RunNumber);
227f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
228f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Append the run number.
229f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $NewDir;
230f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($TmpMode) {
231f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $NewDir = "$Dir/$Prog-$DateString-$RunNumber";
232f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
233f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  else {
234f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $NewDir = "$Dir/$DateString-$RunNumber";
235f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
236f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
237f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Make sure that the directory does not exist in order to avoid hijack.
238f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (-e $NewDir) {
239f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DieDiag("The directory '$NewDir' already exists.\n");
240f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
241f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
242f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  mkpath($NewDir);
243f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  return $NewDir;
244f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
245f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
246f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub SetHtmlEnv {
247f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
248f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  die "Wrong number of arguments." if (scalar(@_) != 2);
249f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
250f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Args = shift;
251f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Dir = shift;
252f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
253f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  die "No build command." if (scalar(@$Args) == 0);
254f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
255f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Cmd = $$Args[0];
256f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
257f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($Cmd =~ /configure/ || $Cmd =~ /autogen/) {
258f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return;
259f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
260f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
261f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($Options{Verbose}) {
262f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Diag("Emitting reports for this run to '$Dir'.\n");
263f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
264f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
265f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  $ENV{'CCC_ANALYZER_HTML'} = $Dir;
266f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
267f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
268f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
269f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# ComputeDigest - Compute a digest of the specified file.
270f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
271f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
272f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub ComputeDigest {
273f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $FName = shift;
274f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DieDiag("Cannot read $FName to compute Digest.\n") if (! -r $FName);
275f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
276f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Use Digest::MD5.  We don't have to be cryptographically secure.  We're
277f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # just looking for duplicate files that come from a non-malicious source.
278f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # We use Digest::MD5 because it is a standard Perl module that should
279f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # come bundled on most systems.
280f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  open(FILE, $FName) or DieDiag("Cannot open $FName when computing Digest.\n");
281f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  binmode FILE;
282f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Result = Digest::MD5->new->addfile(*FILE)->hexdigest;
283f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  close(FILE);
284f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
285f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Return the digest.
286f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  return $Result;
287f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
288f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
289f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
290f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#  UpdatePrefix - Compute the common prefix of files.
291f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
292f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
293f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $Prefix;
294f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
295f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub UpdatePrefix {
296f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $x = shift;
297f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $y = basename($x);
298f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  $x =~ s/\Q$y\E$//;
299f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
300f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (!defined $Prefix) {
301f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $Prefix = $x;
302f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return;
303f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
304f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
305f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  chop $Prefix while (!($x =~ /^\Q$Prefix/));
306f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
307f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
308f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub GetPrefix {
309f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  return $Prefix;
310f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
311f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
312f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
313f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#  UpdateInFilePath - Update the path in the report file.
314f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
315f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
316f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub UpdateInFilePath {
317f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $fname = shift;
318f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $regex = shift;
319f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $newtext = shift;
320f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
321f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  open (RIN, $fname) or die "cannot open $fname";
322f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  open (ROUT, ">", "$fname.tmp") or die "cannot open $fname.tmp";
323f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
324f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  while (<RIN>) {
325f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    s/$regex/$newtext/;
326f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print ROUT $_;
327f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
328f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
329f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  close (ROUT);
330f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  close (RIN);
331f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  rename("$fname.tmp", $fname)
332f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
333f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
334f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
335f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# AddStatLine - Decode and insert a statistics line into the database.
336f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
337f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
338f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub AddStatLine {
339f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Line  = shift;
340f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Stats = shift;
341f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $File  = shift;
342f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
343f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  print $Line . "\n";
344f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
345f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Regex = qr/(.*?)\ ->\ Total\ CFGBlocks:\ (\d+)\ \|\ Unreachable
346f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      \ CFGBlocks:\ (\d+)\ \|\ Exhausted\ Block:\ (yes|no)\ \|\ Empty\ WorkList:
347f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      \ (yes|no)/x;
348f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
349f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($Line !~ $Regex) {
350f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return;
351f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
352f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
353f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Create a hash of the interesting fields
354f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Row = {
355f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Filename    => $File,
356f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Function    => $1,
357f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Total       => $2,
358f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Unreachable => $3,
359f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Aborted     => $4,
360f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Empty       => $5
361f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  };
362f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
363f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Add them to the stats array
364f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  push @$Stats, $Row;
365f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
366f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
367f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
368f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# ScanFile - Scan a report file for various identifying attributes.
369f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
370f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
371f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Sometimes a source file is scanned more than once, and thus produces
372f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# multiple error reports.  We use a cache to solve this problem.
373f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
374f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy %AlreadyScanned;
375f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
376f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub ScanFile {
377f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
378f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Index = shift;
379f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Dir = shift;
380f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $FName = shift;
381f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Stats = shift;
382f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
383f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Compute a digest for the report file.  Determine if we have already
384f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # scanned a file that looks just like it.
385f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
386f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $digest = ComputeDigest("$Dir/$FName");
387f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
388f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (defined $AlreadyScanned{$digest}) {
389f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    # Redundant file.  Remove it.
390f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    unlink("$Dir/$FName");
391f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return;
392f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
393f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
394f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  $AlreadyScanned{$digest} = 1;
395f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
396f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # At this point the report file is not world readable.  Make it happen.
397f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  chmod(0644, "$Dir/$FName");
398f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
399f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Scan the report file for tags.
400f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  open(IN, "$Dir/$FName") or DieDiag("Cannot open '$Dir/$FName'\n");
401f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
402f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $BugType        = "";
403f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $BugFile        = "";
404f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $BugFunction    = "";
405f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $BugCategory    = "";
406f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $BugDescription = "";
407f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $BugPathLength  = 1;
408f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $BugLine        = 0;
409f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
410f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  while (<IN>) {
411f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    last if (/<!-- BUGMETAEND -->/);
412f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
413f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (/<!-- BUGTYPE (.*) -->$/) {
414f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $BugType = $1;
415f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
416f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    elsif (/<!-- BUGFILE (.*) -->$/) {
417f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $BugFile = abs_path($1);
418f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (!defined $BugFile) {
419f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot         # The file no longer exists: use the original path.
420f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot         $BugFile = $1;
421f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
422f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      UpdatePrefix($BugFile);
423f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
424f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    elsif (/<!-- BUGPATHLENGTH (.*) -->$/) {
425f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $BugPathLength = $1;
426f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
427f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    elsif (/<!-- BUGLINE (.*) -->$/) {
428f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $BugLine = $1;
429f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
430f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    elsif (/<!-- BUGCATEGORY (.*) -->$/) {
431f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $BugCategory = $1;
432f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
433f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    elsif (/<!-- BUGDESC (.*) -->$/) {
434f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $BugDescription = $1;
435f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
436f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    elsif (/<!-- FUNCTIONNAME (.*) -->$/) {
437f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $BugFunction = $1;
438f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
439f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
440f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
441f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
442f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
443f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  close(IN);
444f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
445f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (!defined $BugCategory) {
446f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $BugCategory = "Other";
447f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
448f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
449f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Don't add internal statistics to the bug reports
450f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($BugCategory =~ /statistics/i) {
451f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    AddStatLine($BugDescription, $Stats, $BugFile);
452f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return;
453f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
454f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
455f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  push @$Index,[ $FName, $BugCategory, $BugType, $BugFile, $BugFunction, $BugLine,
456f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                 $BugPathLength ];
457f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
458f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($Options{ShowDescription}) {
459f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      push @{ $Index->[-1] }, $BugDescription
460f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
461f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
462f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
463f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
464f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# CopyFiles - Copy resource files to target directory.
465f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
466f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
467f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub CopyFiles {
468f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
469f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Dir = shift;
470f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
471f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $JS = Cwd::realpath("$RealBin/../share/scan-build/sorttable.js");
472f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
473f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DieDiag("Cannot find 'sorttable.js'.\n")
474f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (! -r $JS);
475f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
476f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  copy($JS, "$Dir");
477f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
478f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n")
479f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (! -r "$Dir/sorttable.js");
480f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
481f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $CSS = Cwd::realpath("$RealBin/../share/scan-build/scanview.css");
482f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
483f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DieDiag("Cannot find 'scanview.css'.\n")
484f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (! -r $CSS);
485f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
486f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  copy($CSS, "$Dir");
487f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
488f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DieDiag("Could not copy 'scanview.css' to '$Dir'.\n")
489f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (! -r $CSS);
490f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
491f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
492f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
493f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# CalcStats - Calculates visitation statistics and returns the string.
494f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
495f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
496f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub CalcStats {
497f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Stats = shift;
498f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
499f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $TotalBlocks = 0;
500f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $UnreachedBlocks = 0;
501f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $TotalFunctions = scalar(@$Stats);
502f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $BlockAborted = 0;
503f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $WorkListAborted = 0;
504f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Aborted = 0;
505f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
506f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Calculate the unique files
507f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $FilesHash = {};
508f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
509f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  foreach my $Row (@$Stats) {
510f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $FilesHash->{$Row->{Filename}} = 1;
511f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $TotalBlocks += $Row->{Total};
512f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $UnreachedBlocks += $Row->{Unreachable};
513f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $BlockAborted++ if $Row->{Aborted} eq 'yes';
514f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $WorkListAborted++ if $Row->{Empty} eq 'no';
515f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $Aborted++ if $Row->{Aborted} eq 'yes' || $Row->{Empty} eq 'no';
516f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
517f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
518f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $TotalFiles = scalar(keys(%$FilesHash));
519f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
520f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Calculations
521f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $PercentAborted = sprintf("%.2f", $Aborted / $TotalFunctions * 100);
522f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $PercentBlockAborted = sprintf("%.2f", $BlockAborted / $TotalFunctions
523f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      * 100);
524f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $PercentWorkListAborted = sprintf("%.2f", $WorkListAborted /
525f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $TotalFunctions * 100);
526f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $PercentBlocksUnreached = sprintf("%.2f", $UnreachedBlocks / $TotalBlocks
527f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      * 100);
528f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
529f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $StatsString = "Analyzed $TotalBlocks blocks in $TotalFunctions functions"
530f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    . " in $TotalFiles files\n"
531f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    . "$Aborted functions aborted early ($PercentAborted%)\n"
532f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    . "$BlockAborted had aborted blocks ($PercentBlockAborted%)\n"
533f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    . "$WorkListAborted had unfinished worklists ($PercentWorkListAborted%)\n"
534f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    . "$UnreachedBlocks blocks were never reached ($PercentBlocksUnreached%)\n";
535f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
536f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  return $StatsString;
537f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
538f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
539f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
540f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Postprocess - Postprocess the results of an analysis scan.
541f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
542f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
543f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy @filesFound;
544f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $baseDir;
545f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub FileWanted {
546f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $baseDirRegEx = quotemeta $baseDir;
547f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $file = $File::Find::name;
548f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
549f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    # The name of the file is generated by clang binary (HTMLDiagnostics.cpp)
550f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($file =~ /report-.*\.html$/) {
551f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot       my $relative_file = $file;
552f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot       $relative_file =~ s/$baseDirRegEx//g;
553f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot       push @filesFound, $relative_file;
554f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
555f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
556f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
557f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub Postprocess {
558f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
559f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Dir           = shift;
560f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $BaseDir       = shift;
561f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $AnalyzerStats = shift;
562f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $KeepEmpty     = shift;
563f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
564f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  die "No directory specified." if (!defined $Dir);
565f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
566f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (! -d $Dir) {
567f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Diag("No bugs found.\n");
568f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return 0;
569f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
570f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
571f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  $baseDir = $Dir . "/";
572f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  find({ wanted => \&FileWanted, follow => 0}, $Dir);
573f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
574f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (scalar(@filesFound) == 0 and ! -e "$Dir/failures") {
575f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (! $KeepEmpty) {
576f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Diag("Removing directory '$Dir' because it contains no reports.\n");
577f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      rmtree($Dir) or die "Cannot rmtree '$Dir' : $!";
578f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
579f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Diag("No bugs found.\n");
580f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return 0;
581f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
582f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
583f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Scan each report file and build an index.
584f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my @Index;
585f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my @Stats;
586f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  foreach my $file (@filesFound) { ScanFile(\@Index, $Dir, $file, \@Stats); }
587f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
588f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Scan the failures directory and use the information in the .info files
589f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # to update the common prefix directory.
590f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my @failures;
591f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my @attributes_ignored;
592f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (-d "$Dir/failures") {
593f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    opendir(DIR, "$Dir/failures");
594f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    @failures = grep { /[.]info.txt$/ && !/attribute_ignored/; } readdir(DIR);
595f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    closedir(DIR);
596f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    opendir(DIR, "$Dir/failures");
597f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    @attributes_ignored = grep { /^attribute_ignored/; } readdir(DIR);
598f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    closedir(DIR);
599f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    foreach my $file (@failures) {
600f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      open IN, "$Dir/failures/$file" or DieDiag("cannot open $file\n");
601f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $Path = <IN>;
602f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (defined $Path) { UpdatePrefix($Path); }
603f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      close IN;
604f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
605f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
606f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
607f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Generate an index.html file.
608f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $FName = "$Dir/index.html";
609f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  open(OUT, ">", $FName) or DieDiag("Cannot create file '$FName'\n");
610f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
611f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Print out the header.
612f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
613f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprint OUT <<ENDTEXT;
614f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<html>
615f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<head>
616f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<title>${Options{HtmlTitle}}</title>
617f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<link type="text/css" rel="stylesheet" href="scanview.css"/>
618f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<script src="sorttable.js"></script>
619f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<script language='javascript' type="text/javascript">
620f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotfunction SetDisplay(RowClass, DisplayVal)
621f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot{
622f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  var Rows = document.getElementsByTagName("tr");
623f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  for ( var i = 0 ; i < Rows.length; ++i ) {
624f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (Rows[i].className == RowClass) {
625f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Rows[i].style.display = DisplayVal;
626f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
627f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
628f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
629f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
630f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotfunction CopyCheckedStateToCheckButtons(SummaryCheckButton) {
631f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  var Inputs = document.getElementsByTagName("input");
632f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  for ( var i = 0 ; i < Inputs.length; ++i ) {
633f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (Inputs[i].type == "checkbox") {
634f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if(Inputs[i] != SummaryCheckButton) {
635f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        Inputs[i].checked = SummaryCheckButton.checked;
636f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        Inputs[i].onclick();
637f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
638f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
639f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
640f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
641f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
642f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotfunction returnObjById( id ) {
643f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (document.getElementById)
644f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        var returnVar = document.getElementById(id);
645f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    else if (document.all)
646f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        var returnVar = document.all[id];
647f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    else if (document.layers)
648f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        var returnVar = document.layers[id];
649f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return returnVar;
650f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
651f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
652f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotvar NumUnchecked = 0;
653f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
654f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotfunction ToggleDisplay(CheckButton, ClassName) {
655f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (CheckButton.checked) {
656f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    SetDisplay(ClassName, "");
657f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (--NumUnchecked == 0) {
658f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      returnObjById("AllBugsCheck").checked = true;
659f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
660f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
661f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  else {
662f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    SetDisplay(ClassName, "none");
663f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    NumUnchecked++;
664f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    returnObjById("AllBugsCheck").checked = false;
665f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
666f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
667f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot</script>
668f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<!-- SUMMARYENDHEAD -->
669f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot</head>
670f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<body>
671f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<h1>${Options{HtmlTitle}}</h1>
672f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
673f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<table>
674f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<tr><th>User:</th><td>${UserName}\@${HostName}</td></tr>
675f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<tr><th>Working Directory:</th><td>${CurrentDir}</td></tr>
676f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<tr><th>Command Line:</th><td>${CmdArgs}</td></tr>
677f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<tr><th>Clang Version:</th><td>${ClangVersion}</td></tr>
678f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<tr><th>Date:</th><td>${Date}</td></tr>
679f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotENDTEXT
680f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
681f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprint OUT "<tr><th>Version:</th><td>${BuildName} (${BuildDate})</td></tr>\n"
682f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (defined($BuildName) && defined($BuildDate));
683f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
684f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprint OUT <<ENDTEXT;
685f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot</table>
686f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotENDTEXT
687f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
688f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (scalar(@filesFound)) {
689f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    # Print out the summary table.
690f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my %Totals;
691f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
692f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    for my $row ( @Index ) {
693f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $bug_type = ($row->[2]);
694f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $bug_category = ($row->[1]);
695f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $key = "$bug_category:$bug_type";
696f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
697f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (!defined $Totals{$key}) { $Totals{$key} = [1,$bug_category,$bug_type]; }
698f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      else { $Totals{$key}->[0]++; }
699f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
700f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
701f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print OUT "<h2>Bug Summary</h2>";
702f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
703f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (defined $BuildName) {
704f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "\n<p>Results in this analysis run are based on analyzer build <b>$BuildName</b>.</p>\n"
705f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
706f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
707f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $TotalBugs = scalar(@Index);
708f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprint OUT <<ENDTEXT;
709f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<table>
710f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<thead><tr><td>Bug Type</td><td>Quantity</td><td class="sorttable_nosort">Display?</td></tr></thead>
711f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<tr style="font-weight:bold"><td class="SUMM_DESC">All Bugs</td><td class="Q">$TotalBugs</td><td><center><input type="checkbox" id="AllBugsCheck" onClick="CopyCheckedStateToCheckButtons(this);" checked/></center></td></tr>
712f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotENDTEXT
713f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
714f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $last_category;
715f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
716f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    for my $key (
717f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      sort {
718f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        my $x = $Totals{$a};
719f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        my $y = $Totals{$b};
720f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        my $res = $x->[1] cmp $y->[1];
721f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $res = $x->[2] cmp $y->[2] if ($res == 0);
722f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $res
723f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      } keys %Totals )
724f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    {
725f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $val = $Totals{$key};
726f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $category = $val->[1];
727f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (!defined $last_category or $last_category ne $category) {
728f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $last_category = $category;
729f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        print OUT "<tr><th>$category</th><th colspan=2></th></tr>\n";
730f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
731f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $x = lc $key;
732f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $x =~ s/[ ,'":\/()]+/_/g;
733f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "<tr><td class=\"SUMM_DESC\">";
734f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT $val->[2];
735f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "</td><td class=\"Q\">";
736f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT $val->[0];
737f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "</td><td><center><input type=\"checkbox\" onClick=\"ToggleDisplay(this,'bt_$x');\" checked/></center></td></tr>\n";
738f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
739f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
740f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Print out the table of errors.
741f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
742f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprint OUT <<ENDTEXT;
743f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot</table>
744f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<h2>Reports</h2>
745f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
746f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<table class="sortable" style="table-layout:automatic">
747f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<thead><tr>
748f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  <td>Bug Group</td>
749f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  <td class="sorttable_sorted">Bug Type<span id="sorttable_sortfwdind">&nbsp;&#x25BE;</span></td>
750f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  <td>File</td>
751f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  <td>Function/Method</td>
752f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  <td class="Q">Line</td>
753f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  <td class="Q">Path Length</td>
754f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotENDTEXT
755f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
756f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotif ($Options{ShowDescription}) {
757f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprint OUT <<ENDTEXT;
758f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    <td class="Q">Description</td>
759f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotENDTEXT
760f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
761f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
762f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprint OUT <<ENDTEXT;
763f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  <td class="sorttable_nosort"></td>
764f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  <!-- REPORTBUGCOL -->
765f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot</tr></thead>
766f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot<tbody>
767f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotENDTEXT
768f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
769f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $prefix = GetPrefix();
770f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $regex;
771f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $InFileRegex;
772f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $InFilePrefix = "File:</td><td>";
773f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
774f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (defined $prefix) {
775f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $regex = qr/^\Q$prefix\E/is;
776f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $InFileRegex = qr/\Q$InFilePrefix$prefix\E/is;
777f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
778f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
779f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    for my $row ( sort { $a->[2] cmp $b->[2] } @Index ) {
780f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $x = "$row->[1]:$row->[2]";
781f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $x = lc $x;
782f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $x =~ s/[ ,'":\/()]+/_/g;
783f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
784f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $ReportFile = $row->[0];
785f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
786f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "<tr class=\"bt_$x\">";
787f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "<td class=\"DESC\">";
788f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT $row->[1]; # $BugCategory
789f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "</td>";
790f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "<td class=\"DESC\">";
791f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT $row->[2]; # $BugType
792f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "</td>";
793f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
794f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      # Update the file prefix.
795f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $fname = $row->[3];
796f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
797f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (defined $regex) {
798f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $fname =~ s/$regex//;
799f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        UpdateInFilePath("$Dir/$ReportFile", $InFileRegex, $InFilePrefix)
800f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
801f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
802f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "<td>";
803f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my @fname = split /\//,$fname;
804f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if ($#fname > 0) {
805f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        while ($#fname >= 0) {
806f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          my $x = shift @fname;
807f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          print OUT $x;
808f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          if ($#fname >= 0) {
809f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot            print OUT "/";
810f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          }
811f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        }
812f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
813f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      else {
814f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        print OUT $fname;
815f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
816f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "</td>";
817f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
818f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "<td class=\"DESC\">";
819f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT $row->[4]; # Function
820f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "</td>";
821f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
822f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      # Print out the quantities.
823f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      for my $j ( 5 .. 6 ) { # Line & Path length
824f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        print OUT "<td class=\"Q\">$row->[$j]</td>";
825f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
826f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
827f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      # Print the rest of the columns.
828f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      for (my $j = 7; $j <= $#{$row}; ++$j) {
829f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        print OUT "<td>$row->[$j]</td>"
830f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
831f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
832f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      # Emit the "View" link.
833f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "<td><a href=\"$ReportFile#EndPath\">View Report</a></td>";
834f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
835f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      # Emit REPORTBUG markers.
836f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "\n<!-- REPORTBUG id=\"$ReportFile\" -->\n";
837f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
838f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      # End the row.
839f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "</tr>\n";
840f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
841f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
842f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print OUT "</tbody>\n</table>\n\n";
843f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
844f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
845f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (scalar (@failures) || scalar(@attributes_ignored)) {
846f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print OUT "<h2>Analyzer Failures</h2>\n";
847f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
848f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (scalar @attributes_ignored) {
849f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "The analyzer's parser ignored the following attributes:<p>\n";
850f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "<table>\n";
851f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "<thead><tr><td>Attribute</td><td>Source File</td><td>Preprocessed File</td><td>STDERR Output</td></tr></thead>\n";
852f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      foreach my $file (sort @attributes_ignored) {
853f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        die "cannot demangle attribute name\n" if (! ($file =~ /^attribute_ignored_(.+).txt/));
854f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        my $attribute = $1;
855f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        # Open the attribute file to get the first file that failed.
856f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        next if (!open (ATTR, "$Dir/failures/$file"));
857f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        my $ppfile = <ATTR>;
858f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        chomp $ppfile;
859f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        close ATTR;
860f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        next if (! -e "$Dir/failures/$ppfile");
861f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        # Open the info file and get the name of the source file.
862f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        open (INFO, "$Dir/failures/$ppfile.info.txt") or
863f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          die "Cannot open $Dir/failures/$ppfile.info.txt\n";
864f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        my $srcfile = <INFO>;
865f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        chomp $srcfile;
866f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        close (INFO);
867f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        # Print the information in the table.
868f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        my $prefix = GetPrefix();
869f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        if (defined $prefix) { $srcfile =~ s/^\Q$prefix//; }
870f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        print OUT "<tr><td>$attribute</td><td>$srcfile</td><td><a href=\"failures/$ppfile\">$ppfile</a></td><td><a href=\"failures/$ppfile.stderr.txt\">$ppfile.stderr.txt</a></td></tr>\n";
871f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        my $ppfile_clang = $ppfile;
872f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $ppfile_clang =~ s/[.](.+)$/.clang.$1/;
873f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        print OUT "  <!-- REPORTPROBLEM src=\"$srcfile\" file=\"failures/$ppfile\" clangfile=\"failures/$ppfile_clang\" stderr=\"failures/$ppfile.stderr.txt\" info=\"failures/$ppfile.info.txt\" -->\n";
874f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
875f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "</table>\n";
876f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
877f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
878f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (scalar @failures) {
879f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "<p>The analyzer had problems processing the following files:</p>\n";
880f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "<table>\n";
881f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "<thead><tr><td>Problem</td><td>Source File</td><td>Preprocessed File</td><td>STDERR Output</td></tr></thead>\n";
882f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      foreach my $file (sort @failures) {
883f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $file =~ /(.+).info.txt$/;
884f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        # Get the preprocessed file.
885f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        my $ppfile = $1;
886f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        # Open the info file and get the name of the source file.
887f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        open (INFO, "$Dir/failures/$file") or
888f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          die "Cannot open $Dir/failures/$file\n";
889f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        my $srcfile = <INFO>;
890f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        chomp $srcfile;
891f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        my $problem = <INFO>;
892f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        chomp $problem;
893f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        close (INFO);
894f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        # Print the information in the table.
895f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        my $prefix = GetPrefix();
896f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        if (defined $prefix) { $srcfile =~ s/^\Q$prefix//; }
897f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        print OUT "<tr><td>$problem</td><td>$srcfile</td><td><a href=\"failures/$ppfile\">$ppfile</a></td><td><a href=\"failures/$ppfile.stderr.txt\">$ppfile.stderr.txt</a></td></tr>\n";
898f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        my $ppfile_clang = $ppfile;
899f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $ppfile_clang =~ s/[.](.+)$/.clang.$1/;
900f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        print OUT "  <!-- REPORTPROBLEM src=\"$srcfile\" file=\"failures/$ppfile\" clangfile=\"failures/$ppfile_clang\" stderr=\"failures/$ppfile.stderr.txt\" info=\"failures/$ppfile.info.txt\" -->\n";
901f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
902f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print OUT "</table>\n";
903f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
904f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print OUT "<p>Please consider submitting preprocessed files as <a href=\"http://clang-analyzer.llvm.org/filing_bugs.html\">bug reports</a>. <!-- REPORTCRASHES --> </p>\n";
905f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
906f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
907f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  print OUT "</body></html>\n";
908f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  close(OUT);
909f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  CopyFiles($Dir);
910f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
911f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Make sure $Dir and $BaseDir are world readable/executable.
912f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  chmod(0755, $Dir);
913f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (defined $BaseDir) { chmod(0755, $BaseDir); }
914f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
915f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Print statistics
916f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  print CalcStats(\@Stats) if $AnalyzerStats;
917f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
918f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Num = scalar(@Index);
919f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($Num == 1) {
920f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Diag("$Num bug found.\n");
921f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  } else {
922f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Diag("$Num bugs found.\n");
923f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
924f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($Num > 0 && -r "$Dir/index.html") {
925f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Diag("Run 'scan-view $Dir' to examine bug reports.\n");
926f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
927f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
928f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DiagCrashes($Dir) if (scalar @failures || scalar @attributes_ignored);
929f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
930f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  return $Num;
931f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
932f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
933f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
934f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# RunBuildCommand - Run the build command.
935f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
936f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
937f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub AddIfNotPresent {
938f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Args = shift;
939f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Arg = shift;
940f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $found = 0;
941f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
942f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  foreach my $k (@$Args) {
943f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($k eq $Arg) {
944f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $found = 1;
945f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      last;
946f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
947f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
948f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
949f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($found == 0) {
950f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    push @$Args, $Arg;
951f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
952f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
953f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
954f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub SetEnv {
955f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $EnvVars = shift @_;
956f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  foreach my $var ('CC', 'CXX', 'CLANG', 'CLANG_CXX',
957f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                   'CCC_ANALYZER_ANALYSIS', 'CCC_ANALYZER_PLUGINS',
958f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                   'CCC_ANALYZER_CONFIG') {
959f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    die "$var is undefined\n" if (!defined $var);
960f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $ENV{$var} = $EnvVars->{$var};
961f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
962f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  foreach my $var ('CCC_ANALYZER_STORE_MODEL',
963f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                   'CCC_ANALYZER_CONSTRAINTS_MODEL',
964f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                   'CCC_ANALYZER_INTERNAL_STATS',
965f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                   'CCC_ANALYZER_OUTPUT_FORMAT',
966f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                   'CCC_CC',
967f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                   'CCC_CXX',
968f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                   'CCC_REPORT_FAILURES',
969f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                   'CLANG_ANALYZER_TARGET',
970f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                   'CCC_ANALYZER_FORCE_ANALYZE_DEBUG_CODE') {
971f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $x = $EnvVars->{$var};
972f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (defined $x) { $ENV{$var} = $x }
973f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
974f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Verbose = $EnvVars->{'VERBOSE'};
975f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($Verbose >= 2) {
976f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $ENV{'CCC_ANALYZER_VERBOSE'} = 1;
977f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
978f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($Verbose >= 3) {
979f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $ENV{'CCC_ANALYZER_LOG'} = 1;
980f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
981f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
982f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
983f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub RunXcodebuild {
984f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Args = shift;
985f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $IgnoreErrors = shift;
986f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $CCAnalyzer = shift;
987f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $CXXAnalyzer = shift;
988f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $EnvVars = shift;
989f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
990f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($IgnoreErrors) {
991f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    AddIfNotPresent($Args,"-PBXBuildsContinueAfterErrors=YES");
992f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
993f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
994f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Detect the version of Xcode.  If Xcode 4.6 or higher, use new
995f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # in situ support for analyzer interposition without needed to override
996f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # the compiler.
997f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  open(DETECT_XCODE, "-|", $Args->[0], "-version") or
998f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    die "error: cannot detect version of xcodebuild\n";
999f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1000f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $oldBehavior = 1;
1001f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1002f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  while(<DETECT_XCODE>) {
1003f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (/^Xcode (.+)$/) {
1004f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $ver = $1;
1005f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if ($ver =~ /^([0-9]+[.][0-9]+)[^0-9]?/) {
1006f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        if ($1 >= 4.6) {
1007f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          $oldBehavior = 0;
1008f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          last;
1009f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        }
1010f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1011f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1012f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1013f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  close(DETECT_XCODE);
1014f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1015f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # If --override-compiler is explicitely requested, resort to the old
1016f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # behavior regardless of Xcode version.
1017f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($Options{OverrideCompiler}) {
1018f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $oldBehavior = 1;
1019f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1020f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1021f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($oldBehavior == 0) {
1022f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $OutputDir = $EnvVars->{"OUTPUT_DIR"};
1023f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $CLANG = $EnvVars->{"CLANG"};
1024f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $OtherFlags = $EnvVars->{"CCC_ANALYZER_ANALYSIS"};
1025f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    push @$Args,
1026f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        "RUN_CLANG_STATIC_ANALYZER=YES",
1027f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        "CLANG_ANALYZER_OUTPUT=plist-html",
1028f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        "CLANG_ANALYZER_EXEC=$CLANG",
1029f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        "CLANG_ANALYZER_OUTPUT_DIR=$OutputDir",
1030f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        "CLANG_ANALYZER_OTHER_FLAGS=$OtherFlags";
1031f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1032f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return (system(@$Args) >> 8);
1033f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1034f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1035f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Default to old behavior where we insert a bogus compiler.
1036f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SetEnv($EnvVars);
1037f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1038f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Check if using iPhone SDK 3.0 (simulator).  If so the compiler being
1039f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # used should be gcc-4.2.
1040f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (!defined $ENV{"CCC_CC"}) {
1041f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    for (my $i = 0 ; $i < scalar(@$Args); ++$i) {
1042f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if ($Args->[$i] eq "-sdk" && $i + 1 < scalar(@$Args)) {
1043f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        if (@$Args[$i+1] =~ /^iphonesimulator3/) {
1044f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          $ENV{"CCC_CC"} = "gcc-4.2";
1045f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          $ENV{"CCC_CXX"} = "g++-4.2";
1046f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        }
1047f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1048f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1049f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1050f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1051f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Disable PCH files until clang supports them.
1052f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  AddIfNotPresent($Args,"GCC_PRECOMPILE_PREFIX_HEADER=NO");
1053f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1054f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # When 'CC' is set, xcodebuild uses it to do all linking, even if we are
1055f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # linking C++ object files.  Set 'LDPLUSPLUS' so that xcodebuild uses 'g++'
1056f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # (via c++-analyzer) when linking such files.
1057f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  $ENV{"LDPLUSPLUS"} = $CXXAnalyzer;
1058f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1059f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  return (system(@$Args) >> 8);
1060f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1061f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1062f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub RunBuildCommand {
1063f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Args = shift;
1064f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $IgnoreErrors = shift;
1065f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Cmd = $Args->[0];
1066f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $CCAnalyzer = shift;
1067f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $CXXAnalyzer = shift;
1068f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $EnvVars = shift;
1069f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1070f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($Cmd =~ /\bxcodebuild$/) {
1071f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return RunXcodebuild($Args, $IgnoreErrors, $CCAnalyzer, $CXXAnalyzer, $EnvVars);
1072f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1073f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1074f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Setup the environment.
1075f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SetEnv($EnvVars);
1076f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1077f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($Cmd =~ /(.*\/?gcc[^\/]*$)/ or
1078f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Cmd =~ /(.*\/?cc[^\/]*$)/ or
1079f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Cmd =~ /(.*\/?llvm-gcc[^\/]*$)/ or
1080f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Cmd =~ /(.*\/?clang$)/ or
1081f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Cmd =~ /(.*\/?ccc-analyzer[^\/]*$)/) {
1082f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1083f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (!($Cmd =~ /ccc-analyzer/) and !defined $ENV{"CCC_CC"}) {
1084f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $ENV{"CCC_CC"} = $1;
1085f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1086f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1087f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    shift @$Args;
1088f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    unshift @$Args, $CCAnalyzer;
1089f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1090f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  elsif ($Cmd =~ /(.*\/?g\+\+[^\/]*$)/ or
1091f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $Cmd =~ /(.*\/?c\+\+[^\/]*$)/ or
1092f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $Cmd =~ /(.*\/?llvm-g\+\+[^\/]*$)/ or
1093f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $Cmd =~ /(.*\/?clang\+\+$)/ or
1094f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $Cmd =~ /(.*\/?c\+\+-analyzer[^\/]*$)/) {
1095f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (!($Cmd =~ /c\+\+-analyzer/) and !defined $ENV{"CCC_CXX"}) {
1096f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $ENV{"CCC_CXX"} = $1;
1097f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1098f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    shift @$Args;
1099f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    unshift @$Args, $CXXAnalyzer;
1100f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1101f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  elsif ($Cmd eq "make" or $Cmd eq "gmake" or $Cmd eq "mingw32-make") {
1102f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    AddIfNotPresent($Args, "CC=$CCAnalyzer");
1103f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    AddIfNotPresent($Args, "CXX=$CXXAnalyzer");
1104f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($IgnoreErrors) {
1105f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      AddIfNotPresent($Args,"-k");
1106f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      AddIfNotPresent($Args,"-i");
1107f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1108f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1109f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1110f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  return (system(@$Args) >> 8);
1111f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1112f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1113f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
1114f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# DisplayHelp - Utility function to display all help options.
1115f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
1116f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1117f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub DisplayHelp {
1118f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1119f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $ArgClangNotFoundErrMsg = shift;
1120f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprint <<ENDTEXT;
1121f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotUSAGE: $Prog [options] <build command> [build options]
1122f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1123f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotENDTEXT
1124f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1125f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (defined $BuildName) {
1126f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print "ANALYZER BUILD: $BuildName ($BuildDate)\n\n";
1127f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1128f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1129f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprint <<ENDTEXT;
1130f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotOPTIONS:
1131f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1132f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -analyze-headers
1133f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1134f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Also analyze functions in #included files.  By default, such functions
1135f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   are skipped unless they are called by functions within the main source file.
1136f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1137f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --force-analyze-debug-code
1138f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1139f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Tells analyzer to enable assertions in code even if they were disabled
1140f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   during compilation to enable more precise results.
1141f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1142f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -o <output location>
1143f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1144f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Specifies the output directory for analyzer reports. Subdirectories will be
1145f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   created as needed to represent separate "runs" of the analyzer. If this
1146f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   option is not specified, a directory is created in /tmp (TMPDIR on Mac OS X)
1147f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   to store the reports.
1148f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1149f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -h
1150f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --help
1151f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1152f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Display this message.
1153f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1154f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -k
1155f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --keep-going
1156f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1157f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Add a "keep on going" option to the specified build command. This option
1158f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   currently supports make and xcodebuild. This is a convenience option; one
1159f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   can specify this behavior directly using build options.
1160f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1161f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --html-title [title]
1162f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --html-title=[title]
1163f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1164f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Specify the title used on generated HTML pages. If not specified, a default
1165f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   title will be used.
1166f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1167f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --show-description
1168f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1169f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Display the description of defects in the list
1170f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1171f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -plist
1172f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1173f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   By default the output of scan-build is a set of HTML files. This option
1174f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   outputs the results as a set of .plist files.
1175f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1176f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -plist-html
1177f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1178f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   By default the output of scan-build is a set of HTML files. This option
1179f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   outputs the results as a set of HTML and .plist files.
1180f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1181f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --status-bugs
1182f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1183f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   By default, the exit status of scan-build is the same as the executed build
1184f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   command. Specifying this option causes the exit status of scan-build to be 1
1185f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   if it found potential bugs and 0 otherwise.
1186f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1187f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --use-cc [compiler path]
1188f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --use-cc=[compiler path]
1189f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1190f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   scan-build analyzes a project by interposing a "fake compiler", which
1191f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   executes a real compiler for compilation and the static analyzer for analysis.
1192f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Because of the current implementation of interposition, scan-build does not
1193f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   know what compiler your project normally uses.  Instead, it simply overrides
1194f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   the CC environment variable, and guesses your default compiler.
1195f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1196f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   In the future, this interposition mechanism to be improved, but if you need
1197f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   scan-build to use a specific compiler for *compilation* then you can use
1198f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   this option to specify a path to that compiler.
1199f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1200f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   If the given compiler is a cross compiler, you may also need to provide
1201f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   --analyzer-target option to properly analyze the source code because static
1202f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   analyzer runs as if the code is compiled for the host machine by default.
1203f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1204f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --use-c++ [compiler path]
1205f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --use-c++=[compiler path]
1206f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1207f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   This is the same as "--use-cc" but for C++ code.
1208f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1209f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --analyzer-target [target triple name for analysis]
1210f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --analyzer-target=[target triple name for analysis]
1211f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1212f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   This provides target triple information to clang static analyzer.
1213f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   It only changes the target for analysis but doesn't change the target of a
1214f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   real compiler given by --use-cc and --use-c++ options.
1215f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1216f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -v
1217f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1218f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Enable verbose output from scan-build. A second and third '-v' increases
1219f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   verbosity.
1220f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1221f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -V
1222f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --view
1223f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1224f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   View analysis results in a web browser when the build completes.
1225f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1226f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotADVANCED OPTIONS:
1227f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1228f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -no-failure-reports
1229f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1230f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Do not create a 'failures' subdirectory that includes analyzer crash reports
1231f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   and preprocessed source files.
1232f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1233f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -stats
1234f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1235f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Generates visitation statistics for the project being analyzed.
1236f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1237f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -maxloop <loop count>
1238f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1239f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Specifiy the number of times a block can be visited before giving up.
1240f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Default is 4. Increase for more comprehensive coverage at a cost of speed.
1241f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1242f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -internal-stats
1243f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1244f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Generate internal analyzer statistics.
1245f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1246f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --use-analyzer [Xcode|path to clang]
1247f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --use-analyzer=[Xcode|path to clang]
1248f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1249f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   scan-build uses the 'clang' executable relative to itself for static
1250f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   analysis. One can override this behavior with this option by using the
1251f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   'clang' packaged with Xcode (on OS X) or from the PATH.
1252f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1253f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --keep-empty
1254f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1255f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Don't remove the build results directory even if no issues were reported.
1256f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1257f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot --override-compiler
1258f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Always resort to the ccc-analyzer even when better interposition methods
1259f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   are available.
1260f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1261f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -analyzer-config <options>
1262f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1263f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Provide options to pass through to the analyzer's -analyzer-config flag.
1264f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Several options are separated with comma: 'key1=val1,key2=val2'
1265f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1266f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot   Available options:
1267f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot     * stable-report-filename=true or false (default)
1268f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot       Switch the page naming to:
1269f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot       report-<filename>-<function/method name>-<id>.html
1270f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot       instead of report-XXXXXX.html
1271f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1272f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotCONTROLLING CHECKERS:
1273f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1274f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot A default group of checkers are always run unless explicitly disabled.
1275f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Checkers may be enabled/disabled using the following options:
1276f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1277f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -enable-checker [checker name]
1278f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -disable-checker [checker name]
1279f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1280f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotLOADING CHECKERS:
1281f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1282f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot Loading external checkers using the clang plugin interface:
1283f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1284f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot -load-plugin [plugin library]
1285f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotENDTEXT
1286f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1287f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (defined $Clang && -x $Clang) {
1288f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    # Query clang for list of checkers that are enabled.
1289f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1290f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    # create a list to load the plugins via the 'Xclang' command line
1291f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    # argument
1292f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my @PluginLoadCommandline_xclang;
1293f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    foreach my $param ( @{$Options{PluginsToLoad}} ) {
1294f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      push ( @PluginLoadCommandline_xclang, "-Xclang" );
1295f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      push ( @PluginLoadCommandline_xclang, "-load" );
1296f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      push ( @PluginLoadCommandline_xclang, "-Xclang" );
1297f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      push ( @PluginLoadCommandline_xclang, $param );
1298f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1299f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1300f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my %EnabledCheckers;
1301f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    foreach my $lang ("c", "objective-c", "objective-c++", "c++") {
1302f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $ExecLine = join(' ', qq/"$Clang"/, @PluginLoadCommandline_xclang, "--analyze", "-x", $lang, "-", "-###", "2>&1", "|");
1303f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      open(PS, $ExecLine);
1304f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      while (<PS>) {
1305f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        foreach my $val (split /\s+/) {
1306f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          $val =~ s/\"//g;
1307f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          if ($val =~ /-analyzer-checker\=([^\s]+)/) {
1308f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot            $EnabledCheckers{$1} = 1;
1309f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          }
1310f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        }
1311f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1312f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1313f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1314f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    # Query clang for complete list of checkers.
1315f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my @PluginLoadCommandline;
1316f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    foreach my $param ( @{$Options{PluginsToLoad}} ) {
1317f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      push ( @PluginLoadCommandline, "-load" );
1318f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      push ( @PluginLoadCommandline, $param );
1319f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1320f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1321f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $ExecLine = join(' ', qq/"$Clang"/, "-cc1", @PluginLoadCommandline, "-analyzer-checker-help", "2>&1", "|");
1322f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    open(PS, $ExecLine);
1323f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $foundCheckers = 0;
1324f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    while (<PS>) {
1325f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (/CHECKERS:/) {
1326f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $foundCheckers = 1;
1327f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        last;
1328f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1329f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1330f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (!$foundCheckers) {
1331f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print "  *** Could not query Clang for the list of available checkers.";
1332f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1333f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    else {
1334f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print("\nAVAILABLE CHECKERS:\n\n");
1335f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $skip = 0;
1336f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot       while(<PS>) {
1337f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        if (/experimental/) {
1338f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          $skip = 1;
1339f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          next;
1340f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        }
1341f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        if ($skip) {
1342f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          next if (!/^\s\s[^\s]/);
1343f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          $skip = 0;
1344f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        }
1345f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        s/^\s\s//;
1346f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        if (/^([^\s]+)/) {
1347f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          # Is the checker enabled?
1348f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          my $checker = $1;
1349f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          my $enabled = 0;
1350f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          my $aggregate = "";
1351f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          foreach my $domain (split /\./, $checker) {
1352f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot            $aggregate .= $domain;
1353f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot            if ($EnabledCheckers{$aggregate}) {
1354f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot              $enabled =1;
1355f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot              last;
1356f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot            }
1357f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot            # append a dot, if an additional domain is added in the next iteration
1358f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot            $aggregate .= ".";
1359f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          }
1360f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1361f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          if ($enabled) {
1362f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot            print " + ";
1363f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          }
1364f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          else {
1365f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot            print "   ";
1366f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          }
1367f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        }
1368f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        else {
1369f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          print "   ";
1370f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        }
1371f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        print $_;
1372f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1373f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print "\nNOTE: \"+\" indicates that an analysis is enabled by default.\n";
1374f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1375f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    close PS;
1376f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1377f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  else {
1378f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    print "  *** Could not query Clang for the list of available checkers.\n";
1379f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (defined  $ArgClangNotFoundErrMsg) {
1380f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      print "  *** Reason: $ArgClangNotFoundErrMsg\n";
1381f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1382f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1383f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1384f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprint <<ENDTEXT
1385f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1386f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotBUILD OPTIONS
1387f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1388f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot You can specify any build option acceptable to the build command.
1389f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1390f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotEXAMPLE
1391f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1392f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot scan-build -o /tmp/myhtmldir make -j4
1393f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1394f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotThe above example causes analysis reports to be deposited into a subdirectory
1395f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotof "/tmp/myhtmldir" and to run "make" with the "-j4" option. A different
1396f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsubdirectory is created each time scan-build analyzes a project. The analyzer
1397f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotshould support most parallel builds, but not distributed builds.
1398f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1399f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotENDTEXT
1400f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1401f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1402f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
1403f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# HtmlEscape - HTML entity encode characters that are special in HTML
1404f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
1405f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1406f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub HtmlEscape {
1407f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # copy argument to new variable so we don't clobber the original
1408f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $arg = shift || '';
1409f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $tmp = $arg;
1410f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  $tmp =~ s/&/&amp;/g;
1411f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  $tmp =~ s/</&lt;/g;
1412f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  $tmp =~ s/>/&gt;/g;
1413f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  return $tmp;
1414f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1415f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1416f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
1417f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# ShellEscape - backslash escape characters that are special to the shell
1418f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
1419f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1420f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub ShellEscape {
1421f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # copy argument to new variable so we don't clobber the original
1422f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $arg = shift || '';
1423f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($arg =~ /["\s]/) { return "'" . $arg . "'"; }
1424f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  return $arg;
1425f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1426f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1427f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
1428f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# FindClang - searches for 'clang' executable.
1429f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
1430f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1431f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub FindClang {
1432f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if (!defined $Options{AnalyzerDiscoveryMethod}) {
1433f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $Clang = Cwd::realpath("$RealBin/bin/clang") if (-f "$RealBin/bin/clang");
1434f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (!defined $Clang || ! -x $Clang) {
1435f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Clang = Cwd::realpath("$RealBin/clang") if (-f "$RealBin/clang");
1436f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1437f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (!defined $Clang || ! -x $Clang) {
1438f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return "error: Cannot find an executable 'clang' relative to" .
1439f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot             " scan-build. Consider using --use-analyzer to pick a version of" .
1440f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot             " 'clang' to use for static analysis.\n";
1441f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1442f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1443f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  else {
1444f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($Options{AnalyzerDiscoveryMethod} =~ /^[Xx]code$/) {
1445f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $xcrun = `which xcrun`;
1446f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      chomp $xcrun;
1447f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if ($xcrun eq "") {
1448f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        return "Cannot find 'xcrun' to find 'clang' for analysis.\n";
1449f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1450f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Clang = `$xcrun -toolchain XcodeDefault -find clang`;
1451f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      chomp $Clang;
1452f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if ($Clang eq "") {
1453f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        return "No 'clang' executable found by 'xcrun'\n";
1454f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1455f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1456f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    else {
1457f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Clang = $Options{AnalyzerDiscoveryMethod};
1458f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (!defined $Clang or not -x $Clang) {
1459f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        return "Cannot find an executable clang at '$Options{AnalyzerDiscoveryMethod}'\n";
1460f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1461f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1462f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1463f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  return undef;
1464f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1465f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1466f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
1467f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Process command-line arguments.
1468f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot##----------------------------------------------------------------------------##
1469f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1470f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $RequestDisplayHelp = 0;
1471f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $ForceDisplayHelp = 0;
1472f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1473f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotsub ProcessArgs {
1474f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $Args = shift;
1475f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $NumArgs = 0;
1476f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1477f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  while (@$Args) {
1478f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1479f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $NumArgs++;
1480f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1481f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    # Scan for options we recognize.
1482f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1483f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $arg = $Args->[0];
1484f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1485f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-h" or $arg eq "--help") {
1486f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $RequestDisplayHelp = 1;
1487f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1488f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1489f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1490f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1491f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq '-analyze-headers') {
1492f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1493f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{AnalyzeHeaders} = 1;
1494f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1495f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1496f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1497f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-o") {
1498f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1499f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1500f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (!@$Args) {
1501f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        DieDiag("'-o' option requires a target directory name.\n");
1502f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1503f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1504f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      # Construct an absolute path.  Uses the current working directory
1505f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      # as a base if the original path was not absolute.
1506f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $OutDir = shift @$Args;
1507f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      mkpath($OutDir) unless (-e $OutDir);  # abs_path wants existing dir
1508f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{OutputDir} = abs_path($OutDir);
1509f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1510f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1511f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1512f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1513f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg =~ /^--html-title(=(.+))?$/) {
1514f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1515f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1516f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (!defined $2 || $2 eq '') {
1517f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        if (!@$Args) {
1518f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          DieDiag("'--html-title' option requires a string.\n");
1519f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        }
1520f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1521f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $Options{HtmlTitle} = shift @$Args;
1522f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      } else {
1523f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $Options{HtmlTitle} = $2;
1524f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1525f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1526f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1527f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1528f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1529f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-k" or $arg eq "--keep-going") {
1530f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1531f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{IgnoreErrors} = 1;
1532f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1533f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1534f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1535f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg =~ /^--use-cc(=(.+))?$/) {
1536f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1537f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $cc;
1538f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1539f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (!defined $2 || $2 eq "") {
1540f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        if (!@$Args) {
1541f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          DieDiag("'--use-cc' option requires a compiler executable name.\n");
1542f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        }
1543f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $cc = shift @$Args;
1544f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1545f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      else {
1546f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $cc = $2;
1547f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1548f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1549f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{UseCC} = $cc;
1550f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1551f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1552f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1553f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg =~ /^--use-c\+\+(=(.+))?$/) {
1554f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1555f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $cxx;
1556f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1557f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (!defined $2 || $2 eq "") {
1558f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        if (!@$Args) {
1559f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          DieDiag("'--use-c++' option requires a compiler executable name.\n");
1560f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        }
1561f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $cxx = shift @$Args;
1562f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1563f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      else {
1564f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $cxx = $2;
1565f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1566f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1567f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{UseCXX} = $cxx;
1568f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1569f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1570f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1571f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg =~ /^--analyzer-target(=(.+))?$/) {
1572f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @ARGV;
1573f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $AnalyzerTarget;
1574f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1575f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (!defined $2 || $2 eq "") {
1576f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        if (!@ARGV) {
1577f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          DieDiag("'--analyzer-target' option requires a target triple name.\n");
1578f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        }
1579f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $AnalyzerTarget = shift @ARGV;
1580f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1581f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      else {
1582f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        $AnalyzerTarget = $2;
1583f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      }
1584f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1585f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{AnalyzerTarget} = $AnalyzerTarget;
1586f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1587f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1588f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1589f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-v") {
1590f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1591f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{Verbose}++;
1592f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1593f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1594f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1595f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-V" or $arg eq "--view") {
1596f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1597f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{ViewResults} = 1;
1598f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1599f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1600f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1601f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "--status-bugs") {
1602f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1603f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{ExitStatusFoundBugs} = 1;
1604f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1605f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1606f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1607f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "--show-description") {
1608f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1609f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{ShowDescription} = 1;
1610f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1611f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1612f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1613f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-store") {
1614f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1615f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{StoreModel} = shift @$Args;
1616f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1617f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1618f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1619f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-constraints") {
1620f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1621f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{ConstraintsModel} = shift @$Args;
1622f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1623f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1624f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1625f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-internal-stats") {
1626f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1627f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{InternalStats} = 1;
1628f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1629f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1630f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1631f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-plist") {
1632f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1633f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{OutputFormat} = "plist";
1634f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1635f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1636f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1637f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-plist-html") {
1638f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1639f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{OutputFormat} = "plist-html";
1640f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1641f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1642f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1643f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-analyzer-config") {
1644f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1645f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      push @{$Options{ConfigOptions}}, shift @$Args;
1646f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1647f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1648f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1649f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-no-failure-reports") {
1650f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1651f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{ReportFailures} = 0;
1652f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1653f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1654f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1655f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-stats") {
1656f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1657f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{AnalyzerStats} = 1;
1658f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1659f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1660f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1661f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-maxloop") {
1662f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1663f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{MaxLoop} = shift @$Args;
1664f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1665f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1666f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1667f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-enable-checker") {
1668f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1669f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $Checker = shift @$Args;
1670f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      # Store $NumArgs to preserve the order the checkers were enabled.
1671f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{EnableCheckers}{$Checker} = $NumArgs;
1672f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      delete $Options{DisableCheckers}{$Checker};
1673f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1674f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1675f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1676f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-disable-checker") {
1677f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1678f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $Checker = shift @$Args;
1679f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      # Store $NumArgs to preserve the order the checkers were disabled.
1680f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{DisableCheckers}{$Checker} = $NumArgs;
1681f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      delete $Options{EnableCheckers}{$Checker};
1682f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1683f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1684f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1685f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "-load-plugin") {
1686f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1687f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      push @{$Options{PluginsToLoad}}, shift @$Args;
1688f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1689f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1690f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1691f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "--use-analyzer") {
1692f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1693f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{AnalyzerDiscoveryMethod} = shift @$Args;
1694f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1695f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1696f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1697f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg =~ /^--use-analyzer=(.+)$/) {
1698f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1699f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{AnalyzerDiscoveryMethod} = $1;
1700f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1701f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1702f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1703f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "--keep-empty") {
1704f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1705f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{KeepEmpty} = 1;
1706f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1707f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1708f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1709f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "--override-compiler") {
1710f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1711f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{OverrideCompiler} = 1;
1712f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1713f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1714f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1715f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($arg eq "--force-analyze-debug-code") {
1716f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      shift @$Args;
1717f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      $Options{ForceAnalyzeDebugCode} = 1;
1718f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      next;
1719f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1720f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1721f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    DieDiag("unrecognized option '$arg'\n") if ($arg =~ /^-/);
1722f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1723f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $NumArgs--;
1724f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    last;
1725f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1726f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  return $NumArgs;
1727f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1728f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1729f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotif (!@ARGV) {
1730f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  $ForceDisplayHelp = 1
1731f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1732f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1733f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotProcessArgs(\@ARGV);
1734f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# All arguments are now shifted from @ARGV. The rest is a build command, if any.
1735f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1736f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotif (!@ARGV and !$RequestDisplayHelp) {
1737f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ErrorDiag("No build command specified.\n\n");
1738f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  $ForceDisplayHelp = 1;
1739f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1740f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1741f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $ClangNotFoundErrMsg = FindClang();
1742f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1743f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotif ($ForceDisplayHelp || $RequestDisplayHelp) {
1744f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DisplayHelp($ClangNotFoundErrMsg);
1745f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  exit $ForceDisplayHelp;
1746f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1747f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1748f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotDieDiag($ClangNotFoundErrMsg) if (defined $ClangNotFoundErrMsg);
1749f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1750f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot$ClangCXX = $Clang;
1751f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotif ($Clang !~ /\+\+(\.exe)?$/) {
1752f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # If $Clang holds the name of the clang++ executable then we leave
1753f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # $ClangCXX and $Clang equal, otherwise construct the name of the clang++
1754f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # executable from the clang executable name.
1755f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1756f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Determine operating system under which this copy of Perl was built.
1757f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  my $IsWinBuild = ($^O =~/msys|cygwin|MSWin32/);
1758f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if($IsWinBuild) {
1759f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $ClangCXX =~ s/.exe$/++.exe/;
1760f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1761f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  else {
1762f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $ClangCXX =~ s/\-\d+\.\d+$//;
1763f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    $ClangCXX .= "++";
1764f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1765f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1766f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1767f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Make sure to use "" to handle paths with spaces.
1768f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot$ClangVersion = HtmlEscape(`"$Clang" --version`);
1769f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1770f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Determine where results go.
1771f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot$CmdArgs = HtmlEscape(join(' ', map(ShellEscape($_), @ARGV)));
1772f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1773f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Determine the output directory for the HTML reports.
1774f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $BaseDir = $Options{OutputDir};
1775f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot$Options{OutputDir} = GetHTMLRunDir($Options{OutputDir});
1776f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1777f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Determine the location of ccc-analyzer.
1778f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $AbsRealBin = Cwd::realpath($RealBin);
1779f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $Cmd = "$AbsRealBin/../libexec/ccc-analyzer";
1780f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $CmdCXX = "$AbsRealBin/../libexec/c++-analyzer";
1781f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1782f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Portability: use less strict but portable check -e (file exists) instead of
1783f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# non-portable -x (file is executable). On some windows ports -x just checks
1784f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# file extension to determine if a file is executable (see Perl language
1785f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# reference, perlport)
1786f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotif (!defined $Cmd || ! -e $Cmd) {
1787f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  $Cmd = "$AbsRealBin/ccc-analyzer";
1788f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DieDiag("'ccc-analyzer' does not exist at '$Cmd'\n") if(! -e $Cmd);
1789f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1790f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotif (!defined $CmdCXX || ! -e $CmdCXX) {
1791f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  $CmdCXX = "$AbsRealBin/c++-analyzer";
1792f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DieDiag("'c++-analyzer' does not exist at '$CmdCXX'\n") if(! -e $CmdCXX);
1793f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1794f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1795f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotDiag("Using '$Clang' for static analysis\n");
1796f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1797f3014761c955345d6e05491608e73228d014afbandroid-build-team RobotSetHtmlEnv(\@ARGV, $Options{OutputDir});
1798f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1799f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy @AnalysesToRun;
1800f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotforeach (sort { $Options{EnableCheckers}{$a} <=> $Options{EnableCheckers}{$b} } 
1801f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot         keys %{$Options{EnableCheckers}}) { 
1802f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Push checkers in order they were enabled.
1803f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  push @AnalysesToRun, "-analyzer-checker", $_;
1804f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1805f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotforeach (sort { $Options{DisableCheckers}{$a} <=> $Options{DisableCheckers}{$b} } 
1806f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot         keys %{$Options{DisableCheckers}}) { 
1807f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  # Push checkers in order they were disabled.
1808f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  push @AnalysesToRun, "-analyzer-disable-checker", $_;
1809f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1810f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotif ($Options{AnalyzeHeaders}) { push @AnalysesToRun, "-analyzer-opt-analyze-headers"; }
1811f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotif ($Options{AnalyzerStats}) { push @AnalysesToRun, '-analyzer-checker=debug.Stats'; }
1812f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotif ($Options{MaxLoop} > 0) { push @AnalysesToRun, "-analyzer-max-loop $Options{MaxLoop}"; }
1813f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1814f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Delay setting up other environment variables in case we can do true
1815f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# interposition.
1816f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $CCC_ANALYZER_ANALYSIS = join ' ', @AnalysesToRun;
1817f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $CCC_ANALYZER_PLUGINS = join ' ', map { "-load ".$_ } @{$Options{PluginsToLoad}};
1818f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $CCC_ANALYZER_CONFIG = join ' ', map { "-analyzer-config ".$_ } @{$Options{ConfigOptions}};
1819f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy %EnvVars = (
1820f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CC' => $Cmd,
1821f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CXX' => $CmdCXX,
1822f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CLANG' => $Clang,
1823f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CLANG_CXX' => $ClangCXX,
1824f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'VERBOSE' => $Options{Verbose},
1825f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CCC_ANALYZER_ANALYSIS' => $CCC_ANALYZER_ANALYSIS,
1826f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CCC_ANALYZER_PLUGINS' => $CCC_ANALYZER_PLUGINS,
1827f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CCC_ANALYZER_CONFIG' => $CCC_ANALYZER_CONFIG,
1828f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'OUTPUT_DIR' => $Options{OutputDir},
1829f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CCC_CC' => $Options{UseCC},
1830f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CCC_CXX' => $Options{UseCXX},
1831f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CCC_REPORT_FAILURES' => $Options{ReportFailures},
1832f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CCC_ANALYZER_STORE_MODEL' => $Options{StoreModel},
1833f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CCC_ANALYZER_CONSTRAINTS_MODEL' => $Options{ConstraintsModel},
1834f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CCC_ANALYZER_INTERNAL_STATS' => $Options{InternalStats},
1835f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CCC_ANALYZER_OUTPUT_FORMAT' => $Options{OutputFormat},
1836f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CLANG_ANALYZER_TARGET' => $Options{AnalyzerTarget},
1837f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  'CCC_ANALYZER_FORCE_ANALYZE_DEBUG_CODE' => $Options{ForceAnalyzeDebugCode}
1838f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot);
1839f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1840f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot# Run the build.
1841f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotmy $ExitStatus = RunBuildCommand(\@ARGV, $Options{IgnoreErrors}, $Cmd, $CmdCXX,
1842f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                \%EnvVars);
1843f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1844f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotif (defined $Options{OutputFormat}) {
1845f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($Options{OutputFormat} =~ /plist/) {
1846f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Diag "Analysis run complete.\n";
1847f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Diag "Analysis results (plist files) deposited in '$Options{OutputDir}'\n";
1848f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1849f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  if ($Options{OutputFormat} =~ /html/) {
1850f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    # Postprocess the HTML directory.
1851f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    my $NumBugs = Postprocess($Options{OutputDir}, $BaseDir,
1852f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                              $Options{AnalyzerStats}, $Options{KeepEmpty});
1853f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1854f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($Options{ViewResults} and -r "$Options{OutputDir}/index.html") {
1855f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Diag "Analysis run complete.\n";
1856f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Diag "Viewing analysis results in '$Options{OutputDir}' using scan-view.\n";
1857f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      my $ScanView = Cwd::realpath("$RealBin/scan-view");
1858f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (! -x $ScanView) { $ScanView = "scan-view"; }
1859f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (! -x $ScanView) { $ScanView = Cwd::realpath("$RealBin/../../scan-view/bin/scan-view"); }
1860f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      exec $ScanView, "$Options{OutputDir}";
1861f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1862f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1863f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if ($Options{ExitStatusFoundBugs}) {
1864f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      exit 1 if ($NumBugs > 0);
1865f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      exit 0;
1866f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
1867f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
1868f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
1869f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1870f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotexit $ExitStatus;
1871