From ac9227ee9130591a17becfaea890e13212980635 Mon Sep 17 00:00:00 2001 From: Resurrected Trader Date: Wed, 17 Jun 2026 22:50:56 +0100 Subject: [PATCH] chore: pin clang-format version and format the tree CI's format check ran whatever clang-format the windows-latest VS bundles, which drifts from the local VS clang-format - notably it infers pointer alignment (East vs West) differently by version, so `check-format` passed locally yet failed in CI (e.g. V8Host.h), turning every PR's format job red regardless of what the PR changed. - build.ps1: prefer a PATH clang-format pinned to $PINNED_CLANG_FORMAT (20.1.8), falling back to the VS-bundled tool for local dev. The version probe is quiet so a non-clang-format `clang-format` shim on PATH (e.g. a Chromium depot_tools wrapper) is ignored rather than erroring. - ci.yml: `pip install clang-format==20.1.8` in the format job so CI uses the pinned version (kept in sync with build.ps1). - Reformat the tree under the pinned version: Version.h's nested #define is indented per IndentPPDirectives: BeforeHash. --- .github/workflows/ci.yml | 6 +++++ build.ps1 | 30 ++++++++++++++++++++--- src/framework/components/config/Version.h | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eabdfb8..7020d2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,6 +28,12 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v4 + # Pin clang-format so CI matches local: build.ps1 prefers a PATH + # clang-format at this version, otherwise an unpinned VS-bundled one drifts + # between machines. Keep this version in sync with $PINNED_CLANG_FORMAT in build.ps1. + - name: Install pinned clang-format + shell: pwsh + run: pip install "clang-format==20.1.8" - name: clang-format check shell: pwsh run: .\build.ps1 check-format diff --git a/build.ps1 b/build.ps1 index 387eb40..a80e9ed 100644 --- a/build.ps1 +++ b/build.ps1 @@ -86,6 +86,28 @@ function Get-LlvmTool { return Resolve-FirstPath $candidates ([System.IO.Path]::GetFileNameWithoutExtension($Exe)) } +# clang-format is version-pinned so CI and local agree. An unpinned, VS-bundled +# clang-format drifts between machines (it infers East vs West pointer alignment +# differently by version, among other things), which makes `check-format` pass +# locally yet fail in CI. CI installs this exact version with +# `pip install clang-format==` (see .github/workflows/ci.yml); locally we +# prefer a matching clang-format on PATH and fall back to the VS-bundled tool. +$PINNED_CLANG_FORMAT = '20.1.8' + +function Get-ClangFormat { + # Pick the first clang-format on PATH that reports the pinned version (CI + # installs it via pip). Scan ALL PATH matches, not just the first, so a + # different-version or non-clang-format `clang-format` ahead on PATH (e.g. a + # Chromium depot_tools wrapper) can't shadow the pinned one. Probe quietly and + # fall back to the VS-bundled tool for local dev. + foreach ($cmd in @(Get-Command clang-format -All -ErrorAction SilentlyContinue)) { + $verLine = '' + try { $verLine = (& $cmd.Source --version 2>$null | Out-String) } catch {} + if ($verLine -match [regex]::Escape($PINNED_CLANG_FORMAT)) { return $cmd.Source } + } + return Get-LlvmTool 'clang-format.exe' +} + # --- Resolve MSBuild --- $msbuildCandidates = @() if ($vsInstall) { @@ -107,9 +129,9 @@ function Get-SourceFiles { switch ($mode) { 'format' { - $clangFormat = Get-LlvmTool 'clang-format.exe' + $clangFormat = Get-ClangFormat if (-not $clangFormat) { - Write-Host 'clang-format not found. Install LLVM tools via Visual Studio or put clang-format.exe on PATH.' -ForegroundColor Red + Write-Host "clang-format not found. Install it with 'pip install clang-format==$PINNED_CLANG_FORMAT' or via Visual Studio LLVM tools." -ForegroundColor Red exit 1 } Write-Host 'Formatting source files...' @@ -118,9 +140,9 @@ switch ($mode) { exit 0 } 'check-format' { - $clangFormat = Get-LlvmTool 'clang-format.exe' + $clangFormat = Get-ClangFormat if (-not $clangFormat) { - Write-Host 'clang-format not found. Install LLVM tools via Visual Studio or put clang-format.exe on PATH.' -ForegroundColor Red + Write-Host "clang-format not found. Install it with 'pip install clang-format==$PINNED_CLANG_FORMAT' or via Visual Studio LLVM tools." -ForegroundColor Red exit 1 } Write-Host 'Checking format...' diff --git a/src/framework/components/config/Version.h b/src/framework/components/config/Version.h index 2ac1da6..bbdbc88 100644 --- a/src/framework/components/config/Version.h +++ b/src/framework/components/config/Version.h @@ -5,5 +5,5 @@ // un-parameterized IDE builds. d2bsng versions start at 2.x so scripts can tell // it apart from legacy d2bs, which topped out at 1.6.x. #ifndef D2BS_VERSION -#define D2BS_VERSION "2.0.0-dev" + #define D2BS_VERSION "2.0.0-dev" #endif