Commit dd08e8e3 authored by Brad King's avatar Brad King
Browse files

clang-format: rename to clang-format-3.8

Formatting depends on the version of the tool used, so define
the formatter based on that version.
parent 182454db
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