From 76a1cfa60eb3030c5235ec52a8c32f308d8f3614 Mon Sep 17 00:00:00 2001 From: Wade Fife Date: Wed, 27 May 2020 09:42:19 -0500 Subject: [PATCH] fpga: tools: Improve detection of setupenv sourcing This change allows detection of attempting to execute setupenv.sh rather than sourcing it, which is required. Original-commit: 6faec1d4a14a1af52681aabf19c9040dcee772ff --- tools/scripts/setupenv_base.sh | 64 ++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/tools/scripts/setupenv_base.sh b/tools/scripts/setupenv_base.sh index 76385c5..5919b3a 100644 --- a/tools/scripts/setupenv_base.sh +++ b/tools/scripts/setupenv_base.sh @@ -37,38 +37,10 @@ function resolve_viv_path { fi } -#---------------------------------------------------------------------------- -# Validate prerequisites -#---------------------------------------------------------------------------- -# Ensure required variables -if [ -z "$REPO_BASE_PATH" ]; then - echo "ERROR: Please define the variable REPO_BASE_PATH before calling this script" - return -fi -if [ -z "$VIVADO_VER" ]; then - echo "ERROR: Please define the variable VIVADO_VER before calling this script" - return -fi -if [ -z "$DISPLAY_NAME" ]; then - echo "ERROR: Please define the variable DISPLAY_NAME before calling this script" - return -fi -if [ ${#PRODUCT_ID_MAP[@]} -eq 0 ]; then - echo "ERROR: Please define the variable PRODUCT_ID_MAP before calling this script" - return -fi - -# Ensure that the script is sourced -if [[ $BASH_SOURCE = $0 ]]; then - echo "ERROR: This script must be sourced." - help - exit 1 -fi - #---------------------------------------------------------------------------- # Help message display function #---------------------------------------------------------------------------- -function help { +function setupenv_help { cat <] [--modelsim-path=] @@ -89,6 +61,36 @@ Optional tools: Mentor Graphics Modelsim (Simulation) EOHELP } + +#---------------------------------------------------------------------------- +# Validate prerequisites +#---------------------------------------------------------------------------- +# Ensure required variables +if [ -z "$REPO_BASE_PATH" ]; then + echo "ERROR: Please define the variable REPO_BASE_PATH before calling this script" + return +fi +if [ -z "$VIVADO_VER" ]; then + echo "ERROR: Please define the variable VIVADO_VER before calling this script" + return +fi +if [ -z "$DISPLAY_NAME" ]; then + echo "ERROR: Please define the variable DISPLAY_NAME before calling this script" + return +fi +if [ ${#PRODUCT_ID_MAP[@]} -eq 0 ]; then + echo "ERROR: Please define the variable PRODUCT_ID_MAP before calling this script" + return +fi + +# Ensure that the script is sourced directly or from another script, and not +# executed. +if [[ ${BASH_SOURCE[0]} == "$0" || ${BASH_SOURCE[1]} == "$0" ]]; then + echo "ERROR: This script must be sourced." + setupenv_help + exit 1 +fi + #---------------------------------------------------------------------------- # Setup and parse command line #---------------------------------------------------------------------------- @@ -106,7 +108,7 @@ PARSE_STATE="" for i in "$@"; do case $i in -h|--help) - help + setupenv_help return 0 ;; --vivado-path=*) @@ -148,7 +150,7 @@ for i in "$@"; do ;; *) echo "ERROR: Unrecognized option: $i" - help + setupenv_help return 1 ;; esac