Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6966bbb6 authored by Steven Moreland's avatar Steven Moreland Committed by android-build-merger
Browse files

Merge "Add functions to jump to specific modules."

am: 4ea66801

Change-Id: I994dcab9f6e6e46290a53a133ce6f7a7f1b10067
parents 9be41822 4ea66801
Loading
Loading
Loading
Loading
+99 −22
Original line number Diff line number Diff line
@@ -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.
- sgrep:      Greps on all local source files.
- 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:
- 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
    fi
    complete -F _lunch lunch

    complete -F _complete-android-module-names gomod
    complete -F _complete-android-module-names m
}

function choosetype()
@@ -1463,6 +1469,77 @@ function godir () {
    \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
function pez {
    "$@"