Skip to content

Commit

Permalink
vab, cli: refactor flag parsing, deprecate programmatic `flag.FlagPar…
Browse files Browse the repository at this point in the history
…ser` usage (#294)
  • Loading branch information
larpon authored Sep 9, 2024
1 parent 8d60541 commit c47c4e8
Show file tree
Hide file tree
Showing 7 changed files with 417 additions and 104 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/ci_emulator_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
# Don't set Java > 8 here (emulator can't be started otherwise, lol) #export JAVA_HOME=$JAVA_HOME_11_X64
#pgrep emulator >/dev/null 2>&1 ||
$ANDROID_SDK_ROOT/emulator/emulator -avd test -no-snapshot -no-window -no-boot-anim -camera-back emulated -camera-front emulated -gpu swiftshader_indirect &
$ANDROID_SDK_ROOT/emulator/emulator -avd test -no-metrics -no-snapshot -no-window -no-boot-anim -camera-back emulated -camera-front emulated -gpu swiftshader_indirect &
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
# Remove packages here if cache is run, and emulator failed
Expand All @@ -101,8 +101,12 @@ jobs:
git clone --depth 1 https://github.com/vlang/v
# Test deployment of single file *after* build
vab --name "V DEPLOY TEST APK" v/examples/gg/bezier.v && vab v_deploy_test_apk.apk
vab --package aab --name "V DEPLOY TEST AAB" v/examples/gg/bezier.v && vab v_deploy_test_aab.aab
echo "Testing vab deployment *after* build"
vab --package-id "io.v.ci.vab.apk.deploytest" --name "V DEPLOY TEST APK" v/examples/gg/bezier.v && vab v_deploy_test_apk.apk
vab --package-id "io.v.ci.vab.aab.deploytest" --name "V DEPLOY TEST AAB" --package aab v/examples/gg/bezier.v && vab v_deploy_test_aab.aab
# Remove app in case cache is run
adb uninstall --user 0 "io.v.ci.vab.apk.deploytest"
adb uninstall --user 0 "io.v.ci.vab.aab.deploytest"
# 'flappylearning' can build but running is currently broken on Android
# Skip fireworks for now
Expand Down
39 changes: 37 additions & 2 deletions cli/cli.v
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@ The following flags does the same as if they were passed to the "v" compiler:
-autofree, -gc <type>, -g, -cg, -prod, -showcc, -skip-unused
Sub-commands:
doctor Display useful info about your system for bug reports'
doctor Display useful info about your system,
(useful for bug reports)
install Install various components. Example:
`vab install "platforms;android-21"'

pub const exe_git_hash = vab_commit_hash()
pub const work_directory = vab_tmp_work_dir()
pub const cache_directory = vab_cache_dir()
pub const rip_vflags = ['-autofree', '-gc', '-g', '-cg', '-prod', 'run', '-showcc', '-skip-unused']
pub const rip_vflags = ['-autofree', '-gc', '-g', '-cg', '-prod', 'run', '-showcc', '-skip-unused'] // NOTE this can be removed when the deprecated `cli.args_to_options()` is removed
pub const special_v_args = ['-autofree', '-gc', '-g', '-cg', '-prod', 'run', '-showcc',
'-skip-unused']
pub const special_flags = ['-v', '--verbosity', '--archs']
pub const subcmds = ['complete', 'test-cleancode']
pub const subcmds_builtin = ['doctor', 'install']
pub const accepted_input_files = ['.v', '.apk', '.aab']

pub const vab_env_vars = [
Expand All @@ -48,8 +55,33 @@ pub const vab_env_vars = [
'VMODULES',
]

pub const vab_documentation_config = flag.DocConfig{
version: '${exe_short_name} ${version_full()}'
description: exe_description
options: flag.DocOptions{
compact: true
}
fields: {
'--gles-version': 'GLES version to use from any of ${android.supported_gles_versions}'
'--package-format': 'App package format. Any of ${android.supported_package_formats}'
'--archs': 'Comma separated string with any of:\n${android.default_archs}'
}
}

// run_vab_sub_command runs and exits a sub-command if found in `args`
pub fn run_vab_sub_command(args []string) {
// Indentify sub-commands.
for subcmd in cli.subcmds {
if subcmd in args {
// First encountered known sub-command is executed on the spot.
exit(launch_cmd(args[args.index(subcmd)..]))
}
}
}

// args_to_options returns an `Option` merged from (CLI/Shell) `arguments` using `defaults` as
// values where no value can be obtained from `arguments`.
@[deprecated: 'use options_from_arguments and run_vab_sub_command instead']
pub fn args_to_options(arguments []string, defaults Options) !(Options, &flag.FlagParser) {
mut args := arguments.clone()

Expand All @@ -69,6 +101,9 @@ pub fn args_to_options(arguments []string, defaults Options) !(Options, &flag.Fl
if special_flag in args {
if special_flag == '-gc' {
gc_type := args[(args.index(special_flag)) + 1]
if gc_type.starts_with('-') {
return error('flag `-gc` requires an non-flag argument')
}
v_flags << special_flag + ' ${gc_type}'
args.delete(args.index(special_flag) + 1)
} else if special_flag.starts_with('-') {
Expand Down
3 changes: 2 additions & 1 deletion cli/doctor.v
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ pub fn doctor(opt Options) {
println('${exe_short_name}
Version ${exe_version} ${exe_git_hash}
Path "${exe_dir}"
Base files "${default_base_files_path}"')
Base files "${default_base_files_path}"
os.args: ${os.args}')

// Shell environment
print_var_if_set := fn (vars map[string]string, var_name string) {
Expand Down
Loading

0 comments on commit c47c4e8

Please sign in to comment.