From 77b21e0c2446ef003ccd07b64f6ec66b0da3e0bd Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Fri, 12 Feb 2021 12:30:36 +0500 Subject: [PATCH] Document environment variables of linux images (#2498) * Document environment variables of linux images * Change adnroid variables * Apply reviews * Remove some variables, fix headers * Show link targets * rename helper * remove symlinks * More links * Dynamic GO variables * Architecture for GO variables * remove GOROOT --- .../SoftwareReport.Android.psm1 | 14 ++- .../SoftwareReport.Browsers.psm1 | 20 +++- .../SoftwareReport.CachedTools.psm1 | 15 ++- .../SoftwareReport/SoftwareReport.Common.psm1 | 18 ++++ .../SoftwareReport.Generator.ps1 | 14 +++ .../helpers/SoftwareReport.Helpers.psm1 | 92 ++++++++++++++++++- 6 files changed, 169 insertions(+), 4 deletions(-) diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Android.psm1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Android.psm1 index f5684535e557..287cca728044 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Android.psm1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Android.psm1 @@ -158,4 +158,16 @@ function Get-AndroidNDKVersions { $ndkFolderPath = Join-Path (Get-AndroidSDKRoot) "ndk" $versions = Get-ChildItem -Path $ndkFolderPath -Name return ($versions -Join "
") -} \ No newline at end of file +} + +function Build-AndroidEnvironmentTable { + $androidVersions = Get-Item env:ANDROID_* + + $shouldResolveLink = 'ANDROID_NDK_PATH', 'ANDROID_NDK_HOME', 'ANDROID_NDK_ROOT', 'ANDROID_NDK_LATEST_HOME' + return $androidVersions | Sort-Object -Property Name | ForEach-Object { + [PSCustomObject] @{ + "Name" = $_.Name + "Value" = if ($shouldResolveLink.Contains($_.Name )) { Get-PathWithLink($_.Value) } else {$_.Value} + } + } +} diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Browsers.psm1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Browsers.psm1 index 9fa03583fde7..e4e44d6fdf49 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Browsers.psm1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Browsers.psm1 @@ -21,4 +21,22 @@ function Get-GeckodriverVersion { function Get-ChromiumVersion { $chromiumVersion = chromium --version | Take-OutputPart -Part 0,1 return $chromiumVersion -} \ No newline at end of file +} + +function Build-BrowserWebdriversEnvironmentTable { + return @( + @{ + "Name" = "CHROMEWEBDRIVER" + "Value" = $env:CHROMEWEBDRIVER + }, + @{ + "Name" = "GECKOWEBDRIVER" + "Value" = $env:GECKOWEBDRIVER + } + ) | ForEach-Object { + [PSCustomObject] @{ + "Name" = $_.Name + "Value" = $_.Value + } + } +} diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.CachedTools.psm1 b/images/linux/scripts/SoftwareReport/SoftwareReport.CachedTools.psm1 index 2b351c522e4a..6f7f9d071edd 100755 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.CachedTools.psm1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.CachedTools.psm1 @@ -28,6 +28,19 @@ function Get-ToolcacheGoVersions { return Get-ChildItem $toolcachePath -Name | Sort-Object { [Version]$_ } } +function Build-GoEnvironmentTable { + return Get-CachedToolInstances -Name "go" -VersionCommand "version" | ForEach-Object { + $Version = [System.Version]($_.Version -Split(" "))[0] + $Name = "GOROOT_$($Version.major)_$($Version.minor)_X64" + $Value = (Get-Item env:\$Name).Value + [PSCustomObject] @{ + "Name" = $Name + "Value" = (Get-Item env:\$Name).Value + "Architecture" = $_. Architecture + } + } +} + function Get-ToolcacheBoostVersions { $Name = "Boost" $toolcachePath = Join-Path $env:AGENT_TOOLSDIRECTORY "boost" @@ -82,4 +95,4 @@ function Build-CachedToolsSection { $output += New-MDList -Lines (Get-ToolcacheRubyVersions) -Style Unordered return $output -} \ No newline at end of file +} diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 index 90c98dcf4ff2..562438cbfae1 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 @@ -306,3 +306,21 @@ function Build-GraalVMTable { "Environment variables" = $envVariables } } + +function Build-PackageManagementEnvironmentTable { + return @( + @{ + "Name" = "CONDA" + "Value" = $env:CONDA + }, + @{ + "Name" = "VCPKG_INSTALLATION_ROOT" + "Value" = $env:VCPKG_INSTALLATION_ROOT + } + ) | ForEach-Object { + [PSCustomObject] @{ + "Name" = $_.Name + "Value" = $_.Value + } + } +} diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 index 21754fe8672e..70bb37067feb 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 @@ -64,6 +64,9 @@ $packageManagementList = @( (Get-Pip3Version), (Get-VcpkgVersion) ) +$markdown += New-MDHeader "Environment variables" -Level 4 +$markdown += Build-PackageManagementEnvironmentTable | New-MDTable +$markdown += New-MDNewLine if (-not (Test-IsUbuntu16)) { $packageManagementList += @( @@ -216,6 +219,10 @@ if (Test-IsUbuntu20) { } $markdown += New-MDList -Style Unordered -Lines $browsersAndDriversList +$markdown += New-MDNewLine +$markdown += New-MDHeader "Environment variables" -Level 4 +$markdown += Build-BrowserWebdriversEnvironmentTable | New-MDTable +$markdown += New-MDNewLine $markdown += New-MDHeader ".NET Core SDK" -Level 3 $markdown += New-MDList -Style Unordered -Lines @( @@ -241,6 +248,10 @@ $markdown += Build-MSSQLToolsSection $markdown += New-MDHeader "Cached Tools" -Level 3 $markdown += Build-CachedToolsSection +$markdown += New-MDHeader "Environment variables" -Level 4 +$markdown += Build-GoEnvironmentTable | New-MDTable +$markdown += New-MDNewLine + $markdown += New-MDHeader "PowerShell Tools" -Level 3 $markdown += New-MDList -Lines (Get-PowershellVersion) -Style Unordered @@ -253,6 +264,9 @@ $markdown += Build-WebServersSection $markdown += New-MDHeader "Android" -Level 3 $markdown += Build-AndroidTable | New-MDTable $markdown += New-MDNewLine +$markdown += New-MDHeader "Environment variables" -Level 4 +$markdown += Build-AndroidEnvironmentTable | New-MDTable +$markdown += New-MDNewLine $markdown += New-MDHeader "Cached Docker images" -Level 3 $markdown += Get-CachedDockerImagesTableData | New-MDTable diff --git a/images/linux/scripts/helpers/SoftwareReport.Helpers.psm1 b/images/linux/scripts/helpers/SoftwareReport.Helpers.psm1 index 4501dee05802..c17236ba1a0d 100644 --- a/images/linux/scripts/helpers/SoftwareReport.Helpers.psm1 +++ b/images/linux/scripts/helpers/SoftwareReport.Helpers.psm1 @@ -20,4 +20,94 @@ function New-MDNewLine { function Restore-UserOwner { sudo chown -R ${env:USER}: $env:HOME -} \ No newline at end of file +} + +function Get-LinkTarget { + param ( + [string] $inputPath + ) + $link = Get-Item $inputPath | Select-Object -ExpandProperty Target + if ($link) { + return " -> $link" + } + return "" +} + +function Get-PathWithLink { + param ( + [string] $inputPath + ) + $link = Get-LinkTarget($inputPath) + return "${inputPath}${link}" +} + +function Get-CachedToolInstances +{ + <# + .SYNOPSIS + Returns hastable of installed cached tools. + + .DESCRIPTION + Return hastable that contains versions and architectures for selected cached tool. + + .PARAMETER Name + Name of cached tool. + + .PARAMETER VersionCommand + Optional parameter. Command to return version of system default tool. + + .EXAMPLE + Get-CachedToolInstances -Name "Python" -VersionCommand "--version" + + #> + + param + ( + [String] $Name, + [String] $VersionCommand + ) + + $toolInstances = @() + $toolPath = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath $Name + + # Get all installed versions from TOOLSDIRECTORY folder + $versions = Get-ChildItem $toolPath | Sort-Object { [System.Version]$_.Name } + foreach ($version in $versions) + { + $instanceInfo = @{} + + # Create instance hashtable + [string]$instanceInfo.Path = Join-Path -Path $toolPath -ChildPath $version.Name + [string]$instanceInfo.Version = $version.Name + + ### Temporary workaround. Currently Boost instances don't have architecture subfolders. + if ($Name -eq "Boost") + { + [string]$instanceInfo.Architecture = "x64, x86" + $toolInstances += $instanceInfo + continue + } + + # Get all architectures for current version + [array]$instanceInfo.Architecture_Array = Get-ChildItem $version.FullName -Name -Directory | Where-Object { $_ -match "^x[0-9]{2}$" } + [string]$instanceInfo.Architecture = $instanceInfo.Architecture_Array -Join ", " + + # Add (default) postfix to version name, in case if current version is in environment path + if (-not ([string]::IsNullOrEmpty($VersionCommand))) + { + $defaultVersion = $(& ($Name.ToLower()) $VersionCommand 2>&1) + $defaultToolVersion = $defaultVersion | Select-String -Pattern "\d+\.\d+\.\d+" -AllMatches ` + | ForEach-Object { $_.Matches.Value } + + if ([version]$version.Name -eq [version]$defaultToolVersion) + { + $instanceInfo.Version += " (Default)" + } + } + + $toolInstances += $instanceInfo + } + + return $toolInstances +} +