r247828 - [analyzer] Improved behavior if Clang was not found, part II

Anton Yartsev via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 16 11:12:15 PDT 2015


Author: ayartsev
Date: Wed Sep 16 13:12:15 2015
New Revision: 247828

URL: http://llvm.org/viewvc/llvm-project?rev=247828&view=rev
Log:
[analyzer] Improved behavior if Clang was not found, part II

- scan-build help: display 'Could not query Clang for the list of available checkers.' + the reason why it happened so if clang was not found.
- display requested/forced help in case of --use-analyzer=Xcode.

Modified:
    cfe/trunk/tools/scan-build/scan-build

Modified: cfe/trunk/tools/scan-build/scan-build
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build/scan-build?rev=247828&r1=247827&r2=247828&view=diff
==============================================================================
--- cfe/trunk/tools/scan-build/scan-build (original)
+++ cfe/trunk/tools/scan-build/scan-build Wed Sep 16 13:12:15 2015
@@ -1100,6 +1100,7 @@ sub RunBuildCommand {
 
 sub DisplayHelp {
 
+  my $ArgClangNotFoundErrMsg = shift;
 print <<ENDTEXT;
 USAGE: $Prog [options] <build command> [build options]
 
@@ -1348,6 +1349,12 @@ ENDTEXT
     }
     close PS;
   }
+  else {
+    print "  *** Could not query Clang for the list of available checkers.\n";
+    if (defined  $ArgClangNotFoundErrMsg) {
+      print "  *** Reason: $ArgClangNotFoundErrMsg\n";
+    }
+  }
 
 print <<ENDTEXT
 
@@ -1393,6 +1400,45 @@ sub ShellEscape {
 }
 
 ##----------------------------------------------------------------------------##
+# FindClang - searches for 'clang' executable.
+##----------------------------------------------------------------------------##
+
+sub FindClang {
+  if (!defined $Options{AnalyzerDiscoveryMethod}) {
+    $Clang = Cwd::realpath("$RealBin/bin/clang") if (-f "$RealBin/bin/clang");
+    if (!defined $Clang || ! -x $Clang) {
+      $Clang = Cwd::realpath("$RealBin/clang") if (-f "$RealBin/clang");
+    }
+    if (!defined $Clang || ! -x $Clang) {
+      return "error: Cannot find an executable 'clang' relative to" .
+             " scan-build. Consider using --use-analyzer to pick a version of" .
+             " 'clang' to use for static analysis.\n";
+    }
+  }
+  else {
+    if ($Options{AnalyzerDiscoveryMethod} =~ /^[Xx]code$/) {
+      my $xcrun = `which xcrun`;
+      chomp $xcrun;
+      if ($xcrun eq "") {
+        return "Cannot find 'xcrun' to find 'clang' for analysis.\n";
+      }
+      $Clang = `$xcrun -toolchain XcodeDefault -find clang`;
+      chomp $Clang;
+      if ($Clang eq "") {
+        return "No 'clang' executable found by 'xcrun'\n";
+      }
+    }
+    else {
+      $Clang = $Options{AnalyzerDiscoveryMethod};
+      if (!defined $Clang or not -x $Clang) {
+        return "Cannot find an executable clang at '$Options{AnalyzerDiscoveryMethod}'\n";
+      }
+    }
+  }
+  return undef;
+}
+
+##----------------------------------------------------------------------------##
 # Process command-line arguments.
 ##----------------------------------------------------------------------------##
 
@@ -1642,45 +1688,15 @@ if (!@ARGV and !$RequestDisplayHelp) {
   $ForceDisplayHelp = 1;
 }
 
-# Find 'clang'
-if (!defined $Options{AnalyzerDiscoveryMethod}) {
-  $Clang = Cwd::realpath("$RealBin/bin/clang") if (-f "$RealBin/bin/clang");
-  if (!defined $Clang || ! -x $Clang) {
-    $Clang = Cwd::realpath("$RealBin/clang") if (-f "$RealBin/clang");
-  }
-  if (!defined $Clang || ! -x $Clang) {
-    if (!$RequestDisplayHelp && !$ForceDisplayHelp) {
-      DieDiag("error: Cannot find an executable 'clang' relative to scan-build." .
-                 "  Consider using --use-analyzer to pick a version of 'clang' to use for static analysis.\n");
-    }
-  }
-}
-else {
-  if ($Options{AnalyzerDiscoveryMethod} =~ /^[Xx]code$/) {
-    my $xcrun = `which xcrun`;
-    chomp $xcrun;
-    if ($xcrun eq "") {
-        DieDiag("Cannot find 'xcrun' to find 'clang' for analysis.\n");
-    }
-    $Clang = `$xcrun -toolchain XcodeDefault -find clang`;
-    chomp $Clang;
-    if ($Clang eq "") {
-      DieDiag("No 'clang' executable found by 'xcrun'\n");
-    }
-  }
-  else {
-    $Clang = $Options{AnalyzerDiscoveryMethod};
-    if (!defined $Clang or not -x $Clang) {
-      DieDiag("Cannot find an executable clang at '$Options{AnalyzerDiscoveryMethod}'\n");
-    }
-  }
-}
+my $ClangNotFoundErrMsg = FindClang();
 
 if ($ForceDisplayHelp || $RequestDisplayHelp) {
-  DisplayHelp();
+  DisplayHelp($ClangNotFoundErrMsg);
   exit $ForceDisplayHelp;
 }
 
+DieDiag($ClangNotFoundErrMsg) if (defined $ClangNotFoundErrMsg);
+
 $ClangCXX = $Clang;
 if ($Clang !~ /\+\+(\.exe)?$/) {
   # If $Clang holds the name of the clang++ executable then we leave




More information about the cfe-commits mailing list