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

clang-format implementation #1740

Merged
merged 45 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
94c2f43
Testing clang-format style check using github CI
ia Jul 11, 2023
b24d945
github/push: implement check-style for clang-format as a separate bui…
ia Jul 11, 2023
1103b50
github/push: add missing packages for check-style/clang-format build …
ia Jul 11, 2023
9bd3501
source/Makefile: check-style - reduce files of interest; update .clan…
ia Jul 12, 2023
6306e9b
source/Makefile: empty lines, spaces & tabs refactoring to unify styl…
ia Jul 12, 2023
5bb5afe
source/Makefile: fix formatting for multi-line variables
ia Jul 12, 2023
5a0f346
source/Makefile: update formatting for multi-line variables
ia Jul 12, 2023
38bea98
source/Makefile: remove spaces on vars assignments to unify style
ia Jul 12, 2023
703498d
source/Makefile: remove unused target style
ia Jul 12, 2023
20e2da7
source/Makefile: implement exclude vars for clang-format related files
ia Jul 12, 2023
af0200a
source/Makefile: exclude configuration.h from clang-format check
ia Jul 12, 2023
96e7c99
Dockerfile: add diffutils in a container to make check-style target u…
ia Jul 12, 2023
a1ef959
source/Makefile: implement parser for clang-format inside check-style…
ia Jul 12, 2023
60cd7a6
source/Makefile: probably final touches on unifying style
ia Jul 12, 2023
a60ca8b
source/Makefile: implement check-style-list target to only list affec…
ia Jul 12, 2023
680c781
source/Makefile: fix missed spaces
ia Jul 12, 2023
791fec8
deploy.sh: add helper routine to deal with clang-format error output …
ia Jul 12, 2023
baa709a
gitignore: add clang-format log explicitly
ia Jul 12, 2023
ad50dc2
Refactoring for clang-format compiance
ia Jul 12, 2023
ec60601
Dockerfile: add sed
ia Jul 12, 2023
4c03e06
Dockerfile: false alarm - remove sed since busybox-sed seems fine
ia Jul 12, 2023
3560e8c
source/Makefile: reduce calls of clang-format & make error log more c…
ia Jul 12, 2023
7df60b0
deploy.sh:check_style() - add removal of DOS EOLs for generated log
ia Jul 12, 2023
18ce274
source/Makefile:check-style: add more empty lines between blocks with…
ia Jul 13, 2023
396f082
source/Makefile: add STOP var to check-style for exit on first failed…
ia Jul 13, 2023
a39dab4
source/Makefile: check-style: make log looks more like traditional di…
ia Jul 13, 2023
d0f87e3
source/Core/BSP/Pinecilv2/MemMang/heap_5.c: clang-format refactoring …
ia Jul 13, 2023
3058f6e
Return headers include order
ia Jul 13, 2023
5365168
clang-format config: disable warnings about non-alphabetic include order
ia Jul 13, 2023
15970a9
clang-format refactoring
ia Jul 13, 2023
ab1a7b3
clang-format refactoring, part 2
ia Jul 13, 2023
2c3c447
clang-format refactoring, part 3
ia Jul 13, 2023
8c387a8
settingsGUI.cpp: refactoring, part 1
ia Jul 13, 2023
1e00a5b
settingsGUI.cpp: refactoring, part 2
ia Jul 13, 2023
5204478
settingsGUI.cpp: refactoring, part 3
ia Jul 13, 2023
b30722d
settingsGUI.cpp: refactoring, part 4
ia Jul 13, 2023
da5534d
clang-format should be happy now
ia Jul 13, 2023
7daf912
workflows/push: put readme check into separate build step & update style
ia Jul 13, 2023
ff8df64
clang-format: giving SortIncludes option second chance by tweaking a …
ia Jul 13, 2023
7f8e70e
source/Makefile: check-style: add homebrew parser to check for { } in…
ia Jul 14, 2023
f53b7db
homebrew-format: add { } for if/else, while, and for & unify some com…
ia Jul 14, 2023
970f3c0
source/Makefile: homebrew-format: fix false negative trigger for mult…
ia Jul 14, 2023
a492c3c
Sleep.cpp: unify style & comments
ia Jul 14, 2023
382ae15
source/Makefile: remove unused debug target
ia Jul 14, 2023
a63d5d0
Merge dev branch to clang-format branch
ia Jul 15, 2023
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
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