|
| 1 | + |
| 2 | +# PowerShell helper functions for Windows build. These can't be built into Releaser because we also |
| 3 | +# need to use them for our regular CI job. |
| 4 | + |
| 5 | +$ProgressPreference = "SilentlyContinue" # prevents console errors from CircleCI host |
| 6 | + |
| 7 | +$vcBaseDir = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC" |
| 8 | +$env:Path += ";$vcBaseDir\Common7\Tools" |
| 9 | + |
| 10 | +# This helper function is based on https://github.com/psake/psake - it allows us to terminate the |
| 11 | +# script if any external command (like "aws" or "dotnet", rather than a PowerShell cmdlet) returns |
| 12 | +# an error code, which PowerShell won't otherwise do. |
| 13 | +function ExecuteOrFail { |
| 14 | + [CmdletBinding()] |
| 15 | + param( |
| 16 | + [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd, |
| 17 | + [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ("Error executing command {0}" -f $cmd) |
| 18 | + ) |
| 19 | + & $cmd |
| 20 | + if ($lastexitcode -ne 0) { |
| 21 | + throw ($errorMessage) |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +function DownloadAndUnzip { |
| 26 | + param( |
| 27 | + [Parameter(Mandatory)][string]$url, |
| 28 | + [Parameter(Mandatory)][string]$filename |
| 29 | + ) |
| 30 | + Write-Host Downloading and expanding $url |
| 31 | + ExecuteOrFail { iwr -outf $filename $url } |
| 32 | + ExecuteOrFail { unzip $filename | Out-Null } |
| 33 | +} |
| 34 | + |
| 35 | +# Using vcvarsall.bat from PowerShell is not straightforward - see |
| 36 | +# https://stackoverflow.com/questions/41399692/running-a-build-script-after-calling-vcvarsall-bat-from-powershell |
| 37 | +# Invokes a Cmd.exe shell script and updates the environment. |
| 38 | +function Invoke-CmdScript { |
| 39 | + param( |
| 40 | + [String] $scriptName |
| 41 | + ) |
| 42 | + $cmdLine = """$scriptName"" $args & set" |
| 43 | + & $Env:SystemRoot\system32\cmd.exe /c $cmdLine | |
| 44 | + select-string '^([^=]*)=(.*)$' | foreach-object { |
| 45 | + $varName = $_.Matches[0].Groups[1].Value |
| 46 | + $varValue = $_.Matches[0].Groups[2].Value |
| 47 | + set-item Env:$varName $varValue |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +function SetupVSToolsEnv { |
| 52 | + param( |
| 53 | + [Parameter(Mandatory)][string]$architecture |
| 54 | + ) |
| 55 | + Write-Host "Setting environment for $architecture" |
| 56 | + Invoke-CmdScript "$vcBaseDir\Auxiliary\Build\vcvarsall.bat" $architecture |
| 57 | +} |
0 commit comments