Commit Graph

22 Commits

Author SHA1 Message Date
Thomas Haller
a6e085b3e8 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
2023-11-22 13:25:04 +01:00
Thomas Haller
cae2011b08 contrib: show clang-format version in failure message
The actual formatting depends on the version of clang-format. Print the
used version, which is in particular interesting when we get an error in
our gitlab-ci check (which uses the correct version).
2023-04-18 19:05:02 +02:00
Thomas Haller
5973e83160 systemd: merge branch systemd into main
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1529
2023-02-13 15:33:02 +01:00
Thomas Haller
2f8bb7c86a contrib: handle non-existing files with nm-code-format.sh -u
"-u" calls `git diff -name-only $UPSTREAM` to get a list of files.
However, if $UPSTREAM contains a file that doesn't exist in the current
checkout, we get a non-existing file name and clang-format will fail.

Avoid that, by filtering only files that exist.

Also, pass "--no-renames" option to git-diff.
2022-09-23 15:32:28 +02:00
Thomas Haller
6e0ede9d65 contrib: add "nm-code-format.sh -u" parameter
Reformatting the entire source tree takes quite long. For fast
development it's useful to only check the files that changes on the
current checkout.

For that there was already the "-F|--fast" option, but that only
compared the files that changed compared to HEAD^.

What actually would be useful is to check the files that changed on the
current branch, compared to some upstream commit. Add "-u|--upstream"
option to specify the upstream commit (usually "main").

As a special twist,

  ./contrib/scripts/nm-code-format.sh -u

is the same as

  ./contrib/scripts/nm-code-format.sh -u main
2022-09-21 10:22:32 +02:00
Thomas Haller
90b267afa7 contrib: add "--fast" flag to nm-core-format.sh to only check changed files
It's not the default, because a caller might not be aware that this flag
exists, and when calling the script without arguments, it should do
correct (albeit slow) thing.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1341
2022-08-24 12:06:34 +02:00
Thomas Haller
670894b667 contrib: fix wrong usage text for "nm-code-format.sh" 2022-04-01 13:51:56 +02:00
Thomas Haller
3e80b4fa63 contrib: reformat by default from "nm-code-format.sh" script
The majority of times when I call this script, I want it to do the reformatting,
not the check-only mode. This is also because we use git, so I start with a
clean working directory and run the reformatting code. In the best case, there
is nothing to reformat, and all is good. I seldom want to only check.

Change the default of the script.
2021-09-16 09:01:50 +02:00
Thomas Haller
4c007c4c27 contrib: fix "nm-code-format.sh" to select files to format
There was always the idea that you could pass paths and filenames
to "nm-code-format.sh" to format only a subset. However, the script
also needs to honor files that should be excluded and don't need
formatting.

Previously, what was implemented via `git ls-files -- ':(exclude)...'`
command, but git-ls-files has a bug ([1]) and might not list all files.

Refactor and do the filtering ourselves.

[1] https://www.spinics.net/lists/git/msg397982.html
2021-09-15 22:08:13 +02:00
Thomas Haller
023c8ad88b code-format: exclude "src/linux-headers" from "nm-code-format.sh" script 2021-09-06 10:00:35 +02:00
Thomas Haller
6439c243e7 systemd: move "src/core/systemd" to "src/libnm-systemd-core"
This follows the recently introduced naming scheme and directory layout.
"libnm-systemd-core" is an independent component, and as such should no
be inside "src/core/".

Move it.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/875
2021-05-30 09:45:05 +02:00
Thomas Haller
3906cc9cf4 build: move c-util/nettools library from "shared/" to "src/" 2021-02-24 12:48:28 +01:00
Thomas Haller
a8c34b9dcf build: move "shared/nm-std-aux" to "src/libnm-std-aux" 2021-02-24 12:48:24 +01:00
Thomas Haller
39225258d6 build: move "shared/systemd" to "src/libnm-systemd-shared" 2021-02-24 12:48:16 +01:00
Thomas Haller
ac1a9e03e4 all: move "src/" directory to "src/core/"
Currently "src/" mostly contains the source code of the daemon.
I say mostly, because that is not true, there are also the device,
settings, wwan, ppp plugins, the initrd generator, the pppd and dhcp
helper, and probably more.

