function gettop { local TOPFILE=build/core/envsetup.mk if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then # The following circumlocution ensures we remove symlinks from TOP. (cd$TOP; PWD= /bin/pwd) else if [ -f $TOPFILE ] ; then # The following circumlocution (repeated below as well) ensures # that we record the true directory name and not one that is # faked up with symlink names. PWD= /bin/pwd else local HERE=$PWD T= while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do \cd .. T=`PWD= /bin/pwd -P` done \cd$HERE if [ -f "$T/$TOPFILE" ]; then echo$T fi fi fi }
functiongodir () { if [[ -z "$1" ]]; then echo"Usage: godir <regex>" return fi T=$(gettop) if [[ ! -f $T/filelist ]]; then echo -n "Creating index..." (\cd$T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist) echo" Done" echo"" fi
local lines
lines=($(\grep "$1"$T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq)) if [[ ${#lines[@]} = 0 ]]; then echo"Not found" return fi
local pathname local choice
if [[ ${#lines[@]} > 1 ]]; then while [[ -z "$pathname" ]]; do local index=1 local line for line in${lines[@]}; do printf"%6s %s\n""[$index]"$line index=$(($index + 1)) done
echo echo -n "Select one: "
unset choice read choice
if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then echo"Invalid choice" continue fi
pathname=${lines[$(($choice-1))]} done else pathname=${lines[0]} fi
if [ "x$SHELL" != "x/bin/bash" ]; then case `ps -o command -p $$` in bash) ;; *) echo"WARNING: Only bash is supported, use of other shell would lead to erroneous results" ;; esac fi
if [ "$1" ] ; then answer=$1 else print_lunch_menu echo -n "Which would you like? [aosp_arm-eng] " read answer fi
local selection= if [ -z "$answer" ] then selection=aosp_arm-eng elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$") then if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ] then selection=${LUNCH_MENU_CHOICES[$(($answer-1))]} fi elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$") then selection=$answer fi
if [ -z "$selection" ] then echo echo"Invalid lunch combo: $answer" return 1 fi
export TARGET_BUILD_APPS= local product=$(echo -n $selection | sed -e "s/-.*$//") check_product $product
if [ $? -ne 0 ] then echo echo"** Don't have a product spec for: '$product'" echo"** Do you have the right repo manifest?" product= fi
local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//") check_variant $variant
if [ $? -ne 0 ] then echo echo"** Invalid variant: '$variant'" echo"** Must be one of ${VARIANT_CHOICES[@]}" variant= fi
if [ -z "$product" -o -z "$variant" ] then echo return 1 fi