]> granicus.if.org Git - clang/commitdiff
Output better paths to display in bug reports and compute a common
authorTed Kremenek <kremenek@apple.com>
Fri, 2 May 2008 22:04:53 +0000 (22:04 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 2 May 2008 22:04:53 +0000 (22:04 +0000)
prefix for all files.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50592 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/HTMLDiagnostics.cpp
utils/scan-build

index cb333b978c159d47a26deee85ac3d2cca1b063b8..22e253848208ab4222b80d85cad2ac8ab506c9ea 100644 (file)
@@ -160,16 +160,17 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) {
   // Get the full directory name of the analyzed file.
 
   const FileEntry* Entry = SMgr.getFileEntryForID(FileID);
-  std::string DirName(Entry->getDir()->getName());
   
   // This is a cludge; basically we want to append either the full
   // working directory if we have no directory information.  This is
   // a work in progress.
 
-  if (DirName == ".")
-    DirName = llvm::sys::Path::GetCurrentDirectory().toString();
-  else if (llvm::sys::Path(Entry->getName()).isAbsolute())
-    DirName = "";
+  std::string DirName = "";
+  
+  if (!llvm::sys::Path(Entry->getName()).isAbsolute()) {
+    llvm::sys::Path P = llvm::sys::Path::GetCurrentDirectory();
+    DirName = P.toString() + "/";
+  }
     
   // Add the name of the file as an <h1> tag.  
   
index 0024c8ec366bc53ddfeefe56ed0a8544a08db011..e35bc2f4a0f6be4c32f5db0f8386f5d2352875f9 100755 (executable)
@@ -17,6 +17,7 @@ use warnings;
 use File::Temp qw/ :mktemp /;
 use FindBin qw($RealBin);
 use Digest::MD5;
+use File::Basename;
 
 my $Verbose = 0;       # Verbose output from this script.
 my $Prog = "scan-build";
@@ -139,6 +140,58 @@ sub ComputeDigest {
   return $Result;
 }
 
+##----------------------------------------------------------------------------##
+#  UpdatePrefix - Compute the common prefix of files.
+##----------------------------------------------------------------------------##
+
+my $Prefix;
+
+sub UpdatePrefix {
+  
+  my $x = shift;
+  my $y = basename($x);
+  $x =~ s/\Q$y\E$//;
+  
+  # Ignore /usr, /Library, /System, /Developer
+
+  return if ( $x =~ /^\/usr/ or $x =~ /^\/Library/
+              or $x =~ /^\/System/ or $x =~ /^\/Developer/);
+
+  
+  if (!defined $Prefix) {
+    $Prefix = $x;
+    return;
+  }
+  
+  chop $Prefix while (!($x =~ /^$Prefix/));
+}
+
+sub GetPrefix {
+  return $Prefix;
+}
+
+##----------------------------------------------------------------------------##
+#  UpdateInFilePath - Update the path in the report file.
+##----------------------------------------------------------------------------##
+
+sub UpdateInFilePath {
+  my $fname = shift;
+  my $regex = shift;
+  my $newtext = shift;
+  
+  open (RIN, $fname) or die "cannot open $fname";
+  open (ROUT, ">$fname.tmp") or die "cannot open $fname.tmp";
+  
+  while (<RIN>) {
+    s/$regex/$newtext/;
+    print ROUT $_;
+  }
+  
+  close (ROUT);
+  close (RIN);
+  `mv $fname.tmp $fname`;
+}
+
 ##----------------------------------------------------------------------------##
 # ScanFile - Scan a report file for various identifying attributes.
 ##----------------------------------------------------------------------------##
@@ -185,6 +238,7 @@ sub ScanFile {
     }
     elsif (/<!-- BUGFILE (.*) -->$/) {
       $BugFile = $1;
+      UpdatePrefix($BugFile);
     }
     elsif (/<!-- BUGPATHLENGTH (.*) -->$/) {
       $BugPathLength = $1;
@@ -351,6 +405,16 @@ print OUT <<ENDTEXT;
 </tr>
 ENDTEXT
 
+  my $prefix = GetPrefix();
+  my $regex;
+  my $InFileRegex;
+  my $InFilePrefix = "File:</td><td>";
+  
+  if (defined($prefix)) { 
+    $regex = qr/^\Q$prefix\E/is;    
+    $InFileRegex = qr/\Q$InFilePrefix$prefix\E/is;
+  }    
+
   for my $row ( sort { $a->[1] cmp $b->[1] } @Index ) {
     
     my $x = lc($row->[1]);
@@ -364,7 +428,20 @@ ENDTEXT
     print OUT lc($row->[1]);
     print OUT "</td>\n";
     
-    for my $j ( 2 .. $#{$row} ) {
+    # Update the file prefix.
+    
+    my $fname = $row->[2];
+    if (defined($regex)) {      
+      $fname =~ s/$regex//;
+      UpdateInFilePath("$Dir/$ReportFile", $InFileRegex, $InFilePrefix)
+    }
+    
+    print "Prefix is '$prefix'\n";
+    print OUT "<td>$fname</td>\n";
+
+    # Print the rest of the columns.
+    
+    for my $j ( 3 .. $#{$row} ) {
       print OUT "<td>$row->[$j]</td>\n"
     }