summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Source/cmcmd.cxx13
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/C-error-Build-result.txt1
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/C-error-Build-stdout.txt4
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/C-error.cmake3
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/CXX-error-Build-result.txt1
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/CXX-error-Build-stdout.txt4
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/CXX-error.cmake3
-rw-r--r--Tests/RunCMake/IncludeWhatYouUse/RunCMakeTest.cmake2
8 files changed, 28 insertions, 3 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 036ddc6a60..f4d17f84ec 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -3,6 +3,7 @@
#include "cmcmd.h"
#include <functional>
+#include <iterator>
#include <cm/optional>
#include <cmext/algorithm>
@@ -346,7 +347,6 @@ int HandleIWYU(const std::string& runCmd, const std::string& /* sourceFile */,
cmList iwyu_cmd{ runCmd, cmList::EmptyElements::Yes };
cm::append(iwyu_cmd, orig_cmd.begin() + 1, orig_cmd.end());
// Run the iwyu command line. Capture its stderr and hide its stdout.
- // Ignore its return code because the tool always returns non-zero.
std::string stdErr;
int ret;
if (!cmSystemTools::RunSingleCommand(iwyu_cmd, nullptr, &stdErr, &ret,
@@ -360,8 +360,15 @@ int HandleIWYU(const std::string& runCmd, const std::string& /* sourceFile */,
std::cerr << "Warning: include-what-you-use reported diagnostics:\n"
<< stdErr << "\n";
}
- // always return 0 we don't want to break the compile
- return 0;
+ // Older versions of iwyu always returned a non-zero exit code,
+ // so ignore it unless the user has enabled errors.
+ auto has_error_opt = std::find_if(
+ iwyu_cmd.cbegin(), iwyu_cmd.cend(),
+ [](std::string const& opt) { return cmHasLiteralPrefix(opt, "--error"); });
+ bool errors_enabled = has_error_opt != iwyu_cmd.cend() &&
+ has_error_opt != iwyu_cmd.cbegin() &&
+ *std::prev(has_error_opt) == "-Xiwyu";
+ return errors_enabled ? ret : 0;
}
int HandleTidy(const std::string& runCmd, const std::string& sourceFile,
diff --git a/Tests/RunCMake/IncludeWhatYouUse/C-error-Build-result.txt b/Tests/RunCMake/IncludeWhatYouUse/C-error-Build-result.txt
new file mode 100644
index 0000000000..d197c913c2
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/C-error-Build-result.txt
@@ -0,0 +1 @@
+[^0]
diff --git a/Tests/RunCMake/IncludeWhatYouUse/C-error-Build-stdout.txt b/Tests/RunCMake/IncludeWhatYouUse/C-error-Build-stdout.txt
new file mode 100644
index 0000000000..cb7467705e
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/C-error-Build-stdout.txt
@@ -0,0 +1,4 @@
+Warning: include-what-you-use reported diagnostics:
+should add these lines:
+*
+#include <\.\.\.>
diff --git a/Tests/RunCMake/IncludeWhatYouUse/C-error.cmake b/Tests/RunCMake/IncludeWhatYouUse/C-error.cmake
new file mode 100644
index 0000000000..d5230bbf8c
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/C-error.cmake
@@ -0,0 +1,3 @@
+enable_language(C)
+set(CMAKE_C_INCLUDE_WHAT_YOU_USE "${PSEUDO_IWYU}" -Xiwyu --error)
+add_executable(main main.c)
diff --git a/Tests/RunCMake/IncludeWhatYouUse/CXX-error-Build-result.txt b/Tests/RunCMake/IncludeWhatYouUse/CXX-error-Build-result.txt
new file mode 100644
index 0000000000..d197c913c2
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/CXX-error-Build-result.txt
@@ -0,0 +1 @@
+[^0]
diff --git a/Tests/RunCMake/IncludeWhatYouUse/CXX-error-Build-stdout.txt b/Tests/RunCMake/IncludeWhatYouUse/CXX-error-Build-stdout.txt
new file mode 100644
index 0000000000..cb7467705e
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/CXX-error-Build-stdout.txt
@@ -0,0 +1,4 @@
+Warning: include-what-you-use reported diagnostics:
+should add these lines:
+*
+#include <\.\.\.>
diff --git a/Tests/RunCMake/IncludeWhatYouUse/CXX-error.cmake b/Tests/RunCMake/IncludeWhatYouUse/CXX-error.cmake
new file mode 100644
index 0000000000..1d10a550d4
--- /dev/null
+++ b/Tests/RunCMake/IncludeWhatYouUse/CXX-error.cmake
@@ -0,0 +1,3 @@
+enable_language(CXX)
+set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "$<1:${PSEUDO_IWYU}>" -Xiwyu --error)
+add_executable(main main.cxx)
diff --git a/Tests/RunCMake/IncludeWhatYouUse/RunCMakeTest.cmake b/Tests/RunCMake/IncludeWhatYouUse/RunCMakeTest.cmake
index 8f99eb1047..8ec24be5ca 100644
--- a/Tests/RunCMake/IncludeWhatYouUse/RunCMakeTest.cmake
+++ b/Tests/RunCMake/IncludeWhatYouUse/RunCMakeTest.cmake
@@ -16,6 +16,8 @@ endfunction()
run_iwyu(C)
run_iwyu(CXX)
+run_iwyu(C-error)
+run_iwyu(CXX-error)
if (NOT RunCMake_GENERATOR STREQUAL "Watcom WMake")
run_iwyu(C-launch)
run_iwyu(CXX-launch)