FormatChecks #2
@@ -45,3 +45,21 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cd ./build/${{ matrix.build_type }}
|
cd ./build/${{ matrix.build_type }}
|
||||||
xvfb-run ctest . --output-on-failure
|
xvfb-run ctest . --output-on-failure
|
||||||
|
|
||||||
|
clang-format:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 120
|
||||||
|
container:
|
||||||
|
image: git.romainboullard.com/bigfootdev/linuxbigfootbuilder:main
|
||||||
|
name: "Clang Format Checks"
|
||||||
|
steps:
|
||||||
|
- name: Install Node.js
|
||||||
|
run: apt-get update && apt-get install -y nodejs
|
||||||
|
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Clang Format Checks
|
||||||
|
run: chmod +x format.sh && ./format.sh --check Bigfoot
|
||||||
@@ -37,11 +37,8 @@ class UUID
|
|||||||
|
|
||||||
~UUID() = default;
|
~UUID() = default;
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
operator std::span<const std::byte, UUID_BYTE_SIZE>() const;
|
operator std::span<const std::byte, UUID_BYTE_SIZE>() const;
|
||||||
[[nodiscard]]
|
|
||||||
operator std::string() const;
|
operator std::string() const;
|
||||||
[[nodiscard]]
|
|
||||||
operator bool() const;
|
operator bool() const;
|
||||||
|
|
||||||
UUID& operator=(const UUID& p_uuid) = default;
|
UUID& operator=(const UUID& p_uuid) = default;
|
||||||
|
|||||||
@@ -92,8 +92,7 @@ class Version
|
|||||||
return m_combined;
|
return m_combined;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]] operator std::string() const;
|
||||||
operator std::string() const;
|
|
||||||
|
|
||||||
constexpr Version& operator=(const Version& p_version) = default;
|
constexpr Version& operator=(const Version& p_version) = default;
|
||||||
|
|
||||||
|
|||||||
87
format.bat
87
format.bat
@@ -1,30 +1,71 @@
|
|||||||
@echo off
|
@echo off
|
||||||
REM Variable that will hold the name of the clang-format command
|
SETLOCAL ENABLEDELAYEDEXPANSION
|
||||||
|
|
||||||
|
REM =========================
|
||||||
|
REM Variables
|
||||||
|
REM =========================
|
||||||
SET FMT=clang-format
|
SET FMT=clang-format
|
||||||
|
SET MODE=
|
||||||
|
SET EXIT_CODE=0
|
||||||
|
|
||||||
REM Function to format files
|
REM =========================
|
||||||
:format
|
REM Parse arguments
|
||||||
for /r %%f in (*.h *.hpp *.m *.mm *.c *.cpp) do (
|
REM =========================
|
||||||
echo %%~nxf | findstr /i "_generated$" >nul
|
:parse_args
|
||||||
if errorlevel 1 (
|
IF "%~1"=="" GOTO end_parse_args
|
||||||
echo format %%f
|
IF "%~1"=="--check" (
|
||||||
%FMT% -i "%%f"
|
SET MODE=check
|
||||||
|
) ELSE IF "%~1"=="--fix" (
|
||||||
|
SET MODE=fix
|
||||||
|
) ELSE (
|
||||||
|
REM Accumulate directories
|
||||||
|
SET DIRS=!DIRS! "%~1"
|
||||||
|
)
|
||||||
|
SHIFT
|
||||||
|
GOTO parse_args
|
||||||
|
:end_parse_args
|
||||||
|
|
||||||
|
IF "%MODE%"=="" (
|
||||||
|
ECHO Usage: %~nx0 --check|--fix <directory> [<directory> ...]
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
||||||
|
|
||||||
|
IF "%DIRS%"=="" (
|
||||||
|
ECHO Please provide at least one directory.
|
||||||
|
EXIT /B 1
|
||||||
|
)
|
||||||
|
|
||||||
|
REM =========================
|
||||||
|
REM Iterate over directories
|
||||||
|
REM =========================
|
||||||
|
FOR %%D IN (%DIRS%) DO (
|
||||||
|
IF NOT EXIST "%%~D" (
|
||||||
|
ECHO %%~D is not a valid directory.
|
||||||
|
SET EXIT_CODE=1
|
||||||
|
GOTO :continue_dirs
|
||||||
)
|
)
|
||||||
)
|
|
||||||
echo ~~~ %1 Done ~~~
|
|
||||||
exit /b
|
|
||||||
|
|
||||||
REM Check if argument is provided
|
REM Recursively find source files
|
||||||
if "%1"=="" (
|
FOR /R "%%~D" %%F IN (*.h *.hpp *.c *.cpp *.m *.mm) DO (
|
||||||
echo Please provide a directory as an argument.
|
SET FILE=%%F
|
||||||
exit /b
|
REM Skip *_generated* files
|
||||||
|
ECHO !FILE! | FINDSTR /I "_generated" >nul
|
||||||
|
IF ERRORLEVEL 1 (
|
||||||
|
IF "%MODE%"=="fix" (
|
||||||
|
ECHO Formatting !FILE!
|
||||||
|
%FMT% -i "!FILE!"
|
||||||
|
) ELSE (
|
||||||
|
ECHO Checking !FILE!
|
||||||
|
%FMT% --dry-run --Werror "!FILE!" 2>nul
|
||||||
|
IF ERRORLEVEL 1 (
|
||||||
|
REM clang-format will already print diagnostics
|
||||||
|
SET EXIT_CODE=1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
:continue_dirs
|
||||||
)
|
)
|
||||||
|
|
||||||
REM Check if directory exists
|
EXIT /B %EXIT_CODE%
|
||||||
if not exist "%1" (
|
|
||||||
echo %1 is not a valid directory.
|
|
||||||
exit /b
|
|
||||||
)
|
|
||||||
|
|
||||||
cd %1
|
|
||||||
call :format
|
|
||||||
|
|||||||
87
format.sh
87
format.sh
@@ -1,31 +1,68 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
# Variable that will hold the name of the clang-format command
|
|
||||||
FMT="clang-format"
|
FMT="clang-format"
|
||||||
|
MODE=""
|
||||||
|
DIRS=()
|
||||||
|
EXIT_CODE=0
|
||||||
|
|
||||||
# Function to format files
|
# =========================
|
||||||
format() {
|
# Parse arguments
|
||||||
for f in $(find "$1" \( -name '*.h' -or -name '*.hpp' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp' \)); do
|
# =========================
|
||||||
# Skip *_generated.h files
|
for arg in "$@"; do
|
||||||
if [[ "$f" == *_generated* ]]; then
|
case "$arg" in
|
||||||
continue
|
--check)
|
||||||
|
MODE="check"
|
||||||
|
;;
|
||||||
|
--fix)
|
||||||
|
MODE="fix"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
DIRS+=("$arg")
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Ensure mode is set
|
||||||
|
if [[ -z "$MODE" ]]; then
|
||||||
|
echo "Usage: $0 --check|--fix <directory> [<directory> ...]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure at least one directory
|
||||||
|
if [[ ${#DIRS[@]} -eq 0 ]]; then
|
||||||
|
echo "Please provide at least one directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# =========================
|
||||||
|
# Process directories
|
||||||
|
# =========================
|
||||||
|
for DIR in "${DIRS[@]}"; do
|
||||||
|
if [[ ! -d "$DIR" ]]; then
|
||||||
|
echo "$DIR is not a valid directory."
|
||||||
|
EXIT_CODE=1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Find all source files safely (null-separated)
|
||||||
|
while IFS= read -r -d '' FILE; do
|
||||||
|
[[ "$FILE" == *_generated* ]] && continue
|
||||||
|
|
||||||
|
if [[ "$MODE" == "fix" ]]; then
|
||||||
|
echo "Formatting $FILE"
|
||||||
|
"$FMT" -i "$FILE"
|
||||||
|
else
|
||||||
|
echo "Checking $FILE"
|
||||||
|
# Check mode: clang-format diagnostic only
|
||||||
|
if ! "$FMT" --dry-run --Werror "$FILE"; then
|
||||||
|
# clang-format prints: file:line:col: error ...
|
||||||
|
EXIT_CODE=1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
echo "format ${f}"
|
done < <(
|
||||||
${FMT} -i "${f}"
|
find "$DIR" \( -name '*.h' -o -name '*.hpp' -o -name '*.c' -o -name '*.cpp' -o -name '*.m' -o -name '*.mm' \) -print0
|
||||||
done
|
)
|
||||||
echo "~~~ $1 Done ~~~"
|
done
|
||||||
}
|
|
||||||
|
|
||||||
# Check if argument is provided
|
exit $EXIT_CODE
|
||||||
if [ -z "$1" ]; then
|
|
||||||
echo "Please provide a directory as an argument."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if directory exists
|
|
||||||
if [ ! -d "$1" ]; then
|
|
||||||
echo "$1 is not a valid directory."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
format "$1"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user