From nobody Fri Apr 26 11:20:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+43528+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43528+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1562796354; cv=none; d=zoho.com; s=zohoarc; b=PAsmoUCDBe+7j9qq3Z01OzIIHctCIT6RFvKgYv52enfaE4DgL3E/luHUkIxktnxLFyVmnEcUKVRWpmjpKQq+agl7xEc26Jqa3ekbAsinSWK32xH7FfWSBpSEZp2WyUUY6THQG93640CKSGJq7hfSZZ3IUn5Y+4K0a1dPxdOcwIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562796354; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=7ckb1UMIxglrhTgyYOvO+t7OV5eGaSgG/VIMet70/IQ=; b=Qb4nG4gfW1X5dqhGfBMj7lnGqocX0BSUZqv6+w7tAvQi+xVZz9XXDLOyl7Q87Mdc3IFxQxwXJWkm4J8CN1INIElu9YqLokG6wZxxJb55UQ0N5zkMkQeCuC9Gpu9VvT+VRmlXo1Cen6/fTM6ZVpTOMRo8ClfDlraoJ7rT7EK+LaM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+43528+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1562796354513818.7113716882494; Wed, 10 Jul 2019 15:05:54 -0700 (PDT) Return-Path: X-Received: from muon.bsdio.com (muon.bsdio.com [65.103.231.193]) by groups.io with SMTP; Wed, 10 Jul 2019 14:17:31 -0700 X-Received: from muon.bsdio.com (localhost [127.0.0.1]) by muon.bsdio.com (Postfix) with ESMTP id F15B3725ED; Wed, 10 Jul 2019 15:17:50 -0600 (MDT) X-Received: from muon.bsdio.com ([127.0.0.1]) by muon.bsdio.com (muon.bsdio.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id nXopvMpwma8u; Wed, 10 Jul 2019 15:17:50 -0600 (MDT) X-Received: from photon.int.bluestop.org (unknown [10.0.10.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by muon.bsdio.com (Postfix) with ESMTPSA; Wed, 10 Jul 2019 15:17:50 -0600 (MDT) From: Rebecca Cran To: devel@edk2.groups.io, Bob Feng , Liming Gao Cc: Rebecca Cran Subject: [edk2-devel] [PATCH] Simplify edksetup.sh Date: Wed, 10 Jul 2019 15:17:26 -0600 Message-Id: <20190710211726.10100-1-rebecca@bsdio.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,rebecca@bsdio.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1562796354; bh=4deJa8thgUIxBV/qAsxyl2eA7VG1zkpzkuQdYxhOpss=; h=Cc:Date:From:Reply-To:Subject:To; b=QzQOcNd1fz6Bg7pL40lAYgj5+n4xs2Oc8wFabxGPpS/UYn7j8lJn+jKkKo+l+j77Y2Y 474tYsJZvQcu9GSUX7iUnwYndxGdQ/93SKC7hlLLJ/1QOYty7nlh+6LuJbwOQQEXIeiFF D4XpopcDR4XTFU4uMSwnEFhDEdz7Z9PbdKI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" o Use '$SCRIPTNAME' consistently instead of 'edksetup.sh' o Use the bash environment variable $PWD instead of executing the pwd command. o Add quotes around variables to ensure they're evaluated correctly. o Simplify SetupPython3() and SetupPython() functions. On Linux, "whereis" matches python3, python3.7, as well as man pages, libs etc. While on macOS it only matches the specified name, and so misses python3.7. Improve this by looping over potential version numbers and seeing if such a binary exists and can be executed. o Since when parsing options '*' matches anything not already matched, remove -?, -h and --help since they're redundant. o When executing arithmetic commands, $ isn't needed before variables. Signed-off-by: Rebecca Cran --- edksetup.sh | 67 ++++++++++++++--------------------------------------- 1 file changed, 18 insertions(+), 49 deletions(-) diff --git a/edksetup.sh b/edksetup.sh index 12a3e26a67..a797ff03d2 100755 --- a/edksetup.sh +++ b/edksetup.sh @@ -49,11 +49,11 @@ function SetWorkspace() return 0 fi =20 - if [ ! ${BASH_SOURCE[0]} -ef ./edksetup.sh ] && [ -z "$PACKAGES_PATH" ] + if [ ! ${BASH_SOURCE[0]} -ef ./$SCRIPTNAME ] && [ -z "$PACKAGES_PATH" ] then echo Run this script from the base of your tree. For example: - echo " cd /Path/To/Edk/Root" - echo " . edksetup.sh" + echo " cd /path/to/edk2/root" + echo " . $SCRIPTNAME" return 1 fi =20 @@ -71,7 +71,7 @@ function SetWorkspace() # # Set $WORKSPACE # - export WORKSPACE=3D`pwd` + export WORKSPACE=3D$PWD return 0 } =20 @@ -107,24 +107,10 @@ function SetupEnv() =20 function SetupPython3() { - if [ $origin_version ];then - origin_version=3D - fi - for python in $(whereis python3) - do - python=3D$(echo $python | grep "[[:digit:]]$" || true) - python_version=3D${python##*python} - if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>&1= );then - continue - fi - if [ -z $origin_version ];then - origin_version=3D$python_version - export PYTHON_COMMAND=3D$python - continue - fi - if [[ "$origin_version" < "$python_version" ]]; then - origin_version=3D$python_version - export PYTHON_COMMAND=3D$python + for python in $(seq -f "python3.%g" 15 -1 1) python3; do + if command -v $python >/dev/null 2>&1; then + export PYTHON_COMMAND=3D$(which $python) + break fi done return 0 @@ -132,8 +118,8 @@ function SetupPython3() =20 function SetupPython() { - if [ $PYTHON_COMMAND ] && [ -z $PYTHON3_ENABLE ];then - if ( command -v $PYTHON_COMMAND >/dev/null 2>&1 );then + if [ -n "$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 t= ools. @@ -141,32 +127,15 @@ function SetupPython() fi fi =20 - if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE =3D=3D TRUE ] - then + if [ "$PYTHON3_ENABLE" =3D=3D "TRUE" ]; then SetupPython3 fi =20 - if [ $PYTHON3_ENABLE ] && [ $PYTHON3_ENABLE !=3D TRUE ] - then - if [ $origin_version ];then - origin_version=3D - fi - for python in $(whereis python2) - do - python=3D$(echo $python | grep "[[:digit:]]$" || true) - python_version=3D${python##*python} - if [ -z "${python_version}" ] || (! command -v $python >/dev/null 2>= &1);then - continue - fi - if [ -z $origin_version ] - then - origin_version=3D$python_version - export PYTHON_COMMAND=3D$python - continue - fi - if [[ "$origin_version" < "$python_version" ]]; then - origin_version=3D$python_version - export PYTHON_COMMAND=3D$python + if [ -n "$PYTHON3_ENABLE" ] && [ "$PYTHON3_ENABLE" !=3D "TRUE" ]; then + for python in $(seq -f "python2.%g" 10 -1 1) python2; do + if command -v $python >/dev/null 2>&1; then + export PYTHON_COMMAND=3D$(which $python) + break fi done return 0 @@ -194,12 +163,12 @@ do RECONFIG=3DTRUE shift ;; - -?|-h|--help|*) + *) HelpMsg break ;; esac - I=3D$(($I - 1)) + I=3D$((I - 1)) done =20 if [ $I -gt 0 ] --=20 2.22.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#43528): https://edk2.groups.io/g/devel/message/43528 Mute This Topic: https://groups.io/mt/32421563/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-