Skip to content
  • Ashish Sadanandan's avatar
    IWYU: Return error code if user enables error reporting · fcacc319
    Ashish Sadanandan authored and Brad King's avatar Brad King committed
    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: <report of all missing includes>
     - Case 2: iwyu arguments: `-Xiwyu --error`
       - return code: 1
       - output: <report of all missing includes>
    
    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
    fcacc319