Also we have source code under libnm-core/, libnm/, clients/, and
shared/ directories. That is all confusing.

We should have one "src" directory, that contains subdirectories. Those
subdirectories should contain individual parts (libraries or
applications), that possibly have dependencies on other subdirectories.
There should be a flat hierarchy of directories under src/, which
contains individual modules.

As the name "src/" is already taken, that prevents any sensible
restructuring of the code.

As a first step, move "src/" to "src/core/". This gives space to
reorganize the code better by moving individual components into "src/".

For inspiration, look at systemd's "src/" directory.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/743
2021-02-04 09:45:55 +01:00
Thomas Haller
8e735a51b8 contrib: handle no files in "nm-code-format.sh"
Calling `clang-format` with no files means to read
stdin, it thus hangs:

   $ ./contrib/scripts/nm-code-format.sh .git

Also, the following does not work:

   $ ./contrib/scripts/nm-code-format.sh src/platform/

hangs. Seems there is a bug in `git ls-files` to not list all files:

   podman run -ti alpine:latest \
      sh -c '
         apk add git &&
         git clone https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git &&
         cd NetworkManager &&
         git checkout -B tmp cd754680a6 &&
         echo ">>>>>>BAD1: $PWD" &&
         git ls-files -- src/platform/ ":(exclude)shared/n-acd"
         echo ">>>>>>GOOD1: $PWD" &&
         git ls-files -- src/platform/ ":(exclude)shared/c-list"
         echo ">>>>>>GOOD2: $PWD" &&
         git ls-files -- src/platform ":(exclude)shared/n-acd"
         echo ">>>>>>GOOD3: $PWD" &&
         git ls-files -- src/vpn/ ":(exclude)shared/n-acd"
      '

Fixes: 9bef4ece92 ('contrib: improve nm-code-format.sh script')
2021-01-13 16:49:09 +01:00
Thomas Haller
9bef4ece92 contrib: improve nm-code-format.sh script
- accept directory names in the command line. In that case,
  still honor the excluded files. That is a major improvement
  for me, because I usually only want to reformat a directory
  that I know has changed and it is fast to only process some
  directories.

- pass all files at once to clang-format. For me that gives
  a significant speed improvement (about 3 times faster), although
  clang-format is only single threaded. Possibly clang-format could
  even be faster by checking files in parallel.
  In case of a style error, the script still falls back to
  iterate over all files to find the first bad file and print
  the full diff. But that is considered an unusual case.

- make it correctly work from calling it from a subdirectory.
  In that case, we only check files inside that directory --
  but still correctly honor the excluded files.
2021-01-13 12:57:48 +01:00
Thomas Haller
d1f8e843d5 shared: don't clang-format "shared/nm-std-aux/unaligned.h"
"shared/nm-std-aux/unaligned.h" is taken from systemd and frequently
re-imported via the "systemd" branch.

It is not our code, and should not be formatted with our clang-format.
2021-01-05 09:37:02 +01:00
Thomas Haller
d07cd5dbf2 all: avoid GNU "which" from shell scripts
"which" is a separate package and may not be installed.
Also, shell has a built-in command for the same purpose.
Use that.
2020-12-11 16:42:23 +01:00
Thomas Haller
8435deecfa contrib: let "nm-code-format.sh" handle files under ./{shared,src}/systemd/
Only the files under ./{shared,src}/systemd/src are copied from systemd.
The other files should be reformatted too.
2020-09-28 20:01:23 +02:00
Antonio Cardace
5119d00374 scripts: better error message for nm-code-format.sh
Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-02 19:20:36 +02:00
Antonio Cardace
715392a45e scripts: add script to format codebase using clang-format
Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-02 17:31:42 +02:00