From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by mx.groups.io with SMTP id smtpd.web10.39602.1683397401930319944 for ; Sat, 06 May 2023 11:23:22 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@bsdio.com header.s=fm1 header.b=ynFYUy2w; spf=pass (domain: bsdio.com, ip: 64.147.123.24, mailfrom: rebecca@bsdio.com) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 9AFE332004AE; Sat, 6 May 2023 14:23:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sat, 06 May 2023 14:23:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdio.com; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:sender:subject :subject:to:to; s=fm1; t=1683397400; x=1683483800; bh=ylyWOsopVF rfEXbKT7njE43L1m/ChZ3t8RvC5xHB+44=; b=ynFYUy2w5GbPtJbG1ZnUrb9J7B UW/RuBSyoJ0KdXoEnFBs+cRhGHg9JwwzNXtinSkcTO/MXqzKV43W1WpcEM3FyOLL bKj1x/XCnIKKw9/DbeLryhFVTEl8+gR5/vilzTzQWrIjsTXQHf520yBOAQI3TU+f paE9iW45GcJA6WhH1eb0NcdQpzdbDz+7bnWlpgrx/LxdlPVwD7RnLDnIXQgkV+M/ WFsObApGcbIAW3KMhUMPbs3Nh8pGVaE+4bbgJ7nkPM1PkLsO1atMhwGynWpT4RL/ HuPg6lZ5JbViBH6PaEWva0k2ViSJLvRPUJp2643+NB8jwDA1wVTLih7KxVsg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1683397400; x=1683483800; bh=ylyWOsopVFrfE XbKT7njE43L1m/ChZ3t8RvC5xHB+44=; b=GxXNSvZGxYGnc5NFvMfeGeNIgKF/3 tvy1Jqq+cpG1DhgBDanS4AgXq/E8UQG3Z1U0JqirNWaf0O5NeTYNi15a2GYtBmYb cpQUuf6hnhwA79XuL8j0Cw2lq+j4LkBJr0Kstx/P/mrifp0/mmUHukSnCodCgTt/ lEg53iSchthCMUTuk8Qeot2XfyaNYfHmoeFcnAJwZPRnUMClu3WPY1Dh8CrUq1ch TqnNjH+/0tt2P1YonCXdTfCI6ZAJoG0o1wV99bnEONxpwmDmEWGG1POnJ/LewlmD kT1MuKQWG9RBMTNlw0bzx9LF/oMNJh2oWfM759EVyCKlW5aRzYxrHgP1A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeefgedguddtudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffoggfgsedtkeertdertddtnecuhfhrohhmpeftvggsvggt tggrucevrhgrnhcuoehrvggsvggttggrsegsshguihhordgtohhmqeenucggtffrrghtth gvrhhnpeeuvdektdelkeeukefgjeejteetffdtudeiffefheevfefgveeulefghfellefg vdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrvg gsvggttggrsegsshguihhordgtohhm X-ME-Proxy: Feedback-ID: i5b994698:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 6 May 2023 14:23:18 -0400 (EDT) From: "Rebecca Cran" To: devel@edk2.groups.io, Liming Gao , Bob Feng , Yuwei Chen , Andrew Fish , Leif Lindholm , Michael D Kinney Cc: Rebecca Cran Subject: [PATCH 1/1] Remove bashisms from edksetup.sh and BaseTools/BuildEnv Date: Sat, 6 May 2023 12:23:11 -0600 Message-Id: <20230506182311.14023-1-rebecca@bsdio.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- BaseTools/BuildEnv | 30 +++---- edksetup.sh | 89 +++----------------- 2 files changed, 26 insertions(+), 93 deletions(-) diff --git a/BaseTools/BuildEnv b/BaseTools/BuildEnv index 275f4c5901aa..bd6235d74fa7 100755 --- a/BaseTools/BuildEnv +++ b/BaseTools/BuildEnv @@ -20,7 +20,8 @@ SetWorkspace() { # # Set $WORKSPACE # - export WORKSPACE=`pwd` + WORKSPACE=$(pwd) + export WORKSPACE return 0 @@ -35,8 +36,7 @@ RestorePreviousConfiguration() { export CONF_PATH=$WORKSPACE/Conf if [ ! -d $WORKSPACE/Conf ] && [ -n "$PACKAGES_PATH" ] then - PATH_LIST=${PACKAGES_PATH//:/ } - for DIR in $PATH_LIST + for DIR in $(echo $PACKAGES_PATH | tr ':' ' ') do if [ -d $DIR/Conf ] then @@ -70,7 +70,13 @@ GenerateShellCodeToUpdatePath() { OUTPUT_FILE=$1 echo "if [ -e $EDK_TOOLS_PATH_BIN ]" >> $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 " export PATH=$EDK_TOOLS_PATH_BIN:\$PATH" >> $OUTPUT_FILE echo " fi" >> $OUTPUT_FILE @@ -84,7 +90,7 @@ StoreCurrentConfiguration() { # OUTPUT_FILE=$CONF_PATH/BuildEnv.sh #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 EDK_TOOLS_PATH $OUTPUT_FILE GenerateShellCodeToUpdatePath $OUTPUT_FILE @@ -130,10 +136,9 @@ SetEdkToolsPath() { # # Try $PACKAGES_PATH # - if [ -n "$PACKAGES_PATH"] + if [ -n "$PACKAGES_PATH" ] then - PATH_LIST=${PACKAGES_PATH//:/ } - for DIR in $PATH_LIST + for DIR in $(echo $PACKAGES_PATH | tr ':' ' ') do if [ -d $DIR/BaseTools ] then @@ -156,10 +161,7 @@ GetBaseToolsBinSubDir() { # # Figure out a uniq directory name from the uname command # - UNAME_DIRNAME=`uname -sm` - UNAME_DIRNAME=${UNAME_DIRNAME// /-} - UNAME_DIRNAME=${UNAME_DIRNAME//\//-} - echo $UNAME_DIRNAME + echo $(uname -sm | tr ' ' '-') } GetEdkToolsPathBinDirectory() { @@ -180,8 +182,6 @@ GetEdkToolsPathBinDirectory() { AddDirToStartOfPath() { DIRNAME=$1 - PATH=$DIRNAME:$DIRNAME:$DIRNAME:$PATH - PATH=${PATH//$DIRNAME:/} PATH=$DIRNAME:$PATH export PATH } @@ -199,7 +199,7 @@ AddEdkToolsToPath() { EDK_TOOLS_PATH_BIN=`GetEdkToolsPathBinDirectory` # 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 echo "Using Pip Basetools" AddDirToStartOfPath $EDK_TOOLS_PATH/BinPipWrappers/PosixLike diff --git a/edksetup.sh b/edksetup.sh index 06d2f041e635..cab3a8c113e0 100755 --- a/edksetup.sh +++ b/edksetup.sh @@ -20,7 +20,7 @@ SCRIPTNAME="edksetup.sh" RECONFIG=FALSE -function HelpMsg() +HelpMsg() { echo "Usage: $SCRIPTNAME [Options]" echo @@ -38,7 +38,7 @@ function HelpMsg() echo "source $SCRIPTNAME" } -function SetWorkspace() +SetWorkspace() { # # If WORKSPACE is already set, then we can return right now @@ -49,10 +49,10 @@ function SetWorkspace() return 0 fi - if [ ! ${BASH_SOURCE[0]} -ef ./$SCRIPTNAME ] && [ -z "$PACKAGES_PATH" ] + if [ ! -f ${SCRIPTNAME} ] && [ -z "$PACKAGES_PATH" ] then - echo Run this script from the base of your tree. For example: - echo " cd /Path/To/Edk/Root" + echo Source this script from the base of your tree. For example: + echo " cd /Path/To/Edk2/Clone" echo " . $SCRIPTNAME" return 1 fi @@ -75,7 +75,7 @@ function SetWorkspace() return 0 } -function SetupEnv() +SetupEnv() { if [ -n "$EDK_TOOLS_PATH" ] then @@ -85,9 +85,7 @@ function SetupEnv() . $WORKSPACE/BaseTools/BuildEnv elif [ -n "$PACKAGES_PATH" ] then - PATH_LIST=$PACKAGES_PATH - PATH_LIST=${PATH_LIST//:/ } - for DIR in $PATH_LIST + for DIR in $(echo $PACKAGES_PATH | tr ':' ' ') do if [ -f "$DIR/BaseTools/BuildEnv" ] then @@ -105,81 +103,16 @@ function SetupEnv() fi } -function SetupPython3() +SetupPython3() { - if [ $origin_version ];then - 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 + export PYTHON_COMMAND=python3 } -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 -} - -function SourceEnv() -{ - SetWorkspace && + SetWorkspace SetupEnv - SetupPython } I=$# -- 2.40.1