Merge getVisualStudioInstances into bootstrap.ps1

This commit is contained in:
Alexander Karatarakis 2018-05-19 17:54:12 -07:00
parent 9e4196d495
commit 555fa8d7cc
3 changed files with 71 additions and 79 deletions

View File

@ -26,9 +26,79 @@ if (!(Test-Path $vcpkgSourcesPath))
return
}
function getVisualStudioInstances()
{
$programFiles = getProgramFiles32bit
$results = New-Object System.Collections.ArrayList
$vswhereExe = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswhereExe)
{
$output = & $vswhereExe -prerelease -legacy -products * -format xml
[xml]$asXml = $output
foreach ($instance in $asXml.instances.instance)
{
$installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash
$installationVersion = $instance.InstallationVersion
$isPrerelease = -7
if (vcpkgHasProperty -object $instance -propertyName "isPrerelease")
{
$isPrerelease = $instance.isPrerelease
}
if ($isPrerelease -eq 0)
{
$releaseType = "PreferenceWeight3::StableRelease"
}
elseif ($isPrerelease -eq 1)
{
$releaseType = "PreferenceWeight2::PreRelease"
}
else
{
$releaseType = "PreferenceWeight1::Legacy"
}
# Placed like that for easy sorting according to preference
$results.Add("<sol>::${releaseType}::${installationVersion}::${installationPath}::<eol>") > $null
}
}
else
{
Write-Verbose "Could not locate vswhere at $vswhereExe"
}
if ("$env:vs140comntools" -ne "")
{
$installationPath = Split-Path -Parent $(Split-Path -Parent "$env:vs140comntools")
$clExe = "$installationPath\VC\bin\cl.exe"
$vcvarsallbat = "$installationPath\VC\vcvarsall.bat"
if ((Test-Path $clExe) -And (Test-Path $vcvarsallbat))
{
$results.Add("<sol>::PreferenceWeight1::Legacy::14.0::$installationPath::<eol>") > $null
}
}
$installationPath = "$programFiles\Microsoft Visual Studio 14.0"
$clExe = "$installationPath\VC\bin\cl.exe"
$vcvarsallbat = "$installationPath\VC\vcvarsall.bat"
if ((Test-Path $clExe) -And (Test-Path $vcvarsallbat))
{
$results.Add("<sol>::PreferenceWeight1::Legacy::14.0::$installationPath::<eol>") > $null
}
$results.Sort()
$results.Reverse()
return $results
}
function findAnyMSBuildWithCppPlatformToolset([string]$withVSPath)
{
$VisualStudioInstances = & $scriptsDir\getVisualStudioInstances.ps1
$VisualStudioInstances = getVisualStudioInstances
if ($VisualStudioInstances -eq $null)
{
throw "Could not find Visual Studio. VS2015 or VS2017 (with C++) needs to be installed."

View File

@ -1,77 +0,0 @@
[CmdletBinding()]
param(
)
Set-StrictMode -Version Latest
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
. "$scriptsDir\VcpkgPowershellUtils.ps1"
$programFiles = getProgramFiles32bit
$results = New-Object System.Collections.ArrayList
$vswhereExe = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswhereExe)
{
$output = & $vswhereExe -prerelease -legacy -products * -format xml
[xml]$asXml = $output
foreach ($instance in $asXml.instances.instance)
{
$installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash
$installationVersion = $instance.InstallationVersion
$isPrerelease = -7
if (vcpkgHasProperty -object $instance -propertyName "isPrerelease")
{
$isPrerelease = $instance.isPrerelease
}
if ($isPrerelease -eq 0)
{
$releaseType = "PreferenceWeight3::StableRelease"
}
elseif ($isPrerelease -eq 1)
{
$releaseType = "PreferenceWeight2::PreRelease"
}
else
{
$releaseType = "PreferenceWeight1::Legacy"
}
# Placed like that for easy sorting according to preference
$results.Add("<sol>::${releaseType}::${installationVersion}::${installationPath}::<eol>") > $null
}
}
else
{
Write-Verbose "Could not locate vswhere at $vswhereExe"
}
if ("$env:vs140comntools" -ne "")
{
$installationPath = Split-Path -Parent $(Split-Path -Parent "$env:vs140comntools")
$clExe = "$installationPath\VC\bin\cl.exe"
$vcvarsallbat = "$installationPath\VC\vcvarsall.bat"
if ((Test-Path $clExe) -And (Test-Path $vcvarsallbat))
{
$results.Add("<sol>::PreferenceWeight1::Legacy::14.0::$installationPath::<eol>") > $null
}
}
$installationPath = "$programFiles\Microsoft Visual Studio 14.0"
$clExe = "$installationPath\VC\bin\cl.exe"
$vcvarsallbat = "$installationPath\VC\vcvarsall.bat"
if ((Test-Path $clExe) -And (Test-Path $vcvarsallbat))
{
$results.Add("<sol>::PreferenceWeight1::Legacy::14.0::$installationPath::<eol>") > $null
}
$results.Sort()
$results.Reverse()
return $results

View File

@ -15,7 +15,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{F589
ProjectSection(SolutionItems) = preProject
..\scripts\bootstrap.ps1 = ..\scripts\bootstrap.ps1
..\scripts\fetchDependency.ps1 = ..\scripts\fetchDependency.ps1
..\scripts\getVisualStudioInstances.ps1 = ..\scripts\getVisualStudioInstances.ps1
..\scripts\get_triplet_environment.cmake = ..\scripts\get_triplet_environment.cmake
..\scripts\internalCI.ps1 = ..\scripts\internalCI.ps1
..\scripts\ports.cmake = ..\scripts\ports.cmake