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
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
---
|
||||
name: deploy_capacitor_to_emulator
|
||||
kind: pipeline
|
||||
lang: bash
|
||||
domain: pipelines
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "deploy_capacitor_to_emulator(app_dir: string, avd_name?: string, package_name?: string) -> void"
|
||||
description: "Pipeline end-to-end: build Capacitor APK + arranca AVD + instala + opcionalmente lanza la app. Valida que el AVD existe, construye el APK con capacitor_build_apk, arranca el emulador de forma idempotente, instala el APK y lanza la app si se da package_name. Imprime comando logcat sugerido al final."
|
||||
tags: [android, capacitor, emulator, deploy, launcher]
|
||||
uses_functions:
|
||||
- capacitor_build_apk_bash_pipelines
|
||||
- android_emulator_list_bash_infra
|
||||
- android_emulator_start_bash_infra
|
||||
- android_apk_install_bash_infra
|
||||
- android_logcat_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/pipelines/deploy_capacitor_to_emulator.sh"
|
||||
params:
|
||||
- name: app_dir
|
||||
desc: "Path al directorio de la app Capacitor. Debe contener package.json y ser un proyecto web compatible con Capacitor. Puede ser relativo al cwd o absoluto."
|
||||
- name: avd_name
|
||||
desc: "Nombre del AVD Android a usar como destino de deploy. Default: Medium_Phone_API_35. Debe existir en la lista de AVDs del sistema."
|
||||
- name: package_name
|
||||
desc: "Package id Android de la app (ej: com.fnregistry.voiceguide). Opcional. Si se provee, lanza la app tras instalarla y muestra comando logcat sugerido."
|
||||
output: "Stdout con pasos de cada fase. Exit 0 = APK instalado (y lanzado si se dio package_name) en el emulador. Exit != 0 si alguna fase falló (AVD no existe, build falla, emulador no arranca, install falla)."
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Build + deploy en AVD por defecto, sin lanzar app
|
||||
bash bash/functions/pipelines/deploy_capacitor_to_emulator.sh apps/voice_guide
|
||||
|
||||
# Build + deploy + lanzar app
|
||||
bash bash/functions/pipelines/deploy_capacitor_to_emulator.sh \
|
||||
apps/voice_guide \
|
||||
Medium_Phone_API_35 \
|
||||
com.fnregistry.voiceguide
|
||||
|
||||
# Con AVD personalizado
|
||||
bash bash/functions/pipelines/deploy_capacitor_to_emulator.sh \
|
||||
apps/voice_guide \
|
||||
Pixel_7_API_34 \
|
||||
com.fnregistry.voiceguide
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
- El APK se busca como `*.apk` en la raiz de `app_dir` tras el build (patron de `capacitor_build_apk`).
|
||||
- El arranque del emulador es idempotente via `android_emulator_start`: si ya hay un emulador corriendo no lanza otro.
|
||||
- El logcat no se sigue automaticamente (no bloqueante). Se imprime el comando para que el usuario lo ejecute si quiere.
|
||||
- Requiere WSL2 + Android SDK instalado en Windows (usa `adb_wsl` para resolver `adb.exe`).
|
||||
- La fase de build puede tardar varios minutos en la primera ejecucion (descarga de Gradle, Capacitor, etc.).
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
#!/usr/bin/env bash
|
||||
# deploy_capacitor_to_emulator — Pipeline end-to-end: build Capacitor APK + arranca AVD + instala + lanza app.
|
||||
#
|
||||
# USO:
|
||||
# deploy_capacitor_to_emulator.sh <app_dir> [avd_name] [package_name]
|
||||
#
|
||||
# ARGUMENTOS:
|
||||
# app_dir Path al directorio de la app Capacitor (debe contener package.json). Obligatorio.
|
||||
# avd_name Nombre del AVD a usar (default: Medium_Phone_API_35). Opcional.
|
||||
# package_name Package id de la app Android (ej: com.fnregistry.voiceguide).
|
||||
# Si se da, lanza la app tras instalar. Opcional.
|
||||
#
|
||||
# EJEMPLO:
|
||||
# bash deploy_capacitor_to_emulator.sh apps/voice_guide Medium_Phone_API_35 com.fnregistry.voiceguide
|
||||
#
|
||||
# REQUISITOS:
|
||||
# - Node.js + pnpm en PATH
|
||||
# - Java 17+ en PATH
|
||||
# - ANDROID_HOME seteado o ~/android-sdk/env.sh disponible
|
||||
# - Emulator Windows accesible desde WSL2 (adb_wsl)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REGISTRY_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Parseo de argumentos
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
APP_DIR="${1:-}"
|
||||
AVD_NAME="${2:-Medium_Phone_API_35}"
|
||||
PACKAGE_NAME="${3:-}"
|
||||
|
||||
if [[ -z "$APP_DIR" ]]; then
|
||||
echo "[deploy_capacitor_to_emulator] ERROR: app_dir es obligatorio." >&2
|
||||
echo "USO: $0 <app_dir> [avd_name] [package_name]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Resolver path absoluto de APP_DIR (puede venir relativo al cwd)
|
||||
if [[ "$APP_DIR" != /* ]]; then
|
||||
APP_DIR="$(pwd)/$APP_DIR"
|
||||
fi
|
||||
|
||||
if [[ ! -d "$APP_DIR" ]]; then
|
||||
echo "[deploy_capacitor_to_emulator] ERROR: directorio no existe: $APP_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f "$APP_DIR/package.json" ]]; then
|
||||
echo "[deploy_capacitor_to_emulator] ERROR: no se encontró package.json en $APP_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "======================================================================"
|
||||
echo " deploy_capacitor_to_emulator"
|
||||
echo "======================================================================"
|
||||
echo " app_dir : $APP_DIR"
|
||||
echo " avd_name : $AVD_NAME"
|
||||
echo " package_name : ${PACKAGE_NAME:-(no lanzar)}"
|
||||
echo "======================================================================"
|
||||
echo ""
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Source adb_wsl para tener helpers ADB y resolver $ADB
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# shellcheck source=../infra/adb_wsl.sh
|
||||
source "$REGISTRY_ROOT/bash/functions/infra/adb_wsl.sh"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Fase 1: Verificar que el AVD existe
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
echo "[deploy_capacitor_to_emulator] [1/4] Verificando AVD '$AVD_NAME'..."
|
||||
|
||||
if ! bash "$REGISTRY_ROOT/bash/functions/infra/android_emulator_list.sh" | grep -qx "$AVD_NAME"; then
|
||||
echo "[deploy_capacitor_to_emulator] ERROR: AVD '$AVD_NAME' no encontrado." >&2
|
||||
echo " AVDs disponibles:" >&2
|
||||
bash "$REGISTRY_ROOT/bash/functions/infra/android_emulator_list.sh" | sed 's/^/ /' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[deploy_capacitor_to_emulator] AVD '$AVD_NAME' existe."
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Fase 2: Build APK
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
echo ""
|
||||
echo "[deploy_capacitor_to_emulator] [2/4] Construyendo APK desde $APP_DIR ..."
|
||||
|
||||
bash "$REGISTRY_ROOT/bash/functions/pipelines/capacitor_build_apk.sh" "$APP_DIR"
|
||||
|
||||
# Localizar APK generado: capacitor_build_apk copia el APK a $APP_DIR/<app_name>.apk
|
||||
APK_PATH=""
|
||||
while IFS= read -r -d '' candidate; do
|
||||
APK_PATH="$candidate"
|
||||
break
|
||||
done < <(find "$APP_DIR" -maxdepth 1 -name "*.apk" -print0 2>/dev/null)
|
||||
|
||||
if [[ -z "$APK_PATH" ]]; then
|
||||
echo "[deploy_capacitor_to_emulator] ERROR: No se encontró ningún .apk en $APP_DIR tras el build." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[deploy_capacitor_to_emulator] APK localizado: $APK_PATH"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Fase 3: Arrancar emulador (idempotente)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
echo ""
|
||||
echo "[deploy_capacitor_to_emulator] [3/4] Arrancando emulador '$AVD_NAME' (idempotente)..."
|
||||
|
||||
bash "$REGISTRY_ROOT/bash/functions/infra/android_emulator_start.sh" "$AVD_NAME"
|
||||
|
||||
echo "[deploy_capacitor_to_emulator] Emulador listo."
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Fase 4: Instalar APK (y lanzar si se dio package_name)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
echo ""
|
||||
echo "[deploy_capacitor_to_emulator] [4/4] Instalando APK..."
|
||||
|
||||
# Source android_apk_install para usar su función
|
||||
# shellcheck source=../infra/android_apk_install.sh
|
||||
source "$REGISTRY_ROOT/bash/functions/infra/android_apk_install.sh"
|
||||
|
||||
android_apk_install "$APK_PATH" "$PACKAGE_NAME"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Diagnóstico no-bloqueante: hint logcat
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
if [[ -n "$PACKAGE_NAME" ]]; then
|
||||
echo ""
|
||||
echo "[deploy_capacitor_to_emulator] Para seguir los logs de la app en tiempo real:"
|
||||
echo " bash $REGISTRY_ROOT/bash/functions/infra/android_logcat.sh --package '$PACKAGE_NAME'"
|
||||
echo ""
|
||||
echo " O los últimos 50 mensajes:"
|
||||
echo " bash $REGISTRY_ROOT/bash/functions/infra/android_logcat.sh --package '$PACKAGE_NAME' --lines 50"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Resumen
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
echo ""
|
||||
echo "======================================================================"
|
||||
echo " DEPLOY COMPLETADO"
|
||||
echo "======================================================================"
|
||||
echo " APK instalado : $APK_PATH"
|
||||
echo " Emulador : $AVD_NAME"
|
||||
if [[ -n "$PACKAGE_NAME" ]]; then
|
||||
echo " App lanzada : $PACKAGE_NAME"
|
||||
fi
|
||||
echo "======================================================================"
|
||||
echo ""
|
||||
@@ -0,0 +1,74 @@
|
||||
---
|
||||
name: init_cpp_app
|
||||
kind: pipeline
|
||||
lang: bash
|
||||
domain: pipelines
|
||||
version: "0.1.0"
|
||||
purity: impure
|
||||
signature: "init_cpp_app(name: string, [--project <p>] [--domain <d>] [--desc <s>] [--tags <csv>]) -> void"
|
||||
description: "Scaffolder estandar de apps C++ del registry. Genera main.cpp + CMakeLists.txt + app.md siguiendo el patron canonico (cfg.about/log/panels, sin app_menubar manual, dockspace via framework), registra la app en cpp/CMakeLists.txt, inicializa repo Gitea dataforge/<name> y ejecuta fn index."
|
||||
tags: [cpp, imgui, scaffold, pipeline, bash, launcher]
|
||||
uses_functions:
|
||||
- ensure_repo_synced_bash_infra
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
params:
|
||||
- name: name
|
||||
desc: "nombre de la app (snake_case). Sera el id en registry.db y el repo dataforge/<name>"
|
||||
- name: "--project"
|
||||
desc: "proyecto bajo projects/ donde crear la app (opcional). Si se omite va a cpp/apps/<name>/"
|
||||
- name: "--domain"
|
||||
desc: "dominio del registry (default: tools)"
|
||||
- name: "--desc"
|
||||
desc: "descripcion breve (frontmatter description + cfg.about/cfg.title)"
|
||||
- name: "--tags"
|
||||
desc: "tags CSV adicionales para el frontmatter (siempre se anade 'imgui')"
|
||||
output: "estructura completa de la app + entry registrada en cpp/CMakeLists.txt + repo Gitea + fn index"
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/pipelines/init_cpp_app.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# App suelta en cpp/apps/<name>/
|
||||
fn run init_cpp_app my_tool --desc "Herramienta para X"
|
||||
|
||||
# App dentro de un proyecto
|
||||
fn run init_cpp_app finance_panel --project budget --desc "Panel de finanzas" --tags "finance,dashboard"
|
||||
```
|
||||
|
||||
## Que genera
|
||||
|
||||
```
|
||||
<dir>/
|
||||
main.cpp # Plantilla canonica: panels[] + cfg.about + cfg.log + run_app(cfg, render)
|
||||
CMakeLists.txt # add_imgui_app(<name> main.cpp)
|
||||
app.md # Frontmatter completo (lang:cpp, framework:imgui, dir_path, repo_url)
|
||||
```
|
||||
|
||||
Y ademas:
|
||||
|
||||
- Registra `add_subdirectory(apps/<name>)` (o el bloque `_DIR` para projects) en `cpp/CMakeLists.txt`.
|
||||
- Crea repo Gitea `dataforge/<name>` con master + commit inicial via `ensure_repo_synced_bash_infra` (requiere `GITEA_URL` y `GITEA_TOKEN`).
|
||||
- Ejecuta `fn index` para registrar la app en `registry.db`.
|
||||
|
||||
## Plantilla `main.cpp`
|
||||
|
||||
La plantilla cumple `cpp/PATTERNS.md`:
|
||||
|
||||
- NO llama `app_menubar` manual (lo dibuja el framework).
|
||||
- NO llama `DockSpaceOverViewport` (auto_dockspace=true por defecto).
|
||||
- Declara `panels[]` con un panel "Main" toggleable.
|
||||
- Setea `cfg.about` (window About) y `cfg.log` (logger + ventana Logs).
|
||||
|
||||
## Despues de crear
|
||||
|
||||
1. Editar `app.md` y completar `uses_functions` cuando la app consuma funciones del registry.
|
||||
2. Anadir las funciones del registry al `CMakeLists.txt` como paths absolutos: `${CMAKE_SOURCE_DIR}/functions/<dom>/<func>.cpp`.
|
||||
3. Build: `cd cpp && cmake --build build --target <name> -j`.
|
||||
Executable
+211
@@ -0,0 +1,211 @@
|
||||
#!/usr/bin/env bash
|
||||
# init_cpp_app — Scaffolder estandar de apps C++ del registry.
|
||||
#
|
||||
# Genera la estructura canonica (main.cpp, CMakeLists.txt, app.md), registra
|
||||
# la app en cpp/CMakeLists.txt, inicializa git + repo Gitea dataforge/<name>,
|
||||
# y ejecuta fn index. La plantilla cumple cpp/PATTERNS.md y .claude/rules/cpp_apps.md.
|
||||
#
|
||||
# Uso:
|
||||
# init_cpp_app <name> [--project <p>] [--domain <d>] [--desc "..."] [--tags "a,b"]
|
||||
#
|
||||
# Por defecto domain=tools, sin proyecto (cpp/apps/<name>/).
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Carga helpers del registry
|
||||
FN_ROOT="${FN_REGISTRY_ROOT:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}"
|
||||
# shellcheck source=/dev/null
|
||||
source "$FN_ROOT/bash/functions/infra/ensure_repo_synced.sh"
|
||||
|
||||
init_cpp_app() {
|
||||
local name=""
|
||||
local project=""
|
||||
local domain="tools"
|
||||
local desc=""
|
||||
local tags=""
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--project) project="$2"; shift 2 ;;
|
||||
--domain) domain="$2"; shift 2 ;;
|
||||
--desc) desc="$2"; shift 2 ;;
|
||||
--tags) tags="$2"; shift 2 ;;
|
||||
-*) echo "init_cpp_app: flag desconocido: $1" >&2; return 2 ;;
|
||||
*) if [[ -z "$name" ]]; then name="$1"; else
|
||||
echo "init_cpp_app: argumento extra: $1" >&2; return 2
|
||||
fi
|
||||
shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$name" ]]; then
|
||||
echo "init_cpp_app: se requiere <name>" >&2
|
||||
echo "Uso: init_cpp_app <name> [--project <p>] [--domain <d>] [--desc \"...\"] [--tags \"a,b\"]" >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
[[ -z "$desc" ]] && desc="App C++ del registry"
|
||||
|
||||
# Resolver dir destino
|
||||
local rel_dir abs_dir
|
||||
if [[ -n "$project" ]]; then
|
||||
if [[ ! -f "$FN_ROOT/projects/$project/project.md" ]]; then
|
||||
echo "init_cpp_app: proyecto '$project' no existe (falta projects/$project/project.md)" >&2
|
||||
return 1
|
||||
fi
|
||||
rel_dir="projects/$project/apps/$name"
|
||||
else
|
||||
rel_dir="cpp/apps/$name"
|
||||
fi
|
||||
abs_dir="$FN_ROOT/$rel_dir"
|
||||
|
||||
if [[ -e "$abs_dir" ]]; then
|
||||
echo "init_cpp_app: $rel_dir ya existe" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
mkdir -p "$abs_dir"
|
||||
|
||||
# ---------- main.cpp ----------
|
||||
cat > "$abs_dir/main.cpp" <<EOF
|
||||
#include <imgui.h>
|
||||
#include "framework/app_base.h"
|
||||
#include "core/icons_tabler.h"
|
||||
#include "core/logger.h"
|
||||
|
||||
// Toggles de paneles (visibles desde el menu View del menubar canonico)
|
||||
static bool g_show_main = true;
|
||||
|
||||
static void draw_main() {
|
||||
if (!ImGui::Begin(TI_HOME " Main", &g_show_main)) {
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
ImGui::TextUnformatted("Hello from $name");
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
static void render() {
|
||||
// El framework dibuja menubar (View/Layouts/Settings/About) y un
|
||||
// DockSpaceOverViewport central (auto_dockspace=true por defecto).
|
||||
// Aqui solo se dibujan los paneles propios de la app.
|
||||
if (g_show_main) draw_main();
|
||||
}
|
||||
|
||||
int main(int /*argc*/, char** /*argv*/) {
|
||||
static fn_ui::PanelToggle panels[] = {
|
||||
{ "Main", nullptr, &g_show_main },
|
||||
};
|
||||
|
||||
fn::AppConfig cfg;
|
||||
cfg.title = "$name — $desc";
|
||||
cfg.about = { "$name", "0.1.0", "$desc" };
|
||||
cfg.log = { "$name.log", 1 };
|
||||
cfg.panels = panels;
|
||||
cfg.panel_count = sizeof(panels) / sizeof(panels[0]);
|
||||
|
||||
return fn::run_app(cfg, render);
|
||||
}
|
||||
EOF
|
||||
|
||||
# ---------- CMakeLists.txt ----------
|
||||
cat > "$abs_dir/CMakeLists.txt" <<EOF
|
||||
add_imgui_app($name
|
||||
main.cpp
|
||||
)
|
||||
target_include_directories($name PRIVATE \${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
if(WIN32)
|
||||
set_target_properties($name PROPERTIES WIN32_EXECUTABLE TRUE)
|
||||
endif()
|
||||
EOF
|
||||
|
||||
# ---------- app.md ----------
|
||||
local repo_url="https://gitea.organic-machine.com/dataforge/$name"
|
||||
local tags_yaml="[imgui]"
|
||||
if [[ -n "$tags" ]]; then
|
||||
# Convierte "a,b,c" -> "[a, b, c]"
|
||||
tags_yaml="[$(echo "$tags" | sed 's/,/, /g'), imgui]"
|
||||
fi
|
||||
|
||||
cat > "$abs_dir/app.md" <<EOF
|
||||
---
|
||||
name: $name
|
||||
lang: cpp
|
||||
domain: $domain
|
||||
description: "$desc"
|
||||
tags: $tags_yaml
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
framework: "imgui"
|
||||
entry_point: "main.cpp"
|
||||
dir_path: "$rel_dir"
|
||||
repo_url: "$repo_url"
|
||||
---
|
||||
|
||||
# $name
|
||||
|
||||
$desc
|
||||
|
||||
## Build
|
||||
|
||||
\`\`\`bash
|
||||
cd cpp && cmake --build build --target $name -j
|
||||
\`\`\`
|
||||
|
||||
## Run
|
||||
|
||||
\`\`\`bash
|
||||
./cpp/build/$name
|
||||
\`\`\`
|
||||
EOF
|
||||
|
||||
# ---------- Registrar en cpp/CMakeLists.txt ----------
|
||||
local cpp_cmake="$FN_ROOT/cpp/CMakeLists.txt"
|
||||
if ! grep -q "# --- $name ---" "$cpp_cmake"; then
|
||||
if [[ -n "$project" ]]; then
|
||||
local upper
|
||||
upper="$(echo "$name" | tr '[:lower:]' '[:upper:]')"
|
||||
cat >> "$cpp_cmake" <<EOF
|
||||
|
||||
# --- $name (lives in projects/$project/apps/) ---
|
||||
set(_${upper}_DIR \${CMAKE_SOURCE_DIR}/../projects/$project/apps/$name)
|
||||
if(EXISTS \${_${upper}_DIR}/CMakeLists.txt)
|
||||
add_subdirectory(\${_${upper}_DIR} \${CMAKE_BINARY_DIR}/apps/$name)
|
||||
endif()
|
||||
EOF
|
||||
else
|
||||
cat >> "$cpp_cmake" <<EOF
|
||||
|
||||
# --- $name ---
|
||||
if(EXISTS \${CMAKE_CURRENT_SOURCE_DIR}/apps/$name/CMakeLists.txt)
|
||||
add_subdirectory(apps/$name)
|
||||
endif()
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
|
||||
# ---------- Git + Gitea ----------
|
||||
if [[ -n "${GITEA_URL:-}" && -n "${GITEA_TOKEN:-}" ]]; then
|
||||
ensure_repo_synced "$abs_dir" "dataforge" "$name" "master" "feat: scaffold $name via init_cpp_app" || \
|
||||
echo "init_cpp_app: warning — ensure_repo_synced fallo, repo no creado" >&2
|
||||
else
|
||||
echo "init_cpp_app: GITEA_URL/GITEA_TOKEN no seteados, omitiendo creacion de repo Gitea" >&2
|
||||
(cd "$abs_dir" && git init -b master >/dev/null 2>&1 || git init >/dev/null 2>&1)
|
||||
fi
|
||||
|
||||
# ---------- fn index ----------
|
||||
if [[ -x "$FN_ROOT/fn" ]]; then
|
||||
(cd "$FN_ROOT" && ./fn index >/dev/null 2>&1) || \
|
||||
echo "init_cpp_app: warning — fn index fallo" >&2
|
||||
fi
|
||||
|
||||
echo "init_cpp_app: $rel_dir creada"
|
||||
echo " - Build: cd $FN_ROOT/cpp && cmake --build build --target $name -j"
|
||||
echo " - app.md: $rel_dir/app.md (rellena uses_functions cuando uses funciones del registry)"
|
||||
}
|
||||
|
||||
# Permitir invocacion directa via 'fn run init_cpp_app ...'
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
init_cpp_app "$@"
|
||||
fi
|
||||
@@ -0,0 +1,117 @@
|
||||
---
|
||||
name: init_kotlin_app
|
||||
kind: pipeline
|
||||
lang: bash
|
||||
domain: pipelines
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "init_kotlin_app(name: string, [--project <p>] [--desc <s>] [--tags <csv>] [--package <id>]) -> void"
|
||||
description: "Scaffolder canonico de app Android Kotlin Compose con FnTheme + Roborazzi tests + e2e_checks declarados. Mirror exacto del patron init_cpp_app para el stack Kotlin."
|
||||
tags: [android, kotlin, compose, scaffolder, launcher]
|
||||
uses_functions:
|
||||
- ensure_repo_synced_bash_infra
|
||||
- gradle_run_bash_infra
|
||||
- gradle_assemble_debug_bash_infra
|
||||
- gradle_unit_test_bash_infra
|
||||
- gradle_screenshot_test_bash_infra
|
||||
- fn_theme_kt_ui
|
||||
- fn_tokens_kt_ui
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
params:
|
||||
- name: name
|
||||
desc: "nombre de la app en snake_case. Sera el id en registry.db y el repo dataforge/<name>"
|
||||
- name: "--project"
|
||||
desc: "proyecto bajo projects/ donde crear la app (opcional). Si se omite va a apps/<name>/. El project.md debe existir"
|
||||
- name: "--desc"
|
||||
desc: "descripcion breve para el frontmatter app.md (default: 'App Android Kotlin Compose')"
|
||||
- name: "--tags"
|
||||
desc: "tags CSV adicionales para el frontmatter (siempre se anaden kotlin, compose, android)"
|
||||
- name: "--package"
|
||||
desc: "application id Android (default: com.fnregistry.<name>). Ej: com.aurgi.scanner"
|
||||
output: "Stdout con pasos y archivos creados. Exit 0 = scaffold completo y ready para build. Exit !=0 si falla validacion (nombre invalido, destino existe, proyecto inexistente) o git init."
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/pipelines/init_kotlin_app.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# App suelta en apps/<name>/
|
||||
fn run init_kotlin_app my_scanner --desc "Escaner de documentos" --package "com.aurgi.scanner"
|
||||
|
||||
# App dentro de un proyecto
|
||||
fn run init_kotlin_app expense_tracker --project budget --desc "Tracker de gastos" --tags "finance,mobile"
|
||||
|
||||
# Con package id personalizado
|
||||
fn run init_kotlin_app pos_terminal --package "com.aurgi.pos" --desc "Terminal de punto de venta"
|
||||
```
|
||||
|
||||
## Que genera
|
||||
|
||||
```
|
||||
apps/<name>/ (o projects/<p>/apps/<name>/)
|
||||
├── settings.gradle.kts # rootProject + include(:app) + composite build ui
|
||||
├── build.gradle.kts # top-level (apply false)
|
||||
├── app/build.gradle.kts # Compose + Material3 + Roborazzi + tests
|
||||
├── gradle.properties
|
||||
├── gradlew # stub ejecutable
|
||||
├── gradle/wrapper/gradle-wrapper.properties # Gradle 8.6
|
||||
├── app/
|
||||
│ └── src/
|
||||
│ ├── main/
|
||||
│ │ ├── AndroidManifest.xml # activity con LAUNCHER intent
|
||||
│ │ ├── kotlin/<pkg_path>/
|
||||
│ │ │ └── MainActivity.kt # FnTheme + Surface + Text("<name> ready")
|
||||
│ │ └── res/values/strings.xml
|
||||
│ ├── test/kotlin/<pkg_path>/
|
||||
│ │ └── ExampleScreenshotTest.kt # Roborazzi: captura FnTheme + Surface
|
||||
│ └── androidTest/kotlin/<pkg_path>/
|
||||
│ └── MainActivityTest.kt # Compose ui-test: assertIsDisplayed("<name> ready")
|
||||
├── app.md # frontmatter registry (lang:kt, framework:compose)
|
||||
├── .gitignore
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## Composite build
|
||||
|
||||
La app apunta via `includeBuild` a `kotlin/functions/ui` del registry (FnTheme + FnTokens).
|
||||
El path relativo se calcula automaticamente:
|
||||
|
||||
| Ubicacion | Path al composite |
|
||||
|---|---|
|
||||
| `apps/<name>/` | `../../kotlin/functions/ui` |
|
||||
| `projects/<p>/apps/<name>/` | `../../../../kotlin/functions/ui` |
|
||||
|
||||
La dependencia se declara como `implementation("fn.compose:ui")` en `app/build.gradle.kts`.
|
||||
|
||||
## e2e_checks generados
|
||||
|
||||
| id | cmd | timeout |
|
||||
|---|---|---|
|
||||
| `unit` | `fn run gradle_unit_test_bash_infra <dir>` | 240s |
|
||||
| `screenshot` | `fn run gradle_screenshot_test_bash_infra <dir>` | 240s |
|
||||
| `build` | `fn run gradle_assemble_debug_bash_infra <dir>` | 360s |
|
||||
| `emu_start` | `fn run android_emulator_start_bash_infra Medium_Phone_API_35` | 240s |
|
||||
| `instrumented` | `fn run gradle_instrumented_test_bash_infra <dir>` | 600s |
|
||||
| `emu_stop` | `fn run android_emulator_stop_bash_infra` | 30s (warning) |
|
||||
|
||||
## Despues de crear
|
||||
|
||||
1. Completar `uses_functions` en `app.md` cuando la app consuma funciones adicionales del registry.
|
||||
2. Para tests Roborazzi: los snapshots se generan en `app/src/test/snapshots/images/` (gitignored).
|
||||
Para actualizar golden images: `./gradlew recordRoborazziDebug`.
|
||||
3. Para tests instrumentados se necesita un AVD creado con `avdmanager create avd -n Medium_Phone_API_35 ...`.
|
||||
|
||||
## Notas
|
||||
|
||||
- `fn_theme_kt_ui` y `fn_tokens_kt_ui` se referencian en `uses_functions` del `app.md` generado
|
||||
aunque todavia no esten indexados en registry.db — son los modulos del composite build.
|
||||
- `ensure_repo_synced_bash_infra` requiere `GITEA_URL` y `GITEA_TOKEN`. Sin ellos se hace
|
||||
`git init + git commit` local y se avisa al usuario.
|
||||
- Si `--project <p>` se especifica, se ejecuta `fn index` al final para registrar la nueva app.
|
||||
Executable
+531
@@ -0,0 +1,531 @@
|
||||
#!/usr/bin/env bash
|
||||
# init_kotlin_app — Scaffolder canonico de apps Android Kotlin Compose del registry.
|
||||
#
|
||||
# Genera la estructura canonica (MainActivity.kt, build.gradle.kts, app.md,
|
||||
# Roborazzi screenshot tests), apuntando al composite build kotlin/functions/ui
|
||||
# para FnTheme + FnTokens, inicializa git + repo Gitea dataforge/<name>.
|
||||
#
|
||||
# Uso:
|
||||
# init_kotlin_app <name> [--project <p>] [--desc "..."] [--tags "a,b"] [--package <com.foo.bar>]
|
||||
#
|
||||
# Por defecto sin proyecto (apps/<name>/), package = com.fnregistry.<name>.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Carga helpers del registry
|
||||
FN_ROOT="${FN_REGISTRY_ROOT:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}"
|
||||
# shellcheck source=/dev/null
|
||||
source "$FN_ROOT/bash/functions/infra/ensure_repo_synced.sh"
|
||||
|
||||
init_kotlin_app() {
|
||||
local name=""
|
||||
local project=""
|
||||
local desc=""
|
||||
local tags=""
|
||||
local pkg_id=""
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--project) project="$2"; shift 2 ;;
|
||||
--desc) desc="$2"; shift 2 ;;
|
||||
--tags) tags="$2"; shift 2 ;;
|
||||
--package) pkg_id="$2"; shift 2 ;;
|
||||
-*) echo "init_kotlin_app: flag desconocido: $1" >&2; return 2 ;;
|
||||
*) if [[ -z "$name" ]]; then name="$1"; else
|
||||
echo "init_kotlin_app: argumento extra: $1" >&2; return 2
|
||||
fi
|
||||
shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$name" ]]; then
|
||||
echo "init_kotlin_app: se requiere <name>" >&2
|
||||
echo "Uso: init_kotlin_app <name> [--project <p>] [--desc \"...\"] [--tags \"a,b\"] [--package <com.foo.bar>]" >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
# Validar snake_case
|
||||
if [[ ! "$name" =~ ^[a-z][a-z0-9_]*$ ]]; then
|
||||
echo "init_kotlin_app: nombre '$name' debe ser snake_case (solo letras minusculas, digitos y _)" >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
[[ -z "$desc" ]] && desc="App Android Kotlin Compose"
|
||||
[[ -z "$pkg_id" ]] && pkg_id="com.fnregistry.$name"
|
||||
|
||||
# Resolver dir destino
|
||||
local rel_dir abs_dir
|
||||
if [[ -n "$project" ]]; then
|
||||
if [[ ! -f "$FN_ROOT/projects/$project/project.md" ]]; then
|
||||
echo "init_kotlin_app: proyecto '$project' no existe (falta projects/$project/project.md)" >&2
|
||||
return 1
|
||||
fi
|
||||
rel_dir="projects/$project/apps/$name"
|
||||
else
|
||||
rel_dir="apps/$name"
|
||||
fi
|
||||
abs_dir="$FN_ROOT/$rel_dir"
|
||||
|
||||
if [[ -e "$abs_dir" ]]; then
|
||||
echo "init_kotlin_app: $rel_dir ya existe" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Convertir package id a path (com.fnregistry.my_app -> com/fnregistry/my_app)
|
||||
local pkg_path
|
||||
pkg_path="$(echo "$pkg_id" | tr '.' '/')"
|
||||
|
||||
# Calcular path relativo al composite build de kotlin/functions/ui
|
||||
# Desde apps/<name>/ -> ../../kotlin/functions/ui
|
||||
# Desde projects/<p>/apps/<n> -> ../../../../kotlin/functions/ui
|
||||
local ui_rel_path
|
||||
if [[ -n "$project" ]]; then
|
||||
ui_rel_path="../../../../kotlin/functions/ui"
|
||||
else
|
||||
ui_rel_path="../../kotlin/functions/ui"
|
||||
fi
|
||||
|
||||
# ---- Crear estructura de directorios ----
|
||||
mkdir -p "$abs_dir/app/src/main/kotlin/$pkg_path"
|
||||
mkdir -p "$abs_dir/app/src/main/res/values"
|
||||
mkdir -p "$abs_dir/app/src/test/kotlin/$pkg_path"
|
||||
mkdir -p "$abs_dir/app/src/androidTest/kotlin/$pkg_path"
|
||||
mkdir -p "$abs_dir/gradle/wrapper"
|
||||
|
||||
echo "init_kotlin_app: creando $rel_dir ..."
|
||||
|
||||
# ---- settings.gradle.kts ----
|
||||
cat > "$abs_dir/settings.gradle.kts" <<EOF
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
rootProject.name = "$name"
|
||||
include(":app")
|
||||
|
||||
// Composite build: FnTheme + FnTokens desde el registry
|
||||
includeBuild("$ui_rel_path") {
|
||||
dependencySubstitution {
|
||||
substitute(module("fn.compose:ui")).using(project(":"))
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# ---- build.gradle.kts (raiz) ----
|
||||
cat > "$abs_dir/build.gradle.kts" <<'EOF'
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id("com.android.application") version "8.4.0" apply false
|
||||
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
|
||||
}
|
||||
EOF
|
||||
|
||||
# ---- app/build.gradle.kts ----
|
||||
cat > "$abs_dir/app/build.gradle.kts" <<EOF
|
||||
plugins {
|
||||
id("com.android.application") version "8.4.0"
|
||||
id("org.jetbrains.kotlin.android") version "1.9.22"
|
||||
id("io.github.takahirom.roborazzi") version "1.20.0"
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "$pkg_id"
|
||||
compileSdk = 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "$pkg_id"
|
||||
minSdk = 24
|
||||
targetSdk = 34
|
||||
versionCode = 1
|
||||
versionName = "0.1.0"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose = true
|
||||
}
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion = "1.5.8"
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
testOptions {
|
||||
unitTests {
|
||||
isIncludeAndroidResources = true
|
||||
all {
|
||||
it.systemProperty("robolectric.graphicsMode", "NATIVE")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("androidx.activity:activity-compose:1.8.2")
|
||||
implementation(platform("androidx.compose:compose-bom:2024.02.00"))
|
||||
implementation("androidx.compose.ui:ui")
|
||||
implementation("androidx.compose.material3:material3")
|
||||
implementation("androidx.compose.ui:ui-tooling-preview")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling")
|
||||
// FnTheme + FnTokens via composite build
|
||||
implementation("fn.compose:ui")
|
||||
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
testImplementation("org.robolectric:robolectric:4.11.1")
|
||||
testImplementation("androidx.compose.ui:ui-test-junit4")
|
||||
testImplementation("io.github.takahirom.roborazzi:roborazzi:1.20.0")
|
||||
testImplementation("io.github.takahirom.roborazzi:roborazzi-compose:1.20.0")
|
||||
testImplementation("io.github.takahirom.roborazzi:roborazzi-junit-rule:1.20.0")
|
||||
androidTestImplementation(platform("androidx.compose:compose-bom:2024.02.00"))
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
|
||||
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest")
|
||||
}
|
||||
EOF
|
||||
|
||||
# ---- gradle.properties ----
|
||||
cat > "$abs_dir/gradle.properties" <<'EOF'
|
||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
android.useAndroidX=true
|
||||
kotlin.code.style=official
|
||||
android.nonTransitiveRClass=true
|
||||
EOF
|
||||
|
||||
# ---- gradle/wrapper/gradle-wrapper.properties ----
|
||||
cat > "$abs_dir/gradle/wrapper/gradle-wrapper.properties" <<'EOF'
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
EOF
|
||||
|
||||
# ---- gradlew + wrapper jar (vendored real wrapper) ----
|
||||
local tmpl_wrapper="$FN_ROOT/bash/functions/pipelines/templates/kotlin/wrapper"
|
||||
if [[ -f "$tmpl_wrapper/gradlew" && -f "$tmpl_wrapper/gradle-wrapper.jar" ]]; then
|
||||
cp "$tmpl_wrapper/gradlew" "$abs_dir/gradlew"
|
||||
cp "$tmpl_wrapper/gradle-wrapper.jar" "$abs_dir/gradle/wrapper/gradle-wrapper.jar"
|
||||
chmod +x "$abs_dir/gradlew"
|
||||
else
|
||||
echo "init_kotlin_app: WARN templates/kotlin/wrapper missing, fallback gradlew stub"
|
||||
cat > "$abs_dir/gradlew" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
echo "gradlew stub — install gradle wrapper or replace with real one" >&2
|
||||
exit 2
|
||||
EOF
|
||||
chmod +x "$abs_dir/gradlew"
|
||||
fi
|
||||
|
||||
# ---- local.properties (Android SDK location, gitignored, per-machine) ----
|
||||
local sdk_path="${ANDROID_SDK_DIR:-$HOME/android-sdk}"
|
||||
if [[ ! -d "$sdk_path" ]] && [[ -d "$HOME/Android/Sdk" ]]; then
|
||||
sdk_path="$HOME/Android/Sdk"
|
||||
fi
|
||||
cat > "$abs_dir/local.properties" <<EOF
|
||||
# Auto-generated by init_kotlin_app. Per-machine, gitignored.
|
||||
sdk.dir=$sdk_path
|
||||
EOF
|
||||
|
||||
# ---- AndroidManifest.xml ----
|
||||
cat > "$abs_dir/app/src/main/AndroidManifest.xml" <<EOF
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@android:style/Theme.Material.Light.NoActionBar">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
EOF
|
||||
|
||||
# ---- res/values/strings.xml ----
|
||||
cat > "$abs_dir/app/src/main/res/values/strings.xml" <<EOF
|
||||
<resources>
|
||||
<string name="app_name">$name</string>
|
||||
</resources>
|
||||
EOF
|
||||
|
||||
# ---- MainActivity.kt ----
|
||||
cat > "$abs_dir/app/src/main/kotlin/$pkg_path/MainActivity.kt" <<EOF
|
||||
package $pkg_id
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import fn.compose.theme.FnTheme
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
FnTheme {
|
||||
Surface(modifier = Modifier.fillMaxSize()) {
|
||||
Text("$name ready")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# ---- ExampleScreenshotTest.kt (Roborazzi) ----
|
||||
cat > "$abs_dir/app/src/test/kotlin/$pkg_path/ExampleScreenshotTest.kt" <<EOF
|
||||
package $pkg_id
|
||||
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import com.github.takahirom.roborazzi.captureRoboImage
|
||||
import fn.compose.theme.FnTheme
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
class ExampleScreenshotTest {
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createComposeRule()
|
||||
|
||||
@Test
|
||||
fun screenshotFnThemeSurface() {
|
||||
composeTestRule.setContent {
|
||||
FnTheme {
|
||||
Surface {
|
||||
Text("$name screenshot")
|
||||
}
|
||||
}
|
||||
}
|
||||
composeTestRule.onRoot().captureRoboImage("src/test/snapshots/images/${name}_smoke.png")
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# ---- MainActivityTest.kt (instrumented) ----
|
||||
cat > "$abs_dir/app/src/androidTest/kotlin/$pkg_path/MainActivityTest.kt" <<EOF
|
||||
package $pkg_id
|
||||
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class MainActivityTest {
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createAndroidComposeRule<MainActivity>()
|
||||
|
||||
@Test
|
||||
fun appLaunchesAndShowsReadyText() {
|
||||
composeTestRule
|
||||
.onNodeWithText("$name ready")
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# ---- app.md frontmatter ----
|
||||
local repo_url="https://gitea.organic-machine.com/dataforge/$name"
|
||||
local tags_yaml="[kotlin, compose, android]"
|
||||
if [[ -n "$tags" ]]; then
|
||||
tags_yaml="[$(echo "$tags" | sed 's/,/, /g'), kotlin, compose, android]"
|
||||
fi
|
||||
|
||||
cat > "$abs_dir/app.md" <<EOF
|
||||
---
|
||||
name: $name
|
||||
domain: tools
|
||||
description: "$desc"
|
||||
tags: $tags_yaml
|
||||
lang: kt
|
||||
framework: compose
|
||||
entry_point: "app/src/main/kotlin/$pkg_path/MainActivity.kt"
|
||||
dir_path: "$rel_dir"
|
||||
repo_url: "$repo_url"
|
||||
uses_functions:
|
||||
- fn_theme_kt_ui
|
||||
- fn_tokens_kt_ui
|
||||
uses_types: []
|
||||
e2e_checks:
|
||||
- id: unit
|
||||
cmd: "fn run gradle_unit_test_bash_infra $rel_dir"
|
||||
timeout_s: 240
|
||||
- id: screenshot
|
||||
cmd: "fn run gradle_screenshot_test_bash_infra $rel_dir"
|
||||
timeout_s: 240
|
||||
- id: build
|
||||
cmd: "fn run gradle_assemble_debug_bash_infra $rel_dir"
|
||||
timeout_s: 360
|
||||
- id: emu_start
|
||||
cmd: "fn run android_emulator_start_bash_infra Medium_Phone_API_35"
|
||||
timeout_s: 240
|
||||
- id: instrumented
|
||||
cmd: "fn run gradle_instrumented_test_bash_infra $rel_dir"
|
||||
timeout_s: 600
|
||||
- id: emu_stop
|
||||
cmd: "fn run android_emulator_stop_bash_infra"
|
||||
severity: warning
|
||||
timeout_s: 30
|
||||
---
|
||||
|
||||
# $name
|
||||
|
||||
$desc
|
||||
|
||||
## Build
|
||||
|
||||
\`\`\`bash
|
||||
fn run gradle_assemble_debug_bash_infra $rel_dir
|
||||
\`\`\`
|
||||
|
||||
## Tests unitarios + Roborazzi screenshots
|
||||
|
||||
\`\`\`bash
|
||||
fn run gradle_unit_test_bash_infra $rel_dir
|
||||
fn run gradle_screenshot_test_bash_infra $rel_dir
|
||||
\`\`\`
|
||||
|
||||
## Tests instrumentados (requiere emulador)
|
||||
|
||||
\`\`\`bash
|
||||
fn run android_emulator_start_bash_infra Medium_Phone_API_35
|
||||
fn run gradle_instrumented_test_bash_infra $rel_dir
|
||||
fn run android_emulator_stop_bash_infra
|
||||
\`\`\`
|
||||
|
||||
## Package
|
||||
|
||||
\`$pkg_id\`
|
||||
|
||||
## FnTheme
|
||||
|
||||
La app usa FnTheme y FnTokens via composite build en \`kotlin/functions/ui\`.
|
||||
Para cambiar colores o tipografia, editar el modulo del registry.
|
||||
EOF
|
||||
|
||||
# ---- .gitignore ----
|
||||
cat > "$abs_dir/.gitignore" <<'EOF'
|
||||
.gradle/
|
||||
build/
|
||||
local.properties
|
||||
*.iml
|
||||
.idea/
|
||||
captures/
|
||||
.externalNativeBuild/
|
||||
.cxx/
|
||||
*.apk
|
||||
*.aab
|
||||
# NOTE: app/src/test/snapshots/ is committed (Roborazzi goldens are test refs).
|
||||
EOF
|
||||
|
||||
# ---- README.md ----
|
||||
cat > "$abs_dir/README.md" <<EOF
|
||||
# $name
|
||||
|
||||
$desc
|
||||
|
||||
Generado con \`init_kotlin_app\` del registry fn_registry.
|
||||
|
||||
## Requisitos
|
||||
|
||||
- Android SDK 34
|
||||
- JDK 17
|
||||
- Gradle 8.6 (via wrapper)
|
||||
- \`kotlin/functions/ui\` modulo del registry (composite build)
|
||||
|
||||
## Build rapido
|
||||
|
||||
\`\`\`bash
|
||||
fn run gradle_assemble_debug_bash_infra $rel_dir
|
||||
\`\`\`
|
||||
EOF
|
||||
|
||||
# ---- Git + Gitea ----
|
||||
if [[ -n "${GITEA_URL:-}" && -n "${GITEA_TOKEN:-}" ]]; then
|
||||
ensure_repo_synced "$abs_dir" "dataforge" "$name" "master" \
|
||||
"feat: scaffold $name via init_kotlin_app" || \
|
||||
echo "init_kotlin_app: warning — ensure_repo_synced fallo, repo no creado" >&2
|
||||
else
|
||||
echo "init_kotlin_app: GITEA_URL/GITEA_TOKEN no seteados, omitiendo creacion de repo Gitea" >&2
|
||||
(cd "$abs_dir" && git init -b master >/dev/null 2>&1 || git init >/dev/null 2>&1 \
|
||||
&& git add -A \
|
||||
&& git commit -m "feat: scaffold $name via init_kotlin_app" --quiet)
|
||||
fi
|
||||
|
||||
# ---- fn index si hay proyecto ----
|
||||
if [[ -n "$project" && -x "$FN_ROOT/fn" ]]; then
|
||||
(cd "$FN_ROOT" && ./fn index >/dev/null 2>&1) || \
|
||||
echo "init_kotlin_app: warning — fn index fallo" >&2
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "init_kotlin_app: $rel_dir creada"
|
||||
echo ""
|
||||
echo " Archivos:"
|
||||
echo " $rel_dir/settings.gradle.kts"
|
||||
echo " $rel_dir/app/build.gradle.kts"
|
||||
echo " $rel_dir/app/src/main/kotlin/$pkg_path/MainActivity.kt"
|
||||
echo " $rel_dir/app/src/test/kotlin/$pkg_path/ExampleScreenshotTest.kt"
|
||||
echo " $rel_dir/app/src/androidTest/kotlin/$pkg_path/MainActivityTest.kt"
|
||||
echo " $rel_dir/app.md"
|
||||
echo ""
|
||||
echo " Pasos siguientes:"
|
||||
echo " fn run gradle_unit_test_bash_infra $rel_dir"
|
||||
echo " fn run gradle_screenshot_test_bash_infra $rel_dir"
|
||||
echo " fn run gradle_assemble_debug_bash_infra $rel_dir"
|
||||
echo ""
|
||||
echo " Para tests instrumentados (emulador):"
|
||||
echo " fn run android_emulator_start_bash_infra Medium_Phone_API_35"
|
||||
echo " fn run gradle_instrumented_test_bash_infra $rel_dir"
|
||||
echo " fn run android_emulator_stop_bash_infra"
|
||||
echo ""
|
||||
echo " Package: $pkg_id"
|
||||
echo " FnTheme composite: $ui_rel_path"
|
||||
}
|
||||
|
||||
# Permitir invocacion directa via 'fn run init_kotlin_app ...'
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
init_kotlin_app "$@"
|
||||
fi
|
||||
@@ -0,0 +1,67 @@
|
||||
---
|
||||
name: run_kotlin_app_tests
|
||||
kind: pipeline
|
||||
lang: bash
|
||||
domain: pipelines
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "run_kotlin_app_tests(project_dir: string, avd_name?: string, --skip-emulator?, --no-stop?) -> int"
|
||||
description: "Pipeline e2e completo de testing app Kotlin: unit JVM + screenshot Roborazzi + build APK + instrumented Compose en emulador."
|
||||
tags: [android, kotlin, compose, test, e2e, launcher]
|
||||
uses_functions:
|
||||
- gradle_unit_test_bash_infra
|
||||
- gradle_screenshot_test_bash_infra
|
||||
- gradle_assemble_debug_bash_infra
|
||||
- gradle_instrumented_test_bash_infra
|
||||
- android_emulator_list_bash_infra
|
||||
- android_emulator_start_bash_infra
|
||||
- android_emulator_stop_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/pipelines/run_kotlin_app_tests.sh"
|
||||
params:
|
||||
- name: project_dir
|
||||
desc: "Raiz del proyecto Android. Debe contener gradlew. Puede ser relativo al cwd o absoluto."
|
||||
- name: avd_name
|
||||
desc: "AVD para instrumented tests. Default: Medium_Phone_API_35. Debe existir en la lista de AVDs del sistema. Ignorado si se pasa --skip-emulator."
|
||||
- name: --skip-emulator
|
||||
desc: "Saltar instrumented tests. El pipeline solo ejecuta unit tests, screenshot tests y build APK, luego sale con exit 0."
|
||||
- name: --no-stop
|
||||
desc: "No parar el emulador al finalizar los instrumented tests. Util en desarrollo iterativo para no esperar el arranque en la siguiente ejecucion."
|
||||
output: "Stdout con tabla resumen de cada step (nombre, OK/FAIL/SKIP, tiempo). Exit 0 = todos los tests pasan. Exit codes: 1=unit tests fallaron, 2=screenshot tests fallaron, 3=build APK fallado, 4=emulador no encontrado o no arranca, 5=instrumented tests fallaron."
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
# Suite completa con AVD por defecto
|
||||
bash bash/functions/pipelines/run_kotlin_app_tests.sh apps/my_kotlin_app
|
||||
|
||||
# Suite completa con AVD especifico
|
||||
bash bash/functions/pipelines/run_kotlin_app_tests.sh apps/my_kotlin_app Pixel_7_API_34
|
||||
|
||||
# Solo tests JVM (unit + screenshot + build), sin emulador
|
||||
bash bash/functions/pipelines/run_kotlin_app_tests.sh apps/my_kotlin_app --skip-emulator
|
||||
|
||||
# Suite completa, dejar emulador corriendo al final
|
||||
bash bash/functions/pipelines/run_kotlin_app_tests.sh apps/my_kotlin_app Medium_Phone_API_35 --no-stop
|
||||
|
||||
# Desde el launcher (fn run)
|
||||
fn run run_kotlin_app_tests apps/my_kotlin_app
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
- Fail-fast: si un paso falla, el pipeline imprime el resumen parcial y sale con el exit code del paso fallido. No continua al siguiente.
|
||||
- El orden de los flags tras `project_dir` es libre: `avd_name` es el primer argumento no-flag; `--skip-emulator` y `--no-stop` pueden aparecer en cualquier posicion.
|
||||
- El arranque del emulador usa `android_emulator_start` que es idempotente: si ya hay un emulador corriendo con ese AVD, no lanza otro.
|
||||
- `adb_wsl` se sourcea para resolver `$ADB` apuntando a `adb.exe` en Windows desde WSL2.
|
||||
- El paso `emulator_stop` se registra como SKIP en la tabla resumen cuando se pasa `--no-stop`.
|
||||
- Requiere WSL2 + Android SDK instalado en Windows. `ANDROID_HOME` o `~/android-sdk/env.sh` deben estar disponibles.
|
||||
@@ -0,0 +1,242 @@
|
||||
#!/usr/bin/env bash
|
||||
# run_kotlin_app_tests — Pipeline e2e completo de testing app Kotlin:
|
||||
# unit JVM + screenshot Roborazzi + build APK + instrumented Compose en emulador.
|
||||
#
|
||||
# USO:
|
||||
# bash run_kotlin_app_tests.sh <project_dir> [avd_name] [--skip-emulator] [--no-stop]
|
||||
#
|
||||
# ARGUMENTOS:
|
||||
# project_dir Raiz del proyecto Android (debe contener gradlew). Obligatorio.
|
||||
# avd_name Nombre del AVD para instrumented tests. Default: Medium_Phone_API_35.
|
||||
# --skip-emulator Saltar instrumented tests (solo unit + screenshot + build).
|
||||
# --no-stop No parar el emulador al finalizar (util en desarrollo iterativo).
|
||||
#
|
||||
# EXIT CODES:
|
||||
# 0 Todos los tests pasan.
|
||||
# 1 Unit tests fallaron.
|
||||
# 2 Screenshot tests fallaron.
|
||||
# 3 Build APK fallado.
|
||||
# 4 AVD no encontrado.
|
||||
# 5 Instrumented tests fallaron.
|
||||
#
|
||||
# EJEMPLO:
|
||||
# bash bash/functions/pipelines/run_kotlin_app_tests.sh apps/my_app
|
||||
# bash bash/functions/pipelines/run_kotlin_app_tests.sh apps/my_app Pixel_7_API_34
|
||||
# bash bash/functions/pipelines/run_kotlin_app_tests.sh apps/my_app --skip-emulator
|
||||
# bash bash/functions/pipelines/run_kotlin_app_tests.sh apps/my_app Medium_Phone_API_35 --no-stop
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REGISTRY_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Parseo de argumentos
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
PROJECT_DIR="${1:-}"
|
||||
AVD_NAME="Medium_Phone_API_35"
|
||||
SKIP_EMULATOR=false
|
||||
NO_STOP=false
|
||||
|
||||
# Primer argumento posicional es project_dir; el resto puede ser flags o avd_name.
|
||||
shift || true
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--skip-emulator) SKIP_EMULATOR=true ;;
|
||||
--no-stop) NO_STOP=true ;;
|
||||
--*)
|
||||
echo "[run_kotlin_app_tests] ERROR: flag desconocido: $arg" >&2
|
||||
echo "USO: $0 <project_dir> [avd_name] [--skip-emulator] [--no-stop]" >&2
|
||||
exit 1
|
||||
;;
|
||||
*) AVD_NAME="$arg" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$PROJECT_DIR" ]]; then
|
||||
echo "[run_kotlin_app_tests] ERROR: project_dir es obligatorio." >&2
|
||||
echo "USO: $0 <project_dir> [avd_name] [--skip-emulator] [--no-stop]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Resolver path absoluto
|
||||
if [[ "$PROJECT_DIR" != /* ]]; then
|
||||
PROJECT_DIR="$(pwd)/$PROJECT_DIR"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Validacion inicial
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
if [[ ! -f "$PROJECT_DIR/gradlew" ]]; then
|
||||
echo "[run_kotlin_app_tests] ERROR: no se encontro gradlew en $PROJECT_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "======================================================================"
|
||||
echo " run_kotlin_app_tests"
|
||||
echo "======================================================================"
|
||||
echo " project_dir : $PROJECT_DIR"
|
||||
echo " avd_name : $AVD_NAME"
|
||||
echo " skip_emulator : $SKIP_EMULATOR"
|
||||
echo " no_stop : $NO_STOP"
|
||||
echo "======================================================================"
|
||||
echo ""
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Tabla de resultados acumulada
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# Arrays paralelos: nombre, status, tiempo
|
||||
STEP_NAMES=()
|
||||
STEP_STATUS=()
|
||||
STEP_TIMES=()
|
||||
|
||||
record_step() {
|
||||
local name="$1" status="$2" elapsed="$3"
|
||||
STEP_NAMES+=("$name")
|
||||
STEP_STATUS+=("$status")
|
||||
STEP_TIMES+=("${elapsed}s")
|
||||
}
|
||||
|
||||
print_summary() {
|
||||
echo ""
|
||||
echo "======================================================================"
|
||||
echo " RESUMEN"
|
||||
printf " %-30s %-6s %s\n" "STEP" "STATUS" "TIEMPO"
|
||||
echo " ------------------------------ ------ ------"
|
||||
for i in "${!STEP_NAMES[@]}"; do
|
||||
printf " %-30s %-6s %s\n" "${STEP_NAMES[$i]}" "${STEP_STATUS[$i]}" "${STEP_TIMES[$i]}"
|
||||
done
|
||||
echo "======================================================================"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Paso 1: Unit tests (JVM)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
echo "[run_kotlin_app_tests] [1/4] Unit tests (JVM)..."
|
||||
T_START=$SECONDS
|
||||
if bash "$REGISTRY_ROOT/bash/functions/infra/gradle_unit_test.sh" "$PROJECT_DIR"; then
|
||||
record_step "unit_tests" "OK" $((SECONDS - T_START))
|
||||
echo "[run_kotlin_app_tests] Unit tests: OK"
|
||||
else
|
||||
record_step "unit_tests" "FAIL" $((SECONDS - T_START))
|
||||
print_summary
|
||||
echo "[run_kotlin_app_tests] ERROR: unit tests fallaron." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Paso 2: Screenshot tests (Roborazzi, JVM)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
echo ""
|
||||
echo "[run_kotlin_app_tests] [2/4] Screenshot tests (Roborazzi, JVM)..."
|
||||
T_START=$SECONDS
|
||||
if bash "$REGISTRY_ROOT/bash/functions/infra/gradle_screenshot_test.sh" "$PROJECT_DIR"; then
|
||||
record_step "screenshot_tests" "OK" $((SECONDS - T_START))
|
||||
echo "[run_kotlin_app_tests] Screenshot tests: OK"
|
||||
else
|
||||
record_step "screenshot_tests" "FAIL" $((SECONDS - T_START))
|
||||
print_summary
|
||||
echo "[run_kotlin_app_tests] ERROR: screenshot tests fallaron." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Paso 3: Build APK debug
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
echo ""
|
||||
echo "[run_kotlin_app_tests] [3/4] Build APK debug..."
|
||||
T_START=$SECONDS
|
||||
if bash "$REGISTRY_ROOT/bash/functions/infra/gradle_assemble_debug.sh" "$PROJECT_DIR"; then
|
||||
record_step "assemble_debug" "OK" $((SECONDS - T_START))
|
||||
echo "[run_kotlin_app_tests] Build APK: OK"
|
||||
else
|
||||
record_step "assemble_debug" "FAIL" $((SECONDS - T_START))
|
||||
print_summary
|
||||
echo "[run_kotlin_app_tests] ERROR: build APK fallado." >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Paso 4: Instrumented tests (emulador)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
if [[ "$SKIP_EMULATOR" == "true" ]]; then
|
||||
record_step "instrumented_tests" "SKIP" 0
|
||||
print_summary
|
||||
echo "[run_kotlin_app_tests] --skip-emulator activo. Pipeline completo (sin instrumented)."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "[run_kotlin_app_tests] [4/4] Instrumented tests en emulador '$AVD_NAME'..."
|
||||
|
||||
# Source adb_wsl para resolver $ADB y helpers de dispositivo
|
||||
# shellcheck source=../infra/adb_wsl.sh
|
||||
source "$REGISTRY_ROOT/bash/functions/infra/adb_wsl.sh"
|
||||
|
||||
# Verificar que el AVD existe
|
||||
echo "[run_kotlin_app_tests] Verificando AVD '$AVD_NAME'..."
|
||||
if ! bash "$REGISTRY_ROOT/bash/functions/infra/android_emulator_list.sh" | grep -qx "$AVD_NAME"; then
|
||||
record_step "emulator_check" "FAIL" 0
|
||||
record_step "instrumented_tests" "SKIP" 0
|
||||
print_summary
|
||||
echo "[run_kotlin_app_tests] ERROR: AVD '$AVD_NAME' no encontrado." >&2
|
||||
echo " AVDs disponibles:" >&2
|
||||
bash "$REGISTRY_ROOT/bash/functions/infra/android_emulator_list.sh" | sed 's/^/ /' >&2
|
||||
exit 4
|
||||
fi
|
||||
record_step "emulator_check" "OK" 0
|
||||
|
||||
# Arrancar emulador (idempotente)
|
||||
echo "[run_kotlin_app_tests] Arrancando emulador '$AVD_NAME' (idempotente)..."
|
||||
T_START=$SECONDS
|
||||
if ! bash "$REGISTRY_ROOT/bash/functions/infra/android_emulator_start.sh" "$AVD_NAME"; then
|
||||
record_step "emulator_start" "FAIL" $((SECONDS - T_START))
|
||||
print_summary
|
||||
echo "[run_kotlin_app_tests] ERROR: no se pudo arrancar el emulador." >&2
|
||||
exit 4
|
||||
fi
|
||||
record_step "emulator_start" "OK" $((SECONDS - T_START))
|
||||
|
||||
# Correr instrumented tests
|
||||
echo "[run_kotlin_app_tests] Corriendo instrumented tests..."
|
||||
T_START=$SECONDS
|
||||
INSTRUMENTED_EXIT=0
|
||||
bash "$REGISTRY_ROOT/bash/functions/infra/gradle_instrumented_test.sh" "$PROJECT_DIR" || INSTRUMENTED_EXIT=$?
|
||||
|
||||
if [[ $INSTRUMENTED_EXIT -eq 0 ]]; then
|
||||
record_step "instrumented_tests" "OK" $((SECONDS - T_START))
|
||||
echo "[run_kotlin_app_tests] Instrumented tests: OK"
|
||||
else
|
||||
record_step "instrumented_tests" "FAIL" $((SECONDS - T_START))
|
||||
fi
|
||||
|
||||
# Parar emulador (salvo --no-stop)
|
||||
if [[ "$NO_STOP" == "false" ]]; then
|
||||
echo "[run_kotlin_app_tests] Parando emulador..."
|
||||
T_START=$SECONDS
|
||||
bash "$REGISTRY_ROOT/bash/functions/infra/android_emulator_stop.sh" || true
|
||||
record_step "emulator_stop" "OK" $((SECONDS - T_START))
|
||||
else
|
||||
record_step "emulator_stop" "SKIP" 0
|
||||
echo "[run_kotlin_app_tests] --no-stop activo: emulador sigue corriendo."
|
||||
fi
|
||||
|
||||
print_summary
|
||||
|
||||
if [[ $INSTRUMENTED_EXIT -ne 0 ]]; then
|
||||
echo "[run_kotlin_app_tests] ERROR: instrumented tests fallaron." >&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
echo "[run_kotlin_app_tests] Pipeline e2e completado con exito."
|
||||
exit 0
|
||||
Binary file not shown.
+251
@@ -0,0 +1,251 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH="\\\"\\\""
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Reference in New Issue
Block a user