cmake-lint-test.sh 1.39 KB
Newer Older
1
2
3
4
5
#!/bin/bash

# Format all CMake-like files with cmake-format
# Determine the applied differences with git,
# return 1 when changes had to be made, so the CI step fails.
6
7
8
9
10
11
12
 
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

13
files=($(git diff origin/master --name-only --diff-filter=d | egrep ".+(CMakeLists.txt|\.cmake(\.in)?)$"))
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
if (( ${#files[@]} )); then
    cmake_lint_tool=false 
    if command -v "cmake-lint" >/dev/null 2>&1; then
        cmake_lint_tool=cmake-lint 
    else 
        echo -e "[${RED}FAIL${NC}]: cmake-lint is not available, but CMake files need linting! Please install cmake-format"
        exit 1 
    fi 
     
    echo -e "[${BLUE}INFO${NC}]: Formatting check with: `$cmake_lint_tool --version`"
    echo -e "[${BLUE}INFO${NC}]: Running '$cmake_lint_tool -l error' on files..." 
     
    if ! "$cmake_lint_tool" -l error "${files[@]}"; then
        echo -e "[${RED}FAIL${NC}]: Ups, something isn't correct with the formatting, please check above errors" 
        echo -e "[${BLUE}INFO${NC}]: From the root directory you can also run:"
        echo "find elsa benchmarks examples tools cmake -name '*.cmake' -o -name 'CMakeLists.txt' | xargs $cmake_lint_tool -l error" 
        exit 1 
    else
        echo -e "[${GREEN}OK${NC}]: Excellent. Formatting check passed" 
    fi 
else 
    echo -e "[${GREEN}OK${NC}]: No CMake files to check" 
fi