aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmil Velikov <emil.velikov@collabora.com>2021-07-26 11:48:04 +0100
committerEmil Velikov <emil.l.velikov@gmail.com>2021-08-01 22:29:58 +0100
commitca13f88096d9973cedefddc27ed0b2732d30da70 (patch)
tree0df54a5b49502d7e28c3dbfe69d9ee7c91f6ddc5
parent8121720cd10f97643b2375e4d2208e46c2920ce9 (diff)
downloadwaffle-ca13f88096d9973cedefddc27ed0b2732d30da70.tar.gz
gitlab-ci: add clang-format stage
Add a small clang-format.sh script, to manage the merge-base commit against which we compare. The magic in there, is copied from the ci-fairy - huge thanks to the team behind it. Notes: - The clang-format-7 dependency tracking it busted across Debian releases - we need to add git explicitly - Don't block the build stage, on clang-format Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
-rw-r--r--.gitlab-ci.yml19
-rwxr-xr-x.gitlab-ci/clang-format.sh46
2 files changed, 64 insertions, 1 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b692dc6..7296817 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,6 +1,6 @@
variables:
FDO_UPSTREAM_REPO: mesa/waffle
- FDO_DISTRIBUTION_TAG: '2021-01-26_4'
+ FDO_DISTRIBUTION_TAG: '2021-07-26'
FDO_DISTRIBUTION_VERSION: 'buster-slim'
include:
@@ -10,6 +10,7 @@ include:
stages:
- container
+ - style-check
- build
- www
@@ -34,11 +35,14 @@ container:
FDO_DISTRIBUTION_PACKAGES: >
bash-completion
ca-certificates
+ clang-format-7
cmake
docbook-xsl
docbook-xml
g++
gcc
+ # w/a packaging bug: required for clang-format-7
+ git
libcmocka-dev
libdrm-dev
libegl1-mesa-dev
@@ -56,6 +60,19 @@ container:
xsltproc
xvfb
+clang-format:
+ extends:
+ - .ci-run-policy
+ - .fdo.container-build@debian
+ stage: style-check
+ variables:
+ GIT_DEPTH: 100
+ image: "$CI_REGISTRY_IMAGE/debian/$FDO_DISTRIBUTION_VERSION:$FDO_DISTRIBUTION_TAG"
+ needs:
+ - container
+ script:
+ - .gitlab-ci/clang-format.sh
+
# BUILD
.build:
extends:
diff --git a/.gitlab-ci/clang-format.sh b/.gitlab-ci/clang-format.sh
new file mode 100755
index 0000000..ceee6b1
--- /dev/null
+++ b/.gitlab-ci/clang-format.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+# vim: et sts=4 sw=4
+
+set -euo pipefail
+
+# The following approach was shamelessly copied from ci-fairy
+# https://gitlab.freedesktop.org/freedesktop/ci-templates/-/blob/master/tools/ci_fairy.py
+if [[ "${CI-}" ]]; then
+ upstream="${FDO_UPSTREAM_REPO-}"
+ if [[ ! "$upstream" ]]; then
+ echo "$FDO_UPSTREAM_REPO not set, using local branches to compare"
+ upstream="${CI_PROJECT_PATH}"
+ fi
+ host="${CI_SERVER_HOST}"
+ token="${CI_JOB_TOKEN}"
+ url="https://gitlab-ci-token:$token@$host/$upstream"
+
+ remote="clang-fairy"
+ if ! git remote | grep -qw "$remote"; then
+ git remote add "$remote" "$url"
+ fi
+ git fetch "$remote"
+ remote_prefix="$remote/"
+else
+ remote_prefix=""
+fi
+
+branch="${CI_MERGE_REQUEST_DIFF_BASE_SHA-}"
+[[ $branch ]] || branch="master"
+# End of the shameless copy
+
+# Older versions of clang-format like 6 and 7 print an annoying message.
+# "no modified files to format". Newer ones like 12 (earlier?), do not.
+formatting_changes=$(git-clang-format-7 --binary "clang-format-7" --commit "$remote_prefix$branch" -q --diff | grep -v "no modified files to format" || true)
+[[ "$formatting_changes" ]] || exit 0
+
+echo "ERROR: Formatting issues detected"
+echo
+echo "Update the codebase as indicated or disable clang-format locally."
+echo
+echo "Formatting suggestion:"
+echo
+echo -e "------------\n$formatting_changes\n------------"
+echo
+
+exit 1