forked from openkylin/platform_build
Add functions to jump to specific modules.
Usage: ...aosp/$ gomod libbase ...aosp/system/core/base$ Using in alias: alias g=gomod complete -F _complete-android-module-names g ...aosp/$ g libbase ...aosp/system/core/base$ Nothing in Android keeps an up to date index of all Android modules and their locations between builds. However, there is a target 'module-info.json' which is used to contain some of that information. This module can be updated using the command 'refreshmod' added here, but it will also be updated during a normal Android build. This also adds auto-complete for m. Bug: N/A Test: manual Change-Id: I06b0b87c308b9fe2798dbc29225906cc30fe59fe
This commit is contained in:
parent
5fbe6abfb7
commit
62054a43fa
77
envsetup.sh
77
envsetup.sh
|
@ -26,6 +26,9 @@ Invoke ". build/envsetup.sh" from your shell to add the following functions to y
|
||||||
- sepgrep: Greps on all local sepolicy files.
|
- sepgrep: Greps on all local sepolicy files.
|
||||||
- sgrep: Greps on all local source files.
|
- sgrep: Greps on all local source files.
|
||||||
- godir: Go to the directory containing a file.
|
- godir: Go to the directory containing a file.
|
||||||
|
- allmod: List all modules.
|
||||||
|
- gomod: Go to the directory containing a module.
|
||||||
|
- refreshmod: Refresh list of modules for allmod/gomod.
|
||||||
|
|
||||||
Environment options:
|
Environment options:
|
||||||
- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
|
- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
|
||||||
|
@ -359,6 +362,9 @@ function addcompletions()
|
||||||
complete -C "bit --tab" bit
|
complete -C "bit --tab" bit
|
||||||
fi
|
fi
|
||||||
complete -F _lunch lunch
|
complete -F _lunch lunch
|
||||||
|
|
||||||
|
complete -F _complete-android-module-names gomod
|
||||||
|
complete -F _complete-android-module-names m
|
||||||
}
|
}
|
||||||
|
|
||||||
function choosetype()
|
function choosetype()
|
||||||
|
@ -1463,6 +1469,77 @@ function godir () {
|
||||||
\cd $T/$pathname
|
\cd $T/$pathname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Update module-info.json in out.
|
||||||
|
function refreshmod() {
|
||||||
|
if [ ! "$ANDROID_PRODUCT_OUT" ]; then
|
||||||
|
echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
|
||||||
|
|
||||||
|
# for the output of the next command
|
||||||
|
mkdir -p $ANDROID_PRODUCT_OUT || return 1
|
||||||
|
|
||||||
|
# Note, can't use absolute path because of the way make works.
|
||||||
|
m out/target/product/$(get_build_var TARGET_DEVICE)/module-info.json \
|
||||||
|
> $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() {
|
||||||
|
if [ ! "$ANDROID_PRODUCT_OUT" ]; then
|
||||||
|
echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&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
|
||||||
|
|
||||||
|
python -c "import json; print '\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys()))"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Go to 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 gomod() {
|
||||||
|
if [ ! "$ANDROID_PRODUCT_OUT" ]; then
|
||||||
|
echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $# -ne 1 ]]; then
|
||||||
|
echo "usage: gomod <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
|
||||||
|
|
||||||
|
local 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)
|
||||||
|
print module_info[module]['path'][0]" 2>/dev/null)
|
||||||
|
|
||||||
|
if [ -z "$relpath" ]; then
|
||||||
|
echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
cd $ANDROID_BUILD_TOP/$relpath
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function _complete-android-module-names() {
|
||||||
|
local word=${COMP_WORDS[COMP_CWORD]}
|
||||||
|
COMPREPLY=( $(allmod | grep -E "^$word") )
|
||||||
|
}
|
||||||
|
|
||||||
# Print colored exit condition
|
# Print colored exit condition
|
||||||
function pez {
|
function pez {
|
||||||
"$@"
|
"$@"
|
||||||
|
|
Loading…
Reference in New Issue