aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Tang2018-06-19 03:34:41 -0500
committerJim Tang2018-07-17 01:27:32 -0500
commita881a257ca29bfd10aca120f4d203377fd8ac1bc (patch)
treeff36fb766b25841cdef0d8d95b0e4d51d343b1f5 /envsetup.sh
parent226dd7183649f480dd3e9592ecc91aabd08152e1 (diff)
downloadplatform-build-a881a257ca29bfd10aca120f4d203377fd8ac1bc.tar.gz
platform-build-a881a257ca29bfd10aca120f4d203377fd8ac1bc.tar.xz
platform-build-a881a257ca29bfd10aca120f4d203377fd8ac1bc.zip
Add Atest tab completion script.
Now Atest can autocomplete module names, dir and filenames with tab completion, and zsh users can benefit from it. Bug: 110629292 Test: In both bash and zsh environments: source build/envsetup.sh && lunch aosp_arm-eng atest <tab><tab> # has candidates adb <tab><tab> # has candidates ENVSETUP_NO_COMPLETION=atest:adb . build/envsetup.sh && lunch aosp_arm-eng atest <tab><tab> # no candidates adb <tab><tab> # no candidates Change-Id: Ib1c9e02feeb8aaf75c0b97821ae26e13ba8df350
Diffstat (limited to 'envsetup.sh')
-rw-r--r--envsetup.sh70
1 files changed, 44 insertions, 26 deletions
diff --git a/envsetup.sh b/envsetup.sh
index 12168e122..58941440b 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -48,12 +48,12 @@ function build_build_var_cache()
48{ 48{
49 local T=$(gettop) 49 local T=$(gettop)
50 # Grep out the variable names from the script. 50 # Grep out the variable names from the script.
51 cached_vars=`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '` 51 cached_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`)
52 cached_abs_vars=`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_abs_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '` 52 cached_abs_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_abs_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`)
53 # Call the build system to dump the "<val>=<value>" pairs as a shell script. 53 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
54 build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \ 54 build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \
55 --vars="$cached_vars" \ 55 --vars="${cached_vars[*]}" \
56 --abs-vars="$cached_abs_vars" \ 56 --abs-vars="${cached_abs_vars[*]}" \
57 --var-prefix=var_cache_ \ 57 --var-prefix=var_cache_ \
58 --abs-var-prefix=abs_var_cache_` 58 --abs-var-prefix=abs_var_cache_`
59 local ret=$? 59 local ret=$?
@@ -317,11 +317,11 @@ function set_sequence_number()
317 317
318# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not. 318# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
319function should_add_completion() { 319function should_add_completion() {
320 local cmd="$1" 320 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
321 case :"$ENVSETUP_NO_COMPLETION": in 321 case :"$ENVSETUP_NO_COMPLETION": in
322 *:"$cmd":*) 322 *:"$cmd":*)
323 return 1 323 return 1
324 ;; 324 ;;
325 esac 325 esac
326 return 0 326 return 0
327} 327}
@@ -330,22 +330,27 @@ function addcompletions()
330{ 330{
331 local T dir f 331 local T dir f
332 332
333 # Keep us from trying to run in something that isn't bash. 333 # Keep us from trying to run in something that's neither bash nor zsh.
334 if [ -z "${BASH_VERSION}" ]; then 334 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
335 return 335 return
336 fi 336 fi
337 337
338 # Keep us from trying to run in bash that's too old. 338 # Keep us from trying to run in bash that's too old.
339 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then 339 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
340 return 340 return
341 fi 341 fi
342 342
343 local completion_files=(
344 system/core/adb/adb.bash
345 system/core/fastboot/fastboot.bash
346 tools/tradefederation/core/atest/atest_completion.sh
347 )
343 # Completion can be disabled selectively to allow users to use non-standard completion. 348 # Completion can be disabled selectively to allow users to use non-standard completion.
344 # e.g. 349 # e.g.
345 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion 350 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
346 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion 351 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
347 for f in system/core/adb/adb.bash system/core/fastboot/fastboot.bash; do 352 for f in ${completion_files[*]}; do
348 if [ -f "$f" ] && should_add_completion $(basename "$f" .bash) ; then 353 if [ -f "$f" ] && should_add_completion "$f"; then
349 . $f 354 . $f
350 fi 355 fi
351 done 356 done
@@ -353,6 +358,7 @@ function addcompletions()
353 if should_add_completion bit ; then 358 if should_add_completion bit ; then
354 complete -C "bit --tab" bit 359 complete -C "bit --tab" bit
355 fi 360 fi
361 complete -F _lunch lunch
356} 362}
357 363
358function choosetype() 364function choosetype()
@@ -646,7 +652,6 @@ function _lunch()
646 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) ) 652 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
647 return 0 653 return 0
648} 654}
649complete -F _lunch lunch
650 655
651# Configures the build to build unbundled apps. 656# Configures the build to build unbundled apps.
652# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME) 657# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
@@ -1562,24 +1567,37 @@ function atest()
1562 "$(gettop)"/tools/tradefederation/core/atest/atest.py "$@" 1567 "$(gettop)"/tools/tradefederation/core/atest/atest.py "$@"
1563} 1568}
1564 1569
1565if [ "x$SHELL" != "x/bin/bash" ]; then 1570# Zsh needs bashcompinit called to support bash-style completion.
1566 case `ps -o command -p $$` in 1571function add_zsh_completion() {
1572 autoload -U compinit && compinit
1573 autoload -U bashcompinit && bashcompinit
1574}
1575
1576function validate_current_shell() {
1577 local current_sh="$(ps -o command -p $$)"
1578 case "$current_sh" in
1567 *bash*) 1579 *bash*)
1580 function check_type() { type -t "$1"; }
1568 ;; 1581 ;;
1582 *zsh*)
1583 function check_type() { type "$1"; }
1584 add_zsh_completion ;;
1569 *) 1585 *)
1570 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results" 1586 echo -e "WARNING: Only bash and zsh are supported.\nUse of other shell would lead to erroneous results."
1571 ;; 1587 ;;
1572 esac 1588 esac
1573fi 1589}
1574 1590
1575# Execute the contents of any vendorsetup.sh files we can find. 1591# Execute the contents of any vendorsetup.sh files we can find.
1576for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \ 1592function source_vendorsetup() {
1577 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \ 1593 for dir in device vendor product; do
1578 `test -d product && find -L product -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` 1594 for f in $(test -d $dir && \
1579do 1595 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
1580 echo "including $f" 1596 echo "including $f"; . $f
1581 . $f 1597 done
1582done 1598 done
1583unset f 1599}
1584 1600
1601validate_current_shell
1602source_vendorsetup
1585addcompletions 1603addcompletions