2023-03-13 17:17:12 -07:00
|
|
|
[string[]] $include = '*.h', '*.hh', '*.hpp', '*.c', '*.cc', '*.cpp'
|
2023-03-30 14:36:36 -07:00
|
|
|
[string[]] $exclude = '*.g.*', '*.refactor'
|
2023-03-13 17:17:12 -07:00
|
|
|
|
|
|
|
|
|
|
|
$path_root = git rev-parse --show-toplevel
|
|
|
|
$path_build = Join-Path $path_root build
|
2023-03-30 14:36:36 -07:00
|
|
|
$path_project = Join-Path $path_root project
|
2023-03-13 17:17:12 -07:00
|
|
|
$path_test = Join-Path $path_root test
|
|
|
|
$path_thirdparty = Join-Path $path_root thirdparty
|
|
|
|
|
|
|
|
$file_spec = Join-Path $path_test zpl.refactor
|
|
|
|
$refactor = Join-Path $path_build refactor.exe
|
|
|
|
|
|
|
|
# Gather the files to be formatted.
|
2023-03-30 14:36:36 -07:00
|
|
|
$targetFiles = @(Get-ChildItem -Recurse -Path $path_thirdparty -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
|
|
|
|
$refactoredFiles = @()
|
2023-03-13 17:17:12 -07:00
|
|
|
|
|
|
|
foreach ( $file in $targetFiles )
|
|
|
|
{
|
|
|
|
$destination = Join-Path $path_test (Split-Path $file -leaf)
|
|
|
|
$destination = $destination.Replace( '.h', '.refactored.h' )
|
2023-03-30 14:36:36 -07:00
|
|
|
$destination = $destination.Replace( '.c', '.refactored.c' )
|
|
|
|
|
|
|
|
$refactoredFiles += $destination
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
write-host "Beginning thirdpary refactor...`n"
|
|
|
|
|
|
|
|
$refactors = @(@())
|
|
|
|
|
|
|
|
if ( $false ){
|
|
|
|
foreach ( $file in $targetFiles )
|
|
|
|
{
|
|
|
|
$destination = Join-Path $path_test (Split-Path $file -leaf)
|
|
|
|
$destination = $destination.Replace( '.h', '.refactored.h' )
|
|
|
|
|
|
|
|
$refactorParams = @(
|
|
|
|
"-src=$($file)",
|
|
|
|
"-dst=$($destination)"
|
|
|
|
"-spec=$($file_spec)"
|
|
|
|
)
|
|
|
|
|
|
|
|
$refactors += (Start-Process $refactor $refactorParams -NoNewWindow -PassThru)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2023-03-13 17:17:12 -07:00
|
|
|
$refactorParams = @(
|
2023-03-30 16:33:46 -07:00
|
|
|
# "-debug",
|
2023-03-30 14:36:36 -07:00
|
|
|
"-num=$($targetFiles.Count)"
|
|
|
|
"-src=$($targetFiles)",
|
|
|
|
"-dst=$($refactoredFiles)",
|
2023-03-13 17:17:12 -07:00
|
|
|
"-spec=$($file_spec)"
|
|
|
|
)
|
|
|
|
|
2023-03-30 14:36:36 -07:00
|
|
|
Start-Process $refactor $refactorParams -NoNewWindow -PassThru -Wait
|
2023-03-13 17:17:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $process in $refactors )
|
|
|
|
{
|
|
|
|
if ( $process )
|
|
|
|
{
|
|
|
|
$process.WaitForExit()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host "`nRefactoring complete`n`n"
|
|
|
|
|
2023-03-30 14:36:36 -07:00
|
|
|
write-host "Beginning project refactor...`n"
|
2023-03-13 17:17:12 -07:00
|
|
|
|
2023-03-30 14:36:36 -07:00
|
|
|
# Gather the files to be formatted.
|
|
|
|
$targetFiles = @(Get-ChildItem -Recurse -Path $path_project -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
|
|
|
|
$refactoredFiles = @()
|
|
|
|
|
|
|
|
$file_spec = Join-Path $path_test project.refactor
|
|
|
|
|
|
|
|
write-host "FILE SPEC:" $file_spec
|
|
|
|
|
|
|
|
foreach ( $file in $targetFiles )
|
2023-03-13 17:17:12 -07:00
|
|
|
{
|
2023-03-30 14:36:36 -07:00
|
|
|
$destination = Join-Path $path_test (Split-Path $file -leaf)
|
|
|
|
$destination = $destination.Replace( '.hpp', '.refactored.hpp' )
|
|
|
|
$destination = $destination.Replace( '.cpp', '.refactored.cpp' )
|
|
|
|
|
|
|
|
$refactoredFiles += $destination
|
|
|
|
}
|
|
|
|
|
|
|
|
$refactorParams = @(
|
2023-03-30 16:33:46 -07:00
|
|
|
# "-debug",
|
2023-03-30 14:36:36 -07:00
|
|
|
"-num=$($targetFiles.Count)"
|
|
|
|
"-src=$($targetFiles)",
|
|
|
|
"-dst=$($refactoredFiles)",
|
|
|
|
"-spec=$($file_spec)"
|
|
|
|
)
|
|
|
|
|
|
|
|
Start-Process $refactor $refactorParams -NoNewWindow -PassThru -Wait
|
|
|
|
|
|
|
|
write-host "`nRefactoring complete`n`n"
|
|
|
|
|
|
|
|
|
|
|
|
# Can't format zpl library... (It hangs clang format)
|
|
|
|
if ( $false ) {
|
2023-03-13 17:17:12 -07:00
|
|
|
Write-Host "Beginning format...`n"
|
|
|
|
|
|
|
|
# Format the files.
|
|
|
|
$formatParams = @(
|
|
|
|
'-i' # In-place
|
|
|
|
'-style=file' # Search for a .clang-format file in the parent directory of the source file.
|
|
|
|
'-verbose'
|
|
|
|
)
|
|
|
|
|
|
|
|
$targetFiles = @(Get-ChildItem -Recurse -Path $path_test -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
|
|
|
|
|
|
|
|
clang-format $formatParams $targetFiles
|
|
|
|
|
|
|
|
Write-Host "`nFormatting complete"
|
|
|
|
}
|