[PATCH] D59406: [analyzer] Teach scan-build to find /usr/bin/clang when installed in /usr/local/bin/

Devin Coughlin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 15 17:54:12 PDT 2019


dcoughlin updated this revision to Diff 190931.
dcoughlin edited the summary of this revision.
dcoughlin added a comment.
Herald added a subscriber: jdoerfert.

Update to restrict the new behavior to when Xcode is present.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59406/new/

https://reviews.llvm.org/D59406

Files:
  tools/scan-build/bin/scan-build


Index: tools/scan-build/bin/scan-build
===================================================================
--- tools/scan-build/bin/scan-build
+++ tools/scan-build/bin/scan-build
@@ -1459,6 +1459,16 @@
   return $arg;
 }
 
+##----------------------------------------------------------------------------##
+# FindXcrun - searches for the 'xcrun' executable. Returns "" if not found.
+##----------------------------------------------------------------------------##
+
+sub FindXcrun {
+  my $xcrun = `which xcrun`;
+  chomp $xcrun;
+  return $xcrun;
+}
+
 ##----------------------------------------------------------------------------##
 # FindClang - searches for 'clang' executable.
 ##----------------------------------------------------------------------------##
@@ -1468,6 +1478,16 @@
     $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) {
+        # When an Xcode toolchain is present, look for a clang in the sibling bin
+        # of the parent of the bin directory. So if scan-build is at
+        # $TOOLCHAIN/usr/local/bin/scan-build look for clang at
+        # $TOOLCHAIN/usr/bin/clang.
+        my $has_xcode_toolchain = FindXcrun() ne "";
+        if ($has_xcode_toolchain && -f "$RealBin/../../bin/clang") {
+          $Clang = Cwd::realpath("$RealBin/../../bin/clang");
+        }
+      }
     }
     if (!defined $Clang || ! -x $Clang) {
       return "error: Cannot find an executable 'clang' relative to" .
@@ -1477,8 +1497,7 @@
   }
   else {
     if ($Options{AnalyzerDiscoveryMethod} =~ /^[Xx]code$/) {
-      my $xcrun = `which xcrun`;
-      chomp $xcrun;
+      my $xcrun = FindXcrun();
       if ($xcrun eq "") {
         return "Cannot find 'xcrun' to find 'clang' for analysis.\n";
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59406.190931.patch
Type: text/x-patch
Size: 1906 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190316/1767591d/attachment.bin>


More information about the cfe-commits mailing list