summaryrefslogtreecommitdiffstats
path: root/clang/tools/scan-build
diff options
context:
space:
mode:
authorAnton Yartsev <anton.yartsev@gmail.com>2015-09-16 18:12:15 +0000
committerAnton Yartsev <anton.yartsev@gmail.com>2015-09-16 18:12:15 +0000
commitc647a6df7274476171490f4d2bccdf5c889a1c85 (patch)
tree0c3860e7f41485cb903783c520abad8d48d58071 /clang/tools/scan-build
parent5e61cfdb9e229c019118667d0c8f9a3d1f536356 (diff)
downloadbcm5719-llvm-c647a6df7274476171490f4d2bccdf5c889a1c85.tar.gz
bcm5719-llvm-c647a6df7274476171490f4d2bccdf5c889a1c85.zip
[analyzer] Improved behavior if Clang was not found, part II
- scan-build help: display 'Could not query Clang for the list of available checkers.' + the reason why it happened so if clang was not found. - display requested/forced help in case of --use-analyzer=Xcode. llvm-svn: 247828
Diffstat (limited to 'clang/tools/scan-build')
-rwxr-xr-xclang/tools/scan-build/scan-build84
1 files changed, 50 insertions, 34 deletions
diff --git a/clang/tools/scan-build/scan-build b/clang/tools/scan-build/scan-build
index 0e7dcc1f830..4b34256e180 100755
--- a/clang/tools/scan-build/scan-build
+++ b/clang/tools/scan-build/scan-build
@@ -1100,6 +1100,7 @@ sub RunBuildCommand {
sub DisplayHelp {
+ my $ArgClangNotFoundErrMsg = shift;
print <<ENDTEXT;
USAGE: $Prog [options] <build command> [build options]
@@ -1348,6 +1349,12 @@ ENDTEXT
}
close PS;
}
+ else {
+ print " *** Could not query Clang for the list of available checkers.\n";
+ if (defined $ArgClangNotFoundErrMsg) {
+ print " *** Reason: $ArgClangNotFoundErrMsg\n";
+ }
+ }
print <<ENDTEXT
@@ -1393,6 +1400,45 @@ sub ShellEscape {
}
##----------------------------------------------------------------------------##
+# FindClang - searches for 'clang' executable.
+##----------------------------------------------------------------------------##
+
+sub FindClang {
+ if (!defined $Options{AnalyzerDiscoveryMethod}) {
+ $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) {
+ return "error: Cannot find an executable 'clang' relative to" .
+ " scan-build. Consider using --use-analyzer to pick a version of" .
+ " 'clang' to use for static analysis.\n";
+ }
+ }
+ else {
+ if ($Options{AnalyzerDiscoveryMethod} =~ /^[Xx]code$/) {
+ my $xcrun = `which xcrun`;
+ chomp $xcrun;
+ if ($xcrun eq "") {
+ return "Cannot find 'xcrun' to find 'clang' for analysis.\n";
+ }
+ $Clang = `$xcrun -toolchain XcodeDefault -find clang`;
+ chomp $Clang;
+ if ($Clang eq "") {
+ return "No 'clang' executable found by 'xcrun'\n";
+ }
+ }
+ else {
+ $Clang = $Options{AnalyzerDiscoveryMethod};
+ if (!defined $Clang or not -x $Clang) {
+ return "Cannot find an executable clang at '$Options{AnalyzerDiscoveryMethod}'\n";
+ }
+ }
+ }
+ return undef;
+}
+
+##----------------------------------------------------------------------------##
# Process command-line arguments.
##----------------------------------------------------------------------------##
@@ -1642,45 +1688,15 @@ if (!@ARGV and !$RequestDisplayHelp) {
$ForceDisplayHelp = 1;
}
-# Find 'clang'
-if (!defined $Options{AnalyzerDiscoveryMethod}) {
- $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) {
- if (!$RequestDisplayHelp && !$ForceDisplayHelp) {
- DieDiag("error: Cannot find an executable 'clang' relative to scan-build." .
- " Consider using --use-analyzer to pick a version of 'clang' to use for static analysis.\n");
- }
- }
-}
-else {
- if ($Options{AnalyzerDiscoveryMethod} =~ /^[Xx]code$/) {
- my $xcrun = `which xcrun`;
- chomp $xcrun;
- if ($xcrun eq "") {
- DieDiag("Cannot find 'xcrun' to find 'clang' for analysis.\n");
- }
- $Clang = `$xcrun -toolchain XcodeDefault -find clang`;
- chomp $Clang;
- if ($Clang eq "") {
- DieDiag("No 'clang' executable found by 'xcrun'\n");
- }
- }
- else {
- $Clang = $Options{AnalyzerDiscoveryMethod};
- if (!defined $Clang or not -x $Clang) {
- DieDiag("Cannot find an executable clang at '$Options{AnalyzerDiscoveryMethod}'\n");
- }
- }
-}
+my $ClangNotFoundErrMsg = FindClang();
if ($ForceDisplayHelp || $RequestDisplayHelp) {
- DisplayHelp();
+ DisplayHelp($ClangNotFoundErrMsg);
exit $ForceDisplayHelp;
}
+DieDiag($ClangNotFoundErrMsg) if (defined $ClangNotFoundErrMsg);
+
$ClangCXX = $Clang;
if ($Clang !~ /\+\+(\.exe)?$/) {
# If $Clang holds the name of the clang++ executable then we leave
OpenPOWER on IntegriCloud