You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bb...@apache.org on 2019/12/05 15:59:04 UTC
[geode-native] branch develop updated: GEODE-7520: Add convenient
target to clangformat everything (#558)
This is an automated email from the ASF dual-hosted git repository.
bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git
The following commit(s) were added to refs/heads/develop by this push:
new 3ad4257 GEODE-7520: Add convenient target to clangformat everything (#558)
3ad4257 is described below
commit 3ad4257f6ba624b28145c6be5c932052ab261219
Author: Blake Bender <bb...@pivotal.io>
AuthorDate: Thu Dec 5 07:58:54 2019 -0800
GEODE-7520: Add convenient target to clangformat everything (#558)
- Add target 'all-clangformat' so we can easily reformat the entire tree
- Add a section about clang-format to BUILDING.md. Explain how to disable it, and also how to run it for all targets
---
BUILDING.md | 17 +++++++++++++++++
cmake/ClangFormat.cmake | 8 +++++++-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/BUILDING.md b/BUILDING.md
index 2f5cded..f483846 100644
--- a/BUILDING.md
+++ b/BUILDING.md
@@ -151,6 +151,23 @@ To override `clang-tidy` options:
```console
$ cmake … -DCMAKE_CXX_CLANG_TIDY=clang-tidy;<options> …
```
+#### Clang-format
+Individual targets in the build tree have their own dependency of the form `<<targetName>>-clangformat`, which uses the `clang-format` executable, wherever it is found, to format and modified files according to the rules specfied in the .clang-format file. This is helpful when submitting changes to geode-native, because an improperly formatted file will fail Travis-CI and have to be fixed prior to merging any pull request. If clang-format is not installed on your system, clangformat ta [...]
+
+To disable `clang-format` in the build:
+
+```
+$ cmake … -DClangFormat_EXECUTABLE='' …
+```
+
+On the other hand, it may also be desirable to run clang-format on the entire source tree. This is also easily done via the `all-clangformat` _in a build with clang-format enabled_. If clang-format has been disabled in the cmake configuration step, as above, the `all-clangformat` target will not exist, and the cmake configuration step will have to be re-run with clang-format enabled.
+
+To run clang-format on the entire source tree:
+
+```
+$ cmake --build . --target all-clangformat
+```
+
## Installing
By default a system-specific location is used by CMake as the destination of the `install` target, e.g., `/usr/local` on UNIX system. To explicitly specify the location in which the Native Client will be installed, add `-DCMAKE_INSTALL_PREFIX=/path/to/installation/destination` to the _initial_ `cmake` execution command.
diff --git a/cmake/ClangFormat.cmake b/cmake/ClangFormat.cmake
index 521b826..65e8651 100644
--- a/cmake/ClangFormat.cmake
+++ b/cmake/ClangFormat.cmake
@@ -17,6 +17,12 @@ set(ClangFormat_FLAGS "-style=file;-fallback-style=Google" CACHE STRING "Flags s
find_package(ClangFormat QUIET)
+add_custom_target(all-clangformat)
+set_target_properties(all-clangformat PROPERTIES
+ EXCLUDE_FROM_ALL TRUE
+ EXCLUDE_FROM_DEFAULT_BUILD TRUE
+ )
+
function(add_clangformat _target)
if (ClangFormat_FOUND)
if (NOT TARGET ${_target})
@@ -50,7 +56,6 @@ function(add_clangformat _target)
COMMENT "Clang-Format ${_source}"
COMMAND ${ClangFormat_EXECUTABLE} ${ClangFormat_FLAGS} -i ${_source_LOCATION}
COMMAND ${CMAKE_COMMAND} -E touch ${_format_file})
-
list(APPEND _clangformat_SOURCES ${_format_file})
endif ()
endforeach ()
@@ -62,6 +67,7 @@ function(add_clangformat _target)
)
set_target_properties(${_clangformat} PROPERTIES FOLDER clangformat)
add_dependencies(${_target} ${_clangformat})
+ add_dependencies(all-clangformat ${_clangformat})
endif ()
endif ()