From d0d97cd5f8a7de20d81e358706074d4b91225787 Mon Sep 17 00:00:00 2001 From: Vasilii Polikarpov <126792224+vpolikarpov-akvelon@users.noreply.github.com> Date: Fri, 16 Jun 2023 18:34:04 +0200 Subject: [PATCH] Cache Android SDK packages list (#7709) --- .../linux/scripts/helpers/Common.Helpers.psm1 | 17 ++++++++++++++--- .../SoftwareReport.Android.psm1 | 18 ++++++++++++++++-- .../scripts/ImageHelpers/InstallHelpers.ps1 | 12 +++++++++++- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/images/linux/scripts/helpers/Common.Helpers.psm1 b/images/linux/scripts/helpers/Common.Helpers.psm1 index 6db094683481..5f0b3e068504 100644 --- a/images/linux/scripts/helpers/Common.Helpers.psm1 +++ b/images/linux/scripts/helpers/Common.Helpers.psm1 @@ -72,9 +72,20 @@ function Get-ToolsetValue { } function Get-AndroidPackages { - $androidSDKManagerPath = "/usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager" - $androidPackages = & $androidSDKManagerPath --list --verbose 2>&1 - return $androidPackages + $packagesListFile = "/usr/local/lib/android/sdk/packages-list.txt" + + if (-Not (Test-Path -Path $packagesListFile -PathType Leaf)) { + (/usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --list --verbose 2>&1) | + Where-Object { $_ -Match "^[^\s]" } | + Where-Object { $_ -NotMatch "^(Loading |Info: Parsing |---|\[=+|Installed |Available )" } | + Where-Object { $_ -NotMatch "^[^;]*$" } | + Out-File -FilePath $packagesListFile + + Write-Host Android packages list: + Get-Content $packagesListFile + } + + return Get-Content $packagesListFile } function Get-EnvironmentVariable($variable) { diff --git a/images/macos/software-report/SoftwareReport.Android.psm1 b/images/macos/software-report/SoftwareReport.Android.psm1 index e2db090fd229..2ba8f23c7ecd 100644 --- a/images/macos/software-report/SoftwareReport.Android.psm1 +++ b/images/macos/software-report/SoftwareReport.Android.psm1 @@ -24,9 +24,23 @@ function Get-AndroidInstalledPackages { } function Get-AndroidPackages { + $androidSDKDir = Get-AndroidSDKRoot $androidSDKManagerPath = Get-AndroidSDKManagerPath - $androidPackages = & $androidSDKManagerPath --list --verbose - return $androidPackages + + $packagesListFile = Join-Path $androidSDKDir "packages-list.txt" + + if (-Not (Test-Path -Path $packagesListFile -PathType Leaf)) { + (& $androidSDKManagerPath --list --verbose) | + Where-Object { $_ -Match "^[^\s]" } | + Where-Object { $_ -NotMatch "^(Loading |Info: Parsing |---|\[=+|Installed |Available )" } | + Where-Object { $_ -NotMatch "^[^;]*$" } | + Out-File -FilePath $packagesListFile + + Write-Host Android packages list: + Get-Content $packagesListFile + } + + return Get-Content $packagesListFile } function Build-AndroidTable { diff --git a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 index 2d895e77b0d2..ed142e17b244 100644 --- a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 @@ -489,7 +489,17 @@ function Get-AndroidPackages { [string]$AndroidSDKManagerPath ) - return (cmd /c "$AndroidSDKManagerPath --list --verbose 2>&1").Trim() | Foreach-Object { $_.Split()[0] } | Where-Object {$_} + $packagesListFile = "C:\Android\android-sdk\packages-list.txt" + + if (-Not (Test-Path -Path $packagesListFile -PathType Leaf)) { + (cmd /c "$AndroidSDKManagerPath --list --verbose 2>&1") | + Where-Object { $_ -Match "^[^\s]" } | + Where-Object { $_ -NotMatch "^(Loading |Info: Parsing |---|\[=+|Installed |Available )" } | + Where-Object { $_ -NotMatch "^[^;]*$" } | + Out-File -FilePath $packagesListFile + } + + return Get-Content $packagesListFile } function Get-AndroidPackagesByName {