Skip to content

Commit

Permalink
[eclipse-wakaamaGH-574] ci: Configure and integrate cmake-format
Browse files Browse the repository at this point in the history
cmake-format ensures that our CMake code adheres to the format accepted
by cmake-format.

The code style is based on default one, with some minor adjustments.
  • Loading branch information
rettichschnidi committed Jan 30, 2022
1 parent 63602c6 commit 100d941
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
21 changes: 21 additions & 0 deletions .cmake-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
with section("format"):
# How wide to allow formatted cmake files
line_width = 120

# How many spaces to tab for indent
tab_size = 4

# Smaller diffs: If a statement is wrapped to more than one line, then dangle
# the closing parenthesis on its own line.
dangle_parens = True

# Settling cross platform disputes: What style line endings to use in the
# output.
line_ending = 'unix'

# Format keywords consistently as 'upper case
keyword_case = 'upper'

with section("markup"):
# What character to use for bulleted lists
bullet_char = '-'
6 changes: 5 additions & 1 deletion .github/workflows/compliance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
run: |
sudo apt update
sudo apt -qy --no-install-recommends install clang-format-10
pip3 install gitlint
pip3 install -r tools/requirements-compliance.txt
- name: Check commits with gitlint
run: |
Expand All @@ -27,6 +27,10 @@ jobs:
run: |
tools/ci/run_ci.sh --branch-target origin/${{ github.base_ref }} --run-clang-format
- name: Check CMakeLists.txt files with cmake-lint
run: |
tools/ci/run_ci.sh --run-cmake-lint
- name: Check Python code with pylint
run: |
cd tests
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ LWM2M_CLIENT_MODE and LWM2M_SERVER_MODE can be defined at the same time.
- Git commit message linter: gitlint
- Build system: ninja
- C code formatting: clang-format, version 10
- CMake list files formatting: cmake-format, version 0.6.13
- Unit testing: CUnit

On Ubuntu 20.04, used in CI, the dependencies can be installed as such:
- `apt install build-essential clang-format clang-format-10 clang-tools-10 cmake gcovr git libcunit1-dev ninja-build python3-pip`
- `pip3 install gitlint`
- `pip3 install -r tools/requirements-compliance.txt`

### Code formatting
New code must be formatted with [clang-format](https://clang.llvm.org/docs/ClangFormat.html).
Expand Down
20 changes: 18 additions & 2 deletions tools/ci/run_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ OPT_WRAPPER_CMD=""
RUN_BUILD=0
RUN_CLANG_FORMAT=0
RUN_CLEAN=0
RUN_CMAKE_LINT=0
RUN_GITLINT=0
RUN_GIT_BLAME_IGNORE=0
RUN_TESTS=0
Expand Down Expand Up @@ -69,9 +70,10 @@ Options:
Available steps (executed by --all):
--run-gitlint Check git commits with gitlint
--run-clang-format Check code formatting with clang-format
--run-clang-format Check C code formatting
--run-git-blame-ignore Validate .git-blame-ignore-revs
--run-clean Remove all build artifacts
--run-cmake-lint Check CMake files formatting
--run-build Build all targets
--run-tests Build and execute tests
"
Expand Down Expand Up @@ -101,13 +103,17 @@ function run_clang_format() {
exit 1
fi

echo "No code formatting errors found"
echo "No C code formatting errors found"
}

function run_clean() {
rm -rf build-wakaama
}

function run_cmake_lint() {
git ls-files '*CMakeLists.txt' '*.cmake' | xargs cmake-lint
}

function run_gitlint() {
commits="${OPT_BRANCH_TARGET}...${OPT_BRANCH_SOURCE}"

Expand Down Expand Up @@ -195,6 +201,7 @@ if ! PARSED_OPTS=$(getopt -o vah \
-l run-build \
-l run-clang-format \
-l run-clean \
-l run-cmake-lint \
-l run-gitlint \
-l run-git-blame-ignore \
-l run-tests \
Expand Down Expand Up @@ -240,6 +247,10 @@ while true; do
RUN_CLEAN=1
shift
;;
--run-cmake-lint)
RUN_CMAKE_LINT=1
shift
;;
--run-build)
RUN_BUILD=1
shift 1
Expand Down Expand Up @@ -287,6 +298,7 @@ while true; do
-a|--all)
RUN_CLANG_FORMAT=1
RUN_CLEAN=1
RUN_CMAKE_LINT=1
RUN_GITLINT=1
RUN_GIT_BLAME_IGNORE=1
RUN_BUILD=1
Expand Down Expand Up @@ -362,6 +374,10 @@ if [ "${RUN_CLEAN}" -eq 1 ]; then
run_clean
fi

if [ "${RUN_CMAKE_LINT}" -eq 1 ]; then
run_cmake_lint
fi

if [ "${RUN_BUILD}" -eq 1 ]; then
run_build
fi
Expand Down
4 changes: 4 additions & 0 deletions tools/requirements-compliance.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake-format
gitlint
pylint
-r ../tests/integration/requirements.txt

0 comments on commit 100d941

Please sign in to comment.