Crusader_Decomp/rebuild/remorse/tools/clean-old-build-artifacts.ps1
Maddo ffb1918f35 Add tests for controller fire attempt suppression and usecode interpreter functionality
- Enhanced isometric_controls_tests.cpp to include assertions for controller fire attempt suppression under various conditions.
- Added tests for the Usecode interpreter in usecode_vm_tests.cpp, verifying script execution and stack manipulation.
- Introduced a new PowerShell script, clean-old-build-artifacts.ps1, to facilitate the cleanup of old build artifacts in specified directories.
2026-10-08 09:01:31 +02:00

56 lines
No EOL
2.3 KiB
PowerShell

[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
param(
[switch]$Apply
)
$repoRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..\..\..'))
$outputRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..\out'))
$allowedBuildDirectories = @('build-nmake', 'build-track-b')
if (-not (Test-Path -LiteralPath $outputRoot -PathType Container)) {
throw "Expected generated output directory was not found: $outputRoot"
}
$outputRootInfo = Get-Item -LiteralPath $outputRoot -Force
if (($outputRootInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0) {
throw "Refusing to use a reparse-point output directory: $outputRoot"
}
$repoPrefix = $repoRoot.TrimEnd('\') + '\'
if (-not $outputRoot.StartsWith($repoPrefix, [System.StringComparison]::OrdinalIgnoreCase)) {
throw "Output directory is outside the repository: $outputRoot"
}
$outputPrefix = $outputRoot.TrimEnd('\') + '\'
$targets = [System.Collections.Generic.List[System.IO.DirectoryInfo]]::new()
foreach ($directoryName in $allowedBuildDirectories) {
$targetPath = [System.IO.Path]::GetFullPath((Join-Path $outputRoot $directoryName))
if (-not $targetPath.StartsWith($outputPrefix, [System.StringComparison]::OrdinalIgnoreCase)) {
throw "Refusing to process a path outside the generated output directory: $targetPath"
}
if (-not (Test-Path -LiteralPath $targetPath -PathType Container)) {
Write-Output "Skip (not present): $targetPath"
continue
}
$targetInfo = Get-Item -LiteralPath $targetPath -Force
if (($targetInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0) {
throw "Refusing to remove a reparse-point build directory: $targetPath"
}
if (-not (Test-Path -LiteralPath (Join-Path $targetPath 'CMakeCache.txt') -PathType Leaf)) {
throw "Refusing to remove a directory without a CMake cache: $targetPath"
}
$targets.Add($targetInfo)
}
foreach ($target in $targets) {
if (-not $Apply) {
Write-Output "Dry run; would remove generated CMake build directory: $($target.FullName)"
continue
}
if ($PSCmdlet.ShouldProcess($target.FullName, 'Remove generated CMake build directory')) {
Remove-Item -LiteralPath $target.FullName -Recurse -Force
Write-Output "Removed: $($target.FullName)"
}
}