diff --git a/images/windows/scripts/build/Configure-Toolset.ps1 b/images/windows/scripts/build/Configure-Toolset.ps1 index 119e72325..6babc0b81 100644 --- a/images/windows/scripts/build/Configure-Toolset.ps1 +++ b/images/windows/scripts/build/Configure-Toolset.ps1 @@ -55,18 +55,17 @@ foreach ($tool in $tools) { foreach ($version in $tool.versions) { Write-Host "Set $($tool.name) $version environment variable..." - $foundVersionArchPath = Get-ToolsetToolFullPath -Name $tool.name -Version $version -Arch $tool.arch + $foundVersionArchPath = Get-TCToolVersionPath -Name $tool.name -Version $version -Arch $tool.arch $envName = $toolEnvVars.variableTemplate -f $version.Split(".") [Environment]::SetEnvironmentVariable($envName, $foundVersionArchPath, "Machine") } } - if (-not ([string]::IsNullOrEmpty($tool.default))) - { + 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 + $toolVersionPath = Get-TCToolVersionPath -Name $tool.name -Version $tool.default -Arch $tool.arch Set-DefaultVariables -ToolVersionPath $toolVersionPath -EnvVars $toolEnvVars } diff --git a/images/windows/scripts/helpers/ImageHelpers.psm1 b/images/windows/scripts/helpers/ImageHelpers.psm1 index cf4721933..bf7672821 100644 --- a/images/windows/scripts/helpers/ImageHelpers.psm1 +++ b/images/windows/scripts/helpers/ImageHelpers.psm1 @@ -23,8 +23,8 @@ Export-ModuleMember -Function @( 'Install-Binary' 'Install-VisualStudio' 'Get-ToolsetContent' - 'Get-ToolsetToolFullPath' - 'Get-ToolcacheToolDirectory' + 'Get-TCToolVersionPath' + 'Get-TCToolPath' 'Stop-SvcWithErrHandling' 'Set-SvcWithErrHandling' 'Start-DownloadWithRetry' diff --git a/images/windows/scripts/helpers/InstallHelpers.ps1 b/images/windows/scripts/helpers/InstallHelpers.ps1 index 0713ed3a6..272fec6aa 100644 --- a/images/windows/scripts/helpers/InstallHelpers.ps1 +++ b/images/windows/scripts/helpers/InstallHelpers.ps1 @@ -393,38 +393,67 @@ function Get-ToolsetContent ConvertFrom-Json -InputObject $toolsetJson } -function Get-ToolcacheToolDirectory { - Param ([string] $ToolName) +function Get-TCToolPath { + <# + .SYNOPSIS + This function returns the full path of a tool in the tool cache. + + .DESCRIPTION + The Get-TCToolPath function takes a tool name as a parameter and returns the full path of the tool in the tool cache. + It uses the AGENT_TOOLSDIRECTORY environment variable to determine the root path of the tool cache. + + .PARAMETER ToolName + The name of the tool for which the path is to be returned. + + .EXAMPLE + Get-TCToolPath -ToolName "Tool1" + + This command returns the full path of "Tool1" in the tool cache. + + #> + Param + ( + [string] $ToolName + ) + $toolcacheRootPath = Resolve-Path $env:AGENT_TOOLSDIRECTORY return Join-Path $toolcacheRootPath $ToolName } -function Get-ToolsetToolFullPath -{ +function Get-TCToolVersionPath { <# + .SYNOPSIS + This function returns the full path of a specific version of a tool in the tool cache. + .DESCRIPTION - Function that return full path to specified toolset tool. + The Get-TCToolVersionPath function takes a tool name, version, and architecture as parameters and returns the full path of the specified version of the tool in the tool cache. + It uses the Get-TCToolPath function to get the root path of the tool. .PARAMETER Name - The name of required tool. + The name of the tool for which the path is to be returned. .PARAMETER Version - The version of required tool. + The version of the tool for which the path is to be returned. If the version number is less than 3 parts, a wildcard is added. .PARAMETER Arch - The architecture of required tool. - #> + The architecture of the tool for which the path is to be returned. Defaults to "x64". + .EXAMPLE + Get-TCToolVersionPath -Name "Tool1" -Version "1.0" -Arch "x86" + + This command returns the full path of version "1.0" of "Tool1" for "x86" architecture in the tool cache. + + #> Param ( - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [string] $Name, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [string] $Version, [string] $Arch = "x64" ) - $toolPath = Get-ToolcacheToolDirectory -ToolName $Name + $toolPath = Get-TCToolPath -ToolName $Name # Add wildcard if missing if ($Version.Split(".").Length -lt 3) { @@ -435,8 +464,8 @@ function Get-ToolsetToolFullPath # Take latest installed version in case if toolset version contains wildcards $foundVersion = Get-Item $versionPath ` - | Sort-Object -Property {[version]$_.name} -Descending ` - | Select-Object -First 1 + | Sort-Object -Property { [version]$_.name } -Descending ` + | Select-Object -First 1 if (-not $foundVersion) { return $null diff --git a/images/windows/scripts/tests/Toolset.Tests.ps1 b/images/windows/scripts/tests/Toolset.Tests.ps1 index 70acfc163..7f2e698eb 100644 --- a/images/windows/scripts/tests/Toolset.Tests.ps1 +++ b/images/windows/scripts/tests/Toolset.Tests.ps1 @@ -35,7 +35,7 @@ function Test-Binaries { @{ Name = $Name; Version = $Version; Arch = $Arch; Binary = $_.Binary; Arguments = $_.Arguments } } It " " -TestCases $testCases { - $binaryFullPath = Join-Path (Get-ToolsetToolFullPath -Name $Name -Version $Version -Arch $Arch) $Binary + $binaryFullPath = Join-Path (Get-TCToolVersionPath -Name $Name -Version $Version -Arch $Arch) $Binary "$binaryFullPath $Arguments" | Should -ReturnZeroExitCode } } @@ -56,7 +56,7 @@ function Test-DefaultVersion { It "default version is located in tool-cache" -TestCases $testCase { $binaryFullPath = Get-WhichTool $Binary - $toolcacheDirectory = Get-ToolcacheToolDirectory -ToolName $Name + $toolcacheDirectory = Get-TCToolPath -ToolName $Name $binaryFullPath | Should -Match ([Regex]::Escape($toolcacheDirectory)) } } @@ -70,7 +70,7 @@ foreach ($tool in $tools) { Context "$version" { $toolInfo = @{ Name = $tool.name; Version = $version; Arch = $tool.arch } It "tool-cache directory exists" -TestCases $toolInfo { - $toolFullPath = Get-ToolsetToolFullPath -Name $Name -Version $Version -Arch $Arch + $toolFullPath = Get-TCToolVersionPath -Name $Name -Version $Version -Arch $Arch $toolFullPath | Should -Exist } @@ -86,4 +86,4 @@ foreach ($tool in $tools) { } } } -} \ No newline at end of file +}