summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevin Coughlin <dcoughlin@apple.com>2019-03-16 01:01:29 +0000
committerDevin Coughlin <dcoughlin@apple.com>2019-03-16 01:01:29 +0000
commita8c64ce548393310c065c7dfe08fb676e3f25370 (patch)
tree9eaa41975633d359f561fe45537d7549887250d6
parente479127491a4e1edc02cf46768a47e9921a73e51 (diff)
[analyzer] Teach scan-build to find clang when installed in /usr/local/bin/
Change scan-build to support the scenario where scan-build is installed in $TOOLCHAIN/usr/local/bin/ but clang itself is installed in $TOOLCHAIN/usr/bin/. This is restricted to when 'xcrun' is present; that is, on the Mac. rdar://problem/48914634 Differential Revision: https://reviews.llvm.org/D59406 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356308 91177308-0d34-0410-b5e6-96231b3b80d8
-rwxr-xr-xtools/scan-build/bin/scan-build23
1 files changed, 21 insertions, 2 deletions
diff --git a/tools/scan-build/bin/scan-build b/tools/scan-build/bin/scan-build
index ed68b3b5a4..903e19a290 100755
--- a/tools/scan-build/bin/scan-build
+++ b/tools/scan-build/bin/scan-build
@@ -1460,6 +1460,16 @@ sub ShellEscape {
}
##----------------------------------------------------------------------------##
+# 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 @@ sub FindClang {
$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 @@ sub FindClang {
}
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";
}