From d3a59026864dd091e0ad3cd9a9a17e64ef955d1c Mon Sep 17 00:00:00 2001 From: Vasilii Polikarpov Date: Wed, 14 Jun 2023 10:27:07 +0200 Subject: [PATCH 1/2] Cache Android SDK packages list --- .../linux/scripts/helpers/Common.Helpers.psm1 | 17 ++++++++++++++--- .../software-report/SoftwareReport.Android.psm1 | 17 ++++++++++++++--- .../win/scripts/ImageHelpers/InstallHelpers.ps1 | 12 +++++++++++- 3 files changed, 39 insertions(+), 7 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..c709efb0e010 100644 --- a/images/macos/software-report/SoftwareReport.Android.psm1 +++ b/images/macos/software-report/SoftwareReport.Android.psm1 @@ -24,9 +24,20 @@ function Get-AndroidInstalledPackages { } function Get-AndroidPackages { - $androidSDKManagerPath = Get-AndroidSDKManagerPath - $androidPackages = & $androidSDKManagerPath --list --verbose - return $androidPackages + $packagesListFile = Join-Path $androidSDKDir "packages-list.txt" + + if (-Not (Test-Path -Path $packagesListFile -PathType Leaf)) { + (/usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --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 { From 45b89d7acc9636d7278e69dc1fbf5778c18c394e Mon Sep 17 00:00:00 2001 From: Vasilii Polikarpov Date: Wed, 14 Jun 2023 10:27:07 +0200 Subject: [PATCH 2/2] Fix Get-AndroidPackages function for macOS --- images/macos/software-report/SoftwareReport.Android.psm1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/images/macos/software-report/SoftwareReport.Android.psm1 b/images/macos/software-report/SoftwareReport.Android.psm1 index c709efb0e010..2ba8f23c7ecd 100644 --- a/images/macos/software-report/SoftwareReport.Android.psm1 +++ b/images/macos/software-report/SoftwareReport.Android.psm1 @@ -24,10 +24,13 @@ function Get-AndroidInstalledPackages { } function Get-AndroidPackages { + $androidSDKDir = Get-AndroidSDKRoot + $androidSDKManagerPath = Get-AndroidSDKManagerPath + $packagesListFile = Join-Path $androidSDKDir "packages-list.txt" if (-Not (Test-Path -Path $packagesListFile -PathType Leaf)) { - (/usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --list --verbose) | + (& $androidSDKManagerPath --list --verbose) | Where-Object { $_ -Match "^[^\s]" } | Where-Object { $_ -NotMatch "^(Loading |Info: Parsing |---|\[=+|Installed |Available )" } | Where-Object { $_ -NotMatch "^[^;]*$" } |