Skip to content

[clang-format][NFC] Add CMake target clang-format-check-format #95873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2024

Conversation

owenca
Copy link
Contributor

@owenca owenca commented Jun 18, 2024

Adapted from polly-check-format.

@llvmbot
Copy link
Member

llvmbot commented Jun 18, 2024

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

Adpated from polly-check-format.


Full diff: https://github.com/llvm/llvm-project/pull/95873.diff

1 Files Affected:

  • (modified) clang/lib/Format/CMakeLists.txt (+24)
diff --git a/clang/lib/Format/CMakeLists.txt b/clang/lib/Format/CMakeLists.txt
index 84a3c136f650a..b787b11ac7b74 100644
--- a/clang/lib/Format/CMakeLists.txt
+++ b/clang/lib/Format/CMakeLists.txt
@@ -29,3 +29,27 @@ add_clang_library(clangFormat
   clangToolingCore
   clangToolingInclusions
   )
+
+file(GLOB_RECURSE files
+  *.cpp
+  *.h
+  ../../include/clang/Format/*.h
+  ../../tools/clang-format/*.cpp
+  ../../unittests/Format/*.cpp
+  ../../unittests/Format/*.h
+  )
+
+set(check_format_depends)
+set(i 0)
+foreach (file IN LISTS files)
+  add_custom_command(OUTPUT clang-format-check-format${i}
+    COMMAND clang-format ${file} | diff -u ${file} -
+    VERBATIM
+    COMMENT "Checking format of ${file}..."
+  )
+  list(APPEND check_format_depends "clang-format-check-format${i}")
+
+  math(EXPR i ${i}+1)
+endforeach ()
+
+add_custom_target(clang-format-check-format DEPENDS ${check_format_depends})

@HazardyKnusperkeks
Copy link
Contributor

I have no idea about cmake files and hopefully never will. So I can't say anything on how you did it, I'm fine with what you want to do.

Copy link
Contributor

@mydeveloperday mydeveloperday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@owenca owenca merged commit f2b17d2 into llvm:main Jun 21, 2024
9 checks passed
@owenca owenca deleted the check-format branch June 21, 2024 16:06
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
@llvm llvm deleted a comment from llvm-ci Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants