forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reformat-cmake
executable file
·43 lines (35 loc) · 973 Bytes
/
reformat-cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
#
# @author René Schwaiger <sanssecours@me.com>
# @brief Reformats CMake source code
# @date 07.05.2018
# @tags reformat
SCRIPTS_DIR=$(dirname "$0")
. "${SCRIPTS_DIR}/include-common"
CMAKE_FORMAT=$(which cmake-format)
cd "$SOURCE"
if [ -z "${CMAKE_FORMAT}" ]; then
printf 2>&1 'Please install `cmake-format`\n'
exit 1
fi
output=$("${CMAKE_FORMAT}" 2>&1 CMakeLists.txt)
if [ $? != 0 ]; then
printf 2>&1 'It seems your local installation of `cmake-format` is broken:\n\n%s' "$output"
exit 1
fi
if [ -z "$(which sponge)" ]; then
printf 2>&1 'Please install `sponge`\n'
exit 1
fi
if [ $# -gt 0 ]; then
files=$(printf "%s\n" "$@" | grep -x -E '.*\.cmake|.*/CMakeLists.txt|CMakeLists.txt')
if [ -z "$files" ]; then
exit 0
fi
else
files=$(git ls-files '*.cmake' '*/CMakeLists.txt' 'CMakeLists.txt')
fi
printf "%s\n" "$files" | sed -nE 's/(.*)/'"'"'\1'"'"'/p' | xargs "$CMAKE_FORMAT" -i
for file in $files; do
unexpand "$file" | sponge "$file"
done