mirror of https://github.com/acidanthera/audk.git
Remove bashisms from edksetup.sh and BaseTools/BuildEnv
Remove bashisms from edksetup.sh and BaseTools/BuildEnv. This allows any POSIX shell to use those scripts, removing the dependency on bash. Signed-off-by: Rebecca Cran <rebecca@bsdio.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
This commit is contained in:
parent
373a95532a
commit
e6447d2a08
|
@ -20,7 +20,8 @@ SetWorkspace() {
|
||||||
#
|
#
|
||||||
# Set $WORKSPACE
|
# Set $WORKSPACE
|
||||||
#
|
#
|
||||||
export WORKSPACE=`pwd`
|
WORKSPACE=$(pwd)
|
||||||
|
export WORKSPACE
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -35,8 +36,7 @@ RestorePreviousConfiguration() {
|
||||||
export CONF_PATH=$WORKSPACE/Conf
|
export CONF_PATH=$WORKSPACE/Conf
|
||||||
if [ ! -d $WORKSPACE/Conf ] && [ -n "$PACKAGES_PATH" ]
|
if [ ! -d $WORKSPACE/Conf ] && [ -n "$PACKAGES_PATH" ]
|
||||||
then
|
then
|
||||||
PATH_LIST=${PACKAGES_PATH//:/ }
|
for DIR in $(echo $PACKAGES_PATH | tr ':' ' ')
|
||||||
for DIR in $PATH_LIST
|
|
||||||
do
|
do
|
||||||
if [ -d $DIR/Conf ]
|
if [ -d $DIR/Conf ]
|
||||||
then
|
then
|
||||||
|
@ -70,7 +70,13 @@ GenerateShellCodeToUpdatePath() {
|
||||||
OUTPUT_FILE=$1
|
OUTPUT_FILE=$1
|
||||||
echo "if [ -e $EDK_TOOLS_PATH_BIN ]" >> $OUTPUT_FILE
|
echo "if [ -e $EDK_TOOLS_PATH_BIN ]" >> $OUTPUT_FILE
|
||||||
echo "then" >> $OUTPUT_FILE
|
echo "then" >> $OUTPUT_FILE
|
||||||
echo " if [ "\${PATH/$EDK_TOOLS_PATH_BIN/}" == "\$PATH" ]" >> $OUTPUT_FILE
|
echo " FOUND_TOOLS_PATH_BIN=0" >> $OUTPUT_FILE
|
||||||
|
echo " for DIR in \$(echo \$PATH | tr ':' ' '); do" >> $OUTPUT_FILE
|
||||||
|
echo " if [ \"\$DIR\" = \"$EDK_TOOLS_PATH_BIN\" ]; then" >> $OUTPUT_FILE
|
||||||
|
echo " FOUND_TOOLS_PATH_BIN=1" >> $OUTPUT_FILE
|
||||||
|
echo " fi" >> $OUTPUT_FILE
|
||||||
|
echo " done" >> $OUTPUT_FILE
|
||||||
|
echo " if [ \$FOUND_TOOLS_PATH_BIN = 0 ]" >> $OUTPUT_FILE
|
||||||
echo " then" >> $OUTPUT_FILE
|
echo " then" >> $OUTPUT_FILE
|
||||||
echo " export PATH=$EDK_TOOLS_PATH_BIN:\$PATH" >> $OUTPUT_FILE
|
echo " export PATH=$EDK_TOOLS_PATH_BIN:\$PATH" >> $OUTPUT_FILE
|
||||||
echo " fi" >> $OUTPUT_FILE
|
echo " fi" >> $OUTPUT_FILE
|
||||||
|
@ -84,7 +90,7 @@ StoreCurrentConfiguration() {
|
||||||
#
|
#
|
||||||
OUTPUT_FILE=$CONF_PATH/BuildEnv.sh
|
OUTPUT_FILE=$CONF_PATH/BuildEnv.sh
|
||||||
#echo Storing current configuration into $OUTPUT_FILE
|
#echo Storing current configuration into $OUTPUT_FILE
|
||||||
echo "# Auto-generated by ${BASH_SOURCE[0]}" >| $OUTPUT_FILE
|
echo "# Auto-generated by BaseTools/BuildEnv" >| $OUTPUT_FILE
|
||||||
GenerateShellCodeToSetVariable WORKSPACE $OUTPUT_FILE
|
GenerateShellCodeToSetVariable WORKSPACE $OUTPUT_FILE
|
||||||
GenerateShellCodeToSetVariable EDK_TOOLS_PATH $OUTPUT_FILE
|
GenerateShellCodeToSetVariable EDK_TOOLS_PATH $OUTPUT_FILE
|
||||||
GenerateShellCodeToUpdatePath $OUTPUT_FILE
|
GenerateShellCodeToUpdatePath $OUTPUT_FILE
|
||||||
|
@ -130,10 +136,9 @@ SetEdkToolsPath() {
|
||||||
#
|
#
|
||||||
# Try $PACKAGES_PATH
|
# Try $PACKAGES_PATH
|
||||||
#
|
#
|
||||||
if [ -n "$PACKAGES_PATH"]
|
if [ -n "$PACKAGES_PATH" ]
|
||||||
then
|
then
|
||||||
PATH_LIST=${PACKAGES_PATH//:/ }
|
for DIR in $(echo $PACKAGES_PATH | tr ':' ' ')
|
||||||
for DIR in $PATH_LIST
|
|
||||||
do
|
do
|
||||||
if [ -d $DIR/BaseTools ]
|
if [ -d $DIR/BaseTools ]
|
||||||
then
|
then
|
||||||
|
@ -156,10 +161,7 @@ GetBaseToolsBinSubDir() {
|
||||||
#
|
#
|
||||||
# Figure out a uniq directory name from the uname command
|
# Figure out a uniq directory name from the uname command
|
||||||
#
|
#
|
||||||
UNAME_DIRNAME=`uname -sm`
|
echo $(uname -sm | tr ' ' '-')
|
||||||
UNAME_DIRNAME=${UNAME_DIRNAME// /-}
|
|
||||||
UNAME_DIRNAME=${UNAME_DIRNAME//\//-}
|
|
||||||
echo $UNAME_DIRNAME
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GetEdkToolsPathBinDirectory() {
|
GetEdkToolsPathBinDirectory() {
|
||||||
|
@ -180,8 +182,6 @@ GetEdkToolsPathBinDirectory() {
|
||||||
|
|
||||||
AddDirToStartOfPath() {
|
AddDirToStartOfPath() {
|
||||||
DIRNAME=$1
|
DIRNAME=$1
|
||||||
PATH=$DIRNAME:$DIRNAME:$DIRNAME:$PATH
|
|
||||||
PATH=${PATH//$DIRNAME:/}
|
|
||||||
PATH=$DIRNAME:$PATH
|
PATH=$DIRNAME:$PATH
|
||||||
export PATH
|
export PATH
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ AddEdkToolsToPath() {
|
||||||
EDK_TOOLS_PATH_BIN=`GetEdkToolsPathBinDirectory`
|
EDK_TOOLS_PATH_BIN=`GetEdkToolsPathBinDirectory`
|
||||||
|
|
||||||
# check if the edk2basetools pip package is available
|
# check if the edk2basetools pip package is available
|
||||||
if $PYTHON_COMMAND -c "import edk2basetools" &> /dev/null; then
|
if $PYTHON_COMMAND -c "import edk2basetools" > /dev/null 2>&1; then
|
||||||
# if it is, use the pip version of the wrappers
|
# if it is, use the pip version of the wrappers
|
||||||
echo "Using Pip Basetools"
|
echo "Using Pip Basetools"
|
||||||
AddDirToStartOfPath $EDK_TOOLS_PATH/BinPipWrappers/PosixLike
|
AddDirToStartOfPath $EDK_TOOLS_PATH/BinPipWrappers/PosixLike
|
||||||
|
|
89
edksetup.sh
89
edksetup.sh
|
@ -20,7 +20,7 @@
|
||||||
SCRIPTNAME="edksetup.sh"
|
SCRIPTNAME="edksetup.sh"
|
||||||
RECONFIG=FALSE
|
RECONFIG=FALSE
|
||||||
|
|
||||||
function HelpMsg()
|
HelpMsg()
|
||||||
{
|
{
|
||||||
echo "Usage: $SCRIPTNAME [Options]"
|
echo "Usage: $SCRIPTNAME [Options]"
|
||||||
echo
|
echo
|
||||||
|
@ -38,7 +38,7 @@ function HelpMsg()
|
||||||
echo "source $SCRIPTNAME"
|
echo "source $SCRIPTNAME"
|
||||||
}
|
}
|
||||||
|
|
||||||
function SetWorkspace()
|
SetWorkspace()
|
||||||
{
|
{
|
||||||
#
|
#
|
||||||
# If WORKSPACE is already set, then we can return right now
|
# If WORKSPACE is already set, then we can return right now
|
||||||
|
@ -49,10 +49,10 @@ function SetWorkspace()
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! ${BASH_SOURCE[0]} -ef ./$SCRIPTNAME ] && [ -z "$PACKAGES_PATH" ]
|
if [ ! -f ${SCRIPTNAME} ] && [ -z "$PACKAGES_PATH" ]
|
||||||
then
|
then
|
||||||
echo Run this script from the base of your tree. For example:
|
echo Source this script from the base of your tree. For example:
|
||||||
echo " cd /Path/To/Edk/Root"
|
echo " cd /Path/To/Edk2/Clone"
|
||||||
echo " . $SCRIPTNAME"
|
echo " . $SCRIPTNAME"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
@ -75,7 +75,7 @@ function SetWorkspace()
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function SetupEnv()
|
SetupEnv()
|
||||||
{
|
{
|
||||||
if [ -n "$EDK_TOOLS_PATH" ]
|
if [ -n "$EDK_TOOLS_PATH" ]
|
||||||
then
|
then
|
||||||
|
@ -85,9 +85,7 @@ function SetupEnv()
|
||||||
. $WORKSPACE/BaseTools/BuildEnv
|
. $WORKSPACE/BaseTools/BuildEnv
|
||||||
elif [ -n "$PACKAGES_PATH" ]
|
elif [ -n "$PACKAGES_PATH" ]
|
||||||
then
|
then
|
||||||
PATH_LIST=$PACKAGES_PATH
|
for DIR in $(echo $PACKAGES_PATH | tr ':' ' ')
|
||||||
PATH_LIST=${PATH_LIST//:/ }
|
|
||||||
for DIR in $PATH_LIST
|
|
||||||
do
|
do
|
||||||
if [ -f "$DIR/BaseTools/BuildEnv" ]
|
if [ -f "$DIR/BaseTools/BuildEnv" ]
|
||||||
then
|
then
|
||||||
|
@ -105,81 +103,16 @@ function SetupEnv()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function SetupPython3()
|
SetupPython3()
|
||||||
{
|
{
|
||||||
if [ $origin_version ];then
|
export PYTHON_COMMAND=python3
|
||||||
origin_version=
|
|
||||||
fi
|
|
||||||
for python in $(whereis python3)
|
|
||||||
do
|
|
||||||
python=$(echo $python | grep "[[:digit:]]$" || true)
|
|
||||||
python_version=${python##*python}
|
|
||||||
if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
if [ -z $origin_version ];then
|
|
||||||
origin_version=$python_version
|
|
||||||
export PYTHON_COMMAND=$python
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
if [[ "$origin_version" < "$python_version" ]]; then
|
|
||||||
origin_version=$python_version
|
|
||||||
export PYTHON_COMMAND=$python
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function SetupPython()
|
SourceEnv()
|
||||||
{
|
{
|
||||||
if [ $PYTHON_COMMAND ] && [ -z $PYTHON3_ENABLE ];then
|
|
||||||
if ( command -v $PYTHON_COMMAND >/dev/null 2>&1 );then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
echo $PYTHON_COMMAND Cannot be used to build or execute the python tools.
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE == TRUE ]
|
|
||||||
then
|
|
||||||
SetupPython3
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE != TRUE ]
|
|
||||||
then
|
|
||||||
if [ $origin_version ];then
|
|
||||||
origin_version=
|
|
||||||
fi
|
|
||||||
for python in $(whereis python2)
|
|
||||||
do
|
|
||||||
python=$(echo $python | grep "[[:digit:]]$" || true)
|
|
||||||
python_version=${python##*python}
|
|
||||||
if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1);then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
if [ -z $origin_version ]
|
|
||||||
then
|
|
||||||
origin_version=$python_version
|
|
||||||
export PYTHON_COMMAND=$python
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
if [[ "$origin_version" < "$python_version" ]]; then
|
|
||||||
origin_version=$python_version
|
|
||||||
export PYTHON_COMMAND=$python
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
SetupPython3
|
SetupPython3
|
||||||
}
|
SetWorkspace
|
||||||
|
|
||||||
function SourceEnv()
|
|
||||||
{
|
|
||||||
SetWorkspace &&
|
|
||||||
SetupEnv
|
SetupEnv
|
||||||
SetupPython
|
|
||||||
}
|
}
|
||||||
|
|
||||||
I=$#
|
I=$#
|
||||||
|
|
Loading…
Reference in New Issue