From a22781ea5a0342ac4834a7fa48bdd57a6b6d8623 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 28 Aug 2025 14:40:27 -0400 Subject: [PATCH 01/10] chore: Remove irrelevant code from runformat --- runformat | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/runformat b/runformat index 2f883a76..2ce71f4a 100755 --- a/runformat +++ b/runformat @@ -21,19 +21,4 @@ if [ "$DETECTED_VERSION" != "${UNCRUSTIFY_VERSION}" ]; then exit 1 fi -# OS variables -[ $(uname -s) = "Darwin" ] && export OSX=1 && export UNIX=1 -[ $(uname -s) = "Linux" ] && export LINUX=1 && export UNIX=1 -uname -s | grep -q "_NT-" && export WINDOWS=1 - -if [ $OSX ] -then - export CPUCOUNT=$(sysctl -n hw.ncpu) -elif [ $LINUX ] -then - export CPUCOUNT=$(nproc) -else - export CPUCOUNT="1" -fi - $UNCRUSTIFY -c .uncrustify.cfg --no-backup *.cpp *.h From a8ac476fde82aaf08e75a09bbab0131151137e0e Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 28 Aug 2025 14:41:58 -0400 Subject: [PATCH 02/10] chore(runformat): Ensure script can be executed from any location This change updates the runformat script to set the working directory to the script's directory, ensuring consistent behavior regardless of the initial execution location. --- runformat | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runformat b/runformat index 2ce71f4a..6e0d0e9d 100755 --- a/runformat +++ b/runformat @@ -11,6 +11,9 @@ # - you can put uncrustify in your PATH # - you can create an environment variable UNCRUSTIFY that has the full path of the binary +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" + UNCRUSTIFY_VERSION="0.72.0" UNCRUSTIFY="${UNCRUSTIFY-uncrustify}" From a2c7556c7fcc9723e3a2b14d5aae3057cafbeffa Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 28 Aug 2025 14:43:03 -0400 Subject: [PATCH 03/10] chore(runformat): Improve script to check version only if found --- runformat | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/runformat b/runformat index 6e0d0e9d..44cf88fe 100755 --- a/runformat +++ b/runformat @@ -17,11 +17,20 @@ cd "$SCRIPT_DIR" UNCRUSTIFY_VERSION="0.72.0" UNCRUSTIFY="${UNCRUSTIFY-uncrustify}" -DETECTED_VERSION=$("$UNCRUSTIFY" --version 2>&1 | grep -o -E '[0-9.]+') -if [ "$DETECTED_VERSION" != "${UNCRUSTIFY_VERSION}" ]; then - echo "You should use version: ${UNCRUSTIFY_VERSION}" - echo "Detected version: ${DETECTED_VERSION}" - exit 1 +err() { echo -e >&2 "ERROR: $@\n"; } +die() { err $@; exit 1; } + +# Check Uncrustify availability +if ! command -v "$UNCRUSTIFY" >/dev/null 2>&1; then + err "Uncrustify executable not found: $UNCRUSTIFY" + die "Add it to PATH or set UNCRUSTIFY=/path/to/uncrustify" +fi + +# Version check +DETECTED_VERSION="$("$UNCRUSTIFY" --version 2>&1 | grep -oE '[0-9]+(\.[0-9]+)*' | head -n1 || true)" +echo "Detected Uncrustify: ${DETECTED_VERSION:-unknown}" +if [[ "$DETECTED_VERSION" != "${UNCRUSTIFY_VERSION}" ]]; then + die "Expected Uncrustify ${UNCRUSTIFY_VERSION}." fi $UNCRUSTIFY -c .uncrustify.cfg --no-backup *.cpp *.h From 2a1817121d939fdd8ade73e66ab91e56f26577c7 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 28 Aug 2025 15:26:22 -0400 Subject: [PATCH 04/10] chore(runformat): Fix expected uncrustify version and update instructions Set version 0.80.1 to match the one from danmar/cppcheck@3726ace5d --- runformat | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/runformat b/runformat index 44cf88fe..24a586db 100755 --- a/runformat +++ b/runformat @@ -1,20 +1,23 @@ #!/bin/bash # -# uncrustify-0.72 is used to format simplecpp and cppcheck source code. +# runformat - format this project's C++ sources with Uncrustify. +# +# Usage: +# ./runformat # format using the configured Uncrustify +# +# Requirements: +# - All developers must use the *exact* same Uncrustify version to avoid format churn. +# - Either: +# * Have `uncrustify` in PATH, or +# * Set env var UNCRUSTIFY=/absolute/path/to/uncrustify +# +# Notes: +# - The config file is expected at: ./.uncrustify.cfg # -# 1. Download source code: https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-0.72.0.zip -# It's important that all developers use the exact same version so we don't get a "format battle". -# 2. Building: -# - Linux: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make -# - Windows: mkdir build && cd build && cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release .. && nmake -# 3. Ensure that the binary "uncrustify" is found by runformat. Either: -# - you can put uncrustify in your PATH -# - you can create an environment variable UNCRUSTIFY that has the full path of the binary - SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" -UNCRUSTIFY_VERSION="0.72.0" +UNCRUSTIFY_VERSION="0.80.1" UNCRUSTIFY="${UNCRUSTIFY-uncrustify}" err() { echo -e >&2 "ERROR: $@\n"; } From 02d6227384c866f69bdae561685f5e9ca348b8d4 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 28 Aug 2025 15:35:07 -0400 Subject: [PATCH 05/10] chore(runformat): Update uncrustify command line arguments to apply changes Also display the diff and "fail" if there are differences --- runformat | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/runformat b/runformat index 24a586db..ae6cdcca 100755 --- a/runformat +++ b/runformat @@ -36,4 +36,16 @@ if [[ "$DETECTED_VERSION" != "${UNCRUSTIFY_VERSION}" ]]; then die "Expected Uncrustify ${UNCRUSTIFY_VERSION}." fi -$UNCRUSTIFY -c .uncrustify.cfg --no-backup *.cpp *.h +# Run formatter +echo "Running formatter..." +$UNCRUSTIFY -c .uncrustify.cfg -l CPP --no-backup --replace *.cpp *.h + +# Show diff and fail if changes exist +echo "Checking for formatting changes..." +git diff --exit-code || { + echo + echo "Formatting changes were applied. Please review and commit." + exit 1 +} + +echo "Formatting is clean." From 455f010972aef99cca2159bbc263cd25ccc39cd5 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 28 Aug 2025 15:35:50 -0400 Subject: [PATCH 06/10] chore(runformat): Explicitly check for uncrustify config file existence --- runformat | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/runformat b/runformat index ae6cdcca..ea16379f 100755 --- a/runformat +++ b/runformat @@ -19,6 +19,7 @@ cd "$SCRIPT_DIR" UNCRUSTIFY_VERSION="0.80.1" UNCRUSTIFY="${UNCRUSTIFY-uncrustify}" +UNCRUSTIFY_CONFIG="${SCRIPT_DIR}/.uncrustify.cfg" err() { echo -e >&2 "ERROR: $@\n"; } die() { err $@; exit 1; } @@ -36,9 +37,12 @@ if [[ "$DETECTED_VERSION" != "${UNCRUSTIFY_VERSION}" ]]; then die "Expected Uncrustify ${UNCRUSTIFY_VERSION}." fi +# Config check +[[ -f "$UNCRUSTIFY_CONFIG" ]] || die "Uncrustify config not found at: $UNCRUSTIFY_CONFIG" + # Run formatter echo "Running formatter..." -$UNCRUSTIFY -c .uncrustify.cfg -l CPP --no-backup --replace *.cpp *.h +$UNCRUSTIFY -c "$UNCRUSTIFY_CONFIG" -l CPP --no-backup --replace *.cpp *.h # Show diff and fail if changes exist echo "Checking for formatting changes..." From 486540859bbe5b598016e705fa8b7edb6db1b081 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 28 Aug 2025 17:54:23 -0400 Subject: [PATCH 07/10] chore(runformat): Add local Uncrustify installation support This change introduces the ability to install a specific version of Uncrustify locally via the `./runformat --install` command. This ensures all developers use the exact same version to avoid format churn. - Adds a new `.runformat-uncrustify` directory to `.gitignore`. - Updates `runformat` script with install logic and usage instructions. - Verifies Uncrustify version and guides user if mismatch is detected. --- .gitignore | 1 + runformat | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 113cf360..34d9c55d 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ *.app simplecpp testrunner +/.runformat-uncrustify # CLion /.idea diff --git a/runformat b/runformat index ea16379f..4df442c0 100755 --- a/runformat +++ b/runformat @@ -4,37 +4,101 @@ # # Usage: # ./runformat # format using the configured Uncrustify +# ./runformat --install # download, build, and use Uncrustify locally # # Requirements: # - All developers must use the *exact* same Uncrustify version to avoid format churn. # - Either: # * Have `uncrustify` in PATH, or -# * Set env var UNCRUSTIFY=/absolute/path/to/uncrustify +# * Set env var UNCRUSTIFY=/absolute/path/to/uncrustify, or +# * Run `./runformat --install` to fetch & build the pinned version locally. # # Notes: +# - The local install lives under: ./.runformat-uncrustify/uncrustify--install # - The config file is expected at: ./.uncrustify.cfg # + +set -euo pipefail + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" UNCRUSTIFY_VERSION="0.80.1" -UNCRUSTIFY="${UNCRUSTIFY-uncrustify}" +UNCRUSTIFY_HASH="6bf662e05c4140dd4df5e45d6690cad96b4ef23c293b85813f5c725bbf1894d0" + +UNCRUSTIFY_LOCAL_DIR="${SCRIPT_DIR}/.runformat-uncrustify" +UNCRUSTIFY_LOCAL_INSTALL_DIR="${UNCRUSTIFY_LOCAL_DIR}/uncrustify-${UNCRUSTIFY_VERSION}-install" +UNCRUSTIFY_LOCAL_INSTALL_EXECUTABLE="${UNCRUSTIFY_LOCAL_INSTALL_DIR}/bin/uncrustify" + +# Allow override via env; default to local pinned build path. +UNCRUSTIFY="${UNCRUSTIFY:-$UNCRUSTIFY_LOCAL_INSTALL_EXECUTABLE}" UNCRUSTIFY_CONFIG="${SCRIPT_DIR}/.uncrustify.cfg" err() { echo -e >&2 "ERROR: $@\n"; } die() { err $@; exit 1; } +install_uncrustify() { + local root="uncrustify-${UNCRUSTIFY_VERSION}" + local file="${root}.tar.gz" + local url="https://github.com/uncrustify/uncrustify/releases/download/${root}/${file}" + + mkdir -p "${UNCRUSTIFY_LOCAL_DIR}" + + echo "Downloading ${file}..." + curl -fsSL -o "${UNCRUSTIFY_LOCAL_DIR}/${file}" "${url}" + + ( cd "${UNCRUSTIFY_LOCAL_DIR}" && { + echo "${UNCRUSTIFY_HASH} ${file}" > "${file}.sha256" + sha256sum -c "${file}.sha256" + rm -f "${file}.sha256" + + command -v cmake >/dev/null 2>&1 || die "cmake executable not found." + + echo "Extracting archive..." + rm -rf "${root}" "${root}-build" "${root}-install" + mkdir -p "${root}" + tar -xzf "${file}" --strip-components=1 -C "${root}" + + echo "Configuring..." + cmake \ + -DCMAKE_BUILD_TYPE:STRING=Release \ + -DCMAKE_INSTALL_PREFIX:PATH="${UNCRUSTIFY_LOCAL_DIR}/${root}-install" \ + -S "${root}" -B "${root}-build" + + echo "Building & installing..." + cmake --build "${root}-build" --config Release --target install --parallel + } + ) + echo "Installed Uncrustify to: ${UNCRUSTIFY_LOCAL_INSTALL_DIR}" +} + +print_usage_and_exit() { + sed -n '2,19p' "$0" | sed 's/^# \{0,1\}//' + exit 0 +} + +# Argument handling +if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then + print_usage_and_exit +fi + +if [[ "${1:-}" == "--install" ]]; then + install_uncrustify + # Ensure we use the freshly installed binary for this run + UNCRUSTIFY="$UNCRUSTIFY_LOCAL_INSTALL_EXECUTABLE" +fi + # Check Uncrustify availability if ! command -v "$UNCRUSTIFY" >/dev/null 2>&1; then err "Uncrustify executable not found: $UNCRUSTIFY" - die "Add it to PATH or set UNCRUSTIFY=/path/to/uncrustify" + die "Add it to PATH, set UNCRUSTIFY=/path/to/uncrustify, or run: $0 --install" fi # Version check DETECTED_VERSION="$("$UNCRUSTIFY" --version 2>&1 | grep -oE '[0-9]+(\.[0-9]+)*' | head -n1 || true)" echo "Detected Uncrustify: ${DETECTED_VERSION:-unknown}" if [[ "$DETECTED_VERSION" != "${UNCRUSTIFY_VERSION}" ]]; then - die "Expected Uncrustify ${UNCRUSTIFY_VERSION}." + die "Expected Uncrustify ${UNCRUSTIFY_VERSION}. Re-run with --install or adjust UNCRUSTIFY." fi # Config check From 1f344cf2c7d4dc8bb2b54bf0d1122634311c1e5a Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 28 Aug 2025 17:55:40 -0400 Subject: [PATCH 08/10] chore(runformat): Enhance script with user-defined install directory This improves the runformat script by adding support for specifying a custom installation directory for Uncrustify using the --install-dir argument. It also refines the argument parsing logic and updates usage documentation to reflect these changes. --- runformat | 112 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 36 deletions(-) diff --git a/runformat b/runformat index 4df442c0..9a57490c 100755 --- a/runformat +++ b/runformat @@ -3,8 +3,13 @@ # runformat - format this project's C++ sources with Uncrustify. # # Usage: -# ./runformat # format using the configured Uncrustify -# ./runformat --install # download, build, and use Uncrustify locally +# ./runformat # format using the configured Uncrustify +# ./runformat --install # download, build, and use Uncrustify locally +# ./runformat --install --install-dir /abs/path +# +# You may also set: +# UNCRUSTIFY=/abs/path/to/uncrustify # use a specific binary +# UNCRUSTIFY_INSTALL_DIR=/abs/path # where `--install` will install # # Requirements: # - All developers must use the *exact* same Uncrustify version to avoid format churn. @@ -26,12 +31,15 @@ cd "$SCRIPT_DIR" UNCRUSTIFY_VERSION="0.80.1" UNCRUSTIFY_HASH="6bf662e05c4140dd4df5e45d6690cad96b4ef23c293b85813f5c725bbf1894d0" -UNCRUSTIFY_LOCAL_DIR="${SCRIPT_DIR}/.runformat-uncrustify" -UNCRUSTIFY_LOCAL_INSTALL_DIR="${UNCRUSTIFY_LOCAL_DIR}/uncrustify-${UNCRUSTIFY_VERSION}-install" -UNCRUSTIFY_LOCAL_INSTALL_EXECUTABLE="${UNCRUSTIFY_LOCAL_INSTALL_DIR}/bin/uncrustify" +UNCRUSTIFY_WORK_DIR="${SCRIPT_DIR}/.runformat-uncrustify" + +# Allow external install dir override (arg or env). If not set, default under work dir. +DEFAULT_INSTALL_DIR="${UNCRUSTIFY_WORK_DIR}/uncrustify-${UNCRUSTIFY_VERSION}-install" +UNCRUSTIFY_INSTALL_DIR="${UNCRUSTIFY_INSTALL_DIR:-$DEFAULT_INSTALL_DIR}" +UNCRUSTIFY_BIN="${UNCRUSTIFY_INSTALL_DIR}/bin/uncrustify" # Allow override via env; default to local pinned build path. -UNCRUSTIFY="${UNCRUSTIFY:-$UNCRUSTIFY_LOCAL_INSTALL_EXECUTABLE}" +UNCRUSTIFY="${UNCRUSTIFY:-$UNCRUSTIFY_BIN}" UNCRUSTIFY_CONFIG="${SCRIPT_DIR}/.uncrustify.cfg" err() { echo -e >&2 "ERROR: $@\n"; } @@ -42,63 +50,95 @@ install_uncrustify() { local file="${root}.tar.gz" local url="https://github.com/uncrustify/uncrustify/releases/download/${root}/${file}" - mkdir -p "${UNCRUSTIFY_LOCAL_DIR}" + mkdir -p "${UNCRUSTIFY_WORK_DIR}" echo "Downloading ${file}..." - curl -fsSL -o "${UNCRUSTIFY_LOCAL_DIR}/${file}" "${url}" + curl -fsSL -o "${UNCRUSTIFY_WORK_DIR}/${file}" "${url}" - ( cd "${UNCRUSTIFY_LOCAL_DIR}" && { - echo "${UNCRUSTIFY_HASH} ${file}" > "${file}.sha256" - sha256sum -c "${file}.sha256" - rm -f "${file}.sha256" + ( + cd "${UNCRUSTIFY_WORK_DIR}" - command -v cmake >/dev/null 2>&1 || die "cmake executable not found." + echo "${UNCRUSTIFY_HASH} ${file}" > "${file}.sha256" + sha256sum -c "${file}.sha256" + rm -f "${file}.sha256" - echo "Extracting archive..." - rm -rf "${root}" "${root}-build" "${root}-install" - mkdir -p "${root}" - tar -xzf "${file}" --strip-components=1 -C "${root}" + command -v cmake >/dev/null 2>&1 || die "cmake executable not found." - echo "Configuring..." - cmake \ - -DCMAKE_BUILD_TYPE:STRING=Release \ - -DCMAKE_INSTALL_PREFIX:PATH="${UNCRUSTIFY_LOCAL_DIR}/${root}-install" \ - -S "${root}" -B "${root}-build" + echo "Extracting archive..." + rm -rf "${root}" "${root}-build" + mkdir -p "${root}" + tar -xzf "${file}" --strip-components=1 -C "${root}" - echo "Building & installing..." - cmake --build "${root}-build" --config Release --target install --parallel - } + echo "Configuring (prefix: ${UNCRUSTIFY_INSTALL_DIR})..." + cmake \ + -DCMAKE_BUILD_TYPE:STRING=Release \ + -DCMAKE_INSTALL_PREFIX:PATH="${UNCRUSTIFY_INSTALL_DIR}" \ + -S "${root}" -B "${root}-build" + + echo "Building & installing..." + cmake --build "${root}-build" --config Release --target install --parallel ) - echo "Installed Uncrustify to: ${UNCRUSTIFY_LOCAL_INSTALL_DIR}" + + echo "Installed Uncrustify to: ${UNCRUSTIFY_INSTALL_DIR}" } print_usage_and_exit() { - sed -n '2,19p' "$0" | sed 's/^# \{0,1\}//' + sed -n '2,24p' "$0" | sed 's/^# \{0,1\}//' exit 0 } -# Argument handling -if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then - print_usage_and_exit -fi - -if [[ "${1:-}" == "--install" ]]; then +# -------------------------- +# Argument parsing +# -------------------------- +DO_INSTALL=0 +# Accept: --install, --install-dir , -h/--help +while [[ $# -gt 0 ]]; do + case "$1" in + -h|--help) + print_usage_and_exit + ;; + --install) + DO_INSTALL=1 + shift + ;; + --install-dir) + [[ $# -ge 2 ]] || die "$1 requires a path argument" + UNCRUSTIFY_INSTALL_DIR="$(readlink -m "$2" 2>/dev/null || realpath -m "$2")" + UNCRUSTIFY_BIN="${UNCRUSTIFY_INSTALL_DIR}/bin/uncrustify" + # Only update UNCRUSTIFY default if user hasn't explicitly set it + if [[ "${UNCRUSTIFY:-}" != "${UNCRUSTIFY_BIN}" ]]; then + UNCRUSTIFY="${UNCRUSTIFY_BIN}" + fi + shift 2 + ;; + *) + # ignore unrecognized positional args for now + shift + ;; + esac +done + +if [[ "$DO_INSTALL" -eq 1 ]]; then install_uncrustify # Ensure we use the freshly installed binary for this run - UNCRUSTIFY="$UNCRUSTIFY_LOCAL_INSTALL_EXECUTABLE" + UNCRUSTIFY="$UNCRUSTIFY_BIN" fi +# -------------------------- +# Validate & run +# -------------------------- + # Check Uncrustify availability if ! command -v "$UNCRUSTIFY" >/dev/null 2>&1; then err "Uncrustify executable not found: $UNCRUSTIFY" - die "Add it to PATH, set UNCRUSTIFY=/path/to/uncrustify, or run: $0 --install" + die "Add it to PATH, set UNCRUSTIFY=/path/to/uncrustify, or run: $0 --install [--install-dir DIR]" fi # Version check DETECTED_VERSION="$("$UNCRUSTIFY" --version 2>&1 | grep -oE '[0-9]+(\.[0-9]+)*' | head -n1 || true)" echo "Detected Uncrustify: ${DETECTED_VERSION:-unknown}" if [[ "$DETECTED_VERSION" != "${UNCRUSTIFY_VERSION}" ]]; then - die "Expected Uncrustify ${UNCRUSTIFY_VERSION}. Re-run with --install or adjust UNCRUSTIFY." + die "Expected Uncrustify ${UNCRUSTIFY_VERSION}. Re-run with --install (and optionally --install-dir) or set UNCRUSTIFY." fi # Config check From feac7af774ed68c9ab251175b3e26c2b4b897e6c Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 28 Aug 2025 17:57:48 -0400 Subject: [PATCH 09/10] chore(runformat): Add support for displaying the expected uncrustify version --- runformat | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/runformat b/runformat index 9a57490c..0dc1ad52 100755 --- a/runformat +++ b/runformat @@ -3,9 +3,10 @@ # runformat - format this project's C++ sources with Uncrustify. # # Usage: -# ./runformat # format using the configured Uncrustify -# ./runformat --install # download, build, and use Uncrustify locally +# ./runformat # format using the configured Uncrustify +# ./runformat --install # download, build, and use Uncrustify locally # ./runformat --install --install-dir /abs/path +# ./runformat --expected-uncrustify-version # print ONLY the expected Uncrustify version # # You may also set: # UNCRUSTIFY=/abs/path/to/uncrustify # use a specific binary @@ -83,7 +84,13 @@ install_uncrustify() { } print_usage_and_exit() { - sed -n '2,24p' "$0" | sed 's/^# \{0,1\}//' + sed -n '2,25p' "$0" | sed 's/^# \{0,1\}//' + exit 0 +} + +# Print ONLY expected Uncrustify version (no extra text). +print_expected_uncrustify_version_and_exit() { + printf '%s\n' "$UNCRUSTIFY_VERSION" exit 0 } @@ -91,6 +98,7 @@ print_usage_and_exit() { # Argument parsing # -------------------------- DO_INSTALL=0 +PRINT_EXPECTED_UNCRUSTIFY_VERSION=0 # Accept: --install, --install-dir , -h/--help while [[ $# -gt 0 ]]; do case "$1" in @@ -111,6 +119,10 @@ while [[ $# -gt 0 ]]; do fi shift 2 ;; + --expected-uncrustify-version) + PRINT_EXPECTED_UNCRUSTIFY_VERSION=1 + shift + ;; *) # ignore unrecognized positional args for now shift @@ -124,6 +136,11 @@ if [[ "$DO_INSTALL" -eq 1 ]]; then UNCRUSTIFY="$UNCRUSTIFY_BIN" fi +# If requested, print ONLY the expected Uncrustify version and exit. +if [[ "$PRINT_EXPECTED_UNCRUSTIFY_VERSION" -eq 1 ]]; then + print_expected_uncrustify_version_and_exit +fi + # -------------------------- # Validate & run # -------------------------- From ab6070c48c5a7b9338b959dd0fa30c9a95c84349 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 28 Aug 2025 18:40:53 -0400 Subject: [PATCH 10/10] ci: Add GitHub Workflow for running uncrustify --- .github/workflows/format.yml | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) 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..4d5657f8 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,62 @@ +# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions +# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners +name: format + +on: + push: + branches: + - 'master' + - 'releases/**' + - '1.*' + tags: + - '1.*' + pull_request: + +permissions: + contents: read + +jobs: + format: + + runs-on: ubuntu-22.04 + + defaults: + run: + shell: bash -euo pipefail {0} + + env: + UNCRUSTIFY_INSTALL_DIR: ${{ github.workspace }}/runformat-uncrustify + + steps: + - uses: actions/checkout@v5 + with: + persist-credentials: false + + - name: Determine uncrustify version + id: get-uncrustify-version + run: | + version="$(./runformat --expected-uncrustify-version)" + echo "Expected uncrustify version: $version" + echo "version=$version" >> "$GITHUB_OUTPUT" + + - name: Set UNCRUSTIFY_VERSION env variable + run: | + version=$(./runformat --expected-uncrustify-version) + echo "version [$version]" + echo "UNCRUSTIFY_VERSION=${version}" >> "$GITHUB_ENV" + + - name: Cache uncrustify + uses: actions/cache@v4 + id: cache-uncrustify + with: + path: ${{ env.UNCRUSTIFY_INSTALL_DIR }} + key: ${{ runner.os }}-uncrustify-${{ steps.get-uncrustify-version.outputs.version }} + + - name: Install uncrustify + if: steps.cache-uncrustify.outputs.cache-hit != 'true' + run: | + ./runformat --install --install-dir "${UNCRUSTIFY_INSTALL_DIR}" + + - name: Uncrustify check + run: | + ./runformat