Commit 77185029 authored by Ben Boeckel's avatar Ben Boeckel
Browse files

clang-format: add version-variable clang-format script

parent 1557bcef
......@@ -8,6 +8,8 @@ foreach(v
add_formatter(clang-format-${v} reformat clang-format-${v})
set_property(GLOBAL PROPERTY "formatter_clang-format-${v}_exclude_from_all" "1")
endforeach()
add_formatter(clang-format reformat clang-format)
set_property(GLOBAL PROPERTY "formatter_clang-format_exclude_from_all" "1")
add_formatter(clang-format-kwsys reformat clang-format-3.8)
set_property(GLOBAL PROPERTY "formatter_clang-format-kwsys_exclude_from_all" "1")
add_formatter(uncrustify reformat uncrustify)
......
#!/bin/sh
# This formatter uses the `clang-format` tool to perform
# formatting of files written in C, C++, and other C-like
# languages (CUDA, GLSL, etc.).
#
# It uses the `clang-format` executable in `$PATH` and checks for
# the existence of the `.clang-format` file as its configuration.
set -e
readonly path="$1"
shift
if [ "$#" -ne 0 ]; then
readonly version="-$1"
shift
else
version=""
fi
readonly value
if ! [ -f "$path" ]; then
echo >&2 'error: could not find file to format: '"$path"
exit 4
fi
if ! which "clang-format$version" > /dev/null; then
echo >&2 'error: could not find the `clang-format'"$version"'` binary'
exit 3
fi
if ! [ -f ".clang-format" ]; then
echo >&2 'error: the `.clang-format` file is missing'
exit 2
fi
exec "clang-format$version" -i "$path"
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)
int main(int argc, char *argv[]) {
return 0;
}
int main(int argc, char *argv[]) {
return 0;
}
int main(int argc, char *argv[]) { return 0; }
int main(int argc, char *argv[]) { return 0; }
int main(int argc, char *argv[]) { return 0; }
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