Hi all,

attached patch makes scan-build work with Strawberry Perl, ActiveState Perl, cygwin perl and msys perl.
Please review.

--
Anton

Index: tools/scan-build/scan-build
===================================================================
--- tools/scan-build/scan-build	(revision 185134)
+++ tools/scan-build/scan-build	(working copy)
@@ -23,6 +23,15 @@
 use Cwd qw/ getcwd abs_path /;
 use Sys::Hostname;
 
+# portability: convert POSIX cygwin path to MS-DOS style path
+sub portablepath {
+  my $PortablePath = shift @_;
+  $PortablePath =~ s/^\/cygdrive\/(\w)/$1:/o if ($^O =~ /cygwin/);
+  return $PortablePath;
+}
+
+$RealBin = portablepath(Cwd::realpath($RealBin));
+
 my $Verbose = 0;       # Verbose output from this script.
 my $Prog = "scan-build";
 my $BuildName;
@@ -32,9 +41,12 @@
 my $UseColor = (defined $TERM and $TERM =~ 'xterm-.*color' and -t STDOUT
                 and defined $ENV{'SCAN_BUILD_COLOR'});
 
-my $UserName = HtmlEscape(getpwuid($<) || 'unknown');
+# portability: getpwuid is not implemented for Win32 (see Perl language reference, perlport)
+my $UserName = ($^O =~/MSWin32/) ? HtmlEscape(getlogin || 'unknown')
+                                 : HtmlEscape(getpwuid($<) || 'unknown');
 my $HostName = HtmlEscape(hostname() || 'unknown');
-my $CurrentDir = HtmlEscape(getcwd());
+my $CurrentDir = HtmlEscape(portablepath(getcwd()));
+
 my $CurrentDirSuffix = basename($CurrentDir);
 
 my @PluginsToLoad;
@@ -369,7 +381,7 @@
       $BugType = $1;
     }
     elsif (/<!-- BUGFILE (.*) -->$/) {
-      $BugFile = abs_path($1);
+      $BugFile = portablepath(abs_path($1));
       UpdatePrefix($BugFile);
     }
     elsif (/<!-- BUGPATHLENGTH (.*) -->$/) {
@@ -410,7 +422,7 @@
 
   my $Dir = shift;
 
-  my $JS = Cwd::realpath("$RealBin/sorttable.js");
+  my $JS = portablepath(Cwd::realpath("$RealBin/sorttable.js"));
   
   DieDiag("Cannot find 'sorttable.js'.\n")
     if (! -r $JS);  
@@ -420,7 +432,7 @@
   DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n")
     if (! -r "$Dir/sorttable.js");
     
-  my $CSS = Cwd::realpath("$RealBin/scanview.css");
+  my $CSS = portablepath(Cwd::realpath("$RealBin/scanview.css"));
   
   DieDiag("Cannot find 'scanview.css'.\n")
     if (! -r $CSS);
@@ -1365,7 +1377,7 @@
     
     # Construct an absolute path.  Uses the current working directory
     # as a base if the original path was not absolute.
-    $HtmlDir = abs_path(shift @ARGV);
+    $HtmlDir = portablepath(abs_path(shift @ARGV));
     
     next;
   }
@@ -1538,9 +1550,9 @@
 
 # Find 'clang'
 if (!defined $AnalyzerDiscoveryMethod) {
-  $Clang = Cwd::realpath("$RealBin/bin/clang");
+  $Clang = portablepath(Cwd::realpath("$RealBin/bin/clang"));
   if (!defined $Clang || ! -x $Clang) {
-    $Clang = Cwd::realpath("$RealBin/clang");
+    $Clang = portablepath(Cwd::realpath("$RealBin/clang"));
   }
   if (!defined $Clang || ! -x $Clang) {
     if (!$RequestDisplayHelp && !$ForceDisplayHelp) {
@@ -1563,7 +1575,7 @@
     }
   }
   else {
-    $Clang = Cwd::realpath($AnalyzerDiscoveryMethod);
+    $Clang = portablepath(Cwd::realpath($AnalyzerDiscoveryMethod));
 	if (!defined $Clang or not -x $Clang) {
    	  DieDiag("Cannot find an executable clang at '$AnalyzerDiscoveryMethod'\n");
 	}
@@ -1599,17 +1611,20 @@
 $HtmlDir = GetHTMLRunDir($HtmlDir);
 
 # Determine the location of ccc-analyzer.
-my $AbsRealBin = Cwd::realpath($RealBin);
+my $AbsRealBin = portablepath(Cwd::realpath($RealBin));
 my $Cmd = "$AbsRealBin/libexec/ccc-analyzer";
 my $CmdCXX = "$AbsRealBin/libexec/c++-analyzer";
 
-if (!defined $Cmd || ! -x $Cmd) {
+# portability: use less strict but portable check -e (file exists) instead of 
+# non-portable -x (file is executable). On some windows ports -x just checks
+# file extension to determine if a file is executable (see Perl language reference, perlport)
+if (!defined $Cmd || ! -e $Cmd) {
   $Cmd = "$AbsRealBin/ccc-analyzer";
-  DieDiag("Executable 'ccc-analyzer' does not exist at '$Cmd'\n") if(! -x $Cmd);
+  DieDiag("'ccc-analyzer' does not exist at '$Cmd'\n") if(! -e $Cmd);
 }
-if (!defined $CmdCXX || ! -x $CmdCXX) {
+if (!defined $CmdCXX || ! -e $CmdCXX) {
   $CmdCXX = "$AbsRealBin/c++-analyzer";
-  DieDiag("Executable 'c++-analyzer' does not exist at '$CmdCXX'\n") if(! -x $CmdCXX);
+  DieDiag("'c++-analyzer' does not exist at '$CmdCXX'\n") if(! -e $CmdCXX);
 }
 
 Diag("Using '$Clang' for static analysis\n");
@@ -1663,7 +1678,7 @@
     if ($ViewResults and -r "$HtmlDir/index.html") {
       Diag "Analysis run complete.\n";
       Diag "Viewing analysis results in '$HtmlDir' using scan-view.\n";
-      my $ScanView = Cwd::realpath("$RealBin/scan-view");
+      my $ScanView = portablepath(Cwd::realpath("$RealBin/scan-view"));
       if (! -x $ScanView) { $ScanView = "scan-view"; }
       exec $ScanView, "$HtmlDir";
     }
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to