| 1 |
#!/usr/bin/env bash |
| 2 |
# ===----------------------------------------------------------------------===## |
| 3 |
# |
| 4 |
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 |
# See https://llvm.org/LICENSE.txt for license information. |
| 6 |
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 |
# |
| 8 |
# ===----------------------------------------------------------------------===## |
| 9 |
|
| 10 |
# Starts a new Docker container using a Docker image containing the Android |
| 11 |
# Emulator and an OS image. Stops and removes the old container if it exists |
| 12 |
# already. |
| 13 |
|
| 14 |
set -e |
| 15 |
|
| 16 |
THIS_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 17 |
. "${THIS_DIR}/emulator-functions.sh" |
| 18 |
|
| 19 |
EMU_IMG="${1}" |
| 20 |
if ! validate_emu_img "${EMU_IMG}"; then |
| 21 |
echo "error: The first argument must be a valid emulator image." >&2 |
| 22 |
exit 1 |
| 23 |
fi |
| 24 |
|
| 25 |
"${THIS_DIR}/stop-emulator.sh" |
| 26 |
|
| 27 |
# Start the container. |
| 28 |
docker run --name libcxx-ci-android-emulator --detach --device /dev/kvm \ |
| 29 |
-eEMU_PARTITION_SIZE=8192 \ |
| 30 |
--volume android-platform-tools:/mnt/android-platform-tools \ |
| 31 |
$(docker_image_of_emu_img ${EMU_IMG}) |
| 32 |
ERR=0 |
| 33 |
docker exec libcxx-ci-android-emulator emulator-wait-for-ready.sh || ERR=${?} |
| 34 |
echo "Emulator container initial logs:" |
| 35 |
docker logs libcxx-ci-android-emulator |
| 36 |
if [ ${ERR} != 0 ]; then |
| 37 |
exit ${ERR} |
| 38 |
fi |
| 39 |
|
| 40 |
# Make sure the device is accessible from outside the emulator container and |
| 41 |
# advertise to the user that this script exists. |
| 42 |
. "${THIS_DIR}/setup-env-for-emulator.sh" |
| 43 |
adb wait-for-device |