Re: [cmake-developers] Integration of clang-tidy

2016-05-03 Thread Daniel Pfeifer
FYI: I have set up a dashboard build that shows the integration in
action: https://open.cdash.org/buildSummary.php?buildid=4349265

Most of the issues have fix-it hints which can be applied
automatically by clang-tidy.

On Thu, Apr 28, 2016 at 3:44 PM, Brad King  wrote:
> On 04/27/2016 06:48 PM, Daniel Pfeifer wrote:
>> It is unrelated. Clang-Tidy picks the interesting pieces from the
>> compiler command line and ignores the rest. Whether cc is given or not
>> makes no difference.
>> But maybe we should leave the decision what to pick to Clang-Tidy? It
>> may be clearer to forward the original command line unmodified.
>
> Applied, thanks!
>
>  Clang-Tidy: Give entire compiler command line to clant-tidy tool
>  https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=304ab71d
>
> -Brad
>
-- 

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


Re: [cmake-developers] Integration of clang-tidy

2016-04-28 Thread Brad King
On 04/27/2016 06:48 PM, Daniel Pfeifer wrote:
> It is unrelated. Clang-Tidy picks the interesting pieces from the
> compiler command line and ignores the rest. Whether cc is given or not
> makes no difference.
> But maybe we should leave the decision what to pick to Clang-Tidy? It
> may be clearer to forward the original command line unmodified.

Applied, thanks!

 Clang-Tidy: Give entire compiler command line to clant-tidy tool
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=304ab71d

-Brad

-- 

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


Re: [cmake-developers] Integration of clang-tidy

2016-04-27 Thread Daniel Pfeifer
On Wed, Apr 27, 2016 at 3:10 PM, Brad King  wrote:
> On 04/26/2016 05:32 PM, Daniel Pfeifer wrote:
>> This is a follow up patch:
>
> Thanks.
>
>> -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());
>
> What is the purpose of this hunk?  Does clang-tidy expect to be
> given the full compiler command line including "cc"?  This does
> not look related to the change described in the commit message.

It is unrelated. Clang-Tidy picks the interesting pieces from the
compiler command line and ignores the rest. Whether cc is given or not
makes no difference.
But maybe we should leave the decision what to pick to Clang-Tidy? It
may be clearer to forward the original command line unmodified.
-- 

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


Re: [cmake-developers] Integration of clang-tidy

2016-04-27 Thread Daniel Pfeifer
On Wed, Apr 27, 2016 at 10:47 PM, Gregor Jasny  wrote:
> Hallo Daniel,
>
> On 09/04/16 00:31, Daniel Pfeifer wrote:
>> I implemented the integration of `clang-tidy` along the lines of the
>> `include-what-you-use` integration.
>> There is a new `_CLANG_TIDY` target property that is initialized
>> with the value of the `CMAKE__CLANG_TIDY` variable.
>> It contains the command line for `clang-tidy` as a ;-list.
>
> I'm wondering what's the advantage of having this built-in support for
> clang tidy over using the generated compile command database instead?

The compile command database is just this: a database of compile
commands. It does not execute clang-tidy at all. To execute clang-tidy
for all source files that are listed in the database, you need a
separate tool.
There is this one, which requires Python:
https://llvm.org/svn/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py

Having this functionality built into CMake means:

* No additional dependencies.
* Warning messages inside your IDE.
* Warning messages on CDash.

Since clang-tidy is executed directly before the compiler for each
individual source file, you may set CMAKE_CXX_CLANG_TIDY to
"clang-tidy;-fix-errors" and successfully compile invalid code. :-)
-- 

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


Re: [cmake-developers] Integration of clang-tidy

2016-04-27 Thread Gregor Jasny via cmake-developers
Hallo Daniel,

On 09/04/16 00:31, Daniel Pfeifer wrote:
> I implemented the integration of `clang-tidy` along the lines of the
> `include-what-you-use` integration.
> There is a new `_CLANG_TIDY` target property that is initialized
> with the value of the `CMAKE__CLANG_TIDY` variable.
> It contains the command line for `clang-tidy` as a ;-list.

