feat(kotlin-compose): design system + 33 components + gallery_kt + e2e android emulator + scaffolder fixes
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
---
|
||||
name: adb_wsl
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "source adb_wsl.sh [ADB=<path>] [ANDROID_SDK_WIN=<sdk_root>]"
|
||||
description: "Wrapper sourceable para usar adb.exe Windows desde WSL2. Resuelve binario, convierte paths, espera boot del emulador."
|
||||
tags: ["android", "adb", "wsl", "windows"]
|
||||
params:
|
||||
- name: ADB
|
||||
desc: "Env var opcional. Path absoluto a adb.exe. Si no se fija, se construye desde ANDROID_SDK_WIN o el default /mnt/c/Users/lucas/AppData/Local/Android/Sdk."
|
||||
- name: ANDROID_SDK_WIN
|
||||
desc: "Env var opcional. Raiz del Android SDK montado en WSL. Default: /mnt/c/Users/lucas/AppData/Local/Android/Sdk."
|
||||
output: "Source-able shell helpers: adb_run, adb_devices, adb_wsl_to_win, adb_wait_boot. Define ADB env var apuntando a Windows adb.exe via ANDROID_SDK_WIN."
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/adb_wsl.sh"
|
||||
---
|
||||
|
||||
## Uso
|
||||
|
||||
```bash
|
||||
# Sourcear (usa SDK default)
|
||||
source bash/functions/infra/adb_wsl.sh
|
||||
|
||||
# Sourcear con SDK custom
|
||||
ANDROID_SDK_WIN=/mnt/d/Android/Sdk source bash/functions/infra/adb_wsl.sh
|
||||
|
||||
# Sourcear con binario fijo
|
||||
ADB=/mnt/c/my/tools/adb.exe source bash/functions/infra/adb_wsl.sh
|
||||
```
|
||||
|
||||
## Funciones expuestas
|
||||
|
||||
### `adb_run "<args...>"`
|
||||
|
||||
Ejecuta `$ADB` con los argumentos dados. Retorna el exit code de `adb.exe`.
|
||||
|
||||
```bash
|
||||
adb_run shell ls /sdcard/
|
||||
adb_run install app.apk
|
||||
```
|
||||
|
||||
### `adb_devices`
|
||||
|
||||
Alias de `adb_run devices`. Lista dispositivos/emuladores conectados.
|
||||
|
||||
```bash
|
||||
adb_devices
|
||||
# List of devices attached
|
||||
# emulator-5554 device
|
||||
```
|
||||
|
||||
### `adb_wsl_to_win <path_wsl>`
|
||||
|
||||
Convierte un path WSL a formato Windows con `wslpath -w`. Si `wslpath` no está disponible retorna el path sin convertir.
|
||||
|
||||
```bash
|
||||
win_path=$(adb_wsl_to_win /home/lucas/proyecto/app.apk)
|
||||
# C:\Users\lucas\AppData\Local\... (o la ruta Windows equivalente)
|
||||
adb_run install "$win_path"
|
||||
```
|
||||
|
||||
### `adb_wait_boot [timeout_s]`
|
||||
|
||||
Espera a que el emulador/dispositivo complete el boot (`sys.boot_completed = 1`). Útil tras lanzar un AVD en CI.
|
||||
|
||||
```bash
|
||||
adb_wait_boot # timeout 120s
|
||||
adb_wait_boot 60 # timeout 60s
|
||||
```
|
||||
|
||||
Retorna `0` si el boot se completó, `1` si expiró el timeout.
|
||||
|
||||
## Smoke test
|
||||
|
||||
```bash
|
||||
bash bash/functions/infra/adb_wsl.sh --self-test
|
||||
# OK
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
- El script es **source-able**: define funciones en el shell actual, no crea subshell.
|
||||
- `ADB` se resuelve una sola vez al sourcing. Si el binario no existe en disco, la carga falla con mensaje en stderr y `return 1` / `exit 1`.
|
||||
- `adb_wait_boot` hace polling cada 3 segundos. Ajustar `interval` si el emulador es especialmente lento.
|
||||
- En WSL2 `wslpath` siempre está disponible; el fallback existe para entornos Linux puros que accidentalmente sourceen el archivo.
|
||||
- Si el emulador requiere `-s <serial>`, pasar el flag directamente a `adb_run`: `adb_run -s emulator-5554 shell ...`.
|
||||
---
|
||||
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env bash
|
||||
# adb_wsl — Wrapper sourceable para usar adb.exe Windows desde WSL2.
|
||||
# Uso: source bash/functions/infra/adb_wsl.sh
|
||||
# Smoke test: bash bash/functions/infra/adb_wsl.sh --self-test
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Resolver ADB
|
||||
# ---------------------------------------------------------------------------
|
||||
# El caller puede fijar ADB antes de sourcing para apuntar a otro binario.
|
||||
if [[ -z "${ADB:-}" ]]; then
|
||||
_sdk_root="${ANDROID_SDK_WIN:-/mnt/c/Users/lucas/AppData/Local/Android/Sdk}"
|
||||
ADB="${_sdk_root}/platform-tools/adb.exe"
|
||||
unset _sdk_root
|
||||
fi
|
||||
|
||||
if [[ ! -f "$ADB" ]]; then
|
||||
echo "adb_wsl: ADB no encontrado en '$ADB'. Fija ADB= o ANDROID_SDK_WIN= antes de sourcear." >&2
|
||||
# Solo abortamos si el script se ejecuta directamente; si se sourcea,
|
||||
# permitimos continuar para que el caller maneje el error.
|
||||
return 1 2>/dev/null || exit 1
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# adb_run "<args...>"
|
||||
# Ejecuta el ADB Windows con los argumentos dados.
|
||||
# Retorna el exit code de adb.exe.
|
||||
# ---------------------------------------------------------------------------
|
||||
adb_run() {
|
||||
"$ADB" "$@"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# adb_devices
|
||||
# Lista dispositivos ADB conectados.
|
||||
# ---------------------------------------------------------------------------
|
||||
adb_devices() {
|
||||
adb_run devices
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# adb_wsl_to_win <path_wsl>
|
||||
# Convierte un path WSL a formato Windows usando wslpath.
|
||||
# Si wslpath no está disponible retorna el path tal cual.
|
||||
# ---------------------------------------------------------------------------
|
||||
adb_wsl_to_win() {
|
||||
local path_wsl="$1"
|
||||
if command -v wslpath &>/dev/null; then
|
||||
wslpath -w "$path_wsl"
|
||||
else
|
||||
echo "$path_wsl"
|
||||
fi
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# adb_wait_boot [timeout_s]
|
||||
# Espera a que el dispositivo/emulador complete el boot (sys.boot_completed=1).
|
||||
# timeout_s: segundos máximos de espera (default 120).
|
||||
# Retorna 0 si boot completado, 1 si timeout.
|
||||
# ---------------------------------------------------------------------------
|
||||
adb_wait_boot() {
|
||||
local timeout_s="${1:-120}"
|
||||
local elapsed=0
|
||||
local interval=3
|
||||
|
||||
while (( elapsed < timeout_s )); do
|
||||
local val
|
||||
val=$(adb_run shell getprop sys.boot_completed 2>/dev/null | tr -d '[:space:]')
|
||||
if [[ "$val" == "1" ]]; then
|
||||
return 0
|
||||
fi
|
||||
sleep "$interval"
|
||||
(( elapsed += interval ))
|
||||
done
|
||||
|
||||
echo "adb_wsl: timeout ${timeout_s}s esperando boot del dispositivo." >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# adb_pick_serial [--serial <S>] [...]
|
||||
# Resuelve el serial a usar para multi-device. Lee --serial X de los args.
|
||||
# Setea globals ADB_PICK_SERIAL y ADB_PICK_REST (no usa stdout para evitar
|
||||
# perder los globals via subshell de $()).
|
||||
# Exit 1 si no hay device disponible.
|
||||
#
|
||||
# Uso tipico:
|
||||
# adb_pick_serial "$@" || { echo "no device" >&2; exit 3; }
|
||||
# local serial="$ADB_PICK_SERIAL"
|
||||
# set -- "${ADB_PICK_REST[@]}"
|
||||
# ---------------------------------------------------------------------------
|
||||
adb_pick_serial() {
|
||||
ADB_PICK_SERIAL="${ADB_SERIAL:-}"
|
||||
ADB_PICK_REST=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--serial) ADB_PICK_SERIAL="$2"; shift 2 ;;
|
||||
--serial=*) ADB_PICK_SERIAL="${1#--serial=}"; shift ;;
|
||||
*) ADB_PICK_REST+=("$1"); shift ;;
|
||||
esac
|
||||
done
|
||||
if [[ -z "$ADB_PICK_SERIAL" ]]; then
|
||||
ADB_PICK_SERIAL=$(adb_run devices 2>/dev/null | awk '/(emulator-|device$)/ && !/List of/ {print $1; exit}')
|
||||
fi
|
||||
if [[ -z "$ADB_PICK_SERIAL" ]]; then
|
||||
echo "adb_wsl: ningun device/emulador conectado." >&2
|
||||
return 1
|
||||
fi
|
||||
if ! adb_run devices 2>/dev/null | awk '{print $1}' | grep -qx "$ADB_PICK_SERIAL"; then
|
||||
echo "adb_wsl: serial '$ADB_PICK_SERIAL' no encontrado en adb devices." >&2
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# adb_s <serial> <args...>
|
||||
# Atajo: adb_run -s <serial> <args...>
|
||||
# ---------------------------------------------------------------------------
|
||||
adb_s() {
|
||||
local serial="$1"; shift
|
||||
adb_run -s "$serial" "$@"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Smoke test (solo si invocado directamente con --self-test)
|
||||
# ---------------------------------------------------------------------------
|
||||
if [[ "${1:-}" == "--self-test" ]]; then
|
||||
adb_run version || exit 1
|
||||
echo "OK"
|
||||
fi
|
||||
@@ -0,0 +1,66 @@
|
||||
---
|
||||
name: android_apk_install
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_apk_install([--serial S], apk_path: string, package_name?: string, activity_name?: string) -> void"
|
||||
description: "Instala APK en device/emulador via adb y opcionalmente lanza la app. Multi-emulator via --serial."
|
||||
tags: [android, adb, apk, wsl]
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target device/emulator serial. Default: first device detected by adb_pick_serial."
|
||||
- name: apk_path
|
||||
desc: "WSL path to APK file"
|
||||
- name: package_name
|
||||
desc: "Optional app package id (e.g. com.fnregistry.voiceguide). Launches the app if provided."
|
||||
- name: activity_name
|
||||
desc: "Optional activity (.MainActivity or fully qualified). Only used with package_name. If omitted, launches via monkey LAUNCHER intent."
|
||||
output: "Stdout con pasos. Exit 0 = install + launch OK. Exit !=0 si install fallo o APK no encontrado."
|
||||
uses_functions: ["adb_wsl_bash_infra"]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_apk_install.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Solo instalar
|
||||
android_apk_install /home/lucas/builds/app-debug.apk
|
||||
|
||||
# Instalar y lanzar con activity explícita
|
||||
android_apk_install /home/lucas/builds/app-debug.apk com.fnregistry.voiceguide .MainActivity
|
||||
|
||||
# Instalar y lanzar sin activity (usa monkey LAUNCHER)
|
||||
android_apk_install /home/lucas/builds/app-debug.apk com.fnregistry.voiceguide
|
||||
|
||||
# Llamada directa desde shell (no sourced)
|
||||
bash bash/functions/infra/android_apk_install.sh /path/to/app.apk com.example.app .MainActivity
|
||||
|
||||
# Override ADB path
|
||||
ADB=/custom/path/adb.exe bash bash/functions/infra/android_apk_install.sh /path/to/app.apk
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
- Requiere WSL2 con `adb.exe` Windows accesible. El path por defecto es
|
||||
`/mnt/c/Users/lucas/AppData/Local/Android/Sdk/platform-tools/adb.exe`.
|
||||
Se puede sobreescribir con `ADB=...` o `ANDROID_SDK_WIN=<sdk_root>` antes
|
||||
de invocar.
|
||||
- `wslpath` se usa para convertir el path WSL a formato Windows (`C:\...`).
|
||||
Si no está disponible (entorno no-WSL), se usa el path tal cual.
|
||||
- La instalación usa `adb install -r` (reinstala si ya existe).
|
||||
- Si `package_name` se da sin `activity_name`, la app se lanza via
|
||||
`adb shell monkey -p <pkg> -c android.intent.category.LAUNCHER 1`,
|
||||
que es equivalente a pulsar el icono del launcher.
|
||||
- El script se puede sourcear (para usar la función en otros scripts) o
|
||||
ejecutar directamente. Cuando se ejecuta directamente, delega en
|
||||
`android_apk_install "$@"`.
|
||||
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_apk_install — Instala APK en device/emulador via adb y opcionalmente lanza la app.
|
||||
# Multi-emulator via --serial <S>.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Source helpers (adb_run, adb_pick_serial, adb_s, adb_wsl_to_win)
|
||||
# shellcheck source=/dev/null
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# android_apk_install [--serial <S>] <apk_path> [package_name] [activity_name]
|
||||
# ---------------------------------------------------------------------------
|
||||
android_apk_install() {
|
||||
local serial
|
||||
adb_pick_serial "$@" || { echo "android_apk_install: no device/emulator." >&2; return 3; }
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
local apk="${1:-}"
|
||||
local package="${2:-}"
|
||||
local activity="${3:-}"
|
||||
|
||||
if [[ -z "$apk" ]]; then
|
||||
echo "android_apk_install: se requiere apk_path como primer argumento." >&2
|
||||
return 1
|
||||
fi
|
||||
if [[ ! -f "$apk" ]]; then
|
||||
echo "android_apk_install: APK no encontrado en '$apk'." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local win_path
|
||||
win_path=$(adb_wsl_to_win "$apk")
|
||||
|
||||
echo "android_apk_install: instalando '$win_path' on $serial ..."
|
||||
adb_s "$serial" install -r "$win_path"
|
||||
echo "android_apk_install: instalacion completada."
|
||||
|
||||
if [[ -n "$package" ]]; then
|
||||
if [[ -n "$activity" ]]; then
|
||||
echo "android_apk_install: lanzando $package/$activity ..."
|
||||
adb_s "$serial" shell am start -n "$package/$activity"
|
||||
else
|
||||
echo "android_apk_install: lanzando $package via monkey LAUNCHER ..."
|
||||
adb_s "$serial" shell monkey -p "$package" -c android.intent.category.LAUNCHER 1
|
||||
fi
|
||||
echo "android_apk_install: app lanzada."
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_apk_install "$@"
|
||||
fi
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
name: android_app_clear
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_app_clear([--serial <S>], package: string) -> void"
|
||||
description: "Wipe app data + cache via pm clear. App keeps installed but factory-state. Multi-emulator via --serial."
|
||||
tags: [android, adb, app, clear, reset]
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target device/emulator serial. Auto-detected if omitted."
|
||||
- name: package
|
||||
desc: "App package whose data to clear (e.g. com.example.app)."
|
||||
output: "Stdout 'cleared data for <pkg> on <serial>'. Exit 0 si pm clear OK."
|
||||
uses_functions: ["adb_wsl_bash_infra"]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_app_clear.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Limpiar datos de una app (autodetecta device)
|
||||
android_app_clear com.example.myapp
|
||||
|
||||
# Con serial explícito
|
||||
android_app_clear --serial emulator-5554 com.example.myapp
|
||||
|
||||
# Llamada directa
|
||||
bash bash/functions/infra/android_app_clear.sh com.example.myapp
|
||||
bash bash/functions/infra/android_app_clear.sh --serial emulator-5554 com.example.myapp
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
- Usa `pm clear` internamente — borra SharedPreferences, bases de datos internas,
|
||||
caché y archivos de la app. La app queda como recién instalada.
|
||||
- El source de `adb_wsl.sh` resuelve el binario `adb.exe` Windows desde WSL2.
|
||||
Se puede sobreescribir con `ADB=...` o `ANDROID_SDK_WIN=<sdk_root>` antes de invocar.
|
||||
- `adb_pick_serial` consume `--serial <S>` de los args y deja el resto en
|
||||
`ADB_PICK_REST`. Si no se da, autodetecta el primer device/emulador activo.
|
||||
- Exit 3 si no hay ningún device conectado (propagado desde `adb_pick_serial`).
|
||||
- Exit 1 si no se pasa package.
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_app_clear — Wipe app data + cache via pm clear. App stays installed.
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=./adb_wsl.sh
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# android_app_clear [--serial <S>] <package>
|
||||
#
|
||||
# --serial <S> Optional target device/emulator serial.
|
||||
# package App package whose data+cache to clear (e.g. com.example.app).
|
||||
#
|
||||
# Calls: adb shell pm clear <package>
|
||||
# The app remains installed but is reset to factory state (no data, no cache).
|
||||
# Exit 0 on success, exit 1 on bad args, exit 3 if no device found.
|
||||
# ---------------------------------------------------------------------------
|
||||
android_app_clear() {
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
local pkg="${1:-}"
|
||||
if [[ -z "$pkg" ]]; then
|
||||
echo "android_app_clear: se requiere <package> como argumento." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
adb_s "$serial" shell pm clear "$pkg"
|
||||
echo "cleared data for $pkg on $serial"
|
||||
}
|
||||
|
||||
# Run directly if not sourced
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_app_clear "$@"
|
||||
fi
|
||||
@@ -0,0 +1,57 @@
|
||||
---
|
||||
name: android_app_info
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_app_info([--serial <S>], package, [--json]) -> stdout"
|
||||
description: "Inspect installed app: version, target SDK, activities via dumpsys package."
|
||||
tags: [android, adb, app, info, dumpsys]
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional ADB serial to target a specific device/emulator. Auto-detected if omitted."
|
||||
- name: "package"
|
||||
desc: "Android package name to inspect (e.g. com.example.myapp)."
|
||||
- name: "--json"
|
||||
desc: "Emit parsed JSON with versionName, versionCode, targetSdk, launcherActivity instead of raw dumpsys output."
|
||||
output: "Raw dumpsys package output, or JSON object {package, versionName, versionCode, targetSdk, launcherActivity}. Outputs JSON null if package not installed (--json mode). Exit 2 if package not found in raw mode, exit 3 if no device."
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_app_info.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Raw dumpsys (full output)
|
||||
source bash/functions/infra/android_app_info.sh
|
||||
android_app_info com.example.myapp
|
||||
|
||||
# Target specific device
|
||||
android_app_info --serial emulator-5554 com.example.myapp
|
||||
|
||||
# Parsed JSON
|
||||
android_app_info com.example.myapp --json
|
||||
# {"package":"com.example.myapp","versionName":"2.1.0","versionCode":210,"targetSdk":34,"launcherActivity":"com.example.myapp/.MainActivity"}
|
||||
|
||||
# Package not installed → JSON null
|
||||
android_app_info com.not.installed --json
|
||||
# null
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
- Sources `adb_wsl.sh` para resolver el binario ADB Windows desde WSL2 y las helpers `adb_pick_serial` / `adb_s`.
|
||||
- `--serial` se consume via `adb_pick_serial`; el resto de los args quedan en `ADB_PICK_REST` y se re-asignan con `set --`.
|
||||
- JSON parsing usa `grep`/`sed`/`awk` sobre la salida de `dumpsys package`. Campos faltantes se emiten como string vacío o 0; no se usa `jq` para no requerir dependencias externas.
|
||||
- `launcherActivity` se extrae buscando el bloque `android.intent.action.MAIN` / `android.intent.category.LAUNCHER` en el listado de intent filters.
|
||||
- Exit codes: 0 = OK, 1 = arg/adb error, 2 = package not found (raw mode), 3 = no device.
|
||||
---
|
||||
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_app_info — Inspect installed app via dumpsys package.
|
||||
# Usage: android_app_info [--serial <S>] <package> [--json]
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
android_app_info() {
|
||||
# Resolve serial (consumes --serial from args, leaves rest in ADB_PICK_REST)
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
# Parse remaining args: package + --json flag
|
||||
local pkg=""
|
||||
local want_json=0
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--json) want_json=1; shift ;;
|
||||
-*) echo "android_app_info: unknown flag '$1'" >&2; return 1 ;;
|
||||
*)
|
||||
if [[ -z "$pkg" ]]; then
|
||||
pkg="$1"
|
||||
else
|
||||
echo "android_app_info: unexpected argument '$1'" >&2
|
||||
return 1
|
||||
fi
|
||||
shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$pkg" ]]; then
|
||||
echo "android_app_info: package argument required" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local dump
|
||||
dump=$(adb_s "$serial" shell dumpsys package "$pkg" 2>&1)
|
||||
local rc=$?
|
||||
if [[ $rc -ne 0 ]]; then
|
||||
echo "android_app_info: adb dumpsys failed (exit $rc)" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# If dumpsys returns nothing meaningful for the package, treat as not installed
|
||||
if ! echo "$dump" | grep -q "Package \["; then
|
||||
if [[ $want_json -eq 1 ]]; then
|
||||
echo "null"
|
||||
else
|
||||
echo "android_app_info: package '$pkg' not found on device" >&2
|
||||
return 2
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ $want_json -eq 0 ]]; then
|
||||
echo "$dump"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# --- JSON extraction ---
|
||||
local versionName versionCode targetSdk launcherActivity
|
||||
|
||||
versionName=$(echo "$dump" | grep -m1 'versionName=' \
|
||||
| sed 's/.*versionName=\([^ ]*\).*/\1/')
|
||||
versionCode=$(echo "$dump" | grep -m1 'versionCode=' \
|
||||
| sed 's/.*versionCode=\([0-9]*\).*/\1/')
|
||||
targetSdk=$(echo "$dump" | grep -m1 'targetSdk=' \
|
||||
| sed 's/.*targetSdk=\([0-9]*\).*/\1/')
|
||||
|
||||
# Primary/launcher activity: look for MAIN/LAUNCHER category block
|
||||
launcherActivity=$(echo "$dump" | awk '
|
||||
/android.intent.action.MAIN/ { found=1 }
|
||||
found && /[a-zA-Z0-9_.]+\/[a-zA-Z0-9_.]+/ {
|
||||
match($0, /[a-zA-Z0-9_.]+\/[a-zA-Z0-9_.]+/)
|
||||
print substr($0, RSTART, RLENGTH)
|
||||
exit
|
||||
}
|
||||
')
|
||||
|
||||
# Emit JSON, quoting strings safely
|
||||
printf '{"package":"%s","versionName":"%s","versionCode":%s,"targetSdk":%s,"launcherActivity":"%s"}\n' \
|
||||
"$pkg" \
|
||||
"${versionName:-}" \
|
||||
"${versionCode:-0}" \
|
||||
"${targetSdk:-0}" \
|
||||
"${launcherActivity:-}"
|
||||
}
|
||||
|
||||
# Run if invoked directly
|
||||
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
||||
android_app_info "$@"
|
||||
fi
|
||||
@@ -0,0 +1,44 @@
|
||||
---
|
||||
name: android_app_kill
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_app_kill([--serial <S>], package: string) -> void"
|
||||
description: "Force-stop running app via am force-stop. Multi-emulator via --serial."
|
||||
tags: [android, adb, app, kill, force-stop]
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target device/emulator serial. Auto-detected if omitted."
|
||||
- name: "package"
|
||||
desc: "App package to force-stop (e.g. com.example.myapp)."
|
||||
output: "Stdout 'killed <pkg> on <serial>'. Exit 0."
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_app_kill.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Detener app en el emulador activo
|
||||
android_app_kill com.example.myapp
|
||||
|
||||
# Detener app en un dispositivo concreto
|
||||
android_app_kill --serial emulator-5554 com.example.myapp
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Usa `adb_pick_serial` de `adb_wsl.sh` para resolver el dispositivo objetivo.
|
||||
Si `--serial` no se pasa, autodetecta el primer device/emulador disponible.
|
||||
Sale con exit 3 si no hay ningun device conectado.
|
||||
`am force-stop` detiene todos los procesos y servicios de la app de forma inmediata.
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_app_kill — Force-stop a running Android app via am force-stop.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=adb_wsl.sh
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
android_app_kill() {
|
||||
local serial pkg
|
||||
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
pkg="${1:?android_app_kill: package name required}"
|
||||
|
||||
adb_s "$serial" shell am force-stop "$pkg"
|
||||
echo "killed $pkg on $serial"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_app_kill "$@"
|
||||
fi
|
||||
@@ -0,0 +1,49 @@
|
||||
---
|
||||
name: android_app_launch
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_app_launch([--serial <S>], package: string, [activity: string]) -> void"
|
||||
description: "Launch app activity via am start. Multi-emulator via --serial."
|
||||
tags: [android, adb, app, launch, activity]
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target serial. Default: first device"
|
||||
- name: "package"
|
||||
desc: "App package id"
|
||||
- name: "activity"
|
||||
desc: "Optional activity. If omitted, launches via LAUNCHER intent"
|
||||
output: "Stdout 'launched <pkg> on <serial>'. Exit 0 ok, 3 no device."
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_app_launch.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Lanzar actividad principal explicitamente
|
||||
android_app_launch com.foo.bar .MainActivity
|
||||
|
||||
# Lanzar por LAUNCHER intent (detecta actividad principal automaticamente)
|
||||
android_app_launch com.foo.bar
|
||||
|
||||
# Multi-emulador: elegir serial concreto
|
||||
android_app_launch --serial emulator-5554 com.foo.bar .MainActivity
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Usa `adb_pick_serial` de `adb_wsl.sh` para resolver el serial objetivo.
|
||||
Si no hay ningun device/emulador disponible, sale con exit code 3.
|
||||
Si `activity` no se especifica, usa `monkey -p <pkg> -c android.intent.category.LAUNCHER 1`
|
||||
para lanzar la actividad principal sin necesidad de conocerla de antemano.
|
||||
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_app_launch — Launch an Android app via adb am start or monkey LAUNCHER intent.
|
||||
# Usage: android_app_launch [--serial <S>] <package> [<activity>]
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
android_app_launch() {
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
local pkg="${1:-}"
|
||||
local activity="${2:-}"
|
||||
|
||||
if [[ -z "$pkg" ]]; then
|
||||
echo "android_app_launch: package is required." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -n "$activity" ]]; then
|
||||
adb_s "$serial" shell am start -n "$pkg/$activity"
|
||||
else
|
||||
adb_s "$serial" shell monkey -p "$pkg" -c android.intent.category.LAUNCHER 1
|
||||
fi
|
||||
|
||||
echo "launched $pkg on $serial"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_app_launch "$@"
|
||||
fi
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
name: android_app_uninstall
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_app_uninstall([--serial <S>] package [--keep-data]) -> void"
|
||||
description: "Uninstall app via adb uninstall. Optionally keep data with --keep-data."
|
||||
tags: [android, adb, app, uninstall]
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target device/emulator serial. Auto-detects first connected device if omitted."
|
||||
- name: "package"
|
||||
desc: "Android package name to uninstall (e.g. com.example.myapp). Mandatory positional argument."
|
||||
- name: "--keep-data"
|
||||
desc: "Keep app data + cache after uninstall (passes -k to pm uninstall)."
|
||||
output: "Stdout 'uninstalled <pkg> on <serial>'. Exit 0 OK."
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_app_uninstall.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Desinstalar en el device por defecto
|
||||
android_app_uninstall com.example.myapp
|
||||
|
||||
# Desinstalar en un device concreto
|
||||
android_app_uninstall --serial emulator-5554 com.example.myapp
|
||||
|
||||
# Desinstalar conservando datos y cache
|
||||
android_app_uninstall --serial emulator-5554 com.example.myapp --keep-data
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Sourcea `adb_wsl.sh` para resolver el binario `adb.exe` en WSL2 y usar
|
||||
`adb_pick_serial` / `adb_s`. Si no hay ningún device conectado y no se
|
||||
pasa `--serial`, la función falla con exit 1 antes de invocar adb.
|
||||
|
||||
El flag `--keep-data` pasa `-k` a `adb uninstall`, equivalente a
|
||||
`pm uninstall -k` — el APK se elimina pero los datos y la caché de la app
|
||||
permanecen en el dispositivo.
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_app_uninstall — Desinstala una app Android via adb uninstall.
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
android_app_uninstall() {
|
||||
# Parse --serial (consumes it, rest stays in ADB_PICK_REST)
|
||||
local serial
|
||||
adb_pick_serial "$@" || return 1
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
# Parse --keep-data flag
|
||||
local keep_data=0
|
||||
local args=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--keep-data) keep_data=1; shift ;;
|
||||
*) args+=("$1"); shift ;;
|
||||
esac
|
||||
done
|
||||
set -- "${args[@]}"
|
||||
|
||||
local pkg="${1:-}"
|
||||
if [[ -z "$pkg" ]]; then
|
||||
echo "android_app_uninstall: package obligatorio." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
if (( keep_data )); then
|
||||
adb_s "$serial" uninstall -k "$pkg" || return 1
|
||||
else
|
||||
adb_s "$serial" uninstall "$pkg" || return 1
|
||||
fi
|
||||
|
||||
echo "uninstalled $pkg on $serial"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_app_uninstall "$@"
|
||||
fi
|
||||
@@ -0,0 +1,51 @@
|
||||
---
|
||||
name: android_emu_battery
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_emu_battery([--serial <S>], level: int, [--charging <true|false>]) -> void"
|
||||
description: "Simulate battery state on emulator (level + charging). Emulator-only."
|
||||
tags: [android, emulator, battery, power]
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional emulator serial (e.g. emulator-5554). Auto-detected if omitted."
|
||||
- name: "level"
|
||||
desc: "Battery level 0-100 to set via 'emu power capacity'."
|
||||
- name: "--charging <true|false>"
|
||||
desc: "AC charging state: true maps to 'on', false maps to 'off'. Omit to leave unchanged."
|
||||
output: "Stdout 'battery: <N>% [charging=...] on <serial>'. Exit 3 if no device found, exit 1 on other errors."
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_emu_battery.sh"
|
||||
notes: "Util para tests bateria baja, modo ahorro energia. Solo funciona con emuladores (serial emulator-*), no con devices fisicos."
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Nivel al 15%, sin cambiar estado de carga
|
||||
android_emu_battery 15
|
||||
|
||||
# Nivel al 5%, forzar descarga (AC off)
|
||||
android_emu_battery 5 --charging false
|
||||
|
||||
# Nivel al 80%, forzar carga (AC on), emulador concreto
|
||||
android_emu_battery --serial emulator-5554 80 --charging true
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Util para tests de bateria baja y modo ahorro de energia. Solo funciona con emuladores Android
|
||||
(serial debe empezar con `emulator-`). No aplica a dispositivos fisicos.
|
||||
|
||||
Requiere que `adb_wsl.sh` este en el mismo directorio. El ADB se resuelve via
|
||||
`ANDROID_SDK_WIN` o la ruta por defecto de la instalacion Windows SDK.
|
||||
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_emu_battery — Simulate battery state on Android emulator (level + charging).
|
||||
# Usage: android_emu_battery [--serial <S>] <level 0-100> [--charging <true|false>]
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
android_emu_battery() {
|
||||
# Resolve serial (consumes --serial from args, leaves rest in ADB_PICK_REST)
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
# Require serial to be an emulator
|
||||
if [[ "$serial" != emulator-* ]]; then
|
||||
echo "android_emu_battery: serial '$serial' is not an emulator (must start with emulator-)." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Parse remaining args: positional level + --charging
|
||||
local level=""
|
||||
local charging=""
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--charging)
|
||||
charging="$2"
|
||||
shift 2
|
||||
;;
|
||||
--charging=*)
|
||||
charging="${1#--charging=}"
|
||||
shift
|
||||
;;
|
||||
-*)
|
||||
echo "android_emu_battery: unknown flag '$1'." >&2
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
if [[ -z "$level" ]]; then
|
||||
level="$1"
|
||||
fi
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Validate level
|
||||
if [[ -z "$level" ]]; then
|
||||
echo "android_emu_battery: level is required (0-100)." >&2
|
||||
return 1
|
||||
fi
|
||||
if ! [[ "$level" =~ ^[0-9]+$ ]] || (( level < 0 || level > 100 )); then
|
||||
echo "android_emu_battery: invalid level '$level' — must be integer 0-100." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Set battery level
|
||||
adb_s "$serial" emu power capacity "$level" || {
|
||||
echo "android_emu_battery: failed to set capacity on $serial." >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
# Set charging state if requested
|
||||
local ch="<unchanged>"
|
||||
if [[ -n "$charging" ]]; then
|
||||
local ac_val
|
||||
case "$charging" in
|
||||
true) ac_val="on" ;;
|
||||
false) ac_val="off" ;;
|
||||
*)
|
||||
echo "android_emu_battery: --charging must be 'true' or 'false', got '$charging'." >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
adb_s "$serial" emu power ac "$ac_val" || {
|
||||
echo "android_emu_battery: failed to set AC charging on $serial." >&2
|
||||
return 1
|
||||
}
|
||||
ch="$charging"
|
||||
fi
|
||||
|
||||
echo "battery: ${level}% [charging=${ch}] on ${serial}"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_emu_battery "$@"
|
||||
fi
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
name: android_emu_geo_fix
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_emu_geo_fix([--serial <S>], longitude: string, latitude: string, [altitude: string]) -> void"
|
||||
description: "Fake GPS location on Android emulator via emu geo fix. Emulator-only (not physical devices)."
|
||||
tags: [android, emulator, geo, gps, location]
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional emulator serial. Auto-detected if omitted."
|
||||
- name: "longitude"
|
||||
desc: "Longitude (decimal degrees). Passed first — opposite to human lat/lon convention."
|
||||
- name: "latitude"
|
||||
desc: "Latitude (decimal degrees)."
|
||||
- name: "altitude"
|
||||
desc: "Optional altitude in meters."
|
||||
output: "Stdout 'GPS set: <lon>, <lat> (alt=...) on <serial>'. Exit 0."
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_emu_geo_fix.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Fijar GPS en Madrid (emulador activo)
|
||||
android_emu_geo_fix -3.7038 40.4168
|
||||
|
||||
# Con altitud
|
||||
android_emu_geo_fix -3.7038 40.4168 650
|
||||
|
||||
# Emulador especifico
|
||||
android_emu_geo_fix --serial emulator-5554 -3.7038 40.4168
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
El orden de argumentos es **longitud primero, latitud segundo** — opuesto a la convencion humana habitual (lat/lon). Esto sigue el protocolo del comando `emu geo fix` de Android.
|
||||
|
||||
Solo funciona en emuladores (`emulator-*`). Si el serial apunta a un dispositivo fisico, la funcion sale con error y exit 1.
|
||||
|
||||
Usa `adb_pick_serial` de `adb_wsl.sh` para resolver el dispositivo objetivo.
|
||||
Sale con exit 3 si no hay ningun device conectado.
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_emu_geo_fix — Fake GPS location on Android emulator via emu geo fix.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=adb_wsl.sh
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
android_emu_geo_fix() {
|
||||
local serial lon lat alt
|
||||
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
lon="${1:?android_emu_geo_fix: longitude required}"
|
||||
lat="${2:?android_emu_geo_fix: latitude required}"
|
||||
alt="${3:-}"
|
||||
|
||||
# geo fix only works on emulators, not physical devices
|
||||
if [[ "$serial" != emulator-* ]]; then
|
||||
echo "android_emu_geo_fix: geo fix only works on emulators (got '$serial')" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
adb_s "$serial" emu geo fix "$lon" "$lat" ${alt:+"$alt"}
|
||||
|
||||
if [[ -n "$alt" ]]; then
|
||||
echo "GPS set: $lon, $lat (alt=$alt) on $serial"
|
||||
else
|
||||
echo "GPS set: $lon, $lat on $serial"
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_emu_geo_fix "$@"
|
||||
fi
|
||||
@@ -0,0 +1,49 @@
|
||||
---
|
||||
name: android_emu_rotate
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_emu_rotate([--serial <S>] [portrait|landscape|0|90|180|270])"
|
||||
description: "Rotate emulator screen. Empty=toggle, or fixed orientation. Locks autorotate."
|
||||
tags: [android, emulator, rotation, orientation]
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional emulator serial. Picked automatically if only one is connected."
|
||||
- name: "orientation"
|
||||
desc: "Empty=toggle via emu rotate, or fixed: portrait/landscape/0/90/180/270."
|
||||
output: "Stdout 'rotated: <orient> on <serial>'."
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_emu_rotate.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Toggle rotation
|
||||
android_emu_rotate
|
||||
|
||||
# Force portrait
|
||||
android_emu_rotate portrait
|
||||
|
||||
# Force landscape on specific emulator
|
||||
android_emu_rotate --serial emulator-5554 landscape
|
||||
|
||||
# Set 270 degrees
|
||||
android_emu_rotate --serial emulator-5554 270
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Deshabilita autorotate (`accelerometer_rotation 0`) antes de aplicar cualquier orientacion fija, de modo que el sistema no la revierta. El toggle (`emu rotate`) no desactiva autorotate: lo usa directamente el daemon del emulador.
|
||||
|
||||
`adb_pick_serial` (de `adb_wsl_bash_infra`) selecciona el unico emulador conectado o falla con exit 3 si hay ambiguedad o ninguno disponible. Los argumentos restantes tras extraer `--serial` quedan en `ADB_PICK_REST`.
|
||||
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_emu_rotate — rotate emulator screen or toggle rotation
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=./adb_wsl.sh
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
android_emu_rotate() {
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
local arg="${1:-}"
|
||||
|
||||
# Disable autorotate before any operation
|
||||
if [[ -n "$arg" ]]; then
|
||||
adb_s "$serial" shell settings put system accelerometer_rotation 0
|
||||
fi
|
||||
|
||||
case "$arg" in
|
||||
"")
|
||||
# Toggle via emu rotate command
|
||||
adb_s "$serial" emu rotate
|
||||
;;
|
||||
portrait|0)
|
||||
adb_s "$serial" shell settings put system accelerometer_rotation 0
|
||||
adb_s "$serial" shell settings put system user_rotation 0
|
||||
;;
|
||||
landscape|90)
|
||||
adb_s "$serial" shell settings put system accelerometer_rotation 0
|
||||
adb_s "$serial" shell settings put system user_rotation 1
|
||||
;;
|
||||
180)
|
||||
adb_s "$serial" shell settings put system accelerometer_rotation 0
|
||||
adb_s "$serial" shell settings put system user_rotation 2
|
||||
;;
|
||||
270)
|
||||
adb_s "$serial" shell settings put system accelerometer_rotation 0
|
||||
adb_s "$serial" shell settings put system user_rotation 3
|
||||
;;
|
||||
*)
|
||||
echo "android_emu_rotate: unknown orientation '$arg'" >&2
|
||||
echo "Usage: android_emu_rotate [--serial <S>] [portrait|landscape|0|90|180|270]" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "rotated: ${arg:-toggle} on $serial"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_emu_rotate "$@"
|
||||
fi
|
||||
@@ -0,0 +1,51 @@
|
||||
---
|
||||
name: android_emulator_list
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_emulator_list([--json])"
|
||||
description: "Lista los AVDs disponibles invocando emulator.exe Windows desde WSL2."
|
||||
tags: [android, emulator, wsl]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
params:
|
||||
- name: "--json"
|
||||
desc: "Optional flag, outputs JSON array instead of newline-separated names"
|
||||
output: "Lista de AVDs disponibles en el SDK Windows. Una por linea, o JSON array con --json."
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_emulator_list.sh"
|
||||
notes: "Lee env var EMULATOR o ANDROID_SDK_WIN. Default Windows path: /mnt/c/Users/lucas/AppData/Local/Android/Sdk/emulator/emulator.exe. Exit 0 si lista (incluso vacia). Exit 1 solo si el binario no existe o no es ejecutable."
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Listar AVDs (una por linea)
|
||||
android_emulator_list
|
||||
|
||||
# Listar AVDs en formato JSON
|
||||
android_emulator_list --json
|
||||
# ["Pixel_7_API_34","Pixel_4_API_30"]
|
||||
|
||||
# Sobreescribir ruta del emulador
|
||||
EMULATOR="/custom/path/emulator.exe" android_emulator_list
|
||||
|
||||
# Sobreescribir SDK base
|
||||
ANDROID_SDK_WIN="/mnt/d/Android/Sdk" android_emulator_list
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
El script es ejecutable directamente (`chmod +x`) o invocable con `bash android_emulator_list.sh`.
|
||||
|
||||
`emulator.exe -list-avds` imprime warnings a stderr que se descartan con `2>/dev/null`. La captura con `mapfile` filtra ademas lineas vacias para producir una lista limpia.
|
||||
|
||||
La variable `EMULATOR` tiene prioridad sobre `ANDROID_SDK_WIN`. Si ninguna esta definida se usa el path Windows por defecto de Lucas.
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_emulator_list — Lista los AVDs disponibles invocando emulator.exe Windows desde WSL2.
|
||||
set -euo pipefail
|
||||
|
||||
# Resolve emulator binary
|
||||
EMULATOR="${EMULATOR:-${ANDROID_SDK_WIN:-/mnt/c/Users/lucas/AppData/Local/Android/Sdk}/emulator/emulator.exe}"
|
||||
|
||||
if [[ ! -x "$EMULATOR" ]]; then
|
||||
echo "error: emulator binary not found or not executable: $EMULATOR" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse flags
|
||||
JSON=false
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--json) JSON=true ;;
|
||||
*) echo "error: unknown argument: $arg" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Collect AVDs, stripping any warnings emulator.exe prints to stderr
|
||||
mapfile -t AVDS < <("$EMULATOR" -list-avds 2>/dev/null || true)
|
||||
|
||||
if $JSON; then
|
||||
# Build JSON array
|
||||
printf '['
|
||||
first=true
|
||||
for avd in "${AVDS[@]}"; do
|
||||
[[ -z "$avd" ]] && continue
|
||||
if $first; then
|
||||
printf '"%s"' "$avd"
|
||||
first=false
|
||||
else
|
||||
printf ',"%s"' "$avd"
|
||||
fi
|
||||
done
|
||||
printf ']\n'
|
||||
else
|
||||
for avd in "${AVDS[@]}"; do
|
||||
[[ -z "$avd" ]] && continue
|
||||
printf '%s\n' "$avd"
|
||||
done
|
||||
fi
|
||||
@@ -0,0 +1,49 @@
|
||||
---
|
||||
name: android_emulator_start
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_emulator_start(avd_name: string, timeout_s: int) -> string"
|
||||
description: "Arranca un AVD en background y espera a que termine de bootear. Idempotente: si ya hay emulador corriendo no lanza otro."
|
||||
tags: [android, emulator, wsl]
|
||||
params:
|
||||
- name: avd_name
|
||||
desc: "Nombre del AVD a arrancar (visible con android_emulator_list o `emulator.exe -list-avds`)"
|
||||
- name: timeout_s
|
||||
desc: "Timeout total en segundos para esperar el boot completo. Opcional, default 180"
|
||||
output: "Serial del device emulado (ej. emulator-5554) en stdout. Exit 0 = boot completo, exit 1 = timeout o emulador murio."
|
||||
uses_functions: ["adb_wsl_bash_infra"]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_emulator_start.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
source bash/functions/infra/android_emulator_start.sh
|
||||
|
||||
# Arrancar AVD con timeout por defecto (180s)
|
||||
serial=$(android_emulator_start "Pixel_6_API_34")
|
||||
echo "Emulador listo: $serial" # emulator-5554
|
||||
|
||||
# Con timeout personalizado
|
||||
serial=$(android_emulator_start "Pixel_6_API_34" 300)
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
- Sourcea `adb_wsl.sh` del mismo directorio si existe (provee `ADB`, `adb_run`, `adb_wait_boot`). Si no, usa implementacion inline.
|
||||
- Resuelve `EMULATOR` y `ADB` desde `ANDROID_SDK_WIN` (default `/mnt/c/Users/lucas/AppData/Local/Android/Sdk`) o desde las variables de entorno `EMULATOR=` / `ADB=` si ya están fijadas.
|
||||
- Idempotente: si `adb devices` ya muestra un `emulator-*`, imprime "already running" + el serial y sale con exit 0 sin lanzar un segundo proceso.
|
||||
- Log del emulador en `/tmp/emulator_<avd>.log`. PID en `/tmp/emulator_<avd>.pid`.
|
||||
- El timeout total se reparte: primera mitad para `adb wait-for-device`, segunda mitad para esperar `sys.boot_completed=1`.
|
||||
- Diseñado para WSL2 con Android SDK instalado en Windows. En Linux nativo basta cambiar las rutas de los binarios via `EMULATOR=` y `ADB=`.
|
||||
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_emulator_start — Arranca un AVD en background y espera a que bootee.
|
||||
# Uso: android_emulator_start <avd_name> [timeout_s]
|
||||
set -euo pipefail
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Source adb_wsl si está disponible (provee ADB, adb_run, adb_wait_boot)
|
||||
# ---------------------------------------------------------------------------
|
||||
_ADB_WSL_SH="$(dirname "${BASH_SOURCE[0]}")/adb_wsl.sh"
|
||||
if [[ -f "$_ADB_WSL_SH" ]]; then
|
||||
# shellcheck source=adb_wsl.sh
|
||||
source "$_ADB_WSL_SH"
|
||||
else
|
||||
# Fallback inline: resolver ADB
|
||||
if [[ -z "${ADB:-}" ]]; then
|
||||
_sdk_root="${ANDROID_SDK_WIN:-/mnt/c/Users/lucas/AppData/Local/Android/Sdk}"
|
||||
ADB="${_sdk_root}/platform-tools/adb.exe"
|
||||
unset _sdk_root
|
||||
fi
|
||||
adb_run() { "$ADB" "$@"; }
|
||||
adb_wait_boot() {
|
||||
local timeout_s="${1:-120}"
|
||||
local elapsed=0 interval=3 val
|
||||
while (( elapsed < timeout_s )); do
|
||||
val=$(adb_run shell getprop sys.boot_completed 2>/dev/null | tr -d '[:space:]')
|
||||
[[ "$val" == "1" ]] && return 0
|
||||
sleep "$interval"
|
||||
(( elapsed += interval ))
|
||||
done
|
||||
echo "android_emulator_start: timeout ${timeout_s}s esperando boot." >&2
|
||||
return 1
|
||||
}
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Resolver EMULATOR
|
||||
# ---------------------------------------------------------------------------
|
||||
if [[ -z "${EMULATOR:-}" ]]; then
|
||||
_sdk_root="${ANDROID_SDK_WIN:-/mnt/c/Users/lucas/AppData/Local/Android/Sdk}"
|
||||
EMULATOR="${_sdk_root}/emulator/emulator.exe"
|
||||
unset _sdk_root
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# android_emulator_start <avd_name> [timeout_s]
|
||||
# ---------------------------------------------------------------------------
|
||||
android_emulator_start() {
|
||||
local AVD="${1:?android_emulator_start requiere el nombre del AVD como primer argumento}"
|
||||
local timeout_s="${2:-180}"
|
||||
|
||||
# Validaciones de entorno
|
||||
if [[ ! -f "$EMULATOR" ]]; then
|
||||
echo "android_emulator_start: emulator.exe no encontrado en '$EMULATOR'. Fija EMULATOR= o ANDROID_SDK_WIN=." >&2
|
||||
return 1
|
||||
fi
|
||||
if [[ ! -f "$ADB" ]]; then
|
||||
echo "android_emulator_start: adb.exe no encontrado en '$ADB'. Fija ADB= o ANDROID_SDK_WIN=." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Idempotencia: si ya hay un emulador corriendo, salir sin lanzar otro
|
||||
if adb_run devices 2>/dev/null | grep -q "emulator-"; then
|
||||
echo "already running"
|
||||
# Imprimir el serial existente
|
||||
adb_run devices 2>/dev/null | grep "emulator-" | awk '{print $1}' | head -n1
|
||||
return 0
|
||||
fi
|
||||
|
||||
local log_file="/tmp/emulator_${AVD}.log"
|
||||
local pid_file="/tmp/emulator_${AVD}.pid"
|
||||
|
||||
# Lanzar emulador en background
|
||||
"$EMULATOR" -avd "$AVD" -no-boot-anim -no-snapshot-load >"$log_file" 2>&1 &
|
||||
local emu_pid=$!
|
||||
echo "$emu_pid" > "$pid_file"
|
||||
|
||||
# Esperar a que el dispositivo aparezca en adb
|
||||
local wait_timeout=$(( timeout_s / 2 ))
|
||||
if ! timeout "$wait_timeout" adb_run wait-for-device 2>/dev/null; then
|
||||
echo "android_emulator_start: timeout esperando que el dispositivo aparezca en adb (${wait_timeout}s)." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Verificar que el proceso del emulador sigue vivo
|
||||
if ! kill -0 "$emu_pid" 2>/dev/null; then
|
||||
echo "android_emulator_start: el proceso del emulador (PID $emu_pid) murió antes de completar el boot." >&2
|
||||
echo " Log: $log_file" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Esperar boot completo (sys.boot_completed=1)
|
||||
local boot_timeout=$(( timeout_s - wait_timeout ))
|
||||
if ! adb_wait_boot "$boot_timeout"; then
|
||||
echo "android_emulator_start: timeout ${timeout_s}s esperando boot completo del AVD '$AVD'." >&2
|
||||
echo " Log: $log_file" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Obtener serial del dispositivo emulado
|
||||
local serial
|
||||
serial=$(adb_run devices 2>/dev/null | grep "emulator-" | awk '{print $1}' | head -n1)
|
||||
|
||||
echo "$serial"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Ejecutar si se invoca directamente (no sourceado)
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_emulator_start "$@"
|
||||
fi
|
||||
@@ -0,0 +1,44 @@
|
||||
---
|
||||
name: android_emulator_stop
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_emulator_stop(serial?: string) -> void"
|
||||
description: "Para uno o todos los emuladores Android via adb emu kill. Si serial esta vacio, detecta todos los emulator-* activos y los para. Idempotente: exit 0 aunque no haya nada que matar."
|
||||
tags: ["android", "emulator", "wsl", "adb"]
|
||||
params:
|
||||
- name: "serial"
|
||||
desc: "Optional emulator serial (e.g. emulator-5554). Empty = kill all running emulators"
|
||||
output: "Imprime numero de emuladores parados. Exit 0 idempotente."
|
||||
uses_functions: ["adb_wsl_bash_infra"]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_emulator_stop.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Parar todos los emuladores en ejecucion
|
||||
android_emulator_stop
|
||||
|
||||
# Parar un emulador concreto
|
||||
android_emulator_stop emulator-5554
|
||||
|
||||
# Sobreescribir ruta de adb
|
||||
ADB=/usr/local/bin/adb android_emulator_stop
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Resuelve `ADB` desde variable de entorno (default: ruta de Android SDK en Windows bajo WSL2).
|
||||
Usa `adb emu kill` en vez de `adb kill-server` para parar solo el emulador sin afectar al daemon adb.
|
||||
`set -euo pipefail` activo, pero los fallos de `adb emu kill` se suprimen con `|| true` para mantener idempotencia.
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_emulator_stop — Para uno o todos los emuladores Android via adb emu kill.
|
||||
set -euo pipefail
|
||||
|
||||
android_emulator_stop() {
|
||||
local serial="${1:-}"
|
||||
local ADB="${ADB:-/mnt/c/Users/lucas/AppData/Local/Android/Sdk/platform-tools/adb.exe}"
|
||||
local killed=0
|
||||
|
||||
if [[ -z "$serial" ]]; then
|
||||
# Detectar todos los emuladores activos
|
||||
local serials
|
||||
serials=$("$ADB" devices 2>/dev/null | grep -E '^emulator-' | awk '{print $1}' || true)
|
||||
|
||||
if [[ -z "$serials" ]]; then
|
||||
echo "android_emulator_stop: no running emulators found"
|
||||
return 0
|
||||
fi
|
||||
|
||||
while IFS= read -r s; do
|
||||
[[ -z "$s" ]] && continue
|
||||
echo "android_emulator_stop: stopping $s"
|
||||
"$ADB" -s "$s" emu kill 2>/dev/null || true
|
||||
((killed++)) || true
|
||||
done <<< "$serials"
|
||||
else
|
||||
echo "android_emulator_stop: stopping $serial"
|
||||
"$ADB" -s "$serial" emu kill 2>/dev/null || true
|
||||
((killed++)) || true
|
||||
fi
|
||||
|
||||
echo "android_emulator_stop: stopped $killed emulator(s)"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Ejecutar si se llama directamente
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_emulator_stop "${1:-}"
|
||||
fi
|
||||
@@ -0,0 +1,63 @@
|
||||
---
|
||||
name: android_input_keyevent
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_input_keyevent([--serial <S>] key: string)"
|
||||
description: "Send key event via adb shell input keyevent. Accepts aliases (BACK, HOME, POWER, ENTER, MENU, RECENT_APPS, VOLUME_UP, VOLUME_DOWN), raw numeric codes, or explicit KEYCODE_* names."
|
||||
tags: [android, adb, input, keyevent, ui-test]
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target device/emulator serial. If omitted, adb_pick_serial resolves the single connected device."
|
||||
- name: "key"
|
||||
desc: "Keycode: short alias (BACK/HOME/POWER/ENTER/MENU/RECENT_APPS/VOLUME_UP/VOLUME_DOWN), raw number (e.g. 4, 26), or explicit KEYCODE_* name."
|
||||
output: "Stdout 'key: <code> on <serial>'."
|
||||
uses_functions: ["adb_wsl_bash_infra"]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_input_keyevent.sh"
|
||||
notes: "Lista completa de keycodes: https://developer.android.com/reference/android/view/KeyEvent. Exit 3 si adb_pick_serial falla (ningun device o ambiguo sin --serial)."
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Pulsar BACK en el unico device conectado
|
||||
android_input_keyevent BACK
|
||||
|
||||
# Pulsar HOME en un emulador especifico
|
||||
android_input_keyevent --serial emulator-5554 HOME
|
||||
|
||||
# Codigo numerico directo
|
||||
android_input_keyevent 26 # POWER
|
||||
|
||||
# KEYCODE_* explicito
|
||||
android_input_keyevent KEYCODE_DPAD_CENTER
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Aliases resueltos internamente:
|
||||
|
||||
| Alias | KEYCODE |
|
||||
|--------------|-----------------------|
|
||||
| BACK | KEYCODE_BACK |
|
||||
| HOME | KEYCODE_HOME |
|
||||
| POWER | KEYCODE_POWER |
|
||||
| ENTER | KEYCODE_ENTER |
|
||||
| MENU | KEYCODE_MENU |
|
||||
| RECENT_APPS | KEYCODE_APP_SWITCH |
|
||||
| VOLUME_UP | KEYCODE_VOLUME_UP |
|
||||
| VOLUME_DOWN | KEYCODE_VOLUME_DOWN |
|
||||
|
||||
Si el argumento no coincide con ningun alias y no es numerico, se construye `KEYCODE_<UPPER>` para pasarlo directo a `adb shell input keyevent`.
|
||||
|
||||
Exit codes: 1 = keycode vacio, 3 = fallo de `adb_pick_serial` (ningun device o ambiguo).
|
||||
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_input_keyevent — Send key event via adb shell input keyevent.
|
||||
# Accepts aliases (BACK, HOME, POWER, ENTER, MENU, RECENT_APPS),
|
||||
# raw numeric codes, or explicit KEYCODE_* names.
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=adb_wsl.sh
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
android_input_keyevent() {
|
||||
# Resolve serial (consumes --serial <S> from args, remainder in ADB_PICK_REST)
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
local raw="${1:-}"
|
||||
if [[ -z "$raw" ]]; then
|
||||
echo "android_input_keyevent: missing keycode argument" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Resolve alias → KEYCODE_*
|
||||
local keycode
|
||||
case "${raw^^}" in
|
||||
BACK) keycode="KEYCODE_BACK" ;;
|
||||
HOME) keycode="KEYCODE_HOME" ;;
|
||||
POWER) keycode="KEYCODE_POWER" ;;
|
||||
ENTER) keycode="KEYCODE_ENTER" ;;
|
||||
MENU) keycode="KEYCODE_MENU" ;;
|
||||
RECENT_APPS) keycode="KEYCODE_APP_SWITCH" ;;
|
||||
VOLUME_UP) keycode="KEYCODE_VOLUME_UP" ;;
|
||||
VOLUME_DOWN) keycode="KEYCODE_VOLUME_DOWN" ;;
|
||||
*)
|
||||
# Already has KEYCODE_ prefix or is a raw number → pass through
|
||||
if [[ "${raw^^}" == KEYCODE_* ]] || [[ "$raw" =~ ^[0-9]+$ ]]; then
|
||||
keycode="$raw"
|
||||
else
|
||||
# Unknown alias: uppercase and prepend KEYCODE_
|
||||
keycode="KEYCODE_${raw^^}"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
adb_s "$serial" shell input keyevent "$keycode"
|
||||
echo "key: $keycode on $serial"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_input_keyevent "$@"
|
||||
fi
|
||||
@@ -0,0 +1,59 @@
|
||||
---
|
||||
name: android_input_swipe
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_input_swipe([--serial <S>], x1: int, y1: int, x2: int, y2: int, [duration_ms: int])"
|
||||
description: "Send swipe gesture between two points with duration."
|
||||
tags: [android, adb, input, swipe, gesture, ui-test]
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target device serial. Overrides ADB_SERIAL envvar."
|
||||
- name: x1
|
||||
desc: "Start X coordinate in pixels."
|
||||
- name: y1
|
||||
desc: "Start Y coordinate in pixels."
|
||||
- name: x2
|
||||
desc: "End X coordinate in pixels."
|
||||
- name: y2
|
||||
desc: "End Y coordinate in pixels."
|
||||
- name: duration_ms
|
||||
desc: "Optional swipe duration in milliseconds. Default 300."
|
||||
output: "Stdout swipe summary line: 'swipe x1,y1 → x2,y2 (Nms) on <serial>'."
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_input_swipe.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
source bash/functions/infra/android_input_swipe.sh
|
||||
|
||||
# Scroll down (swipe up)
|
||||
android_input_swipe 540 1400 540 400
|
||||
|
||||
# Scroll up slowly on a specific device
|
||||
android_input_swipe --serial emulator-5554 540 400 540 1400 800
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Requiere `adb_wsl.sh` (sourceado automáticamente). Usa `adb_pick_serial` para
|
||||
resolver el dispositivo objetivo a partir de `--serial`, `ADB_SERIAL` o el
|
||||
único device disponible.
|
||||
|
||||
Los cuatro argumentos de coordenadas se validan como enteros antes de invocar
|
||||
adb — acepta coordenadas negativas (edge cases de hardware con ejes invertidos).
|
||||
|
||||
Exit 3 si `adb_pick_serial` no puede resolver el serial (sin devices o ambiguo).
|
||||
Exit 1 si faltan coordenadas o alguna no es numérica.
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_input_swipe — Send swipe gesture between two points via adb shell input swipe.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=adb_wsl.sh
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# android_input_swipe [--serial <S>] <x1> <y1> <x2> <y2> [duration_ms]
|
||||
#
|
||||
# $1 x1 Start X coordinate in pixels (obligatorio).
|
||||
# $2 y1 Start Y coordinate in pixels (obligatorio).
|
||||
# $3 x2 End X coordinate in pixels (obligatorio).
|
||||
# $4 y2 End Y coordinate in pixels (obligatorio).
|
||||
# $5 duration_ms Swipe duration in milliseconds (opcional, default 300).
|
||||
#
|
||||
# Envvar ADB_SERIAL overrides --serial.
|
||||
# ---------------------------------------------------------------------------
|
||||
android_input_swipe() {
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
local x1="${1:-}"
|
||||
local y1="${2:-}"
|
||||
local x2="${3:-}"
|
||||
local y2="${4:-}"
|
||||
local dur="${5:-300}"
|
||||
|
||||
if [[ -z "$x1" || -z "$y1" || -z "$x2" || -z "$y2" ]]; then
|
||||
echo "android_input_swipe: se requieren cuatro argumentos: x1 y1 x2 y2." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Validar que los cuatro coordenadas son numericas (enteros o negativos).
|
||||
local coord
|
||||
for coord in "$x1" "$y1" "$x2" "$y2"; do
|
||||
if ! [[ "$coord" =~ ^-?[0-9]+$ ]]; then
|
||||
echo "android_input_swipe: coordenada no numerica: '$coord'." >&2
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
adb_s "$serial" shell input swipe "$x1" "$y1" "$x2" "$y2" "$dur"
|
||||
echo "swipe $x1,$y1 → $x2,$y2 (${dur}ms) on $serial"
|
||||
}
|
||||
|
||||
# Ejecutar si se llama directamente (no sourceado)
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_input_swipe "$@"
|
||||
fi
|
||||
@@ -0,0 +1,46 @@
|
||||
---
|
||||
name: android_input_tap
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_input_tap([--serial <S>], x: int, y: int) -> void"
|
||||
description: "Send tap gesture at screen coordinates via adb shell input tap."
|
||||
tags: [android, adb, input, tap, ui-test, gesture]
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target device serial. Auto-detected if omitted."
|
||||
- name: "x"
|
||||
desc: "X coordinate in pixels (non-negative integer)."
|
||||
- name: "y"
|
||||
desc: "Y coordinate in pixels (non-negative integer)."
|
||||
output: "Stdout 'tap @ <x>,<y> on <serial>'."
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_input_tap.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Auto-detect device
|
||||
android_input_tap 540 960
|
||||
|
||||
# Target specific device
|
||||
android_input_tap --serial emulator-5554 540 960
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Sources `adb_wsl.sh` para resolver el binario ADB y exponer `adb_pick_serial` / `adb_s`.
|
||||
Usa `adb_pick_serial` para consumir `--serial` de los args y autodetectar el device si no se pasa.
|
||||
Valida X e Y con regex `^[0-9]+$` antes de invocar adb.
|
||||
Exit 3 si no hay device/emulador disponible (propagado desde `adb_pick_serial`).
|
||||
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_input_tap — Send tap gesture at screen coordinates via adb shell input tap.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=./adb_wsl.sh
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# android_input_tap [--serial <S>] <x> <y>
|
||||
#
|
||||
# --serial <S> Optional target device serial (also auto-detected).
|
||||
# x X coordinate in pixels (non-negative integer).
|
||||
# y Y coordinate in pixels (non-negative integer).
|
||||
#
|
||||
# Exits:
|
||||
# 0 tap sent successfully
|
||||
# 1 missing or invalid coordinates
|
||||
# 3 no device/emulator available
|
||||
# ---------------------------------------------------------------------------
|
||||
android_input_tap() {
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
local x="${1:-}"
|
||||
local y="${2:-}"
|
||||
|
||||
if [[ -z "$x" || -z "$y" ]]; then
|
||||
echo "android_input_tap: se requieren X e Y como argumentos posicionales." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ ! "$x" =~ ^[0-9]+$ ]]; then
|
||||
echo "android_input_tap: X debe ser un entero no negativo, recibido '$x'." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ ! "$y" =~ ^[0-9]+$ ]]; then
|
||||
echo "android_input_tap: Y debe ser un entero no negativo, recibido '$y'." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
adb_s "$serial" shell input tap "$x" "$y"
|
||||
echo "tap @ $x,$y on $serial"
|
||||
}
|
||||
|
||||
# Ejecutar si se llama directamente (no sourceado)
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_input_tap "$@"
|
||||
fi
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
name: android_input_text
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_input_text([--serial <S>], text: string) -> void"
|
||||
description: "Type text in focused field via adb shell input text. Spaces handled."
|
||||
tags: [android, adb, input, text, ui-test]
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_input_text.sh"
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target device serial. If omitted, autodetects first connected device/emulator."
|
||||
- name: "text"
|
||||
desc: "Text to type (spaces become %s as required by adb)."
|
||||
output: "Stdout 'typed: <text>'. Exit 0."
|
||||
notes: |
|
||||
adb input text replaces spaces with %s. Funcion lo hace automaticamente.
|
||||
Special chars " $ ` se escapan con backslash para evitar interpretacion por el shell.
|
||||
Exit 3 si no hay ningun device disponible (propagado desde adb_pick_serial).
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
source bash/functions/infra/android_input_text.sh
|
||||
|
||||
# Tipar en el device por defecto
|
||||
android_input_text "hello world"
|
||||
# → typed: hello world (envia "hello%sworld" a adb)
|
||||
|
||||
# Tipar en un device especifico
|
||||
android_input_text --serial emulator-5554 "user@example.com"
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
`adb shell input text` no acepta espacios directos — los convierte a `%s` internamente. Esta funcion hace la sustitucion antes de llamar a adb para que el comportamiento sea predecible.
|
||||
|
||||
Los caracteres `"`, `$` y `` ` `` se escapan con backslash para que el shell no los interprete al construir el comando.
|
||||
|
||||
Depende de `adb_wsl_bash_infra` para resolver el binario `adb.exe` en WSL2 y para `adb_pick_serial` / `adb_s`.
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_input_text — Type text in focused field via adb shell input text.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=adb_wsl.sh
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# android_input_text [--serial <S>] <text>
|
||||
#
|
||||
# $1 text Text to type in the currently focused field (obligatorio).
|
||||
# Spaces are replaced with %s as required by adb input text.
|
||||
# Special chars " $ ` are escaped with backslash.
|
||||
#
|
||||
# Envvar ADB_SERIAL overrides --serial.
|
||||
# ---------------------------------------------------------------------------
|
||||
android_input_text() {
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
local text="${1:-}"
|
||||
if [[ -z "$text" ]]; then
|
||||
echo "android_input_text: se requiere el texto como primer argumento." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# adb input text does not support raw spaces; replace with %s.
|
||||
# Also escape " $ ` which the shell would interpret inside the adb command.
|
||||
local escaped
|
||||
escaped="${text// /%s}"
|
||||
escaped="${escaped//\"/\\\"}"
|
||||
escaped="${escaped//\$/\\\$}"
|
||||
escaped="${escaped//\`/\\\`}"
|
||||
|
||||
adb_s "$serial" shell input text "$escaped"
|
||||
echo "typed: $text"
|
||||
}
|
||||
|
||||
# Ejecutar si se llama directamente (no sourceado)
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_input_text "$@"
|
||||
fi
|
||||
@@ -0,0 +1,59 @@
|
||||
---
|
||||
name: android_logcat
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_logcat([--serial <S>] [--package <name>] [--level <V|D|I|W|E|F>] [--lines <N>] [--clear])"
|
||||
description: "Lee logcat del device/emulador, opcionalmente filtrado por package y nivel. Multi-emulator via --serial."
|
||||
tags: [android, adb, logcat, wsl]
|
||||
uses_functions: ["adb_wsl_bash_infra"]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target device/emulator serial. Default: first device detected."
|
||||
- name: "--package <name>"
|
||||
desc: "Filter by app package (resolves PID via adb shell pidof)"
|
||||
- name: "--level <L>"
|
||||
desc: "Min log level V/D/I/W/E/F, default I"
|
||||
- name: "--lines <N>"
|
||||
desc: "Dump last N lines and exit. Default: follow indefinidamente"
|
||||
- name: "--clear"
|
||||
desc: "Clear log buffer before reading"
|
||||
output: "Logcat output a stdout. Follow indefinido sin --lines. Exit 130 si Ctrl-C. Exit 2 si --package y el proceso no corre."
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_logcat.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Follow completo sin filtros
|
||||
android_logcat
|
||||
|
||||
# Solo logs de una app, nivel Warning y superior
|
||||
android_logcat --package com.example.myapp --level W
|
||||
|
||||
# Dump de las últimas 200 líneas y salir
|
||||
android_logcat --lines 200
|
||||
|
||||
# Limpiar buffer y hacer follow solo de errores de la app
|
||||
android_logcat --clear --package com.example.myapp --level E
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
- Resuelve `adb` o `adb.exe` en PATH (compatible con WSL2 usando el binario Windows).
|
||||
- `--package` usa `adb shell pidof -s` para obtener el PID actual. Si la app no está corriendo, sale con exit 2.
|
||||
- `--lines N` activa modo dump (`-d -t N`); sin él, el follow es indefinido hasta Ctrl-C (exit 130).
|
||||
- `--clear` ejecuta `adb logcat -c` antes de leer, descartando el buffer acumulado.
|
||||
- El filtro de nivel se aplica como `*:<level>` al final del comando logcat.
|
||||
- En follow mode, `trap INT TERM` garantiza exit limpio (exit 130) al interrumpir.
|
||||
- CR (`\r`) del output de `adb.exe` en WSL se limpia al resolver el PID.
|
||||
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_logcat — Lee logcat del device/emulador, opcionalmente filtrado por package y nivel.
|
||||
# Multi-emulator via --serial <S>.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
android_logcat() {
|
||||
local serial
|
||||
adb_pick_serial "$@" || { echo "android_logcat: no device/emulator." >&2; return 3; }
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
local package=""
|
||||
local level="I"
|
||||
local lines=""
|
||||
local do_clear=0
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--package) package="$2"; shift 2 ;;
|
||||
--level) level="$2"; shift 2 ;;
|
||||
--lines) lines="$2"; shift 2 ;;
|
||||
--clear) do_clear=1; shift ;;
|
||||
*) echo "android_logcat: unknown argument: $1" >&2; return 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $do_clear -eq 1 ]]; then
|
||||
adb_s "$serial" logcat -c
|
||||
fi
|
||||
|
||||
local pid_filter=""
|
||||
if [[ -n "$package" ]]; then
|
||||
local pid
|
||||
pid=$(adb_s "$serial" shell pidof -s "$package" 2>/dev/null || true)
|
||||
pid="${pid//$'\r'/}"
|
||||
if [[ -z "$pid" ]]; then
|
||||
echo "android_logcat: package '$package' is not running on $serial" >&2
|
||||
return 2
|
||||
fi
|
||||
pid_filter="--pid=$pid"
|
||||
fi
|
||||
|
||||
local -a cmd=(logcat -v time)
|
||||
[[ -n "$lines" ]] && cmd+=(-d -t "$lines")
|
||||
[[ -n "$pid_filter" ]] && cmd+=("$pid_filter")
|
||||
cmd+=("*:${level}")
|
||||
|
||||
trap 'exit 130' INT TERM
|
||||
|
||||
adb_s "$serial" "${cmd[@]}"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
||||
android_logcat "$@"
|
||||
fi
|
||||
@@ -0,0 +1,46 @@
|
||||
---
|
||||
name: android_pull
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_pull [--serial <S>] remote_path local_path"
|
||||
description: "Pull file/dir from Android device to WSL via adb pull."
|
||||
tags: [android, adb, pull, file, transfer]
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target device serial. If omitted, adb_pick_serial auto-detects the connected device."
|
||||
- name: "remote_path"
|
||||
desc: "Source path on the Android device (e.g. /sdcard/Pictures/foo.png)."
|
||||
- name: "local_path"
|
||||
desc: "Destination path in the WSL filesystem. Parent directories are created automatically."
|
||||
output: "Stdout 'pulled: <remote> → <local> from <serial>'."
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_pull.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Pull a single file (auto-detect device)
|
||||
android_pull /sdcard/Pictures/foo.png ~/Downloads/foo.png
|
||||
|
||||
# Pull a directory to a specific local path with explicit serial
|
||||
android_pull --serial emulator-5554 /sdcard/DCIM ~/Downloads/DCIM
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Sources `adb_wsl.sh` for `adb_pick_serial`, `ADB_PICK_REST`, `adb_wsl_to_win`, and `adb_s`.
|
||||
The local path is converted to a Windows path via `adb_wsl_to_win` before passing to `adb pull`,
|
||||
which is required because `adb.exe` (Windows binary) does not understand WSL paths.
|
||||
Exit code 3 when no device serial can be resolved.
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_pull — Pull file/dir from Android device to WSL via adb pull.
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
android_pull() {
|
||||
local serial remote local_path win_local
|
||||
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
remote="${1:?remote_path required}"
|
||||
local_path="${2:?local_path required}"
|
||||
|
||||
mkdir -p "$(dirname "$local_path")"
|
||||
|
||||
win_local=$(adb_wsl_to_win "$local_path")
|
||||
|
||||
adb_s "$serial" pull "$remote" "$win_local"
|
||||
|
||||
echo "pulled: $remote → $local_path from $serial"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_pull "$@"
|
||||
fi
|
||||
@@ -0,0 +1,50 @@
|
||||
---
|
||||
name: android_push
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_push([--serial <S>], local_path: string, remote_path: string) -> void"
|
||||
description: "Push file/dir from WSL to Android device via adb push."
|
||||
tags: [android, adb, push, file, transfer]
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target device/emulator serial. Auto-detected if omitted."
|
||||
- name: "local_path"
|
||||
desc: "WSL source path to file or directory to push."
|
||||
- name: "remote_path"
|
||||
desc: "Device destination path, e.g. /sdcard/Download/foo.txt."
|
||||
output: "Stdout 'pushed: <local> → <remote> on <serial>'. Exit 0."
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_push.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Push a file to the active emulator
|
||||
android_push /tmp/data.json /sdcard/Download/data.json
|
||||
|
||||
# Push to a specific device
|
||||
android_push --serial emulator-5554 /tmp/data.json /sdcard/Download/data.json
|
||||
|
||||
# Push a directory
|
||||
android_push --serial R5CR1234567 ~/exports/bundle /sdcard/Download/bundle
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Usa `adb_pick_serial` de `adb_wsl.sh` para resolver el dispositivo objetivo.
|
||||
Si `--serial` no se pasa, autodetecta el primer device/emulador disponible.
|
||||
Sale con exit 3 si no hay ningun device conectado.
|
||||
Valida que `local_path` existe en WSL antes de convertir y enviar.
|
||||
Convierte el path WSL a Windows con `adb_wsl_to_win` (requiere `wslpath`; si no está disponible usa el path tal cual).
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_push — Push file/dir from WSL to Android device via adb push.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=adb_wsl.sh
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
android_push() {
|
||||
local serial local_path remote_path win_local
|
||||
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
local_path="${1:?android_push: local_path required}"
|
||||
remote_path="${2:?android_push: remote_path required}"
|
||||
|
||||
if [[ ! -e "$local_path" ]]; then
|
||||
echo "android_push: '$local_path' not found." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
win_local=$(adb_wsl_to_win "$local_path")
|
||||
|
||||
adb_s "$serial" push "$win_local" "$remote_path"
|
||||
echo "pushed: $local_path → $remote_path on $serial"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_push "$@"
|
||||
fi
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
name: android_screen_record
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_screen_record([--serial <S>] [--duration <s>] [--bit-rate <bps>] [--size <WxH>] output_path: string) -> void"
|
||||
description: "Record screen video via adb screenrecord, pulls to local path."
|
||||
tags: [android, adb, screen, record, video]
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target device serial. If omitted, autodetects first connected device/emulator."
|
||||
- name: "output_path"
|
||||
desc: "WSL destination path for the recorded .mp4 file."
|
||||
- name: "--duration <s>"
|
||||
desc: "Recording duration in seconds. Default 30, max 180 (adb screenrecord built-in limit)."
|
||||
- name: "--bit-rate <bps>"
|
||||
desc: "Video bit rate in bits per second. Default 4000000 (4 Mbps)."
|
||||
- name: "--size <WxH>"
|
||||
desc: "Video dimensions e.g. 720x1280. Default: device native resolution."
|
||||
output: "Stdout 'recorded: <path> (<s>s from <serial>)'. MP4 file written to output_path."
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_screen_record.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
source bash/functions/infra/android_screen_record.sh
|
||||
|
||||
# Record 15 seconds to a local file
|
||||
android_screen_record --duration 15 /tmp/demo.mp4
|
||||
|
||||
# Specific device, custom resolution, higher bitrate
|
||||
android_screen_record --serial emulator-5554 --duration 60 --bit-rate 8000000 --size 1080x2400 ~/videos/session.mp4
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
`adb screenrecord` tiene un limite maximo de 180 segundos por grabacion. Para capturas mas largas, encadenar multiples llamadas y concatenar los MP4 resultantes (ej. con `ffmpeg -f concat`).
|
||||
|
||||
El archivo temporal en el dispositivo es siempre `/sdcard/__rec.mp4` y se elimina tras el pull. Si la grabacion falla a mitad, el archivo puede quedar en el dispositivo; en ese caso ejecutar `adb shell rm /sdcard/__rec.mp4` manualmente.
|
||||
|
||||
Exit codes: 0 exito, 2 falta output_path, 3 ningun device encontrado.
|
||||
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_screen_record — Record screen video via adb screenrecord, pulls to local path.
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=adb_wsl.sh
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# android_screen_record [--serial <S>] [--duration <s>] [--bit-rate <bps>] [--size <WxH>] <output_path>
|
||||
#
|
||||
# Args:
|
||||
# --serial <S> Optional: target device serial (default: autodetect)
|
||||
# --duration <s> Recording duration in seconds (default: 30, max: 180)
|
||||
# --bit-rate <bps> Video bit rate (default: 4000000)
|
||||
# --size <WxH> Video dimensions e.g. 720x1280 (default: device native)
|
||||
# output_path WSL destination path for the .mp4 file
|
||||
#
|
||||
# Exit codes:
|
||||
# 0 success
|
||||
# 1 general error
|
||||
# 2 missing output_path argument
|
||||
# 3 no device/emulator found
|
||||
# ---------------------------------------------------------------------------
|
||||
android_screen_record() {
|
||||
local dur=30
|
||||
local bit_rate=4000000
|
||||
local size=""
|
||||
|
||||
# Parse flags first pass to extract serial; remaining args go to ADB_PICK_REST.
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
# Parse remaining flags
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--duration) dur="$2"; shift 2 ;;
|
||||
--duration=*) dur="${1#--duration=}"; shift ;;
|
||||
--bit-rate) bit_rate="$2"; shift 2 ;;
|
||||
--bit-rate=*) bit_rate="${1#--bit-rate=}"; shift ;;
|
||||
--size) size="$2"; shift 2 ;;
|
||||
--size=*) size="${1#--size=}"; shift ;;
|
||||
-*) echo "android_screen_record: unknown flag '$1'" >&2; return 1 ;;
|
||||
*) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
local output="${1:-}"
|
||||
if [[ -z "$output" ]]; then
|
||||
echo "android_screen_record: output_path is required." >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
# Build adb screenrecord args
|
||||
local rec_args=("shell" "screenrecord" "--time-limit" "$dur")
|
||||
rec_args+=("--bit-rate" "$bit_rate")
|
||||
[[ -n "$size" ]] && rec_args+=("--size" "$size")
|
||||
rec_args+=("/sdcard/__rec.mp4")
|
||||
|
||||
echo "android_screen_record: recording ${dur}s from $serial..." >&2
|
||||
adb_s "$serial" "${rec_args[@]}" || {
|
||||
echo "android_screen_record: screenrecord failed." >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
adb_s "$serial" pull /sdcard/__rec.mp4 "$output" || {
|
||||
echo "android_screen_record: pull failed." >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
adb_s "$serial" shell rm /sdcard/__rec.mp4
|
||||
|
||||
echo "recorded: $output (${dur}s from $serial)"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_screen_record "$@"
|
||||
fi
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
name: android_screenshot
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_screenshot([--serial <S>], output_path: string) -> void"
|
||||
description: "Capture screen as PNG via adb exec-out screencap -p."
|
||||
tags: [android, adb, screenshot, screen, capture]
|
||||
uses_functions: [adb_wsl_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional ADB serial to target a specific device/emulator. If omitted, autodetects the first connected device."
|
||||
- name: "output_path"
|
||||
desc: "WSL path where the PNG screenshot will be written (e.g. /tmp/screen.png). Parent directory is created if absent."
|
||||
output: "Stdout 'screenshot: <path> (<bytes> bytes) from <serial>'. PNG file written to disk."
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_screenshot.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
source bash/functions/infra/android_screenshot.sh
|
||||
android_screenshot /tmp/screen.png
|
||||
# screenshot: /tmp/screen.png (123456 bytes) from emulator-5554
|
||||
|
||||
# Targeting a specific device:
|
||||
android_screenshot --serial emulator-5554 /tmp/screen.png
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Sources `adb_wsl.sh` from its own directory, so `ADB` and `ANDROID_SDK_WIN` env vars
|
||||
are respected as with all other android_* functions.
|
||||
|
||||
Exit codes:
|
||||
- `0` — screenshot captured successfully.
|
||||
- `1` — missing output path, screencap produced empty file, or adb error.
|
||||
- `3` — no device/emulator connected (propagated from `adb_pick_serial`).
|
||||
|
||||
The emptiness check (`! -s`) handles the case where `adb exec-out` exits 0 but writes
|
||||
zero bytes (e.g. device locked, screencap permission denied). In that case the file is
|
||||
removed and exit 1 is returned.
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_screenshot — Capture screen as PNG via adb exec-out screencap -p.
|
||||
|
||||
android_screenshot() {
|
||||
local SCRIPT_DIR
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=bash/functions/infra/adb_wsl.sh
|
||||
source "$SCRIPT_DIR/adb_wsl.sh" || return 1
|
||||
|
||||
# Resolve serial, consume --serial from args
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
local output="${1:-}"
|
||||
if [[ -z "$output" ]]; then
|
||||
echo "android_screenshot: output_path is required." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Ensure parent directory exists
|
||||
mkdir -p "$(dirname "$output")"
|
||||
|
||||
# Capture screen
|
||||
adb_s "$serial" exec-out screencap -p > "$output"
|
||||
|
||||
# Verify file created and non-empty
|
||||
if [[ ! -f "$output" ]] || [[ ! -s "$output" ]]; then
|
||||
rm -f "$output"
|
||||
echo "android_screenshot: screencap produced empty or missing file." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local size
|
||||
size=$(stat -c%s "$output" 2>/dev/null || stat -f%z "$output" 2>/dev/null)
|
||||
echo "screenshot: $output ($size bytes) from $serial"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_screenshot "$@"
|
||||
fi
|
||||
@@ -0,0 +1,43 @@
|
||||
---
|
||||
name: android_shell
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "android_shell([--serial <S>], cmd ...args)"
|
||||
description: "Execute arbitrary shell command on Android device. Multi-emulator via --serial."
|
||||
tags: [android, adb, shell, exec]
|
||||
params:
|
||||
- name: "--serial <S>"
|
||||
desc: "Optional target device serial. Omit to auto-pick (single device) or use ADB_SERIAL env."
|
||||
- name: "cmd ...args"
|
||||
desc: "Shell command + args to run on device. Variadic."
|
||||
output: "Passthrough stdout/stderr de adb shell. Exit code = shell command exit."
|
||||
uses_functions: ["adb_wsl_bash_infra"]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/android_shell.sh"
|
||||
notes: "Para comandos complejos con pipes/redirects mejor `adb_s $serial shell 'cmd | other'` directo via adb_run."
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
android_shell pm list packages
|
||||
android_shell --serial emulator-5554 getprop ro.product.model
|
||||
android_shell df -h /sdcard
|
||||
android_shell ls -la /data/local/tmp
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Sourcea `adb_wsl.sh` para resolver `adb_pick_serial` (maneja `--serial`, `ADB_SERIAL`, y auto-detect de dispositivo unico) y `adb_s` (wrapper de `adb -s`). El array `ADB_PICK_REST` contiene los args restantes tras consumir `--serial`.
|
||||
|
||||
Para comandos con pipes o redirects que bash interpretaria localmente, mejor pasar como string unico: `adb_s "$serial" shell 'cmd | grep foo'`.
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
# android_shell — Execute arbitrary shell command on Android device via adb shell
|
||||
|
||||
# shellcheck source=./adb_wsl.sh
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
android_shell() {
|
||||
adb_pick_serial "$@" || exit 3
|
||||
local serial="$ADB_PICK_SERIAL"
|
||||
set -- "${ADB_PICK_REST[@]}"
|
||||
|
||||
adb_s "$serial" shell "$@"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
android_shell "$@"
|
||||
fi
|
||||
@@ -0,0 +1,65 @@
|
||||
---
|
||||
name: build_wasm_cpp_app
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "0.1.0"
|
||||
purity: impure
|
||||
signature: "build_wasm_cpp_app(app_name: string, [--no-budget-check]) -> void"
|
||||
description: "Compila una app C++ del registry (cpp/apps/<name>) a WASM via emscripten. Sale build/wasm/<name>/<name>.{html,js,wasm,wasm.gz}. Falla si gzip > 2 MB."
|
||||
tags: [wasm, emscripten, cpp, build, gamedev]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
example: "bash bash/functions/infra/build_wasm_cpp_app.sh engine_smoke"
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/build_wasm_cpp_app.sh"
|
||||
params:
|
||||
- name: app_name
|
||||
desc: "Nombre del directorio bajo cpp/apps/. Debe contener CMakeLists.txt self-sufficient (top-level project) con guard `if(EMSCRIPTEN)` para flags wasm."
|
||||
- name: "--no-budget-check"
|
||||
desc: "Opcional. Salta verificacion de tamaño (gzip < 2 MB hard, < 1.5 MB soft)."
|
||||
output: "Reporte de tamaños en stdout. Crea build/wasm/<app>/<app>.html/.js/.wasm/.wasm.gz. Exit 3 si excede budget hard."
|
||||
---
|
||||
|
||||
# build_wasm_cpp_app
|
||||
|
||||
Compila apps C++ del registry a WebAssembly. Issue 0072d (parte del stack gamedev).
|
||||
|
||||
## Requisitos
|
||||
|
||||
- `emsdk` instalado y activo en el shell, o presente en `<repo>/emsdk/` (autoactiva).
|
||||
- `cpp/apps/<app>/CMakeLists.txt` con bloque `if(EMSCRIPTEN) ... endif()` que define los flags wasm (USE_WEBGL2, FULL_ES3, ALLOW_MEMORY_GROWTH, etc.).
|
||||
- `cpp/CMakeLists.txt` debe seguir tolerando configuracion via `emcmake`. La app target se elige con `cmake --build $BUILD_DIR --target <app>`.
|
||||
|
||||
## Flujo
|
||||
|
||||
1. Localiza `emcc` en PATH o autoactiva `<repo>/emsdk/emsdk_env.sh`.
|
||||
2. `emcmake cmake -S cpp -B build/wasm/<app> -DCMAKE_BUILD_TYPE=MinSizeRel`
|
||||
3. `cmake --build build/wasm/<app> --target <app> -j`
|
||||
4. `gzip -9 -k <app>.wasm` y `brotli -q 11 -k <app>.wasm` (si brotli disponible).
|
||||
5. Reporta tamaños y compara contra budget (1.5 MB gzip soft, 2 MB hard).
|
||||
|
||||
## Budgets
|
||||
|
||||
| Limite | Valor | Comportamiento |
|
||||
|---|---|---|
|
||||
| Soft | 1.5 MB gzip | Warning, sigue |
|
||||
| Hard | 2 MB gzip | Exit 3, falla |
|
||||
|
||||
Skip con `--no-budget-check`.
|
||||
|
||||
## Apps soportadas
|
||||
|
||||
Cualquier app bajo `cpp/apps/<name>/` cuyo `CMakeLists.txt` defina target con flags emscripten. Probada con: `engine_smoke` (issue 0072a).
|
||||
|
||||
## Errores comunes
|
||||
|
||||
- `emcc no encontrado` → instalar emsdk segun instrucciones del propio script.
|
||||
- `<app>.wasm no encontrado` → fallo de build. Re-ejecutar con `2>&1 | tee` para ver compiler errors.
|
||||
- `wasm.gz excede budget` → revisar bloat, usar `twiggy top` o `wasm-objdump -h`. Ver issue 0072d.
|
||||
Executable
+83
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env bash
|
||||
# build_wasm_cpp_app — compila app cpp/apps/<name> a WASM via emscripten.
|
||||
#
|
||||
# Uso:
|
||||
# build_wasm_cpp_app.sh <app_name> [--no-budget-check]
|
||||
#
|
||||
# Salida: build/wasm/<name>/<name>.{html,js,wasm}
|
||||
# + <name>.wasm.gz (gzip -9) y <name>.wasm.br (brotli -11 si esta).
|
||||
#
|
||||
# Requiere: emsdk activo en el shell (source emsdk/emsdk_env.sh) o que
|
||||
# exista emsdk/ en la raiz del repo y se autoactive.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
APP="${1:?Uso: $0 <app_name> [--no-budget-check]}"
|
||||
SHIFT_FLAG="${2:-}"
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/../../.. && pwd)"
|
||||
SRC_DIR="$REPO_ROOT/cpp/apps/$APP"
|
||||
BUILD_DIR="$REPO_ROOT/build/wasm/$APP"
|
||||
|
||||
if [ ! -d "$SRC_DIR" ]; then
|
||||
echo "ERROR: $SRC_DIR no existe" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Activate emsdk if not already in PATH.
|
||||
if ! command -v emcc >/dev/null 2>&1; then
|
||||
if [ -f "$REPO_ROOT/emsdk/emsdk_env.sh" ]; then
|
||||
# shellcheck disable=SC1091
|
||||
source "$REPO_ROOT/emsdk/emsdk_env.sh" >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
if ! command -v emcc >/dev/null 2>&1; then
|
||||
echo "ERROR: emcc no encontrado. Instala emsdk:" >&2
|
||||
echo " git clone https://github.com/emscripten-core/emsdk.git" >&2
|
||||
echo " cd emsdk && ./emsdk install latest && ./emsdk activate latest" >&2
|
||||
echo " source ./emsdk_env.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "── emcc: $(emcc --version | head -n1)"
|
||||
echo "── source: $SRC_DIR"
|
||||
echo "── build: $BUILD_DIR"
|
||||
|
||||
mkdir -p "$BUILD_DIR"
|
||||
# Build the app directly (NOT the full cpp/ tree). Each app's CMakeLists.txt
|
||||
# is expected to be self-sufficient as top-level (issue 0072a pattern).
|
||||
emcmake cmake -S "$SRC_DIR" -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=MinSizeRel
|
||||
cmake --build "$BUILD_DIR" --target "$APP" -j
|
||||
|
||||
WASM_DIR=$(find "$BUILD_DIR" -name "$APP.wasm" -printf '%h\n' -quit 2>/dev/null || true)
|
||||
if [ -z "$WASM_DIR" ]; then
|
||||
echo "ERROR: no se encontro $APP.wasm en $BUILD_DIR" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
cd "$WASM_DIR"
|
||||
gzip -9 -k -f "$APP.wasm"
|
||||
if command -v brotli >/dev/null 2>&1; then
|
||||
brotli -q 11 -k -f "$APP.wasm"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "── Sizes (in $WASM_DIR) ──"
|
||||
for f in "$APP".html "$APP".js "$APP".wasm "$APP".wasm.gz "$APP".wasm.br; do
|
||||
[ -f "$f" ] && printf "%-32s %10d bytes\n" "$f" "$(stat -c%s "$f")"
|
||||
done
|
||||
|
||||
# Budget check (1.5 MB gzip soft, 2 MB hard)
|
||||
if [ "$SHIFT_FLAG" != "--no-budget-check" ]; then
|
||||
SIZE_GZ=$(stat -c%s "$APP.wasm.gz")
|
||||
HARD=$((2 * 1024 * 1024))
|
||||
SOFT=$((1572864)) # 1.5 MB
|
||||
if [ "$SIZE_GZ" -gt "$HARD" ]; then
|
||||
echo "❌ $APP.wasm.gz = $SIZE_GZ bytes > $HARD (2 MB hard limit)" >&2
|
||||
exit 3
|
||||
elif [ "$SIZE_GZ" -gt "$SOFT" ]; then
|
||||
echo "⚠ $APP.wasm.gz = $SIZE_GZ bytes > $SOFT (1.5 MB soft limit)"
|
||||
else
|
||||
echo "✓ $APP.wasm.gz = $SIZE_GZ bytes within soft limit (1.5 MB)"
|
||||
fi
|
||||
fi
|
||||
@@ -0,0 +1,44 @@
|
||||
---
|
||||
name: gradle_assemble_debug
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "gradle_assemble_debug(project_dir: string, module: string) -> string"
|
||||
description: "Build APK debug de un modulo Android via gradlew assembleDebug."
|
||||
tags: ["android", "gradle", "build", "apk"]
|
||||
params:
|
||||
- name: project_dir
|
||||
desc: "Raiz del proyecto Gradle Android"
|
||||
- name: module
|
||||
desc: "Nombre del modulo Gradle. Default: app"
|
||||
output: "Stdout con build log + ultima linea 'APK: <path>'. Exit 0 = build OK. Exit !=0 si fallo."
|
||||
uses_functions: ["gradle_run_bash_infra"]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/gradle_assemble_debug.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
gradle_assemble_debug /path/to/MyApp
|
||||
# APK: /path/to/MyApp/app/build/outputs/apk/debug/app-debug.apk
|
||||
|
||||
gradle_assemble_debug /path/to/MyApp mylibrary
|
||||
# APK: /path/to/MyApp/mylibrary/build/outputs/apk/debug/mylibrary-debug.apk
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
APK queda en <project>/<module>/build/outputs/apk/debug/. Variants flavor no soportados aun (anadir arg si surge).
|
||||
|
||||
Depende de `gradle_run_bash_infra` (`gradle_run.sh` en el mismo directorio), que debe existir y estar indexado antes de hacer `fn index` de esta funcion.
|
||||
---
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
# gradle_assemble_debug — Build APK debug de un modulo Android via gradlew assembleDebug.
|
||||
set -euo pipefail
|
||||
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/gradle_run.sh"
|
||||
|
||||
gradle_assemble_debug() {
|
||||
local project_dir="$1"
|
||||
local module="${2:-app}"
|
||||
|
||||
gradle_run "$project_dir" ":$module:assembleDebug"
|
||||
|
||||
local apk
|
||||
apk=$(find "$project_dir/$module/build/outputs/apk/debug" -name "*.apk" | head -1)
|
||||
|
||||
echo "APK: $apk"
|
||||
}
|
||||
|
||||
gradle_assemble_debug "$@"
|
||||
@@ -0,0 +1,56 @@
|
||||
---
|
||||
name: gradle_clean
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "gradle_clean(project_dir: string) -> int"
|
||||
description: "Limpia build artifacts de un proyecto Android (gradle clean + rm .gradle + rm build)."
|
||||
tags: [android, gradle, clean, build]
|
||||
params:
|
||||
- name: project_dir
|
||||
desc: "Raiz del proyecto Gradle"
|
||||
output: "Stdout build log de gradle clean. Exit code = exit gradlew."
|
||||
uses_functions: [gradle_run_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/gradle_clean.sh"
|
||||
notes: "Util cuando builds incrementales se corrompen. NO borra .idea ni gradle.properties. Para reset total usar `rm -rf $project_dir/{.gradle,build,app/build}`."
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Como libreria
|
||||
source bash/functions/infra/gradle_clean.sh
|
||||
gradle_clean /path/to/MyApp
|
||||
|
||||
# Directo
|
||||
bash bash/functions/infra/gradle_clean.sh /path/to/MyApp
|
||||
```
|
||||
|
||||
## Comportamiento
|
||||
|
||||
1. Invoca `gradle_run "$project_dir" "clean"` — si falla, propaga su exit code y para.
|
||||
2. `rm -rf "$project_dir/.gradle"` — best-effort (ignora si no existe).
|
||||
3. `rm -rf "$project_dir/build"` — best-effort (ignora si no existe).
|
||||
4. Retorna 0 siempre que gradle clean haya terminado OK.
|
||||
|
||||
## Notas
|
||||
|
||||
Source-able y ejecutable directo. Sourcear `gradle_run.sh` al inicio garantiza
|
||||
que `JAVA_HOME` y `ANDROID_HOME` se resuelven con la misma logica que el resto
|
||||
de las funciones gradle_*.
|
||||
|
||||
Los directorios `.gradle` (cache de dependencias y metadata del daemon) y
|
||||
`build` (outputs compilados) son los principales responsables de builds
|
||||
corrompidos. Su eliminacion fuerza una descarga/recompilacion completa en el
|
||||
siguiente build.
|
||||
---
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
# gradle_clean — Limpia build artifacts de un proyecto Android.
|
||||
#
|
||||
# Uso como libreria: source bash/functions/infra/gradle_clean.sh
|
||||
# Uso directo: bash bash/functions/infra/gradle_clean.sh <project_dir>
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=./gradle_run.sh
|
||||
source "$SCRIPT_DIR/gradle_run.sh"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# gradle_clean <project_dir>
|
||||
#
|
||||
# Ejecuta `gradlew clean` en el proyecto y luego elimina los directorios
|
||||
# de cache .gradle y build (best-effort).
|
||||
#
|
||||
# Exits:
|
||||
# 0 — gradle clean exitoso (los rm son best-effort, no afectan exit code)
|
||||
# * — exit code propagado de gradle_run / gradlew
|
||||
# ---------------------------------------------------------------------------
|
||||
gradle_clean() {
|
||||
local project_dir="$1"
|
||||
|
||||
gradle_run "$project_dir" "clean" || return $?
|
||||
|
||||
# Best-effort: eliminar caches locales; ignorar errores si no existen
|
||||
rm -rf "${project_dir}/.gradle" 2>/dev/null || true
|
||||
rm -rf "${project_dir}/build" 2>/dev/null || true
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Ejecucion directa
|
||||
# ---------------------------------------------------------------------------
|
||||
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
||||
gradle_clean "$@"
|
||||
fi
|
||||
@@ -0,0 +1,46 @@
|
||||
---
|
||||
name: gradle_instrumented_test
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "gradle_instrumented_test(project_dir: string, module: string) -> int"
|
||||
description: "Corre instrumented tests Compose en emulador/device Android conectado."
|
||||
tags: ["android", "gradle", "test", "compose", "emulator"]
|
||||
uses_functions: ["gradle_run_bash_infra", "adb_wsl_bash_infra"]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/gradle_instrumented_test.sh"
|
||||
params:
|
||||
- name: project_dir
|
||||
desc: "Raiz del proyecto Gradle"
|
||||
- name: module
|
||||
desc: "Modulo. Default app"
|
||||
output: "Stdout con resultados. Linea final 'REPORT: <path>'. Exit: 0=OK, 3=no device, otro=fallos tests."
|
||||
notes: "Requiere emulador corriendo. Lanzar antes con android_emulator_start. connectedAndroidTest corre en TODOS los devices conectados."
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Correr instrumented tests del modulo app
|
||||
gradle_instrumented_test /home/user/MyAndroidProject
|
||||
|
||||
# Correr instrumented tests de un modulo especifico
|
||||
gradle_instrumented_test /home/user/MyAndroidProject feature_login
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Requiere emulador corriendo. Lanzar antes con android_emulator_start. connectedAndroidTest corre en TODOS los devices conectados.
|
||||
|
||||
El script verifica que haya al menos un emulador o device conectado antes de lanzar Gradle. Si no hay ninguno, imprime un mensaje descriptivo a stderr y sale con exit code 3, permitiendo al llamador distinguir "no device" de "tests fallaron".
|
||||
|
||||
La linea `REPORT: <path>` se imprime siempre al final (incluso si los tests fallan), para que el llamador pueda abrir el reporte HTML independientemente del resultado.
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
# gradle_instrumented_test — corre instrumented tests Compose en emulador/device Android conectado
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/gradle_run.sh"
|
||||
source "$SCRIPT_DIR/adb_wsl.sh"
|
||||
|
||||
gradle_instrumented_test() {
|
||||
local project_dir="${1:?project_dir required}"
|
||||
local module="${2:-app}"
|
||||
|
||||
# Verificar device o emulador conectado
|
||||
local devices
|
||||
devices=$(adb_run devices | tail -n +2 | grep -E "(emulator|device)$" || true)
|
||||
if [[ -z "$devices" ]]; then
|
||||
echo "no Android device/emulator connected. Run android_emulator_start first." >&2
|
||||
return 3
|
||||
fi
|
||||
|
||||
local exit_code=0
|
||||
gradle_run "$project_dir" ":${module}:connectedDebugAndroidTest" || exit_code=$?
|
||||
|
||||
echo "REPORT: ${project_dir}/${module}/build/reports/androidTests/connected/index.html"
|
||||
|
||||
return "$exit_code"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
||||
gradle_instrumented_test "$@"
|
||||
fi
|
||||
@@ -0,0 +1,72 @@
|
||||
---
|
||||
name: gradle_run
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "gradle_run(project_dir: string, task...: string) -> int"
|
||||
description: "Wrapper canonico para invocar gradlew Android en WSL2 con JDK 17 + ANDROID_HOME validados."
|
||||
tags: [android, gradle, kotlin, build]
|
||||
params:
|
||||
- name: project_dir
|
||||
desc: "Path absoluto al proyecto Gradle (debe contener gradlew)"
|
||||
- name: task
|
||||
desc: "Tarea(s) Gradle a ejecutar (ej. assembleDebug, :app:test). Variadic"
|
||||
output: "Stdout/stderr del build Gradle. Exit code = exit code de gradlew. Exit 1 si JDK17 missing, exit 2 si no hay gradlew."
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/gradle_run.sh"
|
||||
notes: "Las demas funciones gradle_* lo sourcean. Reutiliza patron de adb_wsl_bash_infra para ser source-able+ejecutable. Cubre tanto SDK Linux (~/Android/Sdk via install_android_sdk) como SDK Windows (/mnt/c/...) montado en WSL."
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Como libreria (en otro script gradle_*)
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/gradle_run.sh"
|
||||
gradle_run "$project_dir" assembleDebug
|
||||
|
||||
# Directo
|
||||
bash bash/functions/infra/gradle_run.sh /path/to/MyApp assembleDebug
|
||||
bash bash/functions/infra/gradle_run.sh /path/to/MyApp :app:test :app:lint
|
||||
```
|
||||
|
||||
## Comportamiento de resolucion
|
||||
|
||||
### JAVA_HOME
|
||||
Si no esta fijado en el entorno, busca en orden:
|
||||
1. `/usr/lib/jvm/java-17-openjdk-amd64`
|
||||
2. `/usr/lib/jvm/temurin-17-jdk-amd64`
|
||||
3. `/opt/android-studio-jbr/jbr`
|
||||
|
||||
Si ninguno existe → error en stderr y `return 1`.
|
||||
|
||||
### ANDROID_HOME
|
||||
Si no esta fijado:
|
||||
1. Intenta `$HOME/Android/Sdk` (SDK Linux via `install_android_sdk_bash_infra`)
|
||||
2. Si no existe, intenta `$ANDROID_SDK_WIN` (SDK Windows montado en `/mnt/c/...`)
|
||||
3. Si ninguno, lo deja vacio — gradle mostrara el error adecuado para builds JVM puros
|
||||
|
||||
## Exit codes
|
||||
|
||||
| Codigo | Significado |
|
||||
|--------|-------------|
|
||||
| 0 | Build exitoso |
|
||||
| 1 | JDK 17 no encontrado |
|
||||
| 2 | `./gradlew` no existe en `project_dir` |
|
||||
| * | Exit code propagado de gradlew |
|
||||
|
||||
## Notas
|
||||
|
||||
Source-able y ejecutable directo. Al sourcear, el caller importa la funcion `gradle_run` sin ejecutarla. Al ejecutar directamente, delega `"$@"` a `gradle_run`.
|
||||
|
||||
No exporta `JAVA_HOME`/`ANDROID_HOME` al entorno del shell padre — los variables se pasan solo al subshell de gradlew para evitar contaminar el entorno.
|
||||
---
|
||||
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env bash
|
||||
# gradle_run — Wrapper canonico para invocar gradlew Android en WSL2.
|
||||
# Valida JDK 17 + ANDROID_HOME antes de delegar al wrapper del proyecto.
|
||||
#
|
||||
# Uso como libreria: source bash/functions/infra/gradle_run.sh
|
||||
# Uso directo: bash bash/functions/infra/gradle_run.sh <project_dir> <task...>
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# gradle_run <project_dir> <task...>
|
||||
#
|
||||
# Resuelve JAVA_HOME y ANDROID_HOME si no estan fijados, luego invoca
|
||||
# ./gradlew con las tareas indicadas en el directorio del proyecto.
|
||||
#
|
||||
# Exits:
|
||||
# 0 — gradlew completado con exito
|
||||
# 1 — JDK 17 no encontrado
|
||||
# 2 — ./gradlew no existe en project_dir
|
||||
# * — exit code propagado de gradlew
|
||||
# ---------------------------------------------------------------------------
|
||||
gradle_run() {
|
||||
local project_dir="$1"
|
||||
shift || true
|
||||
|
||||
# ---- Resolver JAVA_HOME ------------------------------------------------
|
||||
local java_home="${JAVA_HOME:-}"
|
||||
if [[ -z "$java_home" ]]; then
|
||||
local _jdk_candidates=(
|
||||
"/usr/lib/jvm/java-17-openjdk-amd64"
|
||||
"/usr/lib/jvm/temurin-17-jdk-amd64"
|
||||
"/opt/android-studio-jbr/jbr"
|
||||
)
|
||||
for _candidate in "${_jdk_candidates[@]}"; do
|
||||
if [[ -d "$_candidate" ]]; then
|
||||
java_home="$_candidate"
|
||||
break
|
||||
fi
|
||||
done
|
||||
unset _jdk_candidates _candidate
|
||||
fi
|
||||
|
||||
if [[ -z "$java_home" ]]; then
|
||||
echo "gradle_run: JDK 17 not found, install via install_android_sdk" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# ---- Resolver ANDROID_HOME ---------------------------------------------
|
||||
local android_home="${ANDROID_HOME:-}"
|
||||
if [[ -z "$android_home" ]]; then
|
||||
local _default_linux="$HOME/Android/Sdk"
|
||||
if [[ -d "$_default_linux" ]]; then
|
||||
android_home="$_default_linux"
|
||||
elif [[ -n "${ANDROID_SDK_WIN:-}" && -d "${ANDROID_SDK_WIN}" ]]; then
|
||||
# SDK Windows montado en WSL via /mnt/c/...
|
||||
android_home="${ANDROID_SDK_WIN}"
|
||||
fi
|
||||
unset _default_linux
|
||||
fi
|
||||
|
||||
# ANDROID_HOME puede quedar vacio si no hay SDK instalado; gradle mostrara
|
||||
# el error adecuado. No bloqueamos aqui para permitir builds puros JVM.
|
||||
|
||||
# ---- Verificar gradlew -------------------------------------------------
|
||||
if [[ ! -f "${project_dir}/gradlew" ]]; then
|
||||
echo "gradle_run: no gradlew in ${project_dir}" >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
# ---- Invocar gradlew ----------------------------------------------------
|
||||
(
|
||||
cd "$project_dir" || return 1
|
||||
JAVA_HOME="$java_home" ANDROID_HOME="${android_home:-}" ./gradlew "$@"
|
||||
)
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Ejecucion directa
|
||||
# ---------------------------------------------------------------------------
|
||||
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
||||
gradle_run "$@"
|
||||
fi
|
||||
@@ -0,0 +1,58 @@
|
||||
---
|
||||
name: gradle_screenshot_test
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "gradle_screenshot_test(project_dir: string, module: string, flag: string) -> int"
|
||||
description: "Corre screenshot tests Roborazzi de Composables (JVM, no necesita emulador)."
|
||||
tags: [android, gradle, test, compose, roborazzi, screenshot]
|
||||
params:
|
||||
- name: project_dir
|
||||
desc: "Raiz del proyecto Android (debe contener gradlew)"
|
||||
- name: module
|
||||
desc: "Modulo Gradle a testear. Default: app"
|
||||
- name: --record
|
||||
desc: "Re-grabar goldens en lugar de verificar"
|
||||
output: "Stdout build log. Si verify y diff: linea 'DIFF: <path>'. Si record: linea 'RECORDED: <path>'. Exit 0 OK, 1 mismatch."
|
||||
uses_functions: [gradle_run_bash_infra]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/gradle_screenshot_test.sh"
|
||||
notes: "Roborazzi corre en JVM (Robolectric) — rapido, no necesita emulador. Goldens viven en src/test/snapshots/ y se commitean al repo. App debe declarar plugin io.github.takahirom.roborazzi en build.gradle.kts."
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Verificar screenshots (modo CI)
|
||||
bash bash/functions/infra/gradle_screenshot_test.sh /path/to/MyApp
|
||||
|
||||
# Modulo no-default
|
||||
bash bash/functions/infra/gradle_screenshot_test.sh /path/to/MyApp feature_login
|
||||
|
||||
# Re-grabar goldens tras cambio de UI intencional
|
||||
bash bash/functions/infra/gradle_screenshot_test.sh /path/to/MyApp app --record
|
||||
```
|
||||
|
||||
## Salida
|
||||
|
||||
| Situacion | Salida |
|
||||
|-----------|--------|
|
||||
| Verify OK | log de Gradle, exit 0 |
|
||||
| Verify FAIL | log + `DIFF: <project>/<module>/build/outputs/roborazzi/`, exit 1 |
|
||||
| Record OK | log + `RECORDED: <project>/<module>/src/test/snapshots/`, exit 0 |
|
||||
|
||||
## Notas
|
||||
|
||||
Source-able y ejecutable directo. Sourcear `gradle_run.sh` resuelve JAVA_HOME y ANDROID_HOME de forma identica al resto de funciones `gradle_*`.
|
||||
|
||||
Los diffs en `build/outputs/roborazzi/` muestran imagen original, imagen actual e imagen de diferencia. Util para revisar regresiones visuales antes de hacer `--record`.
|
||||
---
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
# gradle_screenshot_test — Corre screenshot tests Roborazzi (JVM, no necesita emulador)
|
||||
|
||||
gradle_screenshot_test() {
|
||||
local project_dir="${1:?project_dir requerido}"
|
||||
local module="${2:-app}"
|
||||
local record_flag="${3:-}"
|
||||
|
||||
local SCRIPT_DIR
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/gradle_run.sh"
|
||||
|
||||
local task
|
||||
if [[ "$record_flag" == "--record" ]]; then
|
||||
task=":${module}:recordRoborazziDebug"
|
||||
else
|
||||
task=":${module}:verifyRoborazziDebug"
|
||||
fi
|
||||
|
||||
local goldens_dir="${project_dir}/${module}/src/test/snapshots"
|
||||
local diff_dir="${project_dir}/${module}/build/outputs/roborazzi"
|
||||
|
||||
gradle_run "$project_dir" "$task"
|
||||
local exit_code=$?
|
||||
|
||||
if [[ "$record_flag" == "--record" ]]; then
|
||||
echo "RECORDED: ${goldens_dir}"
|
||||
elif [[ $exit_code -ne 0 ]]; then
|
||||
echo "DIFF: ${diff_dir}"
|
||||
fi
|
||||
|
||||
return $exit_code
|
||||
}
|
||||
|
||||
# Source-able y ejecutable directo
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
gradle_screenshot_test "$@"
|
||||
fi
|
||||
@@ -0,0 +1,66 @@
|
||||
---
|
||||
name: gradle_unit_test
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "gradle_unit_test(project_dir: string, module: string, --variant <name>: string) -> int"
|
||||
description: "Corre unit tests JVM de un modulo Android (no requiere emulador)."
|
||||
tags: ["android", "gradle", "kotlin", "test", "junit"]
|
||||
uses_functions: ["gradle_run_bash_infra"]
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/gradle_unit_test.sh"
|
||||
params:
|
||||
- name: project_dir
|
||||
desc: "Raiz del proyecto Android con settings.gradle[.kts]."
|
||||
- name: module
|
||||
desc: "Modulo Gradle. Default: app"
|
||||
- name: "--variant <name>"
|
||||
desc: "Build variant (Debug|Release). Default Debug"
|
||||
output: "Stdout con resultados JUnit. Linea final 'REPORT: <path_html>'. Exit code = test runner exit (0 OK, 1 fallos)."
|
||||
notes: |
|
||||
JVM only — Compose Composables que necesitan device se testean con
|
||||
gradle_instrumented_test. Para tests Compose en JVM usar Roborazzi
|
||||
(gradle_screenshot_test).
|
||||
|
||||
La funcion hace source de gradle_run.sh desde el mismo directorio
|
||||
(bash/functions/infra/). La dependencia gradle_run_bash_infra debe
|
||||
existir junto a este archivo.
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
source bash/functions/infra/gradle_unit_test.sh
|
||||
|
||||
# Tests del modulo app con variante Debug (por defecto)
|
||||
gradle_unit_test /home/lucas/projects/myapp
|
||||
|
||||
# Tests del modulo :core con variante Release
|
||||
gradle_unit_test /home/lucas/projects/myapp core --variant Release
|
||||
|
||||
# Verificar que paso
|
||||
if gradle_unit_test /home/lucas/projects/myapp; then
|
||||
echo "Todos los tests pasaron"
|
||||
else
|
||||
echo "Hay tests fallidos — revisar el report HTML"
|
||||
fi
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
JVM only — Compose Composables que necesitan device se testean con
|
||||
`gradle_instrumented_test`. Para tests Compose en JVM usar Roborazzi
|
||||
(`gradle_screenshot_test`).
|
||||
|
||||
El task ejecutado es `:$module:test${variant}UnitTest` (ej.
|
||||
`:app:testDebugUnitTest`). El report HTML se imprime al final como
|
||||
`REPORT: <path>` para facilitar parseo por agentes o scripts upstream.
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
# gradle_unit_test — Corre unit tests JVM de un modulo Android (no requiere emulador)
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/gradle_run.sh"
|
||||
|
||||
gradle_unit_test() {
|
||||
local project_dir="$1"
|
||||
local module="${2:-app}"
|
||||
local variant="Debug"
|
||||
|
||||
# Parsear flag opcional --variant (consumir project_dir y module primero)
|
||||
local nshift=$(( $# < 2 ? $# : 2 ))
|
||||
shift "$nshift"
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--variant)
|
||||
variant="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$project_dir" ]]; then
|
||||
echo "gradle_unit_test: project_dir es obligatorio" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local task=":${module}:test${variant}UnitTest"
|
||||
local report="${project_dir}/${module}/build/reports/tests/test${variant}UnitTest/index.html"
|
||||
|
||||
gradle_run "$project_dir" "$task"
|
||||
local exit_code=$?
|
||||
|
||||
echo "REPORT: $report"
|
||||
return $exit_code
|
||||
}
|
||||
Reference in New Issue
Block a user