diff options
author | Thomas Haller <thaller@redhat.com> | 2023-07-25 13:28:45 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-07-25 13:34:49 (GMT) |
commit | 6baf233922eed48d64f07ae69ad3ec09df762e22 (patch) | |
tree | ef1606b7da26bf1ba5b520c1420e788f02fa1460 | |
parent | ee2876e3ad60bf316a897b48a0d0b84fab2adb0d (diff) | |
download | libnl-6baf233922eed48d64f07ae69ad3ec09df762e22.zip libnl-6baf233922eed48d64f07ae69ad3ec09df762e22.tar.gz libnl-6baf233922eed48d64f07ae69ad3ec09df762e22.tar.bz2 |
clang-format: add "tools/clang-format-container.sh" script
This helps somewhat with the problem, that we need the correct
version of clang-format for the formatting script.
The script runs a Fedora container. It needs a working podman setup.
-rwxr-xr-x | tools/clang-format-container.sh | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/clang-format-container.sh b/tools/clang-format-container.sh new file mode 100755 index 0000000..a9445e7 --- /dev/null +++ b/tools/clang-format-container.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +set -e + +die() { + echo "$@" >&2 + exit 1 +} + +DIR="$(realpath "$(dirname "$0")/../")" +cd "$DIR" + +# The correct clang-format version is the one from the Fedora version used in our +# github action pipeline. Parse it from ".github/workflows/ci.yml". +FEDORA_VERSION="$(sed -n 's/^ image: fedora:\([0-9]\+\)$/\1/p' .github/workflows/ci.yml)" + +test -n "$FEDORA_VERSION" || die "Could not detect the Fedora version in .github/workflows/ci.yml" + +PODNAME="libnl-code-format-f$FEDORA_VERSION" + +RENEW=0 +for a; do + case "$a" in + -f) + RENEW=1 + ;; + *) + die "invalid argument \"$a\"" + ;; + esac +done + +set -x + +if [ "$RENEW" == 1 ]; then + if podman container exists "$PODNAME" ; then + podman rm "$PODNAME" + fi +fi + +if ! podman container exists "$PODNAME" ; then + podman run \ + --name="$PODNAME" \ + -v "$DIR:/tmp/libnl3:Z" \ + -w /tmp/libnl3 \ + "fedora:$FEDORA_VERSION" \ + /bin/bash -c 'dnf upgrade -y && dnf install -y git /usr/bin/clang-format && tools/clang-format.sh -i' + exit 0 +fi + +podman start -a "$PODNAME" |