Skip to content

Commit

Permalink
clang-format: rework container script
Browse files Browse the repository at this point in the history
Build a container image for the code formatting, and run that.
  • Loading branch information
thom311 committed Dec 2, 2023
1 parent aea3f9f commit f33e8cd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
57 changes: 26 additions & 31 deletions tools/clang-format-container.sh
Expand Up @@ -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[@]}"
5 changes: 5 additions & 0 deletions tools/clang-format.sh
Expand Up @@ -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() {
Expand Down

0 comments on commit f33e8cd

Please sign in to comment.