Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #9236/2b2872f0 backport][stable-10] Add android sdk module #9293

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented Dec 20, 2024

This is a backport of PR #9236 as merged into main (2b2872f).

SUMMARY

This module allows to manage Android SDK packages

ISSUE TYPE
  • New Module/Plugin Pull Request
COMPONENT NAME

android_sdk

ADDITIONAL INFORMATION

This module uses sdkmanager binary, which is used to install Android SDK packages. Usually, Android SDK packages are installed by Android developers using Android Studio IDE, but in case when a server needs to be set up to be used as a CI/CD runner to build Android applications, sdkmanager command line tool is used instead.
In order to use this module, sdkmanager binary must be present on the target machine. The official way of installing sdkmanager is described here: https://developer.android.com/tools/sdkmanager
There is one caveat I'm not entirely sure how/whether to fix. For some of the packages installed with sdkmanager a license must be accepted beforehand. The accepted licenses are placed inside the directory containing Android SDK, in a subdirectory licenses as a file containing a single string:

[vagrant@alma licenses]$ pwd
/usr/local/android/sdk/licenses
[vagrant@alma licenses]$ ls
android-googletv-license     android-sdk-preview-license
android-sdk-arm-dbt-license  google-gdk-license
android-sdk-license          mips-android-sysimage-license
[vagrant@alma licenses]$ cat android-sdk-license 

24333f8a63b6825ea9c5514f83c2829b004d1fee

There are three ways how a license may be accepted

  1. if, after requesting of installation of a new package, sdkmanager sees that the license for the package has not been accepted, a command line prompt will be displayed that the user is supposed to answer interactively.
  2. sdkmanager --licenses command may be used. In this case sdkmanager prints every license that has not been accepted sequentially and prompts the user after each one.
  3. a file, containing the license as a string (I suppose, it is some sort of a hash), must be placed inside licenses subdirectory for any license that must be accepted (but IMO this is error-prone as there might be new licenses, which can't be known in advance).

The easiest way to accept licenses from an Ansible playbook is to use the following task:

- name: Accept all licenses
  shell: 'yes | sdkmanager --licenses'

I haven't figured a straightforward way of how to accept licenses from inside the module. What I tried was to use data parameter of module.run_command function to send y to stdin, but the problem is that in case if we try to use the 2nd approach from the list above (sdkmanager --license), the sdkmanager tool prints multiple prompts for each license that is not accepted. The data parameter sends y only to the first license prompt, but the remaining prompts hang the module as they are waiting for the user input. Another idea was to use data='y' every time a package is installed (1st approach), but this may also lead to the module hanging as there might be several packages requested for installation, and if they belong to different licenses, this ends up the same way.
So, I decided that the module assumes that all licenses are accepted in advance (this is reflected in the "Notes" section of the documentation).

* adds simple implementation of adding and removing android sdk packages

* adds package update

* adds simple installed packages parsing

* moves parsing logic to a separate class

* adds absent state for sdkmanager packages and setup for tests

* adds output for installing and removing packages

* removes version from Package object since it is not possible to specify version for a package while using sdkmanager

* adds 'latest' state

* adds tests

* fixes crash when sdkmanager is invoked from python with LC_ALL=C

* fixes latest state

* adds sdk_root parameter

* adds channel parameter

* simplifies regexps, removes unused named groups

* minor refactoring of sdkmanager parsing

* adds java dependency variable for different distributions

* adds RETURN documentation

* adds check for nonexisting package

* adds check for non-accepted licenses

* removes excessive methods from sdkmanager

* removes unused 'update' module parameter, packages may be updated using 'latest' state

* minor refactoring

* adds EXAMPLES doc section

* adds DOCUMENTATION section and license headers

* fixes formatting issues

* removes diff_params

* adds maintainer

* fixes sanity check issues in sdkmanager

* adds java dependency for macos and moves some tests to a separate FreeBSD configuration

* fixes dependencies setup for OSX

* fixes dependencies setup for OSX (2)

* fixes dependencies setup for OSX (3)

* Apply minor suggestions from code review

Co-authored-by: Alexei Znamensky <[email protected]>

* applies code review suggestions

* changes force_lang from C.UTF-8 to auto in sdkmanager (as per discussion #9236 (comment))

* Revert "changes force_lang from C.UTF-8 to auto in sdkmanager (as per discussion #9236 (comment))"

This reverts commit 619f28d.

* fixes some more comments from review

* minor sanity issue fix

* uses the 'changed' test instead of checking the 'changed' attribute

* adds 'accept_licenses' parameter. Installation is now performed independently for each package specified.

* removes "Accept licenses" task from examples

* fixes docs sanity issues

* applies minor suggestions from code review

* fixes regexps. The previous version didn't match versions like "32.1.0 rc1". Also, this allows to simplify the parsing logic as there is no need to skip table headers anymore.

* renamed sdkmanager.py to android_sdkmanager.py

* applies minor suggestions from code review

Co-authored-by: Felix Fontein <[email protected]>

* updates BOTMETA

* reordered BOTMETA

---------

Co-authored-by: Alexei Znamensky <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit 2b2872f)
@patchback patchback bot mentioned this pull request Dec 20, 2024
@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added backport integration tests/integration module module module_utils module_utils needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor plugins plugin (any type) tests tests and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Dec 20, 2024
@felixfontein felixfontein merged commit 69aea38 into stable-10 Dec 20, 2024
129 checks passed
@felixfontein felixfontein deleted the patchback/backports/stable-10/2b2872f0efe7f2fcf2c8c0e2b40764d940c79dff/pr-9236 branch December 20, 2024 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport integration tests/integration module_utils module_utils module module new_contributor Help guide this first time contributor plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants