[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

llvm-svn: 356308
This commit is contained in:
Devin Coughlin 2019-03-16 01:01:29 +00:00
parent 49e978f780
commit a61641ef40
1 changed files with 21 additions and 2 deletions

View File

@ -1459,6 +1459,16 @@ sub ShellEscape {
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 @@ 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";
}