Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/swift-5.1-branch' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-ci committed Mar 16, 2019
2 parents 188f114 + ba2109e commit 3b69e77
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tools/scan-build/bin/scan-build
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,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.
##----------------------------------------------------------------------------##
Expand All @@ -1469,6 +1479,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" .
Expand All @@ -1478,8 +1498,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";
}
Expand Down

0 comments on commit 3b69e77

Please sign in to comment.