I'm wondering what's the advantage of having this built-in support for
clang tidy over using the generated compile command database instead?

Thanks,
Gregor
-- 

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


Re: [cmake-developers] Integration of clang-tidy

2016-04-27 Thread Brad King
On 04/26/2016 05:32 PM, Daniel Pfeifer wrote:
> This is a follow up patch:

Thanks.

> -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());

What is the purpose of this hunk?  Does clang-tidy expect to be
given the full compiler command line including "cc"?  This does
not look related to the change described in the commit message.

I've applied the change without that hunk:

 Clang-Tidy: copy stdout to sterr; ignore original stderr
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=04d74a7f

Thanks,
-Brad

-- 

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


Re: [cmake-developers] Integration of clang-tidy

2016-04-26 Thread Daniel Pfeifer
On Mon, Apr 11, 2016 at 5:26 PM, Brad King  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 `_CLANG_TIDY` target property that is initialized
>> with the value of the `CMAKE__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 
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& 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, , 0,
-cmSystemTools::OUTPUT_PASSTHROUGH))
+// Run the tidy command line.  Capture its stdout and hide its stderr.
+std::string stdOut;
+if(!cmSystemTools::RunSingleCommand(tidy_cmd, , 0, , 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

Re: [cmake-developers] Integration of clang-tidy

2016-04-11 Thread Brad King
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 `_CLANG_TIDY` target property that is initialized
> with the value of the `CMAKE__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

Thanks,
-Brad
-- 

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


[cmake-developers] Integration of clang-tidy

2016-04-08 Thread Daniel Pfeifer
Hi,

I implemented the integration of `clang-tidy` along the lines of the
`include-what-you-use` integration.
There is a new `_CLANG_TIDY` target property that is initialized
with the value of the `CMAKE__CLANG_TIDY` variable.
It contains the command line for `clang-tidy` as a ;-list.

Example use:

$ cmake -DCMAKE_CXX_CLANG_TIDY:STRING="clang-tidy;-checks=-*,readability-*" ..
$ cmake --build .

It is also possible to let `clang-tidy` apply fixit hints directly:

$ cmake 
-DCMAKE_CXX_CLANG_TIDY:STRING="clang-tidy;-checks=-*,readability-redundant-string-cstr;-fix"
..

The output is recognized by CTest's diagnostic parser. I haven't
checked how they look on CDash.

cheers, Daniel
From c1996b295d2e49134b6f5ef2be690588e5bf2732 Mon Sep 17 00:00:00 2001
From: Daniel Pfeifer 
Date: Fri, 8 Apr 2016 22:09:27 +0200
Subject: [PATCH] Provide integration for clang-tidy

