Skip to content

Commit

Permalink
clang-format implementation (#1740)
Browse files Browse the repository at this point in the history
* Testing clang-format style check using github CI

* github/push: implement check-style for clang-format as a separate build step

* github/push: add missing packages for check-style/clang-format build step

* source/Makefile: check-style - reduce files of interest; update .clang-format to keep enums init

* source/Makefile: empty lines, spaces & tabs refactoring to unify style - part 1 out of N

* source/Makefile: fix formatting for multi-line variables

* source/Makefile: update formatting for multi-line variables

* source/Makefile: remove spaces on vars assignments to unify style

* source/Makefile: remove unused target style

* source/Makefile: implement exclude vars for clang-format related files

* source/Makefile: exclude configuration.h from clang-format check

* Dockerfile: add diffutils in a container to make check-style target using advanced version of diff to get more advanced output to parse & navigate log more easily

* source/Makefile: implement parser for clang-format inside check-style target to make output compatible with gcc-like error compilation format for compatibility with IDEs/editors for easy navigation over files to fix style errors

* source/Makefile: probably final touches on unifying style

* source/Makefile: implement check-style-list target to only list affected file names with wrong code style for debug purposes

* source/Makefile: fix missed spaces

* deploy.sh: add helper routine to deal with clang-format error output logging from makefile

* gitignore: add clang-format log explicitly

* Refactoring for clang-format compiance

* Dockerfile: add sed

* Dockerfile: false alarm - remove sed since busybox-sed seems fine

* source/Makefile: reduce calls of clang-format & make error log more clean, clear, and tidy

* deploy.sh:check_style() - add removal of DOS EOLs for generated log

* source/Makefile:check-style: add more empty lines between blocks with errors for readability when suggestion is too long & heavy

* source/Makefile: add STOP var to check-style for exit on first failed file

* source/Makefile: check-style: make log looks more like traditional diff/patch output

* source/Core/BSP/Pinecilv2/MemMang/heap_5.c: clang-format refactoring using reasonable advises ... and then disable it in Makefile from scanning by clang-format

* Return headers include order

* clang-format config: disable warnings about non-alphabetic include order

* clang-format refactoring

* clang-format refactoring, part 2

* clang-format refactoring, part 3

* settingsGUI.cpp: refactoring, part 1

* settingsGUI.cpp: refactoring, part 2

* settingsGUI.cpp: refactoring, part 3

* settingsGUI.cpp: refactoring, part 4

* clang-format should be happy now

* workflows/push: put readme check into separate build step & update style

* clang-format: giving SortIncludes option second chance by tweaking a couple of headers a bit

* source/Makefile: check-style: add homebrew parser to check for { } in conditional blocks

* homebrew-format: add { } for if/else, while, and for & unify some comments style; left two errors intentionally to debug & improve parser

* source/Makefile: homebrew-format: fix false negative trigger for multi-line condition in if-s

* Sleep.cpp: unify style & comments

* source/Makefile: remove unused debug target
  • Loading branch information
ia authored Jul 16, 2023
1 parent ca79638 commit d95af7d
Show file tree
Hide file tree
Showing 43 changed files with 1,555 additions and 1,359 deletions.
66 changes: 49 additions & 17 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
- name: Git ownership exception
run: git config --global --add safe.directory /__w/IronOS/IronOS && git config --global safe.directory "$GITHUB_WORKSPACE"

- name: build ${{ matrix.model }}
- name: Build ${{ matrix.model }}
run: cd source && ./build.sh -m ${{ matrix.model }}

- name: copy license text
- name: Copy license files
run: |
cp LICENSE source/Hexfile/LICENSE
cp scripts/LICENSE_RELEASE.md source/Hexfile/LICENSE_RELEASE.md
Expand All @@ -55,6 +55,7 @@ jobs:
name: metadata
path: source/Hexfile/${{ matrix.model }}.json


build_multi-lang:
runs-on: ubuntu-20.04
container:
Expand All @@ -77,10 +78,10 @@ jobs:
- name: Git ownership exception
run: git config --global --add safe.directory /__w/IronOS/IronOS && git config --global safe.directory "$GITHUB_WORKSPACE"

- name: build ${{ matrix.model }}
- name: Build ${{ matrix.model }}
run: cd source && make -j$(nproc) model="${{ matrix.model }}" firmware-multi_compressed_European firmware-multi_compressed_Bulgarian+Russian+Serbian+Ukrainian firmware-multi_Chinese+Japanese

- name: copy license text
- name: Copy license files
run: |
cp LICENSE source/Hexfile/LICENSE
cp scripts/LICENSE_RELEASE.md source/Hexfile/LICENSE_RELEASE.md
Expand All @@ -106,20 +107,21 @@ jobs:
name: metadata
path: source/Hexfile/${{ matrix.model }}_multi-lang.json


tests:
runs-on: ubuntu-20.04
container:
image: alpine:3.16

steps:
- name: deps
- name: Install dependencies (apk)
run: apk add --no-cache python3 py3-pip make git bash findutils gcc musl-dev

- uses: actions/checkout@v3
with:
submodules: true

- name: install black
- name: Install dependencies (python)
run: python3 -m pip install bdflib

- name: Run python tests
Expand All @@ -133,36 +135,49 @@ jobs:
chmod +x brieflz_test.py
./brieflz_test.py
check_formatting:
check_c-cpp:
runs-on: ubuntu-20.04
container:
image: alpine:3.16

steps:
- name: deps
run: apk add --no-cache python3 py3-pip make git black sed diffutils
- name: Install dependencies (apk)
run: apk add --no-cache make git diffutils findutils clang-extra-tools

- uses: actions/checkout@v3
with:
submodules: true

- name: install black
run: python3 -m pip install bdflib flake8

- name: Check formatting with clang-format
- name: Check format style with clang-format
run: cd source && make clean && make check-style


check_python:
runs-on: ubuntu-20.04
container:
image: alpine:3.16

steps:
- name: Install dependencies (apk)
run: apk add --no-cache python3 py3-pip make git black

- uses: actions/checkout@v3
with:
submodules: true

- name: Install dependencies (python)
run: python3 -m pip install bdflib flake8

- name: Check python formatting with black
run: black --check Translations

- name: Check python with flake8
run: flake8 Translations

- name: Check autogenerated Documentation/README.md
run: /bin/sh ./scripts/deploy.sh docs_readme

shellcheck:
name: runner / shellcheck
check_shell:
name: check_shell
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -173,3 +188,20 @@ jobs:
reporter: github-pr-review # Change reporter.
exclude: "./.git/*" # Optional.
check_all_files_with_shebangs: "false" # Optional.


check_readme:
runs-on: ubuntu-20.04
container:
image: alpine:3.16

steps:
- name: Install dependencies (apk)
run: apk add --no-cache git

- uses: actions/checkout@v3
with:
submodules: true

- name: Check autogenerated Documentation/README.md
run: /bin/sh ./scripts/deploy.sh docs_readme
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,6 @@ TS100/KiCad/TS100.bak
Logo GUI/TS100 Logo Editor/TS100 Logo Editor/obj/
Logo GUI/TS100 Logo Editor/TS100 Logo Editor/bin/

# Tests/linters/sanitizers
source/check-style.log

4 changes: 2 additions & 2 deletions scripts/IronOS.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ WORKDIR /build/source
# Installing the two compilers (ARM & RISCV), python3 & pip, clang tools:
## - compilers: gcc-*, newlib-*
## - python3: py*, black (required to check Python code formatting)
## - misc: findutils, make, git
## - misc: findutils, make, git, diffutils
## - musl-dev (required for the multi lang firmwares)
## - clang (required for clang-format to check C++ code formatting)

ARG APK_COMPS="gcc-riscv-none-elf gcc-arm-none-eabi newlib-riscv-none-elf \
newlib-arm-none-eabi"
ARG APK_PYTHON="python3 py3-pip black"
ARG APK_MISC="findutils make git"
ARG APK_MISC="findutils make git diffutils"
ARG APK_DEV="musl-dev clang bash clang-extra-tools"

# PIP packages
Expand Down
46 changes: 32 additions & 14 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### helper functions

# brief help (some supported commands may be missing!)
usage()
{
echo -e "\nUsage: ${0} [CMD]\n"
Expand All @@ -19,9 +20,11 @@ usage()
echo -e "\tclean - delete created docker container (but not pre-downloaded data for it)\n"
echo "CMD (helper routines):"
echo -e "\tdocs_readme - generate & OVERWRITE(!) README.md inside Documentation/ based on nav section from mkdocs.yml if it changed\n"
echo -e "\tcheck_style - run clang-format using source/Makefile and generate gcc-compatible error log in source/check-style.log\n"
echo -e "STORAGE NOTICE: for \"shell\" and \"build\" commands extra files will be downloaded so make sure that you have ~5GB of free space.\n"
}

# Documentation/README.md automagical generation routine
docs_readme()
{
# WARNING: ON RUN Documentaion/README.md MAY BE OVERWRITTEN WITHOUT ANY WARNINGS / CONFIRMATIONS !!!
Expand Down Expand Up @@ -67,10 +70,34 @@ EOF
return "${ret}"
}

# check_style routine for those who too lazy to do it everytime manually
check_style()
{
log="source/check-style.log"
make -C source check-style 2>&1 | tee "${log}"
chmod 0666 "${log}"
sed -i -e 's,\r,,g' "${log}"
return 0
}

### main

docker_conf="Env.yml"

# get absolute location of project root dir to make docker happy with config(s)
# (successfully tested on relatively POSIX-compliant Dash shell)

# this script
script_file="/deploy.sh"
# IronOS/scripts/deploy.sh
script_path="${PWD}"/"${0}"
# IronOS/scripts/
script_dir=${script_path%"${script_file}"}
# IronOS/
root_dir="${script_dir}/.."
# IronOS/Env.yml
docker_file="-f ${root_dir}/${docker_conf}"

# allow providing custom path to docker tool using DOCKER_BIN external env. var.
# (compose sub-command must be included, i.e. DOCKER_BIN="/usr/local/bin/docker compose" ./deploy.sh)

Expand Down Expand Up @@ -103,6 +130,11 @@ if [ "docs_readme" = "${cmd}" ]; then
exit "${?}"
fi;

if [ "check_style" = "${cmd}" ]; then
check_style
exit "${?}"
fi;

# if docker is not presented in any way show warning & exit

if [ -z "${docker_bin}" ]; then
Expand All @@ -124,20 +156,6 @@ else
exit 1
fi;

# get absolute location of project root dir to make docker happy with config(s)
# (successfully tested on relatively POSIX-compliant Dash shell)

# this script
script_file="/deploy.sh"
# IronOS/scripts/deploy.sh
script_path="${PWD}"/"${0}"
# IronOS/scripts/
script_dir=${script_path%"${script_file}"}
# IronOS/
root_dir="${script_dir}/.."
# IronOS/Env.yml
docker_file="-f ${root_dir}/${docker_conf}"

# change dir to project root dir & run constructed command

cd "${root_dir}" || exit 1
Expand Down
1 change: 1 addition & 0 deletions source/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AllowShortEnumsOnASingleLine: false ### <<< Keeps enums as is
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
Expand Down
12 changes: 7 additions & 5 deletions source/Core/BSP/MHP30/Setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ void Setup_HAL() {
MX_IWDG_Init();
HAL_ADC_Start(&hadc2);
HAL_ADCEx_MultiModeStart_DMA(&hadc1, ADCReadings,
(ADC_SAMPLES * ADC_CHANNELS)); // start DMA of normal readings
// HAL_ADCEx_InjectedStart(&hadc1); // enable injected readings
// HAL_ADCEx_InjectedStart(&hadc2); // enable injected readings
(ADC_SAMPLES * ADC_CHANNELS)); // start DMA of normal readings
// HAL_ADCEx_InjectedStart(&hadc1); // enable injected readings
// HAL_ADCEx_InjectedStart(&hadc2); // enable injected readings
}

