Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Add git-clang-format #595

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
Language: Cpp
BasedOnStyle: LLVM
IndentWidth: 4
ColumnLimit: 120
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file contains all commits which are purely cosmetics

# Cleaning up Eclipse headers
6a458fbc7a0e96a9fdd7d2b429c6924c5de7b35a
21 changes: 20 additions & 1 deletion .github/workflows/compliance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ jobs:
run: |
pip3 install gitlint

- name: Check commits with checkpatch
- name: Check commits with gitlint
run: |
tools/ci/run_ci.sh --branch-target origin/${{ github.base_ref }} --run-gitlint

check-clang-format:
name: Run clang-format
runs-on: ubuntu-20.04

steps:
- name: Checkout code including full history
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install clang-format
run: |
sudo apt update
sudo apt -qy --no-install-recommends install clang-format-10

- name: Check commits with clang-format
run: |
tools/ci/run_ci.sh --branch-target origin/${{ github.base_ref }} --run-clang-format
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,39 @@ Several compilation switches are used:
Depending on your platform, you need to define LWM2M_BIG_ENDIAN or LWM2M_LITTLE_ENDIAN.
LWM2M_CLIENT_MODE and LWM2M_SERVER_MODE can be defined at the same time.

## Development

### Dependencies and Tools
- Mandatory:
- Compiler: GCC and/or Clang
- Optional (but strongly recommended):
- Build system generator: CMake 3.13+
- Version control system: Git (and a GitHub account)
- Git commit message linter: gitlint
- Build system: ninja
- C code formatting: clang-format, version 10
- 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`

### Code formatting
New code must be formatted with [clang-format](https://clang.llvm.org/docs/ClangFormat.html).

The style is based on the LLVM style, but with 4 instead of 2 spaces indentation and allowing for 120 instead of 80
characters per line.

To check if your code matches the expected style, the following commands are helpful:
- `git clang-format-10 --diff`: Show what needs to be changed to match the expected code style
- `git clang-format-10`: Apply all needed changes directly
- `git clang-format-10 --commit master`: Fix code style for all changes since master

If existing code gets reformatted, this must be done in a separate commit. Its commit id has to be added to the file
`.git-blame-ignore-revs` and committed in yet another commit.

### Running CI tests locally
To avoid unneeded load on the GitHub infrastructure, please consider running `tools/ci/run_ci.sh --all` before pushing.

## Examples

Expand Down
4 changes: 4 additions & 0 deletions coap/er-coap-13/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
DisableFormat: true
SortIncludes: false
...
33 changes: 16 additions & 17 deletions core/discover.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
/*******************************************************************************
*
* Copyright (c) 2015 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* David Navarro, Intel Corporation - initial API and implementation
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*******************************************************************************/

*
* Copyright (c) 2015 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* David Navarro, Intel Corporation - initial API and implementation
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*******************************************************************************/

#include "internals.h"

Expand Down
2 changes: 1 addition & 1 deletion core/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Pascal Rieux - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
* Tuve Nordius, Husqvarna Group - Please refer to git log
*
*
*******************************************************************************/
/*
Copyright (c) 2013, 2014 Intel Corporation
Expand Down
2 changes: 1 addition & 1 deletion core/liblwm2m.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Toby Jaffey - Please refer to git log
* Pascal Rieux - Please refer to git log
* Tuve Nordius, Husqvarna Group - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
2 changes: 1 addition & 1 deletion core/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* Contributors:
* David Navarro, Intel Corporation - initial API and implementation
*
*
*******************************************************************************/

#include "internals.h"
Expand Down
2 changes: 1 addition & 1 deletion core/management.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
* Tuve Nordius, Husqvarna Group - Please refer to git log
*
*
*******************************************************************************/
/*
Copyright (c) 2013, 2014 Intel Corporation
Expand Down
2 changes: 1 addition & 1 deletion core/uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Toby Jaffey - Please refer to git log
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
2 changes: 1 addition & 1 deletion core/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Toby Jaffey - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
* Tuve Nordius, Husqvarna Group - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
36 changes: 18 additions & 18 deletions data/data.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/*******************************************************************************
*
* Copyright (c) 2013, 2014 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* David Navarro, Intel Corporation - initial API and implementation
* Fabien Fleutot - Please refer to git log
* Bosch Software Innovations GmbH - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*******************************************************************************/
*
* Copyright (c) 2013, 2014 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* David Navarro, Intel Corporation - initial API and implementation
* Fabien Fleutot - Please refer to git log
* Bosch Software Innovations GmbH - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*******************************************************************************/

#include "internals.h"
#include <float.h>
Expand Down
1 change: 0 additions & 1 deletion data/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*
*******************************************************************************/


#include "internals.h"
#include <ctype.h>
#include <stdlib.h>
Expand Down
1 change: 0 additions & 1 deletion data/json_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*
*******************************************************************************/


#include "internals.h"
#include <float.h>

Expand Down
1 change: 0 additions & 1 deletion data/senml_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*
*******************************************************************************/


#include "internals.h"
#include <ctype.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion data/tlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Fabien Fleutot - Please refer to git log
* Bosch Software Innovations GmbH - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
*******************************************************************************/

#include "internals.h"
Expand Down
1 change: 0 additions & 1 deletion examples/bootstrap_server/bootstrap_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*
*******************************************************************************/


#include "liblwm2m.h"

#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/client/object_access_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
******************************************************************************/

/*
Expand Down
4 changes: 2 additions & 2 deletions examples/client/object_connectivity_moni.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
*
* Copyright (c) 2014 Bosch Software Innovations GmbH Germany.
* Copyright (c) 2014 Bosch Software Innovations GmbH Germany.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
Expand All @@ -14,7 +14,7 @@
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
2 changes: 1 addition & 1 deletion examples/client/object_connectivity_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
2 changes: 1 addition & 1 deletion examples/client/object_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
2 changes: 1 addition & 1 deletion examples/client/object_firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Pascal Rieux - Please refer to git log
* Gregory Lemercier - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
4 changes: 2 additions & 2 deletions examples/client/object_location.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
*
*
* Copyright (c) 2014 Bosch Software Innovations GmbH, Germany.
*
* All rights reserved. This program and the accompanying materials
Expand All @@ -15,7 +15,7 @@
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
******************************************************************************/
/*! \file
LWM2M object "Location" implementation
Expand Down
2 changes: 1 addition & 1 deletion examples/client/object_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Pascal Rieux - Please refer to git log
* Ville Skyttä - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
2 changes: 1 addition & 1 deletion examples/client/object_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
2 changes: 1 addition & 1 deletion examples/client/object_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Ville Skyttä - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
* Tuve Nordius, Husqvarna Group - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
2 changes: 1 addition & 1 deletion examples/lightclient/object_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
2 changes: 1 addition & 1 deletion examples/lightclient/object_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
2 changes: 1 addition & 1 deletion examples/lightclient/object_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
2 changes: 1 addition & 1 deletion examples/lightclient/object_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Pascal Rieux - Please refer to git log
* Ville Skyttä - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
*******************************************************************************/

/*
Expand Down
2 changes: 1 addition & 1 deletion examples/shared/commandline.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* David Navarro, Intel Corporation - initial API and implementation
* Fabien Fleutot - Please refer to git log
* Scott Bertin, AMETEK, Inc. - Please refer to git log
*
*
*******************************************************************************/

#include <string.h>
Expand Down