Skip to content

Commit

Permalink
Add Run-CleanupStep
Browse files Browse the repository at this point in the history
1. Separated vcpkg cleanup into `Run-CleanupStep`
2. Added `StagedArtifacts` to be removed in `Run-CleanupStep`, if it exists (ex. subsequent local runs)
  • Loading branch information
mike-malburg committed Oct 2, 2024
1 parent 34bd9fb commit db4cfe5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions invoke-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ param(
$global:showDebug = $ShowDebug
Import-Module "$PSScriptRoot/scripts/ps-modules/Build" -Force -DisableNameChecking
Run-WriteParamsStep -packageAndFeatures $PackageAndFeatures -scriptArgs $PSBoundParameters
Run-CleanupStep
Run-SetupVcPkgStep $VcPkgHash
Run-PreBuildStep $PackageAndFeatures
Run-InstallPackageStep -packageAndFeatures $PackageAndFeatures -linkType $LinkType -buildType $BuildType
Expand Down
37 changes: 27 additions & 10 deletions scripts/ps-modules/Build/Build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,32 @@ function Run-WriteParamsStep {
Write-Message (Get-PSObjectAsFormattedList -Object $scriptArgs)
}

function Run-CleanupStep {
Write-Banner -Level 3 -Title "Cleaning files"

Write-Message "Removing vcpkg cache..."
if ( (Get-IsOnWindowsOS) ) {
$vcpkgCacheDir = "$env:LocalAppData/vcpkg/archives"
} elseif ( (Get-IsOnMacOS) ) {
$vcpkgCacheDir = "$HOME/.cache/vcpkg/archives"
}
if (Test-Path -Path $vcpkgCacheDir -PathType Container) {
Remove-Item -Path $vcpkgCacheDir -Recurse -Force
}

Write-Message "Removing vcpkg dir..."
$vcpkgInstallDir = "./vcpkg"
if (Test-Path -Path $vcpkgInstallDir -PathType Container) {
Remove-Item -Path $vcpkgInstallDir -Recurse -Force
}

Write-Message "Removing StagedArtifacts..."
$stagedArtifactsDir = "./StagedArtifacts"
if (Test-Path -Path $stagedArtifactsDir -PathType Container) {
Remove-Item -Path $stagedArtifactsDir -Recurse -Force
}
}

function Run-SetupVcpkgStep {
param(
[string]$repoHash
Expand All @@ -169,20 +195,11 @@ function Run-SetupVcpkgStep {
$installDir = "./vcpkg"
if ( (Get-IsOnWindowsOS) ) {
$bootstrapScript = "./bootstrap-vcpkg.bat"
$cacheDir = "$env:LocalAppData/vcpkg/archives"
} elseif ( (Get-IsOnMacOS) ) {
$bootstrapScript = "./bootstrap-vcpkg.sh"
$cacheDir = "$HOME/.cache/vcpkg/archives"
}

Write-Banner -Level 3 -Title "Setting up vcpkg"
Write-Message "Removing vcpkg..."
if (Test-Path -Path $cacheDir -PathType Container) {
Remove-Item -Path $cacheDir -Recurse -Force
}
if (Test-Path -Path $installDir -PathType Container) {
Remove-Item -Path $installDir -Recurse -Force
}

Write-Message "$(NL)Installing vcpkg..."
if (-not (Test-Path -Path $installDir -PathType Container)) {
Expand Down Expand Up @@ -413,7 +430,7 @@ function Resolve-Symlink {
return $currentPath.FullName
}

Export-ModuleMember -Function Get-PackageInfo, Run-WriteParamsStep, Run-SetupVcpkgStep, Run-PreBuildStep, Run-InstallPackageStep, Run-PrestageAndFinalizeBuildArtifactsStep, Run-PostBuildStep, Run-StageBuildArtifactsStep, Run-StageSourceArtifactsStep
Export-ModuleMember -Function Get-PackageInfo, Run-WriteParamsStep, Run-SetupVcpkgStep, Run-PreBuildStep, Run-InstallPackageStep, Run-PrestageAndFinalizeBuildArtifactsStep, Run-PostBuildStep, Run-StageBuildArtifactsStep, Run-StageSourceArtifactsStep, Run-CleanupStep
Export-ModuleMember -Function NL, Write-Banner, Write-Message, Get-PSObjectAsFormattedList, Get-IsOnMacOS, Get-IsOnWindowsOS, Resolve-Symlink

if ( (Get-IsOnMacOS) ) {
Expand Down

0 comments on commit db4cfe5

Please sign in to comment.