Commit 3fff801d authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'clang-format-3.8'

dd08e8e3 clang-format: rename to clang-format-3.8
182454db

 cmake: teach add_formatter to support configured formatters
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !10
parents a3a0f318 dd08e8e3
...@@ -19,12 +19,18 @@ function (add_formatter name type) ...@@ -19,12 +19,18 @@ function (add_formatter name type)
endif () endif ()
endforeach () endforeach ()
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/format.${name}")
set(script "${CMAKE_CURRENT_BINARY_DIR}/format.${name}")
else()
set(script "${CMAKE_CURRENT_SOURCE_DIR}/format.${name}")
endif()
set_property(GLOBAL APPEND set_property(GLOBAL APPEND
PROPERTY formatters "${name}") PROPERTY formatters "${name}")
set_property(GLOBAL APPEND set_property(GLOBAL APPEND
PROPERTY "formatter_${name}_tools" "${tools_exist}") PROPERTY "formatter_${name}_tools" "${tools_exist}")
set_property(GLOBAL APPEND set_property(GLOBAL APPEND
PROPERTY "formatter_${name}_script" "${CMAKE_CURRENT_SOURCE_DIR}/format.${name}") PROPERTY "formatter_${name}_script" "${script}")
option("ENABLE_${name}" "Install the ${tool} formatter script" "${tools_exist}") option("ENABLE_${name}" "Install the ${tool} formatter script" "${tools_exist}")
...@@ -41,12 +47,18 @@ function (add_formatter name type) ...@@ -41,12 +47,18 @@ function (add_formatter name type)
endfunction () endfunction ()
function (install_formatter name) function (install_formatter name)
get_property(script GLOBAL PROPERTY "formatter_${name}_script")
install( install(
PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/format.${name}" PROGRAMS "${script}"
DESTINATION "bin" DESTINATION "bin"
COMPONENT "formatters") COMPONENT "formatters")
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${name}.yaml.in")
set(yaml_in "${CMAKE_CURRENT_BINARY_DIR}/${name}.yaml.in")
else()
set(yaml_in "${CMAKE_CURRENT_SOURCE_DIR}/${name}.yaml.in")
endif()
configure_file( configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/${name}.yaml.in" "${yaml_in}"
"${CMAKE_CURRENT_BINARY_DIR}/${name}.yaml" "${CMAKE_CURRENT_BINARY_DIR}/${name}.yaml"
@ONLY) @ONLY)
install( install(
......
add_formatter(clang-format reformat clang-format) foreach(v
add_formatter(clang-format-kwsys reformat clang-format) 3.8
)
set(ver ${v})
configure_file(format.clang-format.in format.clang-format-${v} @ONLY)
configure_file(clang-format.yaml.in clang-format-${v}.yaml.in COPYONLY)
add_formatter(clang-format-${v} reformat clang-format-${v})
endforeach()
add_formatter(clang-format-kwsys reformat clang-format-3.8)
formatter_clang-format: formatter_clang-format:
kind: "clang-format" kind: "clang-format"
script: "@CMAKE_INSTALL_PREFIX@/bin/format.clang-format" script: "@script@"
config_files: config_files:
- ".clang-format" - ".clang-format"
#!/bin/sh #!/bin/sh
# This formatter is meant specifically for the KWSys project. # This formatter is meant specifically for the KWSys project.
# It performs special filtering before and after running # It performs special filtering before and after running
# `clang-format` in order to protect `@KWSYS_NAMESPACE@` # `clang-format-3.8` in order to protect `@KWSYS_NAMESPACE@`
# and other placholders using `@`. # and other placholders using `@`.
# #
# This formatter uses the `clang-format` tool to perform # This formatter uses the `clang-format-3.8` tool to perform
# formatting of files written in C, C++, and other C-like # formatting of files written in C, C++, and other C-like
# languages (CUDA, GLSL, etc.). # languages (CUDA, GLSL, etc.).
# #
# It uses the `clang-format` executable in `$PATH` and checks for # It uses the `clang-format-3.8` executable in `$PATH` and checks for
# the existence of the `.clang-format` file as its configuration. # the existence of the `.clang-format` file as its configuration.
set -e set -e
...@@ -21,8 +21,8 @@ if ! [ -f "$path" ]; then ...@@ -21,8 +21,8 @@ if ! [ -f "$path" ]; then
exit 4 exit 4
fi fi
if ! which "clang-format" > /dev/null; then if ! which "clang-format-3.8" > /dev/null; then
echo >&2 'error: could not find the `clang-format` binary' echo >&2 'error: could not find the `clang-format-3.8` binary'
exit 3 exit 3
fi fi
...@@ -35,7 +35,7 @@ fi ...@@ -35,7 +35,7 @@ fi
# clang-format can understand the symbols and preserve lengths. # clang-format can understand the symbols and preserve lengths.
sed -i 's/@\(KWSYS_[A-Z0-9_]\+\)@/x\1x/g' "$path" sed -i 's/@\(KWSYS_[A-Z0-9_]\+\)@/x\1x/g' "$path"
clang-format -i "$path" clang-format-3.8 -i "$path"
# Restore the original `@KWSYS_...@` placeholders. # Restore the original `@KWSYS_...@` placeholders.
sed -i 's/x\(KWSYS_[A-Z0-9_]\+\)x/@\1@/g' "$path" sed -i 's/x\(KWSYS_[A-Z0-9_]\+\)x/@\1@/g' "$path"
#!/bin/sh #!/bin/sh
# This formatter uses the `clang-format` tool to perform # This formatter uses the `clang-format-@ver@` tool to perform
# formatting of files written in C, C++, and other C-like # formatting of files written in C, C++, and other C-like
# languages (CUDA, GLSL, etc.). # languages (CUDA, GLSL, etc.).
# #
# It uses the `clang-format` executable in `$PATH` and checks for # It uses the `clang-format-@ver@` executable in `$PATH` and checks for
# the existence of the `.clang-format` file as its configuration. # the existence of the `.clang-format` file as its configuration.
set -e set -e
...@@ -16,8 +16,8 @@ if ! [ -f "$path" ]; then ...@@ -16,8 +16,8 @@ if ! [ -f "$path" ]; then
exit 4 exit 4
fi fi
if ! which "clang-format" > /dev/null; then if ! which "clang-format-@ver@" > /dev/null; then
echo >&2 'error: could not find the `clang-format` binary' echo >&2 'error: could not find the `clang-format-@ver@` binary'
exit 3 exit 3
fi fi
...@@ -26,4 +26,4 @@ if ! [ -f ".clang-format" ]; then ...@@ -26,4 +26,4 @@ if ! [ -f ".clang-format" ]; then
exit 2 exit 2
fi fi
exec clang-format -i "$path" exec clang-format-@ver@ -i "$path"
add_formatter_test(clang-format-3.8 pass format.c pass)
add_formatter_test(clang-format-3.8 format format.c format)
add_formatter_test(clang-format-3.8 no-config-file format.c fail)
add_formatter_test(clang-format pass format.c pass)
add_formatter_test(clang-format format format.c format)
add_formatter_test(clang-format no-config-file format.c fail)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment