public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2] edksetup.sh: Simplify SetupPython3 and SetupPython functions.
@ 2019-07-16  2:36 rebecca
  2019-07-16 10:41 ` Laszlo Ersek
  2019-07-16 11:35 ` Leif Lindholm
  0 siblings, 2 replies; 7+ messages in thread
From: rebecca @ 2019-07-16  2:36 UTC (permalink / raw)
  To: devel, lersek, bob.c.feng, liming.gao, leif.lindholm,
	michael.d.kinney, afish
  Cc: Rebecca Cran

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 <rebecca@bsdio.com>
---
 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
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-07-16 16:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-16  2:36 [PATCH v2] edksetup.sh: Simplify SetupPython3 and SetupPython functions rebecca
2019-07-16 10:41 ` Laszlo Ersek
2019-07-16 11:35 ` Leif Lindholm
2019-07-16 14:17   ` [edk2-devel] " rebecca
2019-07-16 14:22     ` Leif Lindholm
2019-07-16 16:36       ` rebecca
2019-07-16 14:31   ` Laszlo Ersek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox