Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 3b69e77

Browse files
committed
Merge remote-tracking branch 'origin/swift-5.1-branch' into stable
2 parents 188f114 + ba2109e commit 3b69e77

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

tools/scan-build/bin/scan-build

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,16 @@ sub ShellEscape {
14601460
return $arg;
14611461
}
14621462

1463+
##----------------------------------------------------------------------------##
1464+
# FindXcrun - searches for the 'xcrun' executable. Returns "" if not found.
1465+
##----------------------------------------------------------------------------##
1466+
1467+
sub FindXcrun {
1468+
my $xcrun = `which xcrun`;
1469+
chomp $xcrun;
1470+
return $xcrun;
1471+
}
1472+
14631473
##----------------------------------------------------------------------------##
14641474
# FindClang - searches for 'clang' executable.
14651475
##----------------------------------------------------------------------------##
@@ -1469,6 +1479,16 @@ sub FindClang {
14691479
$Clang = Cwd::realpath("$RealBin/bin/clang") if (-f "$RealBin/bin/clang");
14701480
if (!defined $Clang || ! -x $Clang) {
14711481
$Clang = Cwd::realpath("$RealBin/clang") if (-f "$RealBin/clang");
1482+
if (!defined $Clang || ! -x $Clang) {
1483+
# When an Xcode toolchain is present, look for a clang in the sibling bin
1484+
# of the parent of the bin directory. So if scan-build is at
1485+
# $TOOLCHAIN/usr/local/bin/scan-build look for clang at
1486+
# $TOOLCHAIN/usr/bin/clang.
1487+
my $has_xcode_toolchain = FindXcrun() ne "";
1488+
if ($has_xcode_toolchain && -f "$RealBin/../../bin/clang") {
1489+
$Clang = Cwd::realpath("$RealBin/../../bin/clang");
1490+
}
1491+
}
14721492
}
14731493
if (!defined $Clang || ! -x $Clang) {
14741494
return "error: Cannot find an executable 'clang' relative to" .
@@ -1478,8 +1498,7 @@ sub FindClang {
14781498
}
14791499
else {
14801500
if ($Options{AnalyzerDiscoveryMethod} =~ /^[Xx]code$/) {
1481-
my $xcrun = `which xcrun`;
1482-
chomp $xcrun;
1501+
my $xcrun = FindXcrun();
14831502
if ($xcrun eq "") {
14841503
return "Cannot find 'xcrun' to find 'clang' for analysis.\n";
14851504
}

0 commit comments

Comments
 (0)