From 92d2c0f7bc08bd98cd6f1d76b65925f5dc018017 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 17 Nov 2023 20:22:53 +0100 Subject: [PATCH] clang-format: rework "nm-code-format-container.sh" script Instead of doing the broken `podman run` and `podman start` approach, build an image ("nm-code-format:f38"), cache it, and use it to run "nm-code-format.sh" via `podman run`. We should build and keep a container image, not a container. The benefit is that this allows to hand over the command line arguments to "nm-code-format.sh". In particular the "-u" and "-F" options, which are life savers. This means, $ contrib/scripts/nm-code-format-container.sh -u works. Try also $ contrib/scripts/nm-code-format-container.sh -h which tells you that you are running inside the container, and how to delete/renew the container image. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1798 (cherry picked from commit a6e085b3e8a86a446c68853db4b0a9aa88efe890) --- CONTRIBUTING.md | 3 +- contrib/scripts/nm-code-format-container.sh | 51 ++++++++++----------- contrib/scripts/nm-code-format.sh | 5 ++ 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4896fef989..f9b3dc02cb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,7 +49,7 @@ Coding Style The formatting is automated using [clang-format](https://clang.llvm.org/docs/ClangFormat.html). Run `./contrib/scripts/nm-code-format.sh -i` ([[1]](contrib/scripts/nm-code-format.sh)) to reformat -the code or run `clang-format` directly. +the code or run `clang-format` directly. Pass `--help` for the list of options. As the generated format depends on the version of clang-format, you need to use the correct clang-format version. That is basically the version that our [gitlab-ci @@ -58,6 +58,7 @@ for the "check-tree" test. This is the version from a recent Fedora installation You may also run `./contrib/scripts/nm-code-format-container.sh` which uses a Fedora container with podman and the correct version of clang-format. +This accepts the same arguments as `./contrib/scripts/nm-code-format.sh`. You are welcome to not bother and open a merge request with wrong formatting, but note that we then will automatically adjust your contribution before diff --git a/contrib/scripts/nm-code-format-container.sh b/contrib/scripts/nm-code-format-container.sh index e6584322d3..7a5ce0d466 100755 --- a/contrib/scripts/nm-code-format-container.sh +++ b/contrib/scripts/nm-code-format-container.sh @@ -16,36 +16,31 @@ FEDORA_VERSION="$(sed '/^ tier: 1/,/^ - name/!d' .gitlab-ci/config.yml | sed test -n "$FEDORA_VERSION" || die "Could not detect the Fedora version in .gitlab-ci/config.yml" -PODNAME="nm-code-format-f$FEDORA_VERSION" +IMAGENAME="nm-code-format:f$FEDORA_VERSION" -RENEW=0 -for a; do - case "$a" in - -f) - RENEW=1 - ;; - *) - die "invalid argument \"$a\"" - ;; - esac -done +ARGS=( "$@" ) -set -x - -if [ "$RENEW" == 1 ]; then - if podman container exists "$PODNAME" ; then - podman rm "$PODNAME" - fi +if ! podman image exists "$IMAGENAME" ; then + echo "Building image \"$IMAGENAME\"..." + podman build \ + --squash-all \ + --tag "$IMAGENAME" \ + -f <(cat <