Skip to content

Commit

Permalink
add code formatting (#465)
Browse files Browse the repository at this point in the history
* add script to use clang-format to reformat all c/cpp source
* add clang formatting workflow to fail if code isn't formatted
* add clang format to development container and vscode config
* remove ubuntu-20..04 version of dev container leaving only ubuntu-latest
* add pre-commit hook
* add basic .clang-format config file
* run pre-commit checks on all files and update them
* add code formatting badge to readme
  • Loading branch information
charlie-foxtrot authored Feb 8, 2024
1 parent 281d7b6 commit e7cd0ec
Show file tree
Hide file tree
Showing 73 changed files with 6,639 additions and 6,919 deletions.
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
BasedOnStyle: Chromium
IndentWidth: 4
ObjCBlockIndentWidth: 4
ColumnLimit: 200
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ RUN DEBIAN_FRONTEND=noninteractive \
tzdata\
git \
sudo \
gdb
gdb \
clang-format-14 \
python3-pip

WORKDIR /app
COPY .github/install_dependencies /app/
RUN /app/install_dependencies

RUN pip install pre-commit

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
19 changes: 0 additions & 19 deletions .devcontainer/Dockerfile.ubuntu-20.04

This file was deleted.

7 changes: 4 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",

"dockerFile": "Dockerfile.ubuntu-latest",
"dockerFile": "Dockerfile",

"updateContentCommand" : "apt-get install git",

"postCreateCommand" : "cmake -B /app/build -DCMAKE_BUILD_TYPE=Debug -DNFM=TRUE -DBUILD_UNITTESTS=true",
"postCreateCommand" : "cmake -B /app/build -DCMAKE_BUILD_TYPE=Debug -DNFM=TRUE -DBUILD_UNITTESTS=true ; pre-commit install",

// vs code extensions to install in the dev container
"customizations": {
Expand All @@ -22,7 +22,8 @@
"twxs.cmake",
"streetsidesoftware.code-spell-checker",
"ms-azuretools.vscode-docker",
"GitHub.vscode-github-actions"
"GitHub.vscode-github-actions",
"xaver.clang-format"
]
}
},
Expand Down
5 changes: 2 additions & 3 deletions .devcontainer/shell.ubuntu-20.04 → .devcontainer/shell
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
cd `dirname $0`/../

# build container
docker build -t rtl_airband.ubuntu-20.04 -f .devcontainer/Dockerfile.ubuntu-20.04 .
docker build -t rtl_airband-dev -f .devcontainer/Dockerfile .

# run bash in container
docker run --rm -v $(pwd):/app/ -it --entrypoint bash rtl_airband.ubuntu-20.04

docker run --rm -v $(pwd):/app/ -it --entrypoint bash rtl_airband-dev
10 changes: 0 additions & 10 deletions .devcontainer/shell.ubuntu-latest

This file was deleted.

2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Please use this template to create your bug report. By providing as much info as
- RTLSDR-Airband version you are using (stable release number or branch/commit):
- `make` options used to build the program:
- Hardware platform (eg. x86_64, Raspberry Pi v4):
- Operating system name and version:
- Operating system name and version:

**What happened?**

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/build_docker_containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:
workflow_dispatch:
schedule:
- cron: '29 13 * * *' # run daily
- cron: '29 13 * * *' # run daily

jobs:
build_docker_containers:
Expand Down Expand Up @@ -51,4 +51,3 @@ jobs:
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}

2 changes: 1 addition & 1 deletion .github/workflows/ci_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:
workflow_dispatch:
schedule:
- cron: '39 13 * * *' # run daily
- cron: '39 13 * * *' # run daily

jobs:
ci_build:
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/code_formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Code Formatting

on:
pull_request:
schedule:
- cron: '39 13 * * *' # run daily

jobs:
code_formatting:
runs-on: ubuntu-latest
steps:

- name: Runner Info
run: printenv | sort

- name: Checkout
uses: actions/checkout@v4

- name: Install Clang Format
run: sudo apt-get install clang-format-14

- name: Run Clang Format
run: |
./scripts/reformat_code
git diff --exit-code
2 changes: 1 addition & 1 deletion .github/workflows/platform_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:
workflow_dispatch:
schedule:
- cron: '39 13 * * *' # run daily
- cron: '39 13 * * *' # run daily

