Static Analyzer: When generating plists for errors reports, generate one plist file per translation unit that contains all of the diagnostics.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62647 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/ccc-analyzer b/utils/ccc-analyzer
index 71f840a..68df56a 100755
--- a/utils/ccc-analyzer
+++ b/utils/ccc-analyzer
@@ -17,10 +17,20 @@
 use Cwd qw/ getcwd abs_path /;
 use File::Temp qw/ tempfile /;
 use File::Path qw / mkpath /;
+use File::Basename;
 
 my $CC = $ENV{'CCC_CC'};
 if (!defined $CC) { $CC = "gcc"; }
- 
+my $CleanupFile;
+my $ResultFile;
+
+# Remove any stale files at exit.
+END { 
+  if (defined $CleanupFile && -z $CleanupFile) {
+    `rm -f $CleanupFile`;
+  }
+}
+
 ##----------------------------------------------------------------------------##
 #  Process Clang Crashes.
 ##----------------------------------------------------------------------------##
@@ -114,9 +124,15 @@
     print STDERR "#SHELL (cd '$dir' && @PrintArgs)\n";
   }
   
-  if ($RunAnalyzer and defined($HtmlDir)) {
-    push @CmdArgs,'-o';
-    push @CmdArgs,$HtmlDir;
+  if ($RunAnalyzer) {
+    if (defined $ResultFile) {
+      push @CmdArgs,'-o';
+      push @CmdArgs, $ResultFile;
+    }
+    elsif (defined $HtmlDir) {
+      push @CmdArgs,'-o';
+      push @CmdArgs, $HtmlDir;
+    }
   }
   
   if (defined $ENV{'CCC_UBI'}) {   
@@ -430,6 +446,14 @@
     
     if (defined $OutputFormat) {
       push @AnalyzeArgs, "-analyzer-output-" . $OutputFormat;
+      if ($OutputFormat eq "plist") {
+        # Change "Output" to be a file.
+        my ($h, $f) = tempfile("report-XXXXXX", SUFFIX => ".plist",
+                               DIR => $HtmlDir);
+        $ResultFile = $f;
+        $CleanupFile = $f;
+      }
+      
     }
 
     push @AnalyzeArgs,@CompileOpts;