1 #===----------------------------------------------------------------------===##
3 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 # See https://llvm.org/LICENSE.txt for license information.
5 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 #===----------------------------------------------------------------------===##
9 # Bash functions for managing the names of emulator system images.
11 # Parse the image name and set variables: API, TYPE, and ARCH.
13 if [[ "${1}" =~
([0-9]+)-(def|goog|play
)-(arm|arm64|x86|x86_64
)$
]]; then
14 API
=${BASH_REMATCH[1]}
15 case ${BASH_REMATCH[2]} in
17 goog
) TYPE
=google_apis
;;
18 play
) TYPE
=google_apis_playstore
;;
20 ARCH
=${BASH_REMATCH[3]}
27 # Check that the emulator image name has valid syntax.
28 validate_emu_img_syntax
() {
31 if ! __parse_emu_img
"${EMU_IMG}"; then
33 error: invalid emulator image name: ${EMU_IMG}
34 expected \"\${API}-\${TYPE}-\${ARCH}\" where API is a number, TYPE is one of
35 (def|goog|play), and ARCH is one of arm, arm64, x86, or x86_64." >&2
40 docker_image_of_emu_img
() {
41 echo "android-emulator-${1}"
44 # Check that the emulator image name has valid syntax and that the Docker image
45 # is present. On failure, writes an error to stderr and exits the script.
48 if ! validate_emu_img_syntax
"${EMU_IMG}"; then
51 # Make sure Docker is working before trusting other Docker commands.
52 # Temporarily suppress command echoing so we only show 'docker info' output
53 # on failure, and only once.
54 if (set +x
; !(docker info
&>/dev
/null || docker info
)); then
55 echo "error: Docker is required for emulator usage but 'docker info' failed" >&2
58 local DOCKER_IMAGE
=$
(docker_image_of_emu_img
${EMU_IMG})
59 if ! docker image inspect
${DOCKER_IMAGE} &>/dev
/null
; then
60 echo "error: emulator Docker image (${DOCKER_IMAGE}) is not installed" >&2
67 __parse_emu_img
"${1}"
73 __parse_emu_img
"${1}"
79 __parse_emu_img
"${1}"
83 # Expand the short emu_img string into the full SDK package string identifying
85 sdk_package_of_emu_img
() {
87 __parse_emu_img
"${1}"
88 echo "system-images;android-${API};${TYPE};$(abi_of_arch ${ARCH})"
91 # Return the Android ABI string for an architecture.
94 arm
) echo armeabi-v7a
;;
95 arm64
) echo aarch64-v8a
;;
97 x86_64
) echo x86_64
;;
98 *) echo "error: unhandled arch ${1}" >&2; exit 1 ;;
104 arm
) echo armv7a-linux-androideabi
;;
105 arm64
) echo aarch64-linux-android
;;
106 x86
) echo i686-linux-android
;;
107 x86_64
) echo x86_64-linux-android
;;
108 *) echo "error: unhandled arch ${1}" >&2; exit 1 ;;