jobs:
platform_build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/version_bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
--repo="$GITHUB_REPOSITORY" \
--title="Version ${tag#v}" \
--generate-notes
- name: Run CI on ${{ steps.tag.outputs.new_tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-shebang-scripts-are-executable

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v14.0.6
hooks:
- id: clang-format
files: src/.*\.cpp|src/.*\.h
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
}
],
"version": 4
}
}
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
}

]
}
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.defaultFormatter": "xaver.clang-format",
"clang-format.executable": "clang-format-14"
}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ RUN apt-get update && \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# set working dir for compiling dependencies
WORKDIR /build_dependencies

# compile / install rtl-sdr-blog version of rtl-sdr for v4 support
RUN git clone https://github.com/rtlsdrblog/rtl-sdr-blog && \
cd rtl-sdr-blog/ && \
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Version 5.0.0 (Jan 21, 2024):

* NOTE: Going forward a release tag will be automatically created on each merge to `main`, and changes will not be reflected in this file. For changes between versions see the repo's [release history](https://github.com/charlie-foxtrot/RTLSDR-Airband/releases).
* NOTE: Going forward PRs will be opened directly against `main` and the `unstable` branch will no longer be used.
* NOTE: This repo has significantly diverged from the original project [microtony/RTLSDR-Airband](https://github.com/microtony/RTLSDR-Airband) so it has been been detached (ie no longer a fork).
* NOTE: This repo has significantly diverged from the original project [microtony/RTLSDR-Airband](https://github.com/microtony/RTLSDR-Airband) so it has been been detached (ie no longer a fork).

* Changes in this release, see [#444](https://github.com/charlie-foxtrot/RTLSDR-Airband/pull/444):
* build and publish docker containers
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
![main](https://github.com/charlie-foxtrot/RTLSDR-Airband/actions/workflows/ci_build.yml/badge.svg?branch=main)
![main](https://github.com/charlie-foxtrot/RTLSDR-Airband/actions/workflows/platform_build.yml/badge.svg?branch=main)
![main](https://github.com/charlie-foxtrot/RTLSDR-Airband/actions/workflows/build_docker_containers.yml/badge.svg?branch=main)
![main](https://github.com/charlie-foxtrot/RTLSDR-Airband/actions/workflows/code_formatting.yml/badge.svg?branch=main)

NOTE: Changes as of v5.0.0:
- PRs will be opened directly against `main` and the `unstable` branch will no longer be used
Expand Down Expand Up @@ -95,4 +96,3 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Copyright (C) 2012 by Steve Markgraf <steve@steve-m.de>
* Copyright (C) 2015 by Kyle Keen <keenerd@gmail.com>
* GNU General Public License Version 2

2 changes: 1 addition & 1 deletion config/mixers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mixers: {
},
mixer2: {
outputs: (
{
{
type = "icecast";
server = "icecast.server.example.org";
port = 8080;
Expand Down
1 change: 0 additions & 1 deletion init.d/rtl_airband-gentoo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ stop() {
--pidfile "${RTLAIRBAND_PIDFILE}" --quiet
eend $?
}

3 changes: 3 additions & 0 deletions scripts/reformat_code
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

find src/*.h src/*.cpp src/hello_fft/*.h src/hello_fft/*.c | xargs clang-format-14 -i
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ if(BUILD_UNITTESTS)
enable_testing()

file(GLOB_RECURSE TEST_FILES "test_*.cpp")
list(APPEND TEST_FILES
list(APPEND TEST_FILES
squelch.cpp
logging.cpp
filters.cpp
Expand Down Expand Up @@ -383,4 +383,3 @@ if(BUILD_UNITTESTS)
gtest_discover_tests(unittests)

endif()

1 change: 0 additions & 1 deletion src/CMakeModules/FindMiriSDR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ if(NOT MIRISDR_FOUND)
mark_as_advanced(MIRISDR_INCLUDE_DIR MIRISDR_LIBRARY)

endif(NOT MIRISDR_FOUND)

1 change: 0 additions & 1 deletion src/CMakeModules/FindRTLSDR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,3 @@ if(NOT RTLSDR_FOUND)
mark_as_advanced(RTLSDR_INCLUDE_DIR RTLSDR_LIBRARY)

endif(NOT RTLSDR_FOUND)

Loading

0 comments on commit e7cd0ec

Please sign in to comment.