Commit 180e9acc authored by Ben Boeckel's avatar Ben Boeckel Committed by Kitware Robot
Browse files

Merge topic 'format-all-reformatters-only'

ff45a371 format.all: silence the git binary
99852f31 cmake: install format.all as a program
cf2663ec cmake: indicate the type of each formatter
49f89ea8

 cmake: simplify a variable name
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Brad King's avatarBrad King <brad.king@kitware.com>
Merge-request: !5
parents 4af2b393 ff45a371
function (add_formatter name) function (add_formatter name type)
if (type STREQUAL "check")
elseif (type STREQUAL "reformat")
else ()
message(FATAL_ERROR
"The formatter type of ${name} must be either `check` or `reformat`.")
endif ()
set_property(GLOBAL APPEND
PROPERTY "formatter_${name}_type" "${type}")
set(tools_exist TRUE) set(tools_exist TRUE)
foreach (tool IN LISTS ARGN) foreach (tool IN LISTS ARGN)
find_program("TOOL_${tool}" find_program("TOOL_${tool}"
...@@ -59,9 +69,16 @@ if (formatters) ...@@ -59,9 +69,16 @@ if (formatters)
continue () continue ()
endif () endif ()
get_property("format_${formatter}_script" GLOBAL # Do not reformat with check-only tools.
get_property(formatter_type GLOBAL
PROPERTY "formatter_${formatter}_type")
if (NOT formatter_type STREQUAL "reformat")
continue ()
endif ()
get_property("formatter_script" GLOBAL
PROPERTY "formatter_${formatter}_script") PROPERTY "formatter_${formatter}_script")
string(APPEND formatters_build "format_all '${formatter}' '${format_${formatter}_script}'\n") string(APPEND formatters_build "format_all '${formatter}' '${formatter_script}'\n")
string(APPEND formatters_install "format_all '${formatter}' 'format.${formatter}'\n") string(APPEND formatters_install "format_all '${formatter}' 'format.${formatter}'\n")
endforeach () endforeach ()
...@@ -77,7 +94,7 @@ if (formatters) ...@@ -77,7 +94,7 @@ if (formatters)
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/format.all" "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/format.all"
@ONLY) @ONLY)
install( install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/format.all" PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/format.all"
DESTINATION "bin" DESTINATION "bin"
COMPONENT "formatters") COMPONENT "formatters")
endif () endif ()
add_formatter(clang-format clang-format) add_formatter(clang-format reformat clang-format)
...@@ -14,7 +14,7 @@ if ! which "parallel" > /dev/null; then ...@@ -14,7 +14,7 @@ if ! which "parallel" > /dev/null; then
exit 3 exit 3
fi fi
if ! git rev-parse --is-inside-work-tree; then if ! git rev-parse --is-inside-work-tree > /dev/null; then
echo >&2 'error: this must be run from inside of a Git work tree' echo >&2 'error: this must be run from inside of a Git work tree'
exit 1 exit 1
fi fi
......
add_formatter(autopep8 autopep8) add_formatter(autopep8 reformat autopep8)
add_formatter(pep8 pep8) add_formatter(pep8 check pep8)
add_formatter(flake8 flake8) add_formatter(flake8 check flake8)
add_formatter(rustfmt rustfmt) add_formatter(rustfmt reformat rustfmt)
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