From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Tue, 16 Jul 2019 11:48:38 -0700 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 832C888309; Tue, 16 Jul 2019 18:48:37 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-117-187.ams2.redhat.com [10.36.117.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1F2019D7C; Tue, 16 Jul 2019 18:48:35 +0000 (UTC) Subject: Re: [PATCH v4 5/6] edksetup.sh: Simplify SetupPython3 and SetupPython functions. To: Rebecca Cran , devel@edk2.groups.io, 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 References: <20190716165538.57960-1-rebecca@bsdio.com> <20190716165538.57960-5-rebecca@bsdio.com> From: "Laszlo Ersek" Message-ID: Date: Tue, 16 Jul 2019 20:48:34 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190716165538.57960-5-rebecca@bsdio.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 16 Jul 2019 18:48:37 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 07/16/19 18:55, Rebecca Cran wrote: > 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() > > function 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 > + for ((pyver=15; pyver>=1; --pyver)); do > + if python=$(command -v python3.$pyver); then > export PYTHON_COMMAND=$python > + break > fi > done > return 0 > @@ -146,27 +132,11 @@ function SetupPython() > 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 > + if [ -n "$PYTHON3_ENABLE" ] && [ "$PYTHON3_ENABLE" != "TRUE" ]; then > + for ((pyver=10; pyver>=1; --pyver)); do > + if python=$(command -v python2.$pyver); then > export PYTHON_COMMAND=$python > + break > fi > done > return 0 > I'm satisfied with the v4 series; let's wait for Leif's verdict on patch #5. Thank you! Laszlo