From 74e89450b735dd021aba526e6d72e68cae072c02 Mon Sep 17 00:00:00 2001 From: Ryan Turner Date: Wed, 10 Sep 2025 13:24:49 -0500 Subject: [PATCH] clang-format: add lint job and update run script Update clang-format script to only run on files that are passing the formatter, that way the clang-format script is useable by CI and contributors. --- .github/workflows/format.yml | 20 +++++++++++ .github/workflows/regenerate_symbols.yml | 15 +++++--- requirements.txt | 9 ++--- scripts/clang_format.sh | 45 +++++++++++++++++++++++- 4 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 00000000..60a7fb22 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,20 @@ +name: "Format sources" +on: + workflow_dispatch: + push: + pull_request: + +jobs: + clang-format: + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + - name: install-deps + run: | + sudo apt-get update + sudo apt-get install -y clang-format + - name: Check if there are format errors + run: ./scripts/clang_format.sh --check diff --git a/.github/workflows/regenerate_symbols.yml b/.github/workflows/regenerate_symbols.yml index 3a712b59..7ad9e19a 100644 --- a/.github/workflows/regenerate_symbols.yml +++ b/.github/workflows/regenerate_symbols.yml @@ -11,22 +11,29 @@ on: jobs: check-symbol-generation: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 with: submodules: recursive + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' - name: install-deps run: | sudo apt update - sudo apt install python3 python3-pip + sudo apt install ffmpeg clang-format - name: Setup symbols script dependencies run: | cd ${{github.workspace}} + pip3 install --upgrade pip pip3 install -r requirements.txt - - name: Run symbols script - run: ./scripts/generate_symbols.py + - name: Run symbols script and then format the output + run: | + ./scripts/generate_symbols.py + ./scripts/clang_format.sh - name: Fail the build if there are changes generated run: | git --no-pager diff diff --git a/requirements.txt b/requirements.txt index 3a0922b1..9e0ddef3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ -pyusb -meson +setuptools>=68.0.0 +pyusb>=1.2.1 +meson>=1.2.0 ffmpeg -cairosvg==2.7.1 -numpy==1.25.2 \ No newline at end of file +cairosvg>=2.7.1 +numpy>=1.25.2 \ No newline at end of file diff --git a/scripts/clang_format.sh b/scripts/clang_format.sh index 43e0d5e1..d0a0225e 100755 --- a/scripts/clang_format.sh +++ b/scripts/clang_format.sh @@ -42,7 +42,50 @@ if [ $# -eq 1 ]; then fi fi -FILE_LIST=$(git ls-files | egrep '\.(c|cpp|h)$' | egrep -v 'lib/|subprojects/|platform/mcu') +# FILE_LIST=$(git ls-files | egrep '\.(c|cpp|h)$' | egrep -v 'lib/|subprojects/|platform/mcu') +# TODO: This is temporarily running on a subset of the repo while we "ratchet up" +# the codebase; see https://github.com/OpenRTX/OpenRTX/issues/346 +# +# Hey you! Have a new source file, or one that you've made changes to? Add it to +# the list below to enforce the new formatting. +FILE_LIST=$(cat <<-EOF +openrtx/include/core/audio_codec.h +openrtx/include/core/battery.h +openrtx/include/core/beeps.h +openrtx/include/core/crc.h +openrtx/include/core/data_conversion.h +openrtx/include/core/datatypes.h +openrtx/include/core/memory_profiling.h +openrtx/include/core/openrtx.h +openrtx/include/core/ui.h +openrtx/include/core/utils.h +openrtx/include/core/xmodem.h +openrtx/include/fonts/symbols/symbols.h +openrtx/include/interfaces/cps_io.h +openrtx/include/interfaces/delays.h +openrtx/include/interfaces/display.h +openrtx/include/interfaces/radio.h +openrtx/include/peripherals/gps.h +openrtx/include/peripherals/rng.h +openrtx/include/peripherals/rtc.h +openrtx/src/core/memory_profiling.cpp +platform/drivers/ADC/ADC0_GDx.h +platform/drivers/audio/MAX9814.h +platform/drivers/baseband/MCP4551.h +platform/drivers/baseband/SA8x8.h +platform/drivers/chSelector/chSelector.h +platform/drivers/display/SH110x_Mod17.h +platform/drivers/display/SSD1306_Mod17.h +platform/drivers/display/SSD1309_Mod17.h +platform/drivers/GPIO/gpio-native.h +platform/drivers/GPS/gps_stm32.h +platform/drivers/GPS/gps_zephyr.h +platform/drivers/USB/usb.h +platform/targets/GDx/hwconfig.h +platform/targets/linux/emulator/sdl_engine.h +platform/targets/ttwrplus/pmu.h +EOF +) CHECK_ARGS="" if [ "$1" == "--check" ]; then