Skip to content

Commit d0c372d

Browse files
chore: pin clang-format version and format the tree
chore: pin clang-format version and format the tree
2 parents 3ce43e6 + ac9227e commit d0c372d

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ jobs:
2828
runs-on: windows-latest
2929
steps:
3030
- uses: actions/checkout@v4
31+
# Pin clang-format so CI matches local: build.ps1 prefers a PATH
32+
# clang-format at this version, otherwise an unpinned VS-bundled one drifts
33+
# between machines. Keep this version in sync with $PINNED_CLANG_FORMAT in build.ps1.
34+
- name: Install pinned clang-format
35+
shell: pwsh
36+
run: pip install "clang-format==20.1.8"
3137
- name: clang-format check
3238
shell: pwsh
3339
run: .\build.ps1 check-format

build.ps1

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,28 @@ function Get-LlvmTool {
8686
return Resolve-FirstPath $candidates ([System.IO.Path]::GetFileNameWithoutExtension($Exe))
8787
}
8888

89+
# clang-format is version-pinned so CI and local agree. An unpinned, VS-bundled
90+
# clang-format drifts between machines (it infers East vs West pointer alignment
91+
# differently by version, among other things), which makes `check-format` pass
92+
# locally yet fail in CI. CI installs this exact version with
93+
# `pip install clang-format==<ver>` (see .github/workflows/ci.yml); locally we
94+
# prefer a matching clang-format on PATH and fall back to the VS-bundled tool.
95+
$PINNED_CLANG_FORMAT = '20.1.8'
96+
97+
function Get-ClangFormat {
98+
# Pick the first clang-format on PATH that reports the pinned version (CI
99+
# installs it via pip). Scan ALL PATH matches, not just the first, so a
100+
# different-version or non-clang-format `clang-format` ahead on PATH (e.g. a
101+
# Chromium depot_tools wrapper) can't shadow the pinned one. Probe quietly and
102+
# fall back to the VS-bundled tool for local dev.
103+
foreach ($cmd in @(Get-Command clang-format -All -ErrorAction SilentlyContinue)) {
104+
$verLine = ''
105+
try { $verLine = (& $cmd.Source --version 2>$null | Out-String) } catch {}
106+
if ($verLine -match [regex]::Escape($PINNED_CLANG_FORMAT)) { return $cmd.Source }
107+
}
108+
return Get-LlvmTool 'clang-format.exe'
109+
}
110+
89111
# --- Resolve MSBuild ---
90112
$msbuildCandidates = @()
91113
if ($vsInstall) {
@@ -107,9 +129,9 @@ function Get-SourceFiles {
107129

108130
switch ($mode) {
109131
'format' {
110-
$clangFormat = Get-LlvmTool 'clang-format.exe'
132+
$clangFormat = Get-ClangFormat
111133
if (-not $clangFormat) {
112-
Write-Host 'clang-format not found. Install LLVM tools via Visual Studio or put clang-format.exe on PATH.' -ForegroundColor Red
134+
Write-Host "clang-format not found. Install it with 'pip install clang-format==$PINNED_CLANG_FORMAT' or via Visual Studio LLVM tools." -ForegroundColor Red
113135
exit 1
114136
}
115137
Write-Host 'Formatting source files...'
@@ -118,9 +140,9 @@ switch ($mode) {
118140
exit 0
119141
}
120142
'check-format' {
121-
$clangFormat = Get-LlvmTool 'clang-format.exe'
143+
$clangFormat = Get-ClangFormat
122144
if (-not $clangFormat) {
123-
Write-Host 'clang-format not found. Install LLVM tools via Visual Studio or put clang-format.exe on PATH.' -ForegroundColor Red
145+
Write-Host "clang-format not found. Install it with 'pip install clang-format==$PINNED_CLANG_FORMAT' or via Visual Studio LLVM tools." -ForegroundColor Red
124146
exit 1
125147
}
126148
Write-Host 'Checking format...'

src/framework/components/config/Version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
// un-parameterized IDE builds. d2bsng versions start at 2.x so scripts can tell
66
// it apart from legacy d2bs, which topped out at 1.6.x.
77
#ifndef D2BS_VERSION
8-
#define D2BS_VERSION "2.0.0-dev"
8+
#define D2BS_VERSION "2.0.0-dev"
99
#endif

0 commit comments

Comments
 (0)