diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/VcpkgPowershellUtils-ClearEnvironment.ps1 | 52 | ||||
| -rw-r--r-- | scripts/VcpkgPowershellUtils.ps1 | 35 | ||||
| -rw-r--r-- | scripts/addPoshVcpkgToPowershellProfile.ps1 | 2 | ||||
| -rw-r--r-- | scripts/bootstrap.ps1 | 46 | ||||
| -rw-r--r-- | scripts/buildsystems/msbuild/applocal.ps1 | 6 | ||||
| -rw-r--r-- | scripts/cmake/vcpkg_apply_patches.cmake | 2 | ||||
| -rw-r--r-- | scripts/fetchDependency.ps1 | 33 | ||||
| -rw-r--r-- | scripts/findAnyMSBuildWithCppPlatformToolset.ps1 | 2 | ||||
| -rw-r--r-- | scripts/findVisualStudioInstallationInstances.ps1 | 2 |
9 files changed, 132 insertions, 48 deletions
diff --git a/scripts/VcpkgPowershellUtils-ClearEnvironment.ps1 b/scripts/VcpkgPowershellUtils-ClearEnvironment.ps1 new file mode 100644 index 000000000..0a133f5f8 --- /dev/null +++ b/scripts/VcpkgPowershellUtils-ClearEnvironment.ps1 @@ -0,0 +1,52 @@ +# Capture environment variables for the System and User. Also add some special/built-in variables. +# These will be used to synthesize a clean environment +$specialEnvironmentMap = @{ "SystemDrive"=$env:SystemDrive; "SystemRoot"=$env:SystemRoot; "UserProfile"=$env:UserProfile } # These are built-in and not set in the registry +$machineEnvironmentMap = [Environment]::GetEnvironmentVariables('Machine') # HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment +$userEnvironmentMap = [Environment]::GetEnvironmentVariables('User') # HKEY_CURRENT_USER\Environment + +# Identify the keySet of environment variable names +$nameSet = ($specialEnvironmentMap.Keys + $machineEnvironmentMap.Keys + $userEnvironmentMap.Keys) | Sort-Object | Select-Object -Unique + +# Any environment variable in the $nameSet should be restored to its original value +foreach ($name in $nameSet) +{ + if ($specialEnvironmentMap.ContainsKey($name)) + { + [Environment]::SetEnvironmentVariable($name, $specialEnvironmentMap[$name], 'Process') + continue; + } + + # PATH needs to be concatenated as it has values in both machine and user environment. Any other values should be set. + if ($name -match 'path') + { + $pathValuePartial = @() + # Machine values before user values + $pathValuePartial += $machineEnvironmentMap[$name] -split ';' + $pathValuePartial += $userEnvironmentMap[$name] -split ';' + $pathValue = $pathValuePartial -join ';' + [Environment]::SetEnvironmentVariable($name, $pathValue, 'Process') + continue; + } + + if ($userEnvironmentMap.ContainsKey($name)) + { + [Environment]::SetEnvironmentVariable($name, $userEnvironmentMap[$name], 'Process') + continue; + } + + if ($machineEnvironmentMap.ContainsKey($name)) + { + [Environment]::SetEnvironmentVariable($name, $machineEnvironmentMap[$name], 'Process') + continue; + } + + throw "Unreachable: Unknown variable $name" +} + +# Any environment variable NOT in the $nameSet should be removed +$processEnvironmentMap = [Environment]::GetEnvironmentVariables('Process') +$variablesForRemoval = $processEnvironmentMap.Keys | Where-Object {$nameSet -notcontains $_} +foreach ($name in $variablesForRemoval) +{ + [Environment]::SetEnvironmentVariable($name, $null, 'Process') +} diff --git a/scripts/VcpkgPowershellUtils.ps1 b/scripts/VcpkgPowershellUtils.ps1 index 5381523f0..63da1a508 100644 --- a/scripts/VcpkgPowershellUtils.ps1 +++ b/scripts/VcpkgPowershellUtils.ps1 @@ -167,15 +167,32 @@ function vcpkgExtractFile( [Parameter(Mandatory=$true)][string]$file, function vcpkgInvokeCommand() { param ( [Parameter(Mandatory=$true)][string]$executable, - [string]$arguments = "", - [switch]$wait) + [string]$arguments = "") Write-Verbose "Executing: ${executable} ${arguments}" - $process = Start-Process -FilePath $executable -ArgumentList $arguments -PassThru - if ($wait) - { - Wait-Process -InputObject $process - $ec = $process.ExitCode - Write-Verbose "Execution terminated with exit code $ec." - } + $process = Start-Process -FilePath "`"$executable`"" -ArgumentList $arguments -PassThru -NoNewWindow + Wait-Process -InputObject $process + $ec = $process.ExitCode + Write-Verbose "Execution terminated with exit code $ec." + return $ec +} + +function vcpkgInvokeCommandClean() +{ + param ( [Parameter(Mandatory=$true)][string]$executable, + [string]$arguments = "") + + Write-Verbose "Clean-Executing: ${executable} ${arguments}" + $scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition + $cleanEnvScript = "$scriptsDir\VcpkgPowershellUtils-ClearEnvironment.ps1" + $command = "& `"$cleanEnvScript`"; & `"$executable`" $arguments" + $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) + $encodedCommand = [Convert]::ToBase64String($bytes) + $arg = "-NoProfile -ExecutionPolicy Bypass -encodedCommand $encodedCommand" + + $process = Start-Process -FilePath powershell.exe -ArgumentList $arg -PassThru -NoNewWindow + Wait-Process -InputObject $process + $ec = $process.ExitCode + Write-Verbose "Execution terminated with exit code $ec." + return $ec }
\ No newline at end of file diff --git a/scripts/addPoshVcpkgToPowershellProfile.ps1 b/scripts/addPoshVcpkgToPowershellProfile.ps1 index 7a12e7d34..dcbd2e0be 100644 --- a/scripts/addPoshVcpkgToPowershellProfile.ps1 +++ b/scripts/addPoshVcpkgToPowershellProfile.ps1 @@ -13,7 +13,7 @@ function findExistingImportModuleDirectives([Parameter(Mandatory=$true)][string] return } -$scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition +$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition . "$scriptsDir\VcpkgPowershellUtils.ps1" $profileEntry = "Import-Module '$scriptsDir\posh-vcpkg'" diff --git a/scripts/bootstrap.ps1 b/scripts/bootstrap.ps1 index 3f40a2ead..03f05d50b 100644 --- a/scripts/bootstrap.ps1 +++ b/scripts/bootstrap.ps1 @@ -4,7 +4,8 @@ param( [Parameter(Mandatory=$False)][string]$withVSPath = "" ) -$scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition +$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition +. "$scriptsDir\VcpkgPowershellUtils.ps1" $vcpkgRootDir = & $scriptsDir\findFileRecursivelyUp.ps1 $scriptsDir .vcpkg-root Write-Verbose("vcpkg Path " + $vcpkgRootDir) @@ -36,26 +37,31 @@ if (!(Test-Path $vcpkgSourcesPath)) return } -try -{ - Push-Location $vcpkgSourcesPath - $msbuildExeWithPlatformToolset = & $scriptsDir\findAnyMSBuildWithCppPlatformToolset.ps1 $withVSPath - $msbuildExe = $msbuildExeWithPlatformToolset[0] - $platformToolset = $msbuildExeWithPlatformToolset[1] - $windowsSDK = & $scriptsDir\getWindowsSDK.ps1 - & $msbuildExe "/p:VCPKG_VERSION=-$gitHash" "/p:DISABLE_METRICS=$disableMetrics" /p:Configuration=Release /p:Platform=x86 /p:PlatformToolset=$platformToolset /p:TargetPlatformVersion=$windowsSDK /m dirs.proj - if ($LASTEXITCODE -ne 0) - { - Write-Error "Building vcpkg.exe failed. Please ensure you have installed Visual Studio with the Desktop C++ workload and the Windows SDK for Desktop C++." - return - } +$msbuildExeWithPlatformToolset = & $scriptsDir\findAnyMSBuildWithCppPlatformToolset.ps1 $withVSPath +$msbuildExe = $msbuildExeWithPlatformToolset[0] +$platformToolset = $msbuildExeWithPlatformToolset[1] +$windowsSDK = & $scriptsDir\getWindowsSDK.ps1 - Write-Verbose("Placing vcpkg.exe in the correct location") +$arguments = ( +"`"/p:VCPKG_VERSION=-$gitHash`"", +"`"/p:DISABLE_METRICS=$disableMetrics`"", +"/p:Configuration=Release", +"/p:Platform=x86", +"/p:PlatformToolset=$platformToolset", +"/p:TargetPlatformVersion=$windowsSDK", +"/m", +"`"$vcpkgSourcesPath\dirs.proj`"") -join " " - Copy-Item $vcpkgSourcesPath\Release\vcpkg.exe $vcpkgRootDir\vcpkg.exe | Out-Null - Copy-Item $vcpkgSourcesPath\Release\vcpkgmetricsuploader.exe $vcpkgRootDir\scripts\vcpkgmetricsuploader.exe | Out-Null -} -finally +# vcpkgInvokeCommandClean cmd "/c echo %PATH%" +$ec = vcpkgInvokeCommandClean $msbuildExe $arguments + +if ($ec -ne 0) { - Pop-Location + Write-Error "Building vcpkg.exe failed. Please ensure you have installed Visual Studio with the Desktop C++ workload and the Windows SDK for Desktop C++." + return } + +Write-Verbose("Placing vcpkg.exe in the correct location") + +Copy-Item $vcpkgSourcesPath\Release\vcpkg.exe $vcpkgRootDir\vcpkg.exe | Out-Null +Copy-Item $vcpkgSourcesPath\Release\vcpkgmetricsuploader.exe $vcpkgRootDir\scripts\vcpkgmetricsuploader.exe | Out-Null diff --git a/scripts/buildsystems/msbuild/applocal.ps1 b/scripts/buildsystems/msbuild/applocal.ps1 index 08a6d9a8f..0b56356a0 100644 --- a/scripts/buildsystems/msbuild/applocal.ps1 +++ b/scripts/buildsystems/msbuild/applocal.ps1 @@ -49,6 +49,7 @@ function resolve([string]$targetBinary) { if (Test-Path "$installedDir\$_") { deployBinary $targetBinaryDir $installedDir "$_" if (Test-Path function:\deployPluginsIfQt) { deployPluginsIfQt $targetBinaryDir "$g_install_root\plugins" "$_" } + if (Test-Path function:\deployOpenNI2) { deployOpenNI2 $targetBinaryDir "$g_install_root" "$_" } resolve "$targetBinaryDir\$_" } elseif (Test-Path "$targetBinaryDir\$_") { Write-Verbose " ${_}: $_ not found in vcpkg; locally deployed" @@ -66,5 +67,10 @@ if (Test-Path "$g_install_root\plugins\qtdeploy.ps1") { . "$g_install_root\plugins\qtdeploy.ps1" } +# Note: This is a hack to make OpenNI2 work. +if (Test-Path "$g_install_root\bin\OpenNI2\openni2deploy.ps1") { + . "$g_install_root\bin\OpenNI2\openni2deploy.ps1" +} + resolve($targetBinary) Write-Verbose $($g_searched | out-string)
\ No newline at end of file diff --git a/scripts/cmake/vcpkg_apply_patches.cmake b/scripts/cmake/vcpkg_apply_patches.cmake index ac6e5cc93..1894d6e9a 100644 --- a/scripts/cmake/vcpkg_apply_patches.cmake +++ b/scripts/cmake/vcpkg_apply_patches.cmake @@ -47,7 +47,7 @@ function(vcpkg_apply_patches) RESULT_VARIABLE error_code ) - if(error_code AND NOT ${_ap_QUIET}) + if(error_code AND NOT _ap_QUIET) message(STATUS "Applying patch failed. This is expected if this patch was previously applied.") endif() diff --git a/scripts/fetchDependency.ps1 b/scripts/fetchDependency.ps1 index e4cab124c..ad0b774d4 100644 --- a/scripts/fetchDependency.ps1 +++ b/scripts/fetchDependency.ps1 @@ -3,7 +3,7 @@ param( [Parameter(Mandatory=$true)][string]$Dependency ) -$scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition +$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition . "$scriptsDir\VcpkgPowershellUtils.ps1" Write-Verbose "Fetching dependency: $Dependency" @@ -20,12 +20,12 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency) if($Dependency -eq "cmake") { - $requiredVersion = "3.10.1" - $downloadVersion = "3.10.1" - $url = "https://cmake.org/files/v3.10/cmake-3.10.1-win32-x86.zip" - $downloadPath = "$downloadsDir\cmake-3.10.1-win32-x86.zip" - $expectedDownloadedFileHash = "6fe010cce1201d884cd7a9535db8a1f16d98b8965341251fde8f1c5069ee58c0" - $executableFromDownload = "$downloadsDir\cmake-3.10.1-win32-x86\bin\cmake.exe" + $requiredVersion = "3.10.2" + $downloadVersion = "3.10.2" + $url = "https://cmake.org/files/v3.10/cmake-3.10.2-win32-x86.zip" + $downloadPath = "$downloadsDir\cmake-3.10.2-win32-x86.zip" + $expectedDownloadedFileHash = "f5f7e41a21d0e9b655aca58498b08e17ecd27796bf82837e2c84435359169dd6" + $executableFromDownload = "$downloadsDir\cmake-3.10.2-win32-x86\bin\cmake.exe" $extractionType = $ExtractionType_ZIP } elseif($Dependency -eq "nuget") @@ -40,11 +40,11 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency) } elseif($Dependency -eq "vswhere") { - $requiredVersion = "2.2.11" - $downloadVersion = "2.2.11" - $url = "https://github.com/Microsoft/vswhere/releases/download/2.2.11/vswhere.exe" + $requiredVersion = "2.3.2" + $downloadVersion = "2.3.2" + $url = "https://github.com/Microsoft/vswhere/releases/download/2.3.2/vswhere.exe" $downloadPath = "$downloadsDir\vswhere-$downloadVersion\vswhere.exe" - $expectedDownloadedFileHash = "0235c2cb6341978abdf32e27fcf1d7af5cb5514c035e529c4cd9283e6f1a261f" + $expectedDownloadedFileHash = "103f2784c4b2c8e70c7c1c03687abbf22bce052aae30639406e4e13ffa29ee04" $executableFromDownload = $downloadPath $extractionType = $ExtractionType_NO_EXTRACTION_REQUIRED } @@ -75,9 +75,12 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency) throw "Unknown program requested" } - Write-Host "Downloading $Dependency..." - vcpkgDownloadFile $url $downloadPath - Write-Host "Downloading $Dependency has completed successfully." + if (!(Test-Path $downloadPath)) + { + Write-Host "Downloading $Dependency..." + vcpkgDownloadFile $url $downloadPath + Write-Host "Downloading $Dependency has completed successfully." + } $downloadedFileHash = vcpkgGetSHA256 $downloadPath vcpkgCheckEqualFileHash -filePath $downloadPath -expectedHash $expectedDownloadedFileHash -actualHash $downloadedFileHash @@ -100,7 +103,7 @@ function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency) { if (-not (Test-Path $executableFromDownload)) { - vcpkgInvokeCommand $downloadPath "-y" -wait:$true + vcpkgInvokeCommand $downloadPath "-y" } } else diff --git a/scripts/findAnyMSBuildWithCppPlatformToolset.ps1 b/scripts/findAnyMSBuildWithCppPlatformToolset.ps1 index 46ba767b9..570ebdf44 100644 --- a/scripts/findAnyMSBuildWithCppPlatformToolset.ps1 +++ b/scripts/findAnyMSBuildWithCppPlatformToolset.ps1 @@ -6,7 +6,7 @@ param( $withVSPath = $withVSPath -replace "\\$" # Remove potential trailing backslash -$scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition +$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition $VisualStudioInstallationInstances = & $scriptsDir\findVisualStudioInstallationInstances.ps1 if ($VisualStudioInstallationInstances -eq $null) { diff --git a/scripts/findVisualStudioInstallationInstances.ps1 b/scripts/findVisualStudioInstallationInstances.ps1 index e3bc67ff6..359da9caa 100644 --- a/scripts/findVisualStudioInstallationInstances.ps1 +++ b/scripts/findVisualStudioInstallationInstances.ps1 @@ -3,7 +3,7 @@ param( ) -$scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition +$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition $vswhereExe = (& $scriptsDir\fetchDependency.ps1 "vswhere") -replace "<sol>::" -replace "::<eol>" $output = & $vswhereExe -prerelease -legacy -products * -format xml |
