forked from yvt/openspades
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-clang-format.ps1
executable file
·37 lines (29 loc) · 1.04 KB
/
run-clang-format.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env pwsh
param(
[string]$SourceDirectory = ".",
[string]$ClangFormat = "clang-format"
)
# TODO: Run clang-format on C++ source files
# Run clang-format on AngelScript source files
$ScriptDirectory = Join-Path $SourceDirectory "Resources" "Scripts"
$Scripts = Get-ChildItem -Recurse -Include "*.as" $ScriptDirectory
$I = 0
foreach ($Item in $Scripts) {
$Path = $Item.FullName
$TmpPath = $Path.Substring(0, $Path.Length - 3) + ".java"
# Make it pretend to be a Java source file (which clang-format understands)
# I didn't choose C++ mainly due to the difference in how accessibility is
# specified.
Copy-Item $Path $TmpPath
# Run clang-format
&$ClangFormat -i -style=file $TmpPath
# Rename it back
Move-Item -Force $TmpPath $Path
# Fix `@ this.`
$Text = Get-Content $Path
$Text = $Text.Replace("@ this.", "@this.")
Set-Content $Path $Text
$I += 1
Write-Progress -Activity "Running clang-format on AngelScript source files" `
-PercentComplete ($I / $Scripts.Count * 100)
}