On Mon, Apr 11, 2016 at 5:26 PM, Brad King <brad.k...@kitware.com> wrote:
> On 04/08/2016 06:31 PM, Daniel Pfeifer wrote:
>> I implemented the integration of `clang-tidy` along the lines of the
>> `include-what-you-use` integration.
>> There is a new `<LANG>_CLANG_TIDY` target property that is initialized
>> with the value of the `CMAKE_<LANG>_CLANG_TIDY` variable.
>> It contains the command line for `clang-tidy` as a ;-list.
>
> Nice.  The patch is very complete.  Applied:
>
>  Add options to run clang-tidy with the compiler
>  https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b2db0170

This is a follow up patch:

Clang-Tidy writes the number of warnings, the number of suppressed
warnings, and instructions on how to suppress warnings to stderr.  Since
each source file is checked individually, this repetitive information is
disturbing and should be suppressed.

The actual warning messages are written to stdout.  Some IDEs (eg.
QtCreator) analyze only stderr for issues.  Redirecting Clang-Tidy's
stdout to stderr makes sure the warnings are correctly displayed.
From 53dc5b84eb6e39a6dac6eb8fab13dcf92d04ed35 Mon Sep 17 00:00:00 2001
From: Daniel Pfeifer <dan...@pfeifer-mail.de>
Date: Tue, 26 Apr 2016 22:50:54 +0200
Subject: [PATCH] Clang-Tidy: copy stdout to sterr; ignore original stderr

Clang-Tidy writes the number of warnings, the number of suppressed
warnings, and instructions on how to suppress warnings to stderr.  Since
each source file is checked individually, this repetitive information is
disturbing and should be suppressed.

The actual warning messages are written to stdout.  Some IDEs (eg.
QtCreator) analyze only stderr for issues.  Redirecting Clang-Tidy's
stdout to stderr makes sure the warnings are correctly displayed.
---
 Source/cmcmd.cxx | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 3c28c35..e9edac4 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -387,15 +387,19 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
         cmSystemTools::ExpandListArgument(tidy, tidy_cmd, true);
         tidy_cmd.push_back(sourceFile);
         tidy_cmd.push_back("--");
-        tidy_cmd.insert(tidy_cmd.end(), orig_cmd.begin()+1, orig_cmd.end());
+        tidy_cmd.insert(tidy_cmd.end(), orig_cmd.begin(), orig_cmd.end());
 
-        // Run the tidy command line.
-        if(!cmSystemTools::RunSingleCommand(tidy_cmd, 0, 0, &ret, 0,
-                                            cmSystemTools::OUTPUT_PASSTHROUGH))
+        // Run the tidy command line.  Capture its stdout and hide its stderr.
+        std::string stdOut;
+        if(!cmSystemTools::RunSingleCommand(tidy_cmd, &stdOut, 0, &ret, 0,
+                                            cmSystemTools::OUTPUT_NONE))
           {
           std::cerr << "Error running '" << tidy_cmd[0] << "'\n";
           return 1;
           }
+
+        // Output the stdout from clang-tidy to stderr
+        std::cerr << stdOut;
         }
 
       // Now run the real compiler command and return its result value.
-- 
2.8.0

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to