From fcacc319d9e1a3ea89b33d58c495f32199f6ec91 Mon Sep 17 00:00:00 2001 From: Ashish Sadanandan Date: Fri, 31 Mar 2023 22:41:48 -0600 Subject: IWYU: Return error code if user enables error reporting Previously CMake ignored the return code from iwyu because old versions of the tool would exit with an error code even when no header include violations were detected. The iwyu project has since changed this behavior, so the tool no longer returns an error code unless the user enables error reporting via command line arguments. Behavior seen with iwyu version 0.19 Source file with missing includes: - Case 1: iwyu arguments: - return code: 0 - output: - Case 2: iwyu arguments: `-Xiwyu --error` - return code: 1 - output: Source file with no missing includes: - Case 1: iwyu arguments: - return code: 0 - output: `(/path/to/file.cc has correct #includes/fwd-decls)` - Case 2: iwyu arguments: `-Xiwyu --error` - return code: 0 - output: `(/path/to/file.cc has correct #includes/fwd-decls)` Teach CMake to return the iwyu return code if the user has invoked the tool with any of these command line arguments included: - `--error[=N]` - `--error_always[=N]` Fixes: #24066 --- Tests/RunCMake/IncludeWhatYouUse/C-error-Build-result.txt | 1 + Tests/RunCMake/IncludeWhatYouUse/C-error-Build-stdout.txt | 4 ++++ Tests/RunCMake/IncludeWhatYouUse/C-error.cmake | 3 +++ Tests/RunCMake/IncludeWhatYouUse/CXX-error-Build-result.txt | 1 + Tests/RunCMake/IncludeWhatYouUse/CXX-error-Build-stdout.txt | 4 ++++ Tests/RunCMake/IncludeWhatYouUse/CXX-error.cmake | 3 +++ Tests/RunCMake/IncludeWhatYouUse/RunCMakeTest.cmake | 2 ++ 7 files changed, 18 insertions(+) create mode 100644 Tests/RunCMake/IncludeWhatYouUse/C-error-Build-result.txt create mode 100644 Tests/RunCMake/IncludeWhatYouUse/C-error-Build-stdout.txt create mode 100644 Tests/RunCMake/IncludeWhatYouUse/C-error.cmake create mode 100644 Tests/RunCMake/IncludeWhatYouUse/CXX-error-Build-result.txt create mode 100644 Tests/RunCMake/IncludeWhatYouUse/CXX-error-Build-stdout.txt create mode 100644 Tests/RunCMake/IncludeWhatYouUse/CXX-error.cmake (limited to 'Tests') 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) -- cgit v1.2.1