From ce000fdc4d7bbc5729f681435b1daf50e9db3a28 Mon Sep 17 00:00:00 2001 From: Guillaume Chelfi Date: Thu, 3 Oct 2019 12:02:46 +0200 Subject: [PATCH] Fix zsh compatibility issue in build/envsetup.sh Arrays are zero indexed in bash and one indexed in zsh by default. This leads to an off-by-one issue in the `godir` and `choosevariant` commands: when prompted to chose an option, in order to pick option "n" you have to input "n+1". In those two specific instances, by using "substring expansion" instead of array indexing, one can get consistent behaviour between bash and zsh (equivalent to zero indexing). Test: manual - # godir $ zsh $ source build/envsetup.sh $ godir SurfaceFlinger # There should be many options # Pick 1, check that you end up in the right location $ godir SurfaceFlinger.cpp # There should be only one possibility # make sure you end up in the right location # repeat with bash (to ensure compatibility is not broken) # choosevariant $ zsh $ source build/envsetup.h $ choosevariant # pick whatever variant you want $ printconfig # make sure the variant matches your choice # repeat with bash (to ensure compatibility is not broken) Change-Id: I998d8fb48b708066b6db28a2129a2b09785fb0b1 --- envsetup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/envsetup.sh b/envsetup.sh index f91b82058..3d5d361c9 100644 --- a/envsetup.sh +++ b/envsetup.sh @@ -524,7 +524,7 @@ function choosevariant() export TARGET_BUILD_VARIANT=$default_value elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then - export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]} + export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1} fi else if check_variant $ANSWER @@ -1295,10 +1295,10 @@ function godir () { echo "Invalid choice" continue fi - pathname=${lines[$(($choice-1))]} + pathname=${lines[@]:$(($choice-1)):1} done else - pathname=${lines[0]} + pathname=${lines[@]:0:1} fi \cd $T/$pathname }