// channel 0 -> temperature sensor, 1-> VIN, 2-> tip
Expand Down Expand Up @@ -154,8 +154,9 @@ static void MX_ADC1_Init(void) {

SET_BIT(hadc1.Instance->CR1, (ADC_CR1_EOSIE)); // Enable end of Normal
// Run ADC internal calibration
while (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK)
while (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK) {
;
}
}

/* ADC2 init function */
Expand Down Expand Up @@ -191,8 +192,9 @@ static void MX_ADC2_Init(void) {
HAL_ADC_ConfigChannel(&hadc2, &sConfig);

// Run ADC internal calibration
while (HAL_ADCEx_Calibration_Start(&hadc2) != HAL_OK)
while (HAL_ADCEx_Calibration_Start(&hadc2) != HAL_OK) {
;
}
}
/* I2C1 init function */
static void MX_I2C1_Init(void) {
Expand Down
4 changes: 2 additions & 2 deletions source/Core/BSP/MHP30/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ void flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
HAL_FLASH_Unlock();
for (uint16_t i = 0; i < (length / 2); i++) {
resetWatchdog();
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, SETTINGS_START_PAGE+ (i*sizeof(uint16_t)), data[i]);
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, SETTINGS_START_PAGE + (i * sizeof(uint16_t)), data[i]);
}
HAL_FLASH_Lock();
}