---
 Help/manual/cmake-properties.7.rst |  1 +
 Help/manual/cmake-variables.7.rst  |  1 +
 Help/prop_tgt/LANG_CLANG_TIDY.rst  | 13 
 Help/release/dev/clang-tidy.rst|  7 ++
 Help/variable/CMAKE_LANG_CLANG_TIDY.rst|  6 ++
 Source/cmMakefileTargetGenerator.cxx   | 19 -
 Source/cmNinjaTargetGenerator.cxx  | 18 -
 Source/cmTarget.cxx|  2 +
 Source/cmcmd.cxx   | 80 --
 Tests/RunCMake/CMakeLists.txt  |  2 +
 Tests/RunCMake/ClangTidy/C-Build-stdout.txt|  1 +
 Tests/RunCMake/ClangTidy/C-launch-Build-stdout.txt |  1 +
 Tests/RunCMake/ClangTidy/C-launch.cmake|  3 +
 Tests/RunCMake/ClangTidy/C.cmake   |  3 +
 Tests/RunCMake/ClangTidy/CMakeLists.txt|  3 +
 Tests/RunCMake/ClangTidy/CXX-Build-stdout.txt  |  1 +
 .../RunCMake/ClangTidy/CXX-launch-Build-stdout.txt |  1 +
 Tests/RunCMake/ClangTidy/CXX-launch.cmake  |  3 +
 Tests/RunCMake/ClangTidy/CXX.cmake |  3 +
 Tests/RunCMake/ClangTidy/RunCMakeTest.cmake| 22 ++
 Tests/RunCMake/ClangTidy/main.c|  1 +
 Tests/RunCMake/ClangTidy/main.cxx  |  1 +
 Tests/RunCMake/pseudo_tidy.c   | 16 +
 23 files changed, 181 insertions(+), 27 deletions(-)
 create mode 100644 Help/prop_tgt/LANG_CLANG_TIDY.rst
 create mode 100644 Help/release/dev/clang-tidy.rst
 create mode 100644 Help/variable/CMAKE_LANG_CLANG_TIDY.rst
 create mode 100644 Tests/RunCMake/ClangTidy/C-Build-stdout.txt
 create mode 100644 Tests/RunCMake/ClangTidy/C-launch-Build-stdout.txt
 create mode 100644 Tests/RunCMake/ClangTidy/C-launch.cmake
 create mode 100644 Tests/RunCMake/ClangTidy/C.cmake
 create mode 100644 Tests/RunCMake/ClangTidy/CMakeLists.txt
 create mode 100644 Tests/RunCMake/ClangTidy/CXX-Build-stdout.txt
 create mode 100644 Tests/RunCMake/ClangTidy/CXX-launch-Build-stdout.txt
 create mode 100644 Tests/RunCMake/ClangTidy/CXX-launch.cmake
 create mode 100644 Tests/RunCMake/ClangTidy/CXX.cmake
 create mode 100644 Tests/RunCMake/ClangTidy/RunCMakeTest.cmake
 create mode 100644 Tests/RunCMake/ClangTidy/main.c
 create mode 100644 Tests/RunCMake/ClangTidy/main.cxx
 create mode 100644 Tests/RunCMake/pseudo_tidy.c

diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index 73d1142..3403dcd 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -197,6 +197,7 @@ Properties on Targets
/prop_tgt/JOB_POOL_COMPILE
/prop_tgt/JOB_POOL_LINK
/prop_tgt/LABELS
+   /prop_tgt/LANG_CLANG_TIDY
/prop_tgt/LANG_COMPILER_LAUNCHER
/prop_tgt/LANG_INCLUDE_WHAT_YOU_USE
/prop_tgt/LANG_VISIBILITY_PRESET
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index 3f73b32..7cf3a3d 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -259,6 +259,7 @@ Variables that Control the Build
/variable/CMAKE_INSTALL_RPATH
/variable/CMAKE_INSTALL_RPATH_USE_LINK_PATH
/variable/CMAKE_IOS_INSTALL_COMBINED
+   /variable/CMAKE_LANG_CLANG_TIDY
/variable/CMAKE_LANG_COMPILER_LAUNCHER
/variable/CMAKE_LANG_INCLUDE_WHAT_YOU_USE
/variable/CMAKE_LANG_VISIBILITY_PRESET
diff --git a/Help/prop_tgt/LANG_CLANG_TIDY.rst b/Help/prop_tgt/LANG_CLANG_TIDY.rst
new file mode 100644
index 000..2887e23
--- /dev/null
+++ b/Help/prop_tgt/LANG_CLANG_TIDY.rst
@@ -0,0 +1,13 @@
+_CLANG_TIDY
+-
+
+This property is implemented only when  is ``C`` or ``CXX``.
+
+Specify a :ref:`;-list ` containing a command
+line for the ``clang-tidy`` tool.  The :ref:`Makefile Generators`
+and the :generator:`Ninja` generator will run this tool along with the
+compiler and report a warning if the tool reports any problems.
+
+This property is initialized by the value of
+the :variable:`CMAKE__CLANG_TIDY` variable if it is set
+when a target is created.
diff --git