osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ci/+/39796?usp=email )
Change subject: lint/lint_diff: run clang-format if config was found ......................................................................
lint/lint_diff: run clang-format if config was found
The osmo-asf4-dfu and osmo-ccid-firmware now have clang-format configs. Adjust the lint script to run clang-format if such a config is found in the repository for which the lint script is running.
Change-Id: Ie210966ebfbada43dd8507b9b48218df4925820d --- M lint/lint_diff.sh 1 file changed, 20 insertions(+), 0 deletions(-)
Approvals: laforge: Looks good to me, but someone else must approve pespin: Looks good to me, but someone else must approve osmith: Looks good to me, approved Jenkins Builder: Verified
diff --git a/lint/lint_diff.sh b/lint/lint_diff.sh index 9458ca7..60fd8b1 100755 --- a/lint/lint_diff.sh +++ b/lint/lint_diff.sh @@ -46,6 +46,25 @@ fi }
+test_clang_format() { + if ! [ -e ".clang-format" ] || ! command -v clang-format >/dev/null; then + return + fi + + echo "Running clang-format on 'git diff $COMMIT'..." + echo + + # Run clang-format-diff and colorize its output + local diff="$(git diff -U0 --relative "$COMMIT" \ + | clang-format-diff -p1 \ + | sed 's/^-/\x1b[41m-/;s/^+/\x1b[42m+/;s/^@/\x1b[34m@/;s/$/\x1b[0m/')" + + if ! [ -z "$diff" ]; then + ERROR=1 + echo "$diff" + fi +} + show_error() { echo echo "Please fix the linting errors above. More information:" @@ -86,6 +105,7 @@ set_commit test_docker_run_rm test_checkpatch +test_clang_format
if [ "$ERROR" = 1 ]; then show_error