From ebd38295c6e5715a0ee04217b248ac69f9ddceab Mon Sep 17 00:00:00 2001 From: Anton Iakimov Date: Thu, 24 Aug 2023 16:09:43 +0200 Subject: [PATCH] run-android: set build abis depending on connected devices abis --- Makefile | 2 ++ scripts/adb_devices_abis.sh | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 scripts/adb_devices_abis.sh diff --git a/Makefile b/Makefile index bf849b7096..2534a7e8fb 100644 --- a/Makefile +++ b/Makefile @@ -272,6 +272,8 @@ run-re-frisk: ##@run Start re-frisk server # TODO: Migrate this to a Nix recipe, much the same way as nix/mobile/android/targets/release-android.nix run-android: export TARGET := android +# INFO: If it's empty (no devices attached, parsing issues, script error) - for Nix it's the same as not set. +run-android: export ANDROID_ABI_INCLUDE ?= $(shell ./scripts/adb_devices_arch.sh) run-android: ##@run Build Android APK and start it on the device npx react-native run-android --appIdSuffix debug diff --git a/scripts/adb_devices_abis.sh b/scripts/adb_devices_abis.sh new file mode 100755 index 0000000000..2c3163812d --- /dev/null +++ b/scripts/adb_devices_abis.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +set -e +typeset -a abis +SCRIPT_NAME=$(basename $0) + +function log() { + echo "${SCRIPT_NAME} ${1}: ${2}" >&2 +} + +# make sure server is running, otherwise sdb will show devices offline +adb start-server + +while IFS= read line; do + read -a arr <<< "${line}" + + device_name="${arr[0]}" + device_status=${arr[1]} + + log "DEBUG" "device_name=${device_name}" + log "DEBUG" "device_status=${device_status}" + + if [[ "${device_status}" != "device" ]]; then + continue + fi + + device_product_abi=$(adb -s ${device_name} shell -n getprop ro.product.cpu.abi) + log "DEBUG" "device_product_abi=${device_product_abi}" + + if [[ ! ${abis[*]} =~ ${device_product_abi} ]]; then + abis+=("${device_product_abi}") + fi +done <<< "$(adb devices | tail -n+2)" + +if [[ ! "${abis[*]}" ]]; then + log "ERROR" "no devices found. Check 'adb devices -l' output and share with Infra team if needed." + exit 3 +fi + +log "DEBUG" "resulting abis:" +IFS=\;; echo "${abis[*]}"