void flash_read_buffer(uint8_t *buffer, const uint16_t length) { memcpy(buffer, (uint8_t*)SETTINGS_START_PAGE, length); }
void flash_read_buffer(uint8_t *buffer, const uint16_t length) { memcpy(buffer, (uint8_t *)SETTINGS_START_PAGE, length); }
6 changes: 4 additions & 2 deletions source/Core/BSP/Miniware/Setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ static void MX_ADC1_Init(void) {
HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected);
SET_BIT(hadc1.Instance->CR1, (ADC_CR1_JEOCIE)); // Enable end of injected conv irq
// Run ADC internal calibration
while (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK)
while (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK) {
;
}
}

/* ADC2 init function */
Expand Down Expand Up @@ -272,8 +273,9 @@ static void MX_ADC2_Init(void) {
HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected);

// Run ADC internal calibration
while (HAL_ADCEx_Calibration_Start(&hadc2) != HAL_OK)
while (HAL_ADCEx_Calibration_Start(&hadc2) != HAL_OK) {
;
}
}
/* I2C1 init function */
static void MX_I2C1_Init(void) {
Expand Down
1 change: 0 additions & 1 deletion source/Core/BSP/Miniware/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "stm32f1xx_hal.h"
#include "string.h"


void flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
FLASH_EraseInitTypeDef pEraseInit;
pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
Expand Down
4 changes: 1 addition & 3 deletions source/Core/BSP/Miniware/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ static void prvTaskExitError(void) {
// therefore not output an 'unreachable code' warning for code that appears
// after it. */
// }
for(;;){

}
for (;;) {}
}
/*-----------------------------------------------------------*/

Expand Down
1 change: 0 additions & 1 deletion source/Core/BSP/Miniware/preRTOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "configuration.h"
#include <I2C_Wrapper.hpp>


void preRToSInit() {
/* Reset of all peripherals, Initializes the Flash interface and the Systick.
*/
Expand Down
14 changes: 7 additions & 7 deletions source/Core/BSP/Pinecil/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ void log_system_state(int32_t PWMWattsx10) {
// Tip_Temp_C,Handle_Temp_C,Output_Power_Wattx10,PWM,Tip_Raw\r\n
// 3+1+3+1+3+1+3+1+5+2 = 23, so sizing at 32 for now

outputLength = snprintf(uartOutputBuffer, uartOutputBufferLength, "%lu,%u,%li,%u,%lu\r\n", //
TipThermoModel::getTipInC(false), // Tip temp in C
getHandleTemperature(0), // Handle temp in C X10
PWMWattsx10, // Output Wattage
pendingPWM, // PWM
TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true) // Tip temp in uV
);
outputLength = snprintf(uartOutputBuffer, uartOutputBufferLength, "%lu,%u,%li,%u,%lu\r\n",
TipThermoModel::getTipInC(false), // Tip temp in C
getHandleTemperature(0), // Handle temp in C X10
PWMWattsx10, // Output Wattage
pendingPWM, // PWM
TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true) // Tip temp in uV
);

// Now print this out the uart via IRQ (DMA cant be used as oled has it)
currentOutputPos = 0;
Expand Down
5 changes: 3 additions & 2 deletions source/Core/BSP/Pinecil/I2C_Wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ enum class i2c_step {
Wait_stop, // Wait for stop to send and we are done
Done, // Finished
Error_occured, // Error occured on the bus

};

struct i2c_state {
i2c_step currentStep;
bool isMemoryWrite;
bool wakePart;
uint8_t deviceAddress;
uint8_t memoryAddress;
uint8_t * buffer;
uint8_t *buffer;
uint16_t numberOfBytes;
dma_parameter_struct dma_init_struct;
};

i2c_state currentState;

void perform_i2c_step() {
Expand Down
Loading

0 comments on commit d95af7d

Please sign in to comment.