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
This commit is contained in:
Wade Fife
2020-05-28 15:11:29 -05:00
parent a46e351a65
commit 76a1cfa60e
+33 -31
View File
@@ -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 <<EOHELP
Usage: source setupenv.sh [--help|-h] [--vivado-path=<PATH>] [--modelsim-path=<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