Skip to content

Commit

Permalink
all: support extra commands, vab <cmd> where <cmd> comes from `va…
Browse files Browse the repository at this point in the history
…b install extra user/vab-<cmd>` (#319)

* vab: use notices for deploy hints

* docs: add "Extending vab" section

* tests: add `v check-md` to `vab test-all`

* paths: add `data()` path based on `os.data_dir()`

* vab: make suggestions if no input could be matched

* doctor: show extra commands with source and hash
  • Loading branch information
larpon authored Oct 11, 2024
1 parent 5800886 commit 08562dc
Show file tree
Hide file tree
Showing 18 changed files with 943 additions and 81 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,65 @@ jobs:
vab examples/sokol/particles -o apks/particles.apk
[ -f apks/particles.apk ]
ubuntu-latest-extra-command:
runs-on: ubuntu-latest
timeout-minutes: 10
env:
VFLAGS: -d vab_allow_extra_commands
VAB_FLAGS: -v 3
steps:
- name: Checkout V
uses: actions/checkout@v4
with:
repository: vlang/v

- name: Build local v
run: make -j4 && sudo ./v symlink

- name: Install dependencies
run: |
v retry -- sudo apt-get update
v retry -- sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev
v retry -- sudo apt-get install --quiet -y libsdl2-mixer-dev libsdl2-image-dev
- name: Checkout SDL
uses: actions/checkout@v4
with:
repository: vlang/sdl
fetch-depth: 0
path: sdl

- name: Simulate "v install sdl"
run: mv sdl ~/.vmodules

- name: Setup vlang/sdl
run: v ~/.vmodules/sdl/setup.vsh

- name: Checkout vab
uses: actions/checkout@v4
with:
path: vab

- name: Install vab
run: |
mv vab ~/.vmodules
v -g ~/.vmodules/vab
sudo ln -s ~/.vmodules/vab/vab /usr/local/bin/vab
- name: Run 'vab --help'
run: vab --help

- name: Install extra command
run: |
vab install extra larpon/vab-sdl
- name: Run vab doctor
run: vab doctor

- name: Test extra command
run: |
vab sdl doctor
ubuntu-latest-vab-can-live-anywhere:
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci_emulator_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:
- name: Run vab --help
run: vab --help

- name: Run vab doctor *before*
run: vab doctor

- name: Install dependencies
run: |
v retry -- sudo apt update
Expand All @@ -66,7 +69,7 @@ jobs:
vab install bundletool
vab install aapt2
- name: Run vab doctor
- name: Run vab doctor *after*
run: vab doctor

- name: Cache emulator
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,16 @@ in the [FAQ](docs/FAQ.md).
# Tests

`vab`, like many other V modules, can be tested with `v test .`.

Note that `vab` has *runtime* tests that requires all [runtime dependencies](#runtime-dependencies)
to be installed in order for the tests to run correctly.
Runtime tests can be run with `vab test-runtime` (also part of `vab test-all`).

# Extending `vab`

The `vab` command-line tool can be extended with custom user commands.
See the "[Extending `vab`](docs/docs.md#extending-vab)" section
in the [documentation](docs/docs.md).

# Notes

Expand Down
55 changes: 50 additions & 5 deletions android/emulator/emulator.v
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ pub fn (o &Options) validate() ! {
if o.avd == '' {
return error('${@MOD}.${@STRUCT}.${@FN}: No Android Virtual Device (avd) sat')
}
avdmanager := env.avdmanager()
avdmanager_list_cmd := [avdmanager, 'list', 'avd', '-c']
util.verbosity_print_cmd(avdmanager_list_cmd, o.verbosity)
avdmanager_list := util.run_or_error(avdmanager_list_cmd)!
avds := avdmanager_list.split('\n')
avds := Emulator.list_avds()!
if o.avd !in avds {
return error('${@MOD}.${@STRUCT}.${@FN}: Android Virtual Device (avd) "${o.avd}" not found.')
}
Expand Down Expand Up @@ -128,6 +124,55 @@ pub fn (mut e Emulator) start(options Options) ! {
}
}

// has_avd returns `true` if `avd_name` can be found. Use `list_avds` to see all locations of AVD's
pub fn Emulator.has_avd(avd_name string) bool {
avds := Emulator.list_avds() or { return false }
return avd_name in avds.keys()
}

// list_avds returns a list of devices detected by running `emulator -list-avds`
// NOTE: for Google reasons, this list can be different from `avdmanager list avd -c`...
pub fn Emulator.list_avds() !map[string]string {
emulator_exe := env.emulator()
list_cmd := [emulator_exe, '-list-avds']
list_res := util.run_or_error(list_cmd)!
list := list_res.split('\n').filter(it != '').filter(!it.contains(' '))
mut m := map[string]string{}
for entry in list {
m[entry] = entry // TODO: should be a path to the AVD...
}
return m
// TODO: find out how to fix this dumb mess for users
// if vab_test_avd !in avds {
// Locating a deterministic location of AVD's has, like so many other Android related things, become a mess.
// (`avdmanager` can put them in places that the `emulator` does not pickup on the *same* host etc... Typical Google-mess)
// ... even passing `--path` to `avdmanager` does not work.
// Here we try a few places and set `ANDROID_AVD_HOME` to make runs a bit more predictable.
// mut avd_home := os.join_path(os.home_dir(), '.android', 'avd')
// eprintln('warning: "${vab_test_avd}" still not in list: ${avds}... trying new location "${avd_home}"')
// os.setenv('ANDROID_AVD_HOME', avd_home, true)
//
// avds = emulator.Emulator.list_avds() or {
// eprintln('${exe_name} error: ${err}')
// exit(1)
// }
// if vab_test_avd !in avds {
// config_dir := os.config_dir() or {
// eprintln('${exe_name} error: ${err}')
// exit(1)
// }
// avd_home = os.join_path(config_dir, '.android', 'avd')
// eprintln('warning: "${vab_test_avd}" still not in list: ${avds}... trying new location "${avd_home}"')
// os.setenv('ANDROID_AVD_HOME', avd_home, true)
//
// avds = emulator.Emulator.list_avds() or {
// eprintln('${exe_name} error: ${err}')
// exit(1)
// }
// }
// }
}

// wait_for_boot blocks execution and waits for the emulator to boot.
// NOTE: this feature is unique to emulator devices.
pub fn (mut e Emulator) wait_for_boot() ! {
Expand Down
Loading

0 comments on commit 08562dc

Please sign in to comment.