Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions scripts/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
# Needed to fail on must_get_env()
set -e

GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
GIT_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && git rev-parse --show-toplevel)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is that better?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is that better?

is better in terms of clarity, correctness, and consistency, especially in more complex scripts or when the script could be sourced.

source "${GIT_ROOT}/scripts/colors.sh"

function must_get_env() {
declare -n VAR_VALUE="$1"
local VAR_NAME="$1"
declare -n VAR_VALUE="$VAR_NAME"
if [[ -n "${VAR_VALUE}" ]]; then
echo "${VAR_VALUE}"
return
fi
echo -e "${RED}No required env variable:${RST} ${BLD}${!VAR_VALUE}${RST}" 1>&2
echo -e "${RED}No required env variable:${RST} ${BLD}${VAR_NAME}${RST}" 1>&2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ! trick works because VAR_VALUE is not a variable but rather a reference to a var created via declare -n:

      -n	make NAME a reference to the variable named by its value

Which means that VAR_VALUE is a reference to $1. We can test this:

 > TEST=something
 > VAR_NAME=TEST
 > declare -n VAR_REF=$VAR_NAME
 > echo $VAR_REF
something
 > echo ${!VAR_REF}
TEST

Your version is clearer, but the result is the same. What I would like to understand is why for you it doesn't expand into the name of variable from the nameref.

exit 1
}

Expand All @@ -25,7 +26,7 @@ nixOpts=()

# We create if now so the trap knows its location
export SECRETS_FILE_PATH=$(mktemp)
chmod 644 ${SECRETS_FILE_PATH}
chmod 644 "${SECRETS_FILE_PATH}"
# If secrets file was created we want to remove it.
trap "rm -vf ${SECRETS_FILE_PATH}" EXIT ERR INT QUIT

Expand Down Expand Up @@ -77,5 +78,4 @@ else
nixOpts+=("--option" "build-use-sandbox" "true")
fi


"${GIT_ROOT}/nix/scripts/build.sh" targets.mobile.android.build "${nixOpts[@]}"