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

Add clang-format and run it on the code-base #384

Merged
merged 6 commits into from
Mar 7, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
BasedOnStyle: LLVM
Language: Cpp
IndentWidth: 2
BreakConstructorInitializersBeforeComma: 'true'
PointerAlignment: Left
IncludeBlocks: Preserve
SortIncludes: false
ColumnLimit: 120
20 changes: 13 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
pull_request:
# Also allow running this workflow manually from the Actions tab.
types: [synchronize, opened, reopened, ready_for_review, converted_to_draft]
workflow_dispatch:
merge_group:

Expand All @@ -14,6 +14,10 @@ concurrency:
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
check-labels:
uses: lf-lang/lingua-franca/.github/workflows/check-labels.yml@master
if: ${{ github.event_name == 'pull_request' }}

unit-tests-single:
uses: ./.github/workflows/unit-tests.yml
with:
Expand Down Expand Up @@ -41,31 +45,31 @@ jobs:
with:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
if: ${{ github.event_name == 'merge_group' || github.ref == 'refs/heads/main' || contains( github.event.pull_request.labels.*.name, 'arduino') }}
if: ${{ !github.event.pull_request.draft || contains( github.event.pull_request.labels.*.name, 'arduino') }}

lf-default-zephyr:
needs: [fetch-lf]
uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@master
with:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
if: ${{ github.event_name == 'merge_group' || github.ref == 'refs/heads/main' ||contains( github.event.pull_request.labels.*.name, 'zephyr') }}
if: ${{ !github.event.pull_request.draft ||contains( github.event.pull_request.labels.*.name, 'zephyr') }}

lf-default:
needs: [fetch-lf]
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master
with:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
all-platforms: ${{ github.event_name == 'merge_group' || github.ref == 'refs/heads/main' || contains( github.event.pull_request.labels.*.name, 'mac') || contains( github.event.pull_request.labels.*.name, 'windows') }}
all-platforms: ${{ !github.event.pull_request.draft || contains( github.event.pull_request.labels.*.name, 'mac') || contains( github.event.pull_request.labels.*.name, 'windows') }}

lf-python:
needs: [fetch-lf]
uses: lf-lang/lingua-franca/.github/workflows/py-tests.yml@master
with:
reactor-c-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
if: ${{ github.event_name == 'merge_group' || github.ref == 'refs/heads/main' ||contains( github.event.pull_request.labels.*.name, 'python') }}
if: ${{ !github.event.pull_request.draft || contains( github.event.pull_request.labels.*.name, 'python') }}

lf-gedf-np:
needs: [fetch-lf]
Expand All @@ -74,7 +78,8 @@ jobs:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
scheduler: GEDF_NP
all-platforms: ${{ github.event_name == 'merge_group' || github.ref == 'refs/heads/main' || contains( github.event.pull_request.labels.*.name, 'mac') || contains( github.event.pull_request.labels.*.name, 'windows') }}
all-platforms: ${{ !github.event.pull_request.draft || contains( github.event.pull_request.labels.*.name, 'mac') || contains( github.event.pull_request.labels.*.name, 'windows') }}
if: ${{ !github.event.pull_request.draft || contains( github.event.pull_request.labels.*.name, 'schedulers') }}

lf-adaptive:
needs: [fetch-lf]
Expand All @@ -83,4 +88,5 @@ jobs:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
scheduler: ADAPTIVE
all-platforms: ${{ github.event_name == 'merge_group' || github.ref == 'refs/heads/main' || contains( github.event.pull_request.labels.*.name, 'mac') || contains( github.event.pull_request.labels.*.name, 'windows') }}
all-platforms: ${{ !github.event.pull_request.draft || contains( github.event.pull_request.labels.*.name, 'mac') || contains( github.event.pull_request.labels.*.name, 'windows') }}
if: ${{ !github.event.pull_request.draft || contains( github.event.pull_request.labels.*.name, 'schedulers') }}
16 changes: 16 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: clang-format-review

# You can be more specific, but it currently only works on pull requests
on: [pull_request]

jobs:
clang-format:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install clang-tidy
run: |
sudo apt-get update
sudo apt-get install -y clang-tidy
- name: Analyze
run: make format-check
264 changes: 0 additions & 264 deletions CONTRIBUTING.md

This file was deleted.

9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file lets you format the code-base with a single command.
FILES := $(shell find . -name '*.c' -o -name '*.h')
.PHONY: format
format:
clang-format -i -style=file $(FILES)

.PHONY: format-check
format-check:
clang-format --dry-run --Werror -style=file $(FILES)
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
## Documentation
To generate and view documentation, see [docs/README.md](docs/README.md).

## Code-formatting
We use clang-format to format our codebase. To run the formatter on all source and header files in reactor-c:
```
make format
```
The CI will do a "dry-run" of the formatter to verify that all files are correctly formatted.

VSCode can be configured to run clang-format on files as they are saved. To achieve this set the following settings:
- editor.formatOnSave: true
- C_Cpp.formatting: clang-format
- C_Cpp.clang_format_style: file


## Testing
The Github Actions tests for this repo will automatically run all the C Lingua Franca tests with each of the available schedulers. The version of the lingua-franca repo that is used to do this is specified by the lingua-franca-ref.txt file in this directory.

Expand Down
Loading
Loading