The open source OpenXR runtime
1#!/bin/sh
2# Copyright 2019, Collabora, Ltd.
3# SPDX-License-Identifier: BSL-1.0
4# Author: Rylie Pavlik <rylie.pavlik@collabora.com>
5
6# Run both format-project and codespell-project, making a patch if any changes can be auto-made.
7# Intended mainly for use in CI, but can be used elsewhere.
8
9set -e
10PATCH_DIR=patches
11PATCH_NAME=fixes.diff
12(
13 cd $(dirname $0)
14
15 # Exit if working tree dirty or uncommitted changes staged.
16 if ! git diff-files --quiet; then
17 echo "ERROR: Cannot perform check/fix, working tree dirty."
18 exit 2
19 fi
20 if ! git diff-index --quiet HEAD -- ; then
21 echo "ERROR: Cannot perform check/fix, changes staged but not committed."
22 exit 2
23 fi
24
25
26 echo "Running codespell..."
27 echo
28 if ./codespell-project.sh; then
29 # No errors, or only errors that could be auto-fixed. e.g. "g a r a n t e e" (remove spaces)
30 CODESPELL_RESULT=true
31 else
32 # At least one non-auto-fixable error. e.g. "a o t h e r" (remove spaces)
33 echo
34 echo "Codespell found at least one issue it couldn't auto-fix, see preceding."
35 echo "If the issue isn't actually a problem, edit IGNORE_WORDS_LIST in $(dirname $0)/codespell-project.sh"
36 echo "Otherwise, you may run \`$(dirname $0)/codespell-project.sh -i 3\` locally to interactively fix."
37 echo
38 CODESPELL_RESULT=false
39 fi
40
41
42 echo "Running clang-format..."
43 echo
44 ./format-project.sh
45
46 echo "Running cmake-format..."
47 echo
48 ./format-cmake.sh
49
50
51 (
52 cd ..
53 mkdir -p $PATCH_DIR
54 # Can't use tee because it hides the exit code
55 if git diff --patch --exit-code > $PATCH_DIR/$PATCH_NAME; then
56 echo
57 echo "clang-format, cmake-format and codespell changed nothing."
58 else
59 echo
60 echo "clang-format and/or codespell made at least one change, please apply the patch in the job artifacts and seen below!"
61 echo "If codespell made a change in error, edit IGNORE_WORDS_LIST in $(dirname $0)/codespell-project.sh"
62 echo
63 echo "---------------------------------------"
64 cat $PATCH_DIR/$PATCH_NAME
65 echo "---------------------------------------"
66
67 exit 1
68 fi
69
70 # It's possible that nobody made a change but codespell found an issue it couldn't auto-fix
71 if ${CODESPELL_RESULT}; then
72 echo "No manual changes required."
73 else
74 echo "However, manual changes to fix the codespell issue(s) required."
75 exit 1
76 fi
77 )
78
79)