summaryrefslogtreecommitdiff
path: root/run-clang-format.ps1
diff options
context:
space:
mode:
authorbriaguya <70942617+briaguya-ai@users.noreply.github.com>2024-05-22 09:46:12 -0400
committerGarrett Cox <garrettjcox@gmail.com>2024-05-22 09:05:05 -0500
commit0a2d89924bf54b29921f04ec5357166bbc74be9a (patch)
tree49b4a6585afc9f240b1f5464bc3156e01cb9d5fc /run-clang-format.ps1
parenta8ffb5bcb6605eb86f6d023bb8ea80f6f614d407 (diff)
clang format (#447)
* add linux clang format script * first shot at powershell * whoops * webrequest is slow, try webclient * just get the one file * simplify and maybe make it work? * whoops again * try a different suggestion * why is it always windows * again * try again * bit of path stuff * chmod +x * add action to check * fix workflow name
Diffstat (limited to 'run-clang-format.ps1')
-rw-r--r--run-clang-format.ps147
1 files changed, 47 insertions, 0 deletions
diff --git a/run-clang-format.ps1 b/run-clang-format.ps1
new file mode 100644
index 000000000..38d4d1422
--- /dev/null
+++ b/run-clang-format.ps1
@@ -0,0 +1,47 @@
+$url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.6/LLVM-14.0.6-win64.exe"
+$llvmInstallerPath = ".\LLVM-14.0.6-win64.exe"
+$clangFormatFilePath = ".\clang-format.exe"
+$requiredVersion = "clang-format version 14.0.6"
+$currentVersion = ""
+
+function Test-7ZipInstalled {
+ $sevenZipPath = "C:\Program Files\7-Zip\7z.exe"
+ return Test-Path $sevenZipPath -PathType Leaf
+}
+
+if (Test-Path $clangFormatFilePath) {
+ $currentVersion = & $clangFormatFilePath --version
+ if (-not ($currentVersion -eq $requiredVersion)) {
+ # Delete the existing file if the version is incorrect
+ Remove-Item $clangFormatFilePath -Force
+ }
+}
+
+if (-not (Test-Path $clangFormatFilePath) -or ($currentVersion -ne $requiredVersion)) {
+ if (-not (Test-7ZipInstalled)) {
+ Write-Host "7-Zip is not installed. Please install 7-Zip and run the script again."
+ exit
+ }
+
+ $wc = New-Object net.webclient
+ $wc.Downloadfile($url, $llvmInstallerPath)
+
+ $sevenZipPath = "C:\Program Files\7-Zip\7z.exe"
+ $specificFileInArchive = "bin\clang-format.exe"
+ & "$sevenZipPath" e $llvmInstallerPath $specificFileInArchive
+
+ Remove-Item $llvmInstallerPath -Force
+}
+
+$basePath = (Resolve-Path .).Path
+$files = Get-ChildItem -Path $basePath\mm -Recurse -File `
+ | Where-Object { ($_.Extension -eq '.c' -or $_.Extension -eq '.cpp' -or `
+ ($_.Extension -eq '.h' -and `
+ (-not ($_.FullName -like "*\mm\src\*" -or $_.FullName -like "*\mm\include\*")))) -and `
+ (-not ($_.FullName -like "*\mm\assets\*")) }
+
+foreach ($file in $files) {
+ $relativePath = $file.FullName.Substring($basePath.Length + 1)
+ Write-Host "Formatting $relativePath"
+ .\clang-format.exe -i $file.FullName
+}