11# !/usr/bin/env pwsh
22
3- # This script downloads boost. It must be invoked with 3 arguments
4- # windows_download_boost.ps1 <boost_version> <msvc version> <architecture>
5- # eg. windows_download_boost.ps1 1.91.0 14.3 64
3+ # This script downloads boost. It must be invoked with 4 arguments
4+ # windows_download_boost.ps1 <boost_version> <msvc version> <architecture> <output_dir>
5+ # eg. windows_download_boost.ps1 1.91.0 14.3 64 C:\local\boost
66
7- if ($args.Count -ne 3 ) {
8- Write-Host " Error: This script requires 3 parameters.\n windows_download_boost.ps1 <boost_version> <msvc version> <architecture>"
7+ if ($args.Count -ne 4 ) {
8+ Write-Host " Error: This script requires 4 parameters.\n windows_download_boost.ps1 <boost_version> <msvc version> <architecture> <output_dir >"
99 exit
1010}
1111# set Invoke-WebRequest to not show progress bar, as it can cause issues in some CI environments
@@ -14,6 +14,9 @@ $ProgressPreference = 'SilentlyContinue'
1414[string ] $version = $args [0 ]
1515[string ] $msvc_version = $args [1 ]
1616[string ] $architecture = $args [2 ]
17+ [string ] $output_dir = $args [3 ]
18+
19+ [string ] $outputfile = Join-Path - Path $output_dir - ChildPath " boost.exe"
1720[int ]$maxRetries = 3
1821[int ]$retryCount = 0
1922[int ]$StatusCode = 200
@@ -23,28 +26,33 @@ $response = $null
2326$version_und = $version.Replace (' .' , ' _' )
2427$uri = " https://github.com/userdocs/boost/releases/download/boost-" + $version + " /boost_" + $version_und + " -msvc-" + $msvc_version + " -" + $architecture + " .exe"
2528
26- if (-not (Test-Path ' C:/local/boost/libs' )) {
27- echo " Boost not cached, downloading it: $uri "
29+ if (-not (Test-Path $output_dir )) {
30+ New-Item - ItemType Directory - Path $output_dir
31+ }
32+
33+ if (-not (Test-Path $outputfile )) {
34+ Write-Host " Boost not cached, downloading it: from $uri to $outputfile "
2835 do {
2936 try {
30- $response = Invoke-WebRequest - Verbose - Debug - Uri " $uri " - OutFile " .\boost.exe "
37+ $response = Invoke-WebRequest - Uri " $uri " - OutFile " $outputfile "
3138 break
3239 } catch {
3340 $StatusCode = $_.Exception.Response.StatusCode
3441 $errorMessage = $_.Exception.Message
42+ $response = $null
3543 $retryCount ++
36- echo " Attempt $retryCount failed: $StatusCode $errorMessage . Retrying $uri ..."
44+ Write-Host " Attempt $retryCount failed: $StatusCode $errorMessage . Retrying $uri ..."
3745 Start-Sleep - Seconds 2 # Wait before retrying
3846 }
3947 } until ($retryCount -ge $maxRetries )
4048
41- if ($response ) {
42- echo " Boost downloaded"
49+ if ($response -eq $null ) {
50+ Write-Host " Request failed after $retryCount attempts."
51+ exit 1
4352 } else {
44- echo " Request failed after $retryCount attempts."
45- # exit 1
53+ Write-Host " Boost downloaded"
4654 }
47- } else { echo " Boost already installed" }
55+ } else { Write-Host " Boost already installed" }
4856
4957if (Test-Path ' ./boost.exe' ) {
5058 echo " Boost executable found."
0 commit comments