|
| 1 | +Using Namespace System |
| 2 | +$url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.6/LLVM-14.0.6-win64.exe" |
| 3 | +$llvmInstallerPath = Join-Path $PSScriptRoot "LLVM-14.0.6-win64.exe" |
| 4 | +$clangFormatFilePath = Join-Path $PSScriptRoot "clang-format.exe" |
| 5 | +$requiredVersion = "clang-format version 14.0.6" |
| 6 | +$currentVersion = "" |
| 7 | + |
| 8 | +function Test-7ZipInstalled { |
| 9 | + $sevenZipPath = "C:\Program Files\7-Zip\7z.exe" |
| 10 | + return Test-Path $sevenZipPath -PathType Leaf |
| 11 | +} |
| 12 | + |
| 13 | +if (Test-Path $clangFormatFilePath) { |
| 14 | + $currentVersion = & $clangFormatFilePath --version |
| 15 | + if (-not ($currentVersion -eq $requiredVersion)) { |
| 16 | + Remove-Item $clangFormatFilePath -Force |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +if (-not (Test-Path $clangFormatFilePath) -or ($currentVersion -ne $requiredVersion)) { |
| 21 | + if (-not (Test-7ZipInstalled)) { |
| 22 | + Write-Host "7-Zip is not installed. Please install 7-Zip and run the script again." |
| 23 | + exit |
| 24 | + } |
| 25 | + |
| 26 | + $wc = New-Object net.webclient |
| 27 | + $wc.Downloadfile($url, $PSScriptRoot + $llvmInstallerPath) |
| 28 | + |
| 29 | + $sevenZipPath = "C:\Program Files\7-Zip\7z.exe" |
| 30 | + $specificFileInArchive = "bin\clang-format.exe" |
| 31 | + & "$sevenZipPath" e $llvmInstallerPath $specificFileInArchive |
| 32 | + |
| 33 | + Remove-Item $llvmInstallerPath -Force |
| 34 | +} |
| 35 | + |
| 36 | +$clangFormat = Join-Path $PSScriptRoot "clang-format.exe" |
| 37 | +$basePath = Join-Path $PSScriptRoot "src" |
| 38 | +$files = @(Get-ChildItem -Path $basePath -Recurse -File ` |
| 39 | + | Where-Object { $_ -ne $null -and ($_.Extension -eq '.c' -or $_.Extension -eq '.cpp' -or ` |
| 40 | + $_.Extension -eq '.h' -or $_.Extension -eq '.hpp') }) |
| 41 | + |
| 42 | +for ($i = 0; $i -lt $files.Length; $i++) { |
| 43 | + $file = $files[$i] |
| 44 | + if ($file -eq $null -or $file.FullName -eq $null) { continue } |
| 45 | + $relativePath = $file.FullName.Substring($basePath.Length + 1) |
| 46 | + Write-Host "Formatting [$($i+1)/$($files.Length)] $relativePath" |
| 47 | + & $clangFormat -i $file.FullName |
| 48 | +} |
0 commit comments