mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-08 11:19:16 +02:00
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 a6e085b3e8)
This commit is contained in:
parent
4ae41a8843
commit
92d2c0f7bc
3 changed files with 30 additions and 29 deletions
|
|
@ -49,7 +49,7 @@ Coding Style
|
||||||
|
|
||||||
The formatting is automated using [clang-format](https://clang.llvm.org/docs/ClangFormat.html).
|
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
|
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
|
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
|
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
|
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.
|
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,
|
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
|
but note that we then will automatically adjust your contribution before
|
||||||
|
|
|
||||||
|
|
@ -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"
|
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
|
ARGS=( "$@" )
|
||||||
for a; do
|
|
||||||
case "$a" in
|
|
||||||
-f)
|
|
||||||
RENEW=1
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
die "invalid argument \"$a\""
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
set -x
|
if ! podman image exists "$IMAGENAME" ; then
|
||||||
|
echo "Building image \"$IMAGENAME\"..."
|
||||||
if [ "$RENEW" == 1 ]; then
|
podman build \
|
||||||
if podman container exists "$PODNAME" ; then
|
--squash-all \
|
||||||
podman rm "$PODNAME"
|
--tag "$IMAGENAME" \
|
||||||
fi
|
-f <(cat <<EOF
|
||||||
|
FROM fedora:$FEDORA_VERSION
|
||||||
|
RUN dnf upgrade -y
|
||||||
|
RUN dnf install -y git /usr/bin/clang-format
|
||||||
|
EOF
|
||||||
|
)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! podman container exists "$PODNAME" ; then
|
CMD=( ./contrib/scripts/nm-code-format.sh "${ARGS[@]}" )
|
||||||
podman run \
|
|
||||||
--name="$PODNAME" \
|
|
||||||
-v "$DIR:/tmp/NetworkManager:Z" \
|
|
||||||
-w /tmp/NetworkManager \
|
|
||||||
"fedora:$FEDORA_VERSION" \
|
|
||||||
/bin/bash -c 'dnf upgrade -y && dnf install -y git /usr/bin/clang-format && ./contrib/scripts/nm-code-format.sh -i'
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
podman start -a "$PODNAME"
|
podman run \
|
||||||
|
--rm \
|
||||||
|
--name "nm-code-format-f$FEDORA_VERSION" \
|
||||||
|
-v "$DIR:/tmp/NetworkManager:Z" \
|
||||||
|
-w /tmp/NetworkManager \
|
||||||
|
-e "_NM_CODE_FORMAT_CONTAINER=$IMAGENAME" \
|
||||||
|
-ti \
|
||||||
|
"$IMAGENAME" \
|
||||||
|
"${CMD[@]}"
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,11 @@ usage() {
|
||||||
printf " -F|--fast Same as \`-u HEAD^\`.\n"
|
printf " -F|--fast Same as \`-u HEAD^\`.\n"
|
||||||
printf " --show-filenames Only print the filenames that would be checked/formatted\n"
|
printf " --show-filenames Only print the filenames that would be checked/formatted\n"
|
||||||
printf " -- Separate options from filenames/directories\n"
|
printf " -- Separate options from filenames/directories\n"
|
||||||
|
if [ -n "${_NM_CODE_FORMAT_CONTAINER+x}" ] ; then
|
||||||
|
printf "\n"
|
||||||
|
printf "Command runs inside container image \"$_NM_CODE_FORMAT_CONTAINER\".\n"
|
||||||
|
printf "Delete/renew image with \`podman rmi \"$_NM_CODE_FORMAT_CONTAINER\"\`.\n"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
ls_files_exist() {
|
ls_files_exist() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue