File: cmake-format.sh

package info (click to toggle)
freerdp3 3.22.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 68,600 kB
  • sloc: ansic: 413,510; cpp: 17,376; xml: 1,721; python: 1,155; sh: 783; lisp: 408; perl: 231; cs: 191; makefile: 111
file content (37 lines) | stat: -rwxr-xr-x 1,012 bytes parent folder | download | duplicates (3)
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
#!/bin/bash -e

SCRIPT_PATH=$(dirname "${BASH_SOURCE[0]}")
SCRIPT_PATH=$(realpath "$SCRIPT_PATH")
SRC_PATH="${SCRIPT_PATH}/.."

FORMAT_ARG="--check"
REST_ARGS=$@
if [ $# -ne 0 ]; then
  if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
    echo "usage: $0 [options] [file, file, ...]"
    echo "\t--check.-c  ... run format check only, no files changed (default)"
    echo "\t--format,-f ... format files in place"
    echo "\t--help,-h   ... print this help"

    exit 1
  fi

  if [ "$1" = "--check" ] || [ "$1" = "-c" ]; then
    FORMAT_ARG="--check"
    REST_ARGS="${@:2}"
  fi
  if [ "$1" = "--format" ] || [ "$1" = "-f" ]; then
    FORMAT_ARG="-i"
    REST_ARGS="${@:2}"
  fi
fi

if [ ! -n "$REST_ARGS" ]; then
  CMAKE_FILES=$(find ${SRC_PATH} -name "*.cmake" -o -name "CMakeLists.txt")
  CMAKE_CI_FILES=$(find ${SRC_PATH}/ci -name "*.txt")
fi

for FILE in $CMAKE_FILES $CMAKE_CI_FILES $REST_ARGS; do
  echo "processing file $FILE..."
  cmake-format -c "$SCRIPT_PATH/cmake-format.yml" $FORMAT_ARG $FILE
done