summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-11-17 16:36:04 (GMT)
committerBrad King <brad.king@kitware.com>2016-11-18 14:43:22 (GMT)
commit80ebc55a7ce934ee357c30713bcb96b209e97963 (patch)
treed57f5b3f499669d4d0290a09e7f4a535e7933a9c
parentce1abfa4149ae0b3920626bef2dd15e8ee8b1940 (diff)
downloadCMake-80ebc55a7ce934ee357c30713bcb96b209e97963.zip
CMake-80ebc55a7ce934ee357c30713bcb96b209e97963.tar.gz
CMake-80ebc55a7ce934ee357c30713bcb96b209e97963.tar.bz2
cmake: Report if the <LANG>_CLANG_TIDY tool exits with non-zero
When using `<LANG>_CLANG_TIDY` our internal launcher for the tool must capture its return code and stderr and report them on failure. Otherwise incorrect command lines silently fail. Closes: #16435
-rw-r--r--Help/release/dev/capture-clang-tidy-errors.rst6
-rw-r--r--Source/cmcmd.cxx13
-rw-r--r--Tests/RunCMake/ClangTidy/C-bad-Build-result.txt1
-rw-r--r--Tests/RunCMake/ClangTidy/C-bad-Build-stdout.txt2
-rw-r--r--Tests/RunCMake/ClangTidy/C-bad.cmake3
-rw-r--r--Tests/RunCMake/ClangTidy/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/pseudo_tidy.c6
7 files changed, 29 insertions, 3 deletions
diff --git a/Help/release/dev/capture-clang-tidy-errors.rst b/Help/release/dev/capture-clang-tidy-errors.rst
new file mode 100644
index 0000000..14c32e6
--- /dev/null
+++ b/Help/release/dev/capture-clang-tidy-errors.rst
@@ -0,0 +1,6 @@
+capture-clang-tidy-errors
+-------------------------
+
+* If a command specified by the :prop_tgt:`<LANG>_CLANG_TIDY` target property
+ returns non-zero at build time this is now treated as an error instead of
+ silently ignored.
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index dca5ffc..f1ce75a 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -358,14 +358,21 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
// Run the tidy command line. Capture its stdout and hide its stderr.
std::string stdOut;
- if (!cmSystemTools::RunSingleCommand(tidy_cmd, &stdOut, CM_NULLPTR,
- &ret, CM_NULLPTR,
+ std::string stdErr;
+ if (!cmSystemTools::RunSingleCommand(tidy_cmd, &stdOut, &stdErr, &ret,
+ CM_NULLPTR,
cmSystemTools::OUTPUT_NONE)) {
- std::cerr << "Error running '" << tidy_cmd[0] << "'\n";
+ std::cerr << "Error running '" << tidy_cmd[0] << "': " << stdErr
+ << "\n";
return 1;
}
// Output the stdout from clang-tidy to stderr
std::cerr << stdOut;
+ // If clang-tidy exited with an error do the same.
+ if (ret != 0) {
+ std::cerr << stdErr;
+ return ret;
+ }
}
if (!lwyu.empty()) {
// Construct the ldd -r -u (link what you use lwyu) command line
diff --git a/Tests/RunCMake/ClangTidy/C-bad-Build-result.txt b/Tests/RunCMake/ClangTidy/C-bad-Build-result.txt
new file mode 100644
index 0000000..d197c91
--- /dev/null
+++ b/Tests/RunCMake/ClangTidy/C-bad-Build-result.txt
@@ -0,0 +1 @@
+[^0]
diff --git a/Tests/RunCMake/ClangTidy/C-bad-Build-stdout.txt b/Tests/RunCMake/ClangTidy/C-bad-Build-stdout.txt
new file mode 100644
index 0000000..2370ce1
--- /dev/null
+++ b/Tests/RunCMake/ClangTidy/C-bad-Build-stdout.txt
@@ -0,0 +1,2 @@
+stdout from bad command line arg '-bad'
+stderr from bad command line arg '-bad'
diff --git a/Tests/RunCMake/ClangTidy/C-bad.cmake b/Tests/RunCMake/ClangTidy/C-bad.cmake
new file mode 100644
index 0000000..aa54c08
--- /dev/null
+++ b/Tests/RunCMake/ClangTidy/C-bad.cmake
@@ -0,0 +1,3 @@
+enable_language(C)
+set(CMAKE_C_CLANG_TIDY "${PSEUDO_TIDY}" -bad)
+add_executable(main main.c)
diff --git a/Tests/RunCMake/ClangTidy/RunCMakeTest.cmake b/Tests/RunCMake/ClangTidy/RunCMakeTest.cmake
index 27cd922..2f41e50 100644
--- a/Tests/RunCMake/ClangTidy/RunCMakeTest.cmake
+++ b/Tests/RunCMake/ClangTidy/RunCMakeTest.cmake
@@ -20,3 +20,4 @@ if (NOT RunCMake_GENERATOR STREQUAL "Watcom WMake")
run_tidy(C-launch)
run_tidy(CXX-launch)
endif()
+run_tidy(C-bad)
diff --git a/Tests/RunCMake/pseudo_tidy.c b/Tests/RunCMake/pseudo_tidy.c
index c950d03..2feeb0f 100644
--- a/Tests/RunCMake/pseudo_tidy.c
+++ b/Tests/RunCMake/pseudo_tidy.c
@@ -1,9 +1,15 @@
#include <stdio.h>
+#include <string.h>
int main(int argc, char* argv[])
{
int i;
for (i = 1; i < argc; ++i) {
+ if (strcmp(argv[i], "-bad") == 0) {
+ fprintf(stdout, "stdout from bad command line arg '-bad'\n");
+ fprintf(stderr, "stderr from bad command line arg '-bad'\n");
+ return 1;
+ }
if (argv[i][0] != '-') {
fprintf(stdout, "%s:0:0: warning: message [checker]\n", argv[i]);
break;