[Windows] Merge several toolset provisioners into single Configure-Toolset script (#1111)

* Add Configure-Toolset for windows

* Set error action preference to stop

* Move toolcache.json to config folder

* Fix in verbose

* Rename toolsets folder

* Move default version functions from install-toolset to configure-toolset

* Rework Configure-Toolset

* Fix typo and remove empty line

* Fix issues

* Fix parameters in helpers

* Fix helper syntax

* Rename defaultVariable
This commit is contained in:
Maksim Petrov
2020-06-30 07:48:55 +03:00
committed by GitHub
parent a89f839675
commit 8d0d6f85cc
13 changed files with 160 additions and 166 deletions

View File

@@ -0,0 +1,84 @@
################################################################################
## File: Configure-Toolset.ps1
## Team: CI-Build
## Desc: Configure Toolset
################################################################################
Function Set-DefaultVariables
{
param
(
[Parameter(Mandatory=$true)]
[object] $EnvVars,
[Parameter(Mandatory=$true)]
[string] $ToolVersionPath
)
$templates = $EnvVars.pathTemplates
foreach ($template in $templates)
{
$toolSystemPath = $template -f $ToolVersionPath
Add-MachinePathItem -PathItem $toolSystemPath | Out-Null
}
if (-not ([string]::IsNullOrEmpty($EnvVars.defaultVariable)))
{
setx $toolEnvVars.defaultVariable $ToolVersionPath /M | Out-Null
}
}
$ErrorActionPreference = "Stop"
Import-Module -Name ImageHelpers -Force -DisableNameChecking
# Define executables for cached tools
$toolsEnvironmentVariables = @{
Python = @{
pathTemplates = @(
"{0}",
"{0}\Scripts"
)
}
Boost = @{
variableTemplate = "BOOST_ROOT_{0}_{1}_{2}"
}
go = @{
pathTemplates = @(
"{0}\bin"
)
defaultVariable = "GOROOT"
variableTemplate = "GOROOT_{0}_{1}_X64"
}
}
$toolsToConfigure = @("Python", "Boost", "Go")
$tools = Get-ToolsetContent | Select-Object -ExpandProperty toolcache `
| Where-Object { $toolsToConfigure -contains $_.name }
Write-Host "Configure toolset tools environment..."
foreach ($tool in $tools)
{
$toolEnvVars = $toolsEnvironmentVariables[$tool.name]
if (-not ([string]::IsNullOrEmpty($toolEnvVars.variableTemplate)))
{
foreach ($version in $tool.versions)
{
Write-Host "Set $($tool.name) $version environment variable..."
$foundVersionArchPath = Get-ToolsetToolFullPath -Name $tool.name -Version $version -Arch $tool.arch
$envName = $toolEnvVars.variableTemplate -f $version.Split(".")
setx $envName $foundVersionArchPath /M | Out-Null
}
}
if (-not ([string]::IsNullOrEmpty($tool.default)))
{
Write-Host "Use $($tool.name) $($tool.default) as a system $($tool.name)..."
$toolVersionPath = Get-ToolsetToolFullPath -Name $tool.name -Version $tool.default -Arch $tool.arch
Set-DefaultVariables -ToolVersionPath $toolVersionPath -EnvVars $toolEnvVars
}
}

View File

@@ -1,19 +0,0 @@
################################################################################
## File: Set-BoostRoot.ps1
## Team: CI-Build
## Desc: Install boost using tool cache
################################################################################
Import-Module -Name ImageHelpers
$SoftwareName = "Boost"
$BoostDirectory = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath $SoftwareName
$BoostVersions = (Get-ToolsetContent | Select-Object -ExpandProperty toolcache | Where-Object { $_.Name -eq "Boost"}).Versions
foreach($BoostVersion in $BoostVersions)
{
$BoostInstallationDir = Join-Path -Path $BoostDirectory -ChildPath "$BoostVersion\X86_64"
$EnvBoostPath = "BOOST_ROOT_{0}" -f ($BoostVersion.Replace('.', '_'))
setx $EnvBoostPath $BoostInstallationDir /M | Out-Null
}

View File

@@ -1,25 +0,0 @@
################################################################################
## File: Install-Go.ps1
## Desc: Install Go
################################################################################
Import-Module -Name ImageHelpers -Force -DisableNameChecking
# Get Go content from toolset
$goTool = Get-ToolsetContent | Select-Object -ExpandProperty toolcache | Where-Object Name -eq "go"
$toolPath = Join-Path $env:AGENT_TOOLSDIRECTORY $goTool.name
foreach($goVersion in $goTool.versions)
{
if ($goVersion.Split(".").Length -lt 3) {
$goVersion += ".*"
}
$expectedVersionPath = Join-Path $toolPath $goVersion
$foundVersion = Get-Item $expectedVersionPath `
| Sort-Object -Property {[version]$_.name} -Descending `
| Select-Object -First 1
# Check for required architecture folder
$foundVersionArchPath = Join-Path $foundVersion $goTool.arch
$envName = "GOROOT_{0}_{1}_X64" -f $goVersion.split(".")
setx $envName "$foundVersionArchPath" /M
}

View File

@@ -29,47 +29,6 @@ Function Install-Asset {
Pop-Location
}
Function Set-DefaultPythonVersion {
param(
[Parameter(Mandatory=$true)]
[object[]] $Toolset
)
$python = $Toolset | Where-Object { ($_.name -eq "Python") -and ($_.default -ne "") } `
| Select-Object default, arch -First 1
if ($python.default -ne $null) {
$pythonPath = Join-Path $Env:AGENT_TOOLSDIRECTORY "/Python/$($python.default)/$($python.arch)" -Resolve
Write-Host "Use Python $($python.default) as a system Python"
Add-MachinePathItem -PathItem $pythonPath
Add-MachinePathItem -PathItem "$pythonPath\Scripts"
} else {
Write-Host "Default Python version not found in toolset file!"
}
}
Function Set-DefaultGoVersion {
param(
[Parameter(Mandatory=$true)]
[object[]] $Toolset
)
$goToolset = $Toolset | Where-Object { ($_.name -eq "go") -and ($_.default -ne "") } `
| Select-Object default, arch -First 1
if ($goToolset.default -ne $null) {
$goPath = Join-Path $Env:AGENT_TOOLSDIRECTORY "/go/$($goToolset.default)/$($goToolset.arch)" -Resolve
Write-Host "Use Go $($goToolset.default) as a system Go"
Add-MachinePathItem -PathItem "$goPath\bin" | Out-Null
# Set the GOROOT environment variable.
setx GOROOT "$goPath" /M | Out-Null
} else {
Write-Host "Default Go version not found in toolset file!"
}
}
$ErrorActionPreference = "Stop"
Import-Module -Name ImageHelpers -Force
@@ -92,15 +51,11 @@ foreach ($tool in $tools) {
| Select-Object -First 1
Write-Host "Installing $($tool.name) $toolVersion $($tool.arch)..."
if ($asset -ne $null) {
if ($null -ne $asset) {
Install-Asset -ReleaseAsset $asset
} else {
Write-Host "Asset was not found in versions manifest"
exit 1
}
}
}
# Install default python version
Set-DefaultPythonVersion -Toolset $tools
Set-DefaultGoVersion -Toolset $tools
}

View File

@@ -75,34 +75,11 @@ $toolsExecutables = @{
$tools = Get-ToolsetContent | Select-Object -ExpandProperty toolcache
foreach($tool in $tools) {
$toolPath = Join-Path $env:AGENT_TOOLSDIRECTORY $tool.name
# Get executables for current tool
$toolExecs = $toolsExecutables[$tool.name]
foreach ($version in $tool.versions) {
# Add wildcard if missing
if ($version.Split(".").Length -lt 3) {
$version += ".*"
}
# Check if version folder exists
$expectedVersionPath = Join-Path $toolPath $version
if (-not (Test-Path $expectedVersionPath)) {
Write-Host "Expected $($tool.name) $version folder is not found!"
exit 1
}
# Take latest installed version in case if toolset version contains wildcards
$foundVersion = Get-Item $expectedVersionPath `
| Sort-Object -Property {[version]$_.name} -Descending `
| Select-Object -First 1
# Check for required architecture folder
$foundVersionArchPath = Join-Path $foundVersion $tool.arch
if (-not (Test-Path $foundVersionArchPath)) {
Write-Host "Expected $($tool.name)($($tool.arch)) $($foundVersion.name) architecture folder is not found!"
exit 1
}
$foundVersionArchPath = Get-ToolsetToolFullPath -Name $tool.name -Version $version -Arch $tool.arch
if ($toolExecs) {
Write-Host "Run validation test for $($tool.name)($($tool.arch)) $($foundVersion.name) executables..."