MyDeveloperDay added a comment.

Using a suggestion from D68551: [clang-format] [NFC] Ensure clang-format is 
itself clang-formatted. <https://reviews.llvm.org/D68551> as an example of its 
usefulness, I modified my clang-format CMakeList.txt to do as Polly does and 
add clang-format check rules, combining this with this revision gives a nice 
integration into the build system that lets you quickly and easily see where 
violations creep in.

I really feel this could help bring clang-format checking into developers build 
workflows using a similar mechanism and it really highlights what is clean and 
what is not.

  # Add target to check formatting of files
  file( GLOB files *.cpp ../../lib/Format/*.cpp ../../lib/Format*.h 
../../unittests/Format/*.cpp ../../include/clang/Format.h)
  
  set(check_format_depends)
  set(update_format_depends)
  set(i 0)
  foreach (file IN LISTS files)
    add_custom_command(OUTPUT clang-format-check-format${i}
      COMMAND clang-format -i -ferror-limit=1 --dry-run -sort-includes 
-style=llvm ${file}
      VERBATIM
      COMMENT "Checking format of ${file}..."
    )
    list(APPEND check_format_depends "clang-format-check-format${i}")
  
    add_custom_command(OUTPUT clang-format-update-format${i}
      COMMAND clang-format -sort-includes -i -style=llvm ${file}
      VERBATIM
      COMMENT "Updating format of ${file}..."
    )
    list(APPEND update_format_depends "clang-format-update-format${i}")
  
    math(EXPR i ${i}+1)
  endforeach ()
  
  add_custom_target(clang-format-check-format DEPENDS ${check_format_depends})
  set_target_properties(clang-format-check-format PROPERTIES FOLDER 
"ClangFormat")
  
  add_custom_target(clang-format-update-format DEPENDS ${update_format_depends})
  set_target_properties(clang-format-update-format PROPERTIES FOLDER 
"ClangFormat")



  [ 94%] Built target obj.clangSema
  [ 94%] Built target clangAST
  [ 94%] Built target clangSema
  [ 94%] Built target clang-format
  [ 94%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/AffectedRangeManager.cpp...
  [ 94%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/BreakableToken.cpp...
  [ 94%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/ContinuationIndenter.cpp...
  [ 94%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/FormatToken.cpp...
  [ 94%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/Format.cpp...
  [ 94%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/FormatTokenLexer.cpp...
  [ 94%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/NamespaceEndCommentsFixer.cpp...
  [ 94%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/SortJavaScriptImports.cpp...
  [ 94%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/TokenAnalyzer.cpp...
  [ 94%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/TokenAnnotator.cpp...
  [ 94%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/UnwrappedLineFormatter.cpp...
  [100%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/UsingDeclarationsSorter.cpp...
  [100%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/UnwrappedLineParser.cpp...
  [100%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../lib/Format/WhitespaceManager.cpp...
  [100%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/CleanupTest.cpp...
  [100%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/FormatTest.cpp...
  [100%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/FormatTestComments.cpp...
  [100%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/FormatTestCSharp.cpp...
  [100%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/FormatTestJS.cpp...
  [100%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/FormatTestJava.cpp...
  
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/CleanupTest.cpp:455:2:
 warning: code should be clang-formatted [-Wclang-format-violations]
  }
   ^
  [100%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/FormatTestProto.cpp...
  [100%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/FormatTestObjC.cpp...
  [100%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/FormatTestRawStrings.cpp...
  
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/FormatTestComments.cpp:31:21:
 warning: code should be clang-formatted [-Wclang-format-violations]
    enum StatusCheck {
                      ^
  [100%] 
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/FormatTestJS.cpp:51:47:
 warning: code should be clang-formatted [-Wclang-format-violations]
      EXPECT_EQ(Code.str(), format(Code, Style))
                                                ^
  Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/FormatTestTableGen.cpp...
  [100%] Checking format of 
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/FormatTestSelective.cpp...
  
C:/llvm/llvm-project/clang/tools/clang-format/../../unittests/Format/FormatTestJava.cpp:455:13:
 warning: code should be clang-formatted [-Wclang-format-violations]
    EXPECT_EQ(
              ^


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68554/new/

https://reviews.llvm.org/D68554



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to