On Thu, Nov 19, 2015 at 3:26 PM, Brad King <brad.k...@kitware.com> wrote: > On 11/19/2015 09:22 AM, Robert Dailey wrote: >> Tonight I will do some testing and submit a patch + example files >> converted to the style Brad suggested. We can fine-tune it as needed. > > Rather than a patch please work on a script to perform the conversion. > Then at any time we can choose to run the script as the one-shot conversion > and commit as a robot user. Any sweeping patch would be too big to > post to the list anyway. Ideally the script should be simple enough > to cut-n-paste into a shell so we can just record it in the commit > message. > > See this commit for an example of this approach: > > https://cmake.org/gitweb?p=cmake.git;a=commit;h=7bbaa428
It took a while, but i figured out .clang-format definitions (there are two required) and a script that, after applying, does not break compilation and unit tests. The .clang-format for the root directory looks like this: --- BasedOnStyle: Mozilla AlignAfterOpenBracket: false AlignOperands: false AllowShortFunctionsOnASingleLine: None AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None ColumnLimit: 79 ContinuationIndentWidth: 4 IncludeCategories: - Regex: 'cmStandardIncludes' Priority: -1 Standard: Cpp03 ... This is the script to perform the reformatting of most C/C++ source code: git ls-files -z -- '*.c' '*.cc' '*.cpp' '*.cxx' '*.h' '*.hh' '*.hpp' '*.hxx' \ | egrep -z -v '(Lexer|Parser|ParserHelper)\.' \ | egrep -z -v '^(Utilities/(KW|cm).*/|Source/(kwsys|CursesDialog/form)/)' \ | egrep -z -v '^Tests/Module/GenerateExportHeader' \ | egrep -z -v '^Tests/RunCMake/CommandLine/cmake_depends/test_UTF-16LE.h' \ | xargs -0 clang-format -i I have attached a patch that adds the .clang-format and two other patches that need to be applied before reformatting. I have pushed all those changes (including reformatting) to github: https://github.com/purpleKarrot/CMake/commits/clang-format Notes: * Trying to reformat Tests/RunCMake/CommandLine/cmake_depends/test_UTF-16LE.h makes clang-format crash. * Clang-Format dedents preprocessor directives. See also: https://llvm.org/bugs/show_bug.cgi?id=17362 * I did not include '*.in' files in the list, because Clang-Format does strange things to @VARIALES@. Please feel free to add/remove options from the .clang-format files. IncludeCategories and Standard should stay as they are. cheers, Daniel
From 452087a4b9f05742aed38040ab8d9b970fd05719 Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer <dan...@pfeifer-mail.de> Date: Wed, 27 Apr 2016 22:47:02 +0200 Subject: [PATCH 1/3] CursesDialog: add missing cmState include --- Source/CursesDialog/cmCursesMainForm.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/CursesDialog/cmCursesMainForm.h b/Source/CursesDialog/cmCursesMainForm.h index 255c823..d194168 100644 --- a/Source/CursesDialog/cmCursesMainForm.h +++ b/Source/CursesDialog/cmCursesMainForm.h @@ -13,6 +13,7 @@ #define cmCursesMainForm_h #include "../cmStandardIncludes.h" +#include "../cmState.h" #include "cmCursesForm.h" #include "cmCursesStandardIncludes.h" -- 2.8.0
From de7ca8575286bf995a771f894bf5087698686482 Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer <dan...@pfeifer-mail.de> Date: Wed, 27 Apr 2016 23:29:43 +0200 Subject: [PATCH 2/3] StringFileTest: add blank line between includes This test generates a header file which is not self-contained. Since Clang-Format reorders includes alphabetically, this makes the test fail. Add a blank line to introduce a logical separation between two blocks of include files. --- Tests/StringFileTest/StringFile.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/StringFileTest/StringFile.cxx b/Tests/StringFileTest/StringFile.cxx index 9eba6bf..073e30c 100644 --- a/Tests/StringFileTest/StringFile.cxx +++ b/Tests/StringFileTest/StringFile.cxx @@ -1,5 +1,6 @@ #include <stdio.h> #include <string.h> + #include "OutputFile.h" int main(int, char*[]) -- 2.8.0
From 8feb2d2efc1287048ca66305db222bb197dcba4d Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer <dan...@pfeifer-mail.de> Date: Wed, 27 Apr 2016 20:31:23 +0200 Subject: [PATCH 3/3] add .clang-format configuration files For most of the code, Standard must be set to Cpp03, so that `A<A<int> >` is not rewritten as `A<A<int>>`. For the code under Tests/CompileFeatures, Standard must be set to Cpp11, so that `U"foo"` is not rewritten as `U "foo"`. Priorize the "cmStandardIncludes.h" header, so that it is always included first. --- .clang-format | 14 ++++++++++++++ Tests/CompileFeatures/.clang-format | 11 +++++++++++ 2 files changed, 25 insertions(+) create mode 100644 .clang-format create mode 100644 Tests/CompileFeatures/.clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..4076bcd --- /dev/null +++ b/.clang-format @@ -0,0 +1,14 @@ +--- +BasedOnStyle: Mozilla +AlignAfterOpenBracket: false +AlignOperands: false +AllowShortFunctionsOnASingleLine: None +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +ColumnLimit: 79 +ContinuationIndentWidth: 4 +IncludeCategories: + - Regex: 'cmStandardIncludes' + Priority: -1 +Standard: Cpp03 +... diff --git a/Tests/CompileFeatures/.clang-format b/Tests/CompileFeatures/.clang-format new file mode 100644 index 0000000..b080e2e --- /dev/null +++ b/Tests/CompileFeatures/.clang-format @@ -0,0 +1,11 @@ +--- +BasedOnStyle: Mozilla +AlignAfterOpenBracket: false +AlignOperands: false +AllowShortFunctionsOnASingleLine: None +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +ColumnLimit: 79 +ContinuationIndentWidth: 4 +Standard: Cpp11 +... -- 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