Files
runner-images/images/linux/scripts/helpers/Common.Helpers.psm1
Mikhail Timofeev f1ab1bd12f [Ubuntu] Switch android tools installation to use sdkmanager from command-line tools (#3650)
* Switch android tools installation to cmdline-tools
* Replace deprecated sdkmanger from sdk-tools to the one from cmdline tools
* Remove patcherv4 from toolsets as it's included in m2repository extras

* Add tests to make sure both sdkmanagers exist

* Return cmdline-tools to software readme
* Get-AndroidInstalledPackages function now use list_installed param
* Create a function to get sdkmanager version = cmdline tools version

* Get rid of hardcoded path to ANDROID_HOME
* Add reloadEtcEnvironment call to installation script
* Use env variable ANDROID_HOME in tests

* Modify software report to output any version

* Change regex pattern to output the group
* Currently the function returns 4. instead of 4.0, this change fixes it
2021-07-07 15:16:46 +03:00

66 lines
1.6 KiB
PowerShell

function Get-CommandResult {
param (
[Parameter(Mandatory=$true)]
[string] $Command,
[switch] $Multiline
)
# Bash trick to suppress and show error output because some commands write to stderr (for example, "python --version")
$stdout = & bash -c "$Command 2>&1"
$exitCode = $LASTEXITCODE
return @{
Output = If ($Multiline -eq $true) { $stdout } else { [string]$stdout }
ExitCode = $exitCode
}
}
function Get-OSName {
lsb_release -ds
}
function Get-KernelVersion {
$kernelVersion = uname -r
return "Linux kernel version: $kernelVersion"
}
function Test-IsUbuntu16 {
return (lsb_release -rs) -eq "16.04"
}
function Test-IsUbuntu18 {
return (lsb_release -rs) -eq "18.04"
}
function Test-IsUbuntu20 {
return (lsb_release -rs) -eq "20.04"
}
function Get-ToolsetContent {
$toolset = Join-Path $env:INSTALLER_SCRIPT_FOLDER "toolset.json"
Get-Content $toolset -Raw | ConvertFrom-Json
}
function Get-ToolsetValue {
param (
[Parameter(Mandatory = $true)]
[string] $KeyPath
)
$jsonNode = Get-ToolsetContent
$pathParts = $KeyPath.Split(".")
# try to walk through all arguments consequentially to resolve specific json node
$pathParts | ForEach-Object {
$jsonNode = $jsonNode.$_
}
return $jsonNode
}
function Get-AndroidPackages {
$androidSDKManagerPath = "/usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager"
$androidPackages = & $androidSDKManagerPath --list --verbose
return $androidPackages
}
function Get-EnvironmentVariable($variable) {
return [System.Environment]::GetEnvironmentVariable($variable)
}