diff options
author | Cole Faust <colefaust@google.com> | 2021-01-23 02:39:37 +0000 |
---|---|---|
committer | Cole Faust <colefaust@google.com> | 2021-01-26 01:50:18 +0000 |
commit | 24c36dbeecf4398c4da8901a047f9708676f3d9b (patch) | |
tree | 6cc3869685889710b0cf5ac03148cd689f069433 /envsetup.sh | |
parent | caf8f60ae41dfe02a91b722f26dc8fe2af93c39b (diff) |
Add outmod and installmod commands
These are analogs to pathmod/gomod that find/install
the module's apk instead of cd'ing to its source
directory.
Bug: None
Change-Id: Iad750e154397f7cfcdd620f1ed6478b05c1225bb
Test: Manually, with bash and zsh
Diffstat (limited to 'envsetup.sh')
-rw-r--r-- | envsetup.sh | 81 |
1 files changed, 68 insertions, 13 deletions
diff --git a/envsetup.sh b/envsetup.sh index 8fa608becb..c03e2cb7d2 100644 --- a/envsetup.sh +++ b/envsetup.sh @@ -33,7 +33,9 @@ Invoke ". build/envsetup.sh" from your shell to add the following functions to y - allmod: List all modules. - gomod: Go to the directory containing a module. - pathmod: Get the directory containing a module. -- refreshmod: Refresh list of modules for allmod/gomod/pathmod. +- outmod: Gets the location of a module's installed outputs with a certain extension. +- installmod: Adb installs a module's built APK. +- refreshmod: Refresh list of modules for allmod/gomod/pathmod/outmod/installmod. - syswrite: Remount partitions (e.g. system.img) as writable, rebooting if necessary. Environment options: @@ -411,7 +413,10 @@ function addcompletions() fi complete -F _lunch lunch + complete -F _complete_android_module_names pathmod complete -F _complete_android_module_names gomod + complete -F _complete_android_module_names outmod + complete -F _complete_android_module_names installmod complete -F _complete_android_module_names m } @@ -1378,9 +1383,8 @@ function refreshmod() { > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1 } -# List all modules for the current device, as cached in module-info.json. If any build change is -# made and it should be reflected in the output, you should run 'refreshmod' first. -function allmod() { +# Verifies that module-info.txt exists, creating it if it doesn't. +function verifymodinfo() { if [ ! "$ANDROID_PRODUCT_OUT" ]; then echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2 return 1 @@ -1390,6 +1394,12 @@ function allmod() { echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2 refreshmod || return 1 fi +} + +# List all modules for the current device, as cached in module-info.json. If any build change is +# made and it should be reflected in the output, you should run 'refreshmod' first. +function allmod() { + verifymodinfo || return 1 python -c "import json; print('\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys())))" } @@ -1397,20 +1407,12 @@ function allmod() { # Get the path of a specific module in the android tree, as cached in module-info.json. If any build change # is made, and it should be reflected in the output, you should run 'refreshmod' first. function pathmod() { - if [ ! "$ANDROID_PRODUCT_OUT" ]; then - echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2 - return 1 - fi - if [[ $# -ne 1 ]]; then echo "usage: pathmod <module>" >&2 return 1 fi - if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then - echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2 - refreshmod || return 1 - fi + verifymodinfo || return 1 local relpath=$(python -c "import json, os module = '$1' @@ -1442,6 +1444,59 @@ function gomod() { cd $path } +# Gets the list of a module's installed outputs, as cached in module-info.json. +# If any build change is made, and it should be reflected in the output, you should run 'refreshmod' first. +function outmod() { + if [[ $# -ne 1 ]]; then + echo "usage: outmod <module>" >&2 + return 1 + fi + + verifymodinfo || return 1 + + local relpath + relpath=$(python -c "import json, os +module = '$1' +module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')) +if module not in module_info: + exit(1) +for output in module_info[module]['installed']: + print(os.path.join('$ANDROID_BUILD_TOP', output))" 2>/dev/null) + + if [ $? -ne 0 ]; then + echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)" >&2 + return 1 + elif [ ! -z "$relpath" ]; then + echo "$relpath" + fi +} + +# adb install a module's apk, as cached in module-info.json. If any build change +# is made, and it should be reflected in the output, you should run 'refreshmod' first. +# Usage: installmod [adb install arguments] <module> +# For example: installmod -r Dialer -> adb install -r /path/to/Dialer.apk +function installmod() { + if [[ $# -eq 0 ]]; then + echo "usage: installmod [adb install arguments] <module>" >&2 + return 1 + fi + + local _path + _path=$(outmod ${@:$#:1}) + if [ $? -ne 0 ]; then + return 1 + fi + + _path=$(echo "$_path" | grep -E \\.apk$ | head -n 1) + if [ -z "$_path" ]; then + echo "Module '$1' does not produce a file ending with .apk (try 'refreshmod' if there have been build changes?)" >&2 + return 1 + fi + local length=$(( $# - 1 )) + echo adb install ${@:1:$length} $_path + adb install ${@:1:$length} $_path +} + function _complete_android_module_names() { local word=${COMP_WORDS[COMP_CWORD]} COMPREPLY=( $(allmod | grep -E "^$word") ) |