From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=none, err=permanent DNS error (domain: bsdio.com, ip: 65.103.231.193, mailfrom: rebecca@bsdio.com) Received: from muon.bsdio.com (muon.bsdio.com [65.103.231.193]) by groups.io with SMTP; Tue, 16 Jul 2019 09:55:46 -0700 Received: from muon.bsdio.com (localhost [127.0.0.1]) by muon.bsdio.com (Postfix) with ESMTP id 0BE08802E2; Tue, 16 Jul 2019 10:56:07 -0600 (MDT) 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 TT50Qdn7IqUi; Tue, 16 Jul 2019 10:56:06 -0600 (MDT) Received: from photon.int.bluestop.org (unknown [10.0.10.120]) (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; Tue, 16 Jul 2019 10:56:06 -0600 (MDT) From: rebecca@bsdio.com To: devel@edk2.groups.io, lersek@redhat.com, bob.c.feng@intel.com, liming.gao@intel.com, michael.d.kinney@intel.com, afish@apple.com, zhijux.fan@intel.com, leif.lindholm@linaro.org Cc: Rebecca Cran Subject: [PATCH v4 5/6] edksetup.sh: Simplify SetupPython3 and SetupPython functions. Date: Tue, 16 Jul 2019 10:55:37 -0600 Message-Id: <20190716165538.57960-5-rebecca@bsdio.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190716165538.57960-1-rebecca@bsdio.com> References: <20190716165538.57960-1-rebecca@bsdio.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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. Signed-off-by: Rebecca Cran Reviewed-by: Laszlo Ersek --- edksetup.sh | 44 +++++++------------------------------------- 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/edksetup.sh b/edksetup.sh index 06d2f041e6..5b90e55ed8 100755 --- a/edksetup.sh +++ b/edksetup.sh @@ -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 + for ((pyver=3D15; pyver>=3D1; --pyver)); do + if python=3D$(command -v python3.$pyver); then export PYTHON_COMMAND=3D$python + break fi done return 0 @@ -146,27 +132,11 @@ function SetupPython() 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 + if [ -n "$PYTHON3_ENABLE" ] && [ "$PYTHON3_ENABLE" !=3D "TRUE" ]; then + for ((pyver=3D10; pyver>=3D1; --pyver)); do + if python=3D$(command -v python2.$pyver); then export PYTHON_COMMAND=3D$python + break fi done return 0 --=20 2.22.0