diff options
author | Thomas Haller <thaller@redhat.com> | 2023-12-01 19:19:08 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-12-02 11:40:53 (GMT) |
commit | f33e8cd6834435b99d5927e52434205800128452 (patch) | |
tree | c4765be5f9071e7081705d35d0b728b40f974521 | |
parent | aea3f9f2d8b6ecf6b69df12ba4e99ca44d6813fb (diff) | |
download | libnl-f33e8cd6834435b99d5927e52434205800128452.zip libnl-f33e8cd6834435b99d5927e52434205800128452.tar.gz libnl-f33e8cd6834435b99d5927e52434205800128452.tar.bz2 |
clang-format: rework container script
Build a container image for the code formatting, and run that.
-rwxr-xr-x | tools/clang-format-container.sh | 57 | ||||
-rwxr-xr-x | tools/clang-format.sh | 5 |
2 files changed, 31 insertions, 31 deletions
diff --git a/tools/clang-format-container.sh b/tools/clang-format-container.sh index a9445e7..69a68b1 100755 --- a/tools/clang-format-container.sh +++ b/tools/clang-format-container.sh @@ -16,36 +16,31 @@ FEDORA_VERSION="$(sed -n 's/^ image: fedora:\([0-9]\+\)$/\1/p' .github/work 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 +IMAGENAME="libnl-code-format-f$FEDORA_VERSION" + +ARGS=( "$@" ) + +if ! podman image exists "$IMAGENAME" ; then + echo "Building image \"$IMAGENAME\"..." + podman build \ + --squash-all \ + --tag "$IMAGENAME" \ + -f <(cat <<EOF +FROM fedora:$FEDORA_VERSION +RUN dnf upgrade -y +RUN dnf install -y git /usr/bin/clang-format +EOF +) 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" +CMD=( ./tools/clang-format.sh "${ARGS[@]}" ) + +podman run \ + --rm \ + --name "libnm-code-format-f$FEDORA_VERSION" \ + -v "$DIR:/tmp/NetworkManager:Z" \ + -w /tmp/NetworkManager \ + -e "_LIBNL_CODE_FORMAT_CONTAINER=$IMAGENAME" \ + -ti \ + "$IMAGENAME" \ + "${CMD[@]}" diff --git a/tools/clang-format.sh b/tools/clang-format.sh index 1dcc8aa..6a0db2a 100755 --- a/tools/clang-format.sh +++ b/tools/clang-format.sh @@ -400,6 +400,11 @@ usage() { printf " -F|--fast Same as \`-u HEAD^\`.\n" printf " -l|--show-filenames Only print the filenames that would be checked/formatted\n" printf " -- Separate options from filenames/directories\n" + if [ -n "${_LIBNL_CODE_FORMAT_CONTAINER+x}" ] ; then + printf "\n" + printf "Command runs inside container image \"$_LIBNL_CODE_FORMAT_CONTAINER\".\n" + printf "Delete/renew image with \`podman rmi \"$_LIBNL_CODE_FORMAT_CONTAINER\"\`.\n" + fi } ls_files_exist() { |