diff options
Diffstat (limited to 'coin/provisioning/common/windows/helpers.ps1')
-rw-r--r-- | coin/provisioning/common/windows/helpers.ps1 | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/coin/provisioning/common/windows/helpers.ps1 b/coin/provisioning/common/windows/helpers.ps1 index 8599791d..9fbf27aa 100644 --- a/coin/provisioning/common/windows/helpers.ps1 +++ b/coin/provisioning/common/windows/helpers.ps1 @@ -148,7 +148,7 @@ function Download if ($CachedUrl.StartsWith("http")) { Invoke-WebRequest -UseBasicParsing $CachedUrl -OutFile $Destination } else { - Copy-Item $CachedUrl $Destination + Copy-Item $CachedUrl $Destination -errorAction stop } } catch { Write-Host "Cached download failed: Downloading from official location: $OfficialUrl" @@ -196,6 +196,28 @@ function Is64BitWinHost return [environment]::Is64BitOperatingSystem } +enum CpuArch { + x64 + x86 + arm64 + unknown +} + +function Get-CpuArchitecture +{ + # Possible values are "AMD64", "IA64", "ARM64", and "x86" + $arch = [System.Environment]::GetEnvironmentVariable('PROCESSOR_ARCHITECTURE', 'Machine') + if ($arch -eq "AMD64") { + return [CpuArch]::x64 + } elseif ($arch -eq "x86") { + return [CpuArch]::x86 + } elseif ($arch -eq "ARM64") { + return [CpuArch]::arm64 + } + + return [CpuArch]::unknown +} + function IsProxyEnabled { return (Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').proxyEnable } @@ -274,3 +296,50 @@ function DeleteSchedulerTask { Write-Host "Disabling $Task from Task Scheduler" SCHTASKS /DELETE /TN "Microsoft\Windows\$Task" /F } + +function GetVSPath { + Param ( + [string]$VSWhere = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe", + [string]$Component = "Microsoft.VisualStudio.Component.VC.Tools.x86.x64" + ) + + return (& $VSWhere -nologo -latest -products * -requires $Component -property installationPath) +} + +function EnterVSDevShell { + Param ( + [string]$HostArch = "amd64", + [string]$Arch = "amd64" + ) + + $vsWere = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" + $vcComponent = "Microsoft.VisualStudio.Component.VC.CoreIde" + # We pick the oldest build tools we can find and use that to be compatible with it and any newer version: + # If MSVC has an ABI break this will stop working, and yet another build must be added. + $VSPath = (& $vsWere -nologo -products * -requires $vcComponent -sort -format value -property installationPath | Select-Object -Last 1) + + Write-Host "Enter VisualStudio developer shell (-host_arch=$HostArch -arch=$Arch)" + try { + Import-Module "$VSPath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" + Enter-VsDevShell -VsInstallPath $VSPath -DevCmdArguments "-host_arch=$HostArch -arch=$Arch -no_logo" + } catch { + Write-Host "Failed to enter VisualStudio DevShell" + return $false + } + return $true +} + +function Invoke-MtCommand { + param( + [String] $vcVarsScript, + [String] $arch, + [String] $manifest, + [String] $executable + ) + $tempFile = [IO.Path]::GetTempFileName() + Add-Content -Path $tempFile -Value $manifest + $cmdLine = """$vcVarsScript"" $arch & mt.exe -manifest ""$tempFile"" -outputresource:""$executable"";1" + Write-Output Executing $cmdLine + & $Env:SystemRoot\system32\cmd.exe /c $cmdLine | Write-Output + Remove-Item $tempFile +} |