11# !/usr/bin/env pwsh
22
3- function Get-ClangFormat {
3+ $ToolConfig = @ {
4+ " clang-format" = @ {
5+ " linux-amd64" = @ {
6+ " url" = " https://github.com/multitheftauto/clang-tools-static-binaries/releases/download/v21.1.7/clang-format-21_linux-amd64"
7+ " filename" = " clang-format"
8+ " hash" = " 3d75779cdc69b06f7e39946b0e50d6ce3dccda1d766e355bf4cf507b1ae13303"
9+ }
10+ " windows-amd64" = @ {
11+ " url" = " https://github.com/multitheftauto/clang-tools-static-binaries/releases/download/v21.1.7/clang-format-21_windows-amd64.exe"
12+ " filename" = " clang-format.exe"
13+ " hash" = " 11defe615493876745f36fb77e9783e7eed03a7f800044ff58619d9293e79409"
14+ }
15+ }
16+ # "clang-tidy" = @{
17+ # "linux-amd64" = @{
18+ # "url" = "https://github.com/multitheftauto/clang-tools-static-binaries/releases/download/v21.1.7/clang-tidy-21_linux-amd64"
19+ # "filename" = "clang-tidy"
20+ # "hash" = "7b35986c04b7c4fc7040c254ac2b5eb0b01ece87c91cccb32e3a4d6ecfa9695f"
21+ # }
22+ # "windows-amd64" = @{
23+ # "url" = "https://github.com/multitheftauto/clang-tools-static-binaries/releases/download/v21.1.7/clang-tidy-21_windows-amd64.exe"
24+ # "filename" = "clang-tidy.exe"
25+ # "hash" = "e6afe42eb50ec9dcdf945d88b220b6b36971573cec7c5b6db22d3535c6cc61c4"
26+ # }
27+ # }
28+ }
29+
30+ function Get-ClangTool {
431 param (
532 [Parameter (Mandatory )] [string ]$RepoRoot ,
6- [string ]$Version = " v21.1.7 "
33+ [Parameter ( Mandatory )] [ string ]$ToolName
734 )
835
9- if ($isLinux ) {
10- $clangFormatUrl = " https://github.com/multitheftauto/clang-tools-static-binaries/releases/download/${Version} /clang-format-21_linux-amd64"
11- $clangFormatFilename = " clang-format"
12- $expectedHash = " 3d75779cdc69b06f7e39946b0e50d6ce3dccda1d766e355bf4cf507b1ae13303"
13- } else {
14- $clangFormatUrl = " https://github.com/multitheftauto/clang-tools-static-binaries/releases/download/${Version} /clang-format-21_windows-amd64.exe"
15- $clangFormatFilename = " clang-format.exe"
16- $expectedHash = " 11defe615493876745f36fb77e9783e7eed03a7f800044ff58619d9293e79409"
36+ $platform = if ($isLinux ) { " linux-amd64" } else { " windows-amd64" }
37+ $toolConfig = $ToolConfig [$ToolName ][$platform ]
38+ if (-not $toolConfig ) {
39+ Write-Error " No configuration found for tool '$ToolName ' on platform '$platform '"
40+ exit 1
1741 }
1842
1943 $binDir = Join-Path $RepoRoot " Build" " tmp"
20- $clangFormatPath = Join-Path $binDir $clangFormatFilename
44+ if (-not (Test-Path $binDir )) {
45+ New-Item - ItemType Directory - Path $binDir | Out-Null
46+ }
2147
2248 # Check existing file
23- if (Test-Path $clangFormatPath ) {
24- $currentHash = (Get-FileHash - Path $clangFormatPath - Algorithm SHA256).Hash
25- if ($currentHash -eq $expectedHash ) {
26- return $clangFormatPath
49+ $toolPath = Join-Path $binDir $toolConfig.filename
50+ if (Test-Path $toolPath ) {
51+ $currentHash = (Get-FileHash - Path $toolPath - Algorithm SHA256).Hash
52+ if ($currentHash -eq $toolConfig.hash ) {
53+ return $toolPath
2754 }
28- Write-Warning " clang-format hash mismatch, re-downloading..."
55+ Write-Warning " $ToolName hash mismatch, re-downloading..."
2956 }
3057
3158 # Download process
32- Write-Host " Downloading clang-format..." - ForegroundColor Cyan
33- if (-not (Test-Path $binDir )) {
34- New-Item - ItemType Directory - Path $binDir | Out-Null
35- }
36-
37- Invoke-WebRequest - Uri $clangFormatUrl - OutFile $clangFormatPath
59+ Write-Host " Downloading $ToolName ..." - ForegroundColor Cyan
60+ Invoke-WebRequest - Uri $toolConfig.url - OutFile $toolPath
3861 if ($isLinux ) {
39- chmod + x $clangFormatPath
62+ chmod + x $toolPath
4063 }
41- Write-Verbose " Downloaded clang-format to $clangFormatPath "
64+ Write-Verbose " Downloaded $ToolName to $toolPath "
4265
4366 # Verify hash
44- $downloadedHash = (Get-FileHash - Path $clangFormatPath - Algorithm SHA256).Hash
45- if ($downloadedHash -ne $expectedHash .ToUpper () ) {
46- Remove-Item $clangFormatPath - ErrorAction SilentlyContinue
47- Write-Error " SHA256 hash mismatch! Expected: $expectedHash , Got: $downloadedHash . The download may be corrupted."
67+ $downloadedHash = (Get-FileHash - Path $toolPath - Algorithm SHA256).Hash
68+ if ($downloadedHash -ne $toolConfig .hash ) {
69+ Remove-Item $toolPath - ErrorAction SilentlyContinue
70+ Write-Error " SHA256 hash mismatch! The download may be corrupted. Expected: $ ( $toolConfig .hash ) Got: $downloadedHash "
4871 exit 1
4972 }
5073
51- Write-Verbose " clang-format verified successfully."
52- return $clangFormatPath
74+ Write-Verbose " $ToolName verified successfully."
75+ return $toolPath
5376}
5477
5578function Invoke-ClangFormat {
@@ -61,8 +84,10 @@ function Invoke-ClangFormat {
6184 Write-Verbose " Changed directory to repository root: $repoRoot "
6285
6386 try {
87+ $clangFormatPath = Get-ClangTool - RepoRoot $repoRoot - ToolName " clang-format"
88+ # $clangTidyPath = Get-ClangTool -RepoRoot $repoRoot -ToolName "clang-tidy"
89+
6490 Write-Verbose " Searching for source files to format..."
65- $clangFormatPath = Get-ClangFormat - RepoRoot $repoRoot
6691 $searchFolders = " Client" , " Server" , " Shared"
6792 $files = Get-ChildItem - Path $searchFolders - Include * .c, * .cc, * .cpp, * .h, * .hh, * .hpp - Recurse - ErrorAction SilentlyContinue | Select-Object - ExpandProperty FullName
6893
0 commit comments