Enforce C/C++ code style across postmarketOS repositories
We had enforced C code linting across all .c files in pmaports.git (pmaports!465). Later we decided to split the sources into their own repositories (which makes sense), but now we don't enforce a consistent code style. This is also the case for osk-sdl for example, for which the source never was part of pmaports.git.
The goal is to make it easy to integrate the check in all project's .gitlab-ci.yml
:
clang-format:
before_script:
- apk -q add git
- git clone -q --depth=1 "https://gitlab.postmarketos.org/postmarketos/ci-common.git"
script:
- ci-common/clang-format/ci_run.sh
To implement this, I suggest to fork ci-common.git and osk-sdl.git. Add it to osk-sdl.git's .gitlab-ci.yml, but change the clone path to point to your fork.
In ci-common.git
, let's add a new subdirectory:
clang-format/
clang-format.sh
.clang-format
ci_run.sh
clang-format.sh
and .clang-format
should be based on pmaports!465. Extend clang-format.sh
to find the clang-format file from the subdir, and to work with c++ files too.
ci_run.sh
should do apk -q add clang
(so we can easily adjust dependencies if necessary) and execute clang-format.sh.
EDIT: bonus points for a CI test, that runs in ci-common.git and verifies that clang-format.sh does its job. We can do that with example files, which we put in clang-format/test/valid.c and clang-format/test/invalid.c.