Skip to content

Commit 2ebcd3b

Browse files
committed
Added clang-format on template
1 parent f88c34c commit 2ebcd3b

4 files changed

Lines changed: 58 additions & 1 deletion

File tree

workspace/template/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build/
22
output/*
3-
.DS_Store
3+
.DS_Store
4+
*.exe

workspace/template/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ foreach(SOURCE_FILE ${SRC_FILES})
4040
COMMAND Python3::Interpreter ${PARENT_DIR}/tools/merge.py
4141
--out ${OUTPUT_FILE}
4242
--includes ${INCLUDE_DIRS}
43+
--assets-dir ${CMAKE_CURRENT_SOURCE_DIR}/output
4344
--src ${SOURCE_FILE}
4445
DEPENDS ${SOURCE_FILE} ${PARENT_DIR}/tools/merge.py
4546
VERBATIM
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if command -v clang-format-14 &> /dev/null; then
2+
CLANG_FORMAT="clang-format-14"
3+
else
4+
CLANG_FORMAT="clang-format"
5+
fi
6+
7+
find src -type f \( -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" \) -print0 | xargs -0 $CLANG_FORMAT -i --verbose

0 commit comments

Comments
 (0)