]> xenbits.xensource.com Git - ovmf.git/commitdiff
BaseTools: Update toolsetup.bat and Tests/PythonTest.py to check ver
authorRebecca Cran <rebecca@bsdio.com>
Mon, 24 Apr 2023 17:10:54 +0000 (11:10 -0600)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 8 May 2023 19:03:18 +0000 (19:03 +0000)
Update toolsetup.bat and Tests/PythonTest.py to check if we're running a
version of Python that's compatible with BaseTools and the Pip
BaseTools.

BaseTools uses syntax from Python 3.6 or newer, so set that as the minimum
version EDK2 requires.

Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
BaseTools/Tests/PythonTest.py
BaseTools/toolsetup.bat

index ec44c7947086c063c98e1c5a4fe78a2fc89dd2bb..b87c78570eae0cd8300ba775e7d6153643b28c71 100644 (file)
@@ -1,9 +1,27 @@
 ## @file\r
-# Test whether PYTHON_COMMAND is available\r
+# Test whether PYTHON_COMMAND is available and the\r
+# minimum Python version is installed.\r
 #\r
 # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
 # SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
+import sys\r
+\r
 if __name__ == '__main__':\r
-    print('TRUE')\r
+    # Check if the major and minor versions required were specified.\r
+    if len(sys.argv) >= 3:\r
+        req_major_version = int(sys.argv[1])\r
+        req_minor_version = int(sys.argv[2])\r
+    else:\r
+        # If the minimum version wasn't specified on the command line,\r
+        # default to 3.6 because BaseTools uses syntax from PEP 526\r
+        # (https://peps.python.org/pep-0526/)\r
+        req_major_version = 3\r
+        req_minor_version = 6\r
+\r
+    if sys.version_info.major == req_major_version and \\r
+       sys.version_info.minor >= req_minor_version:\r
+        sys.exit(0)\r
+    else:\r
+        sys.exit(1)\r
index 3d13e9fad2867342115ff132e8d9a534499cb512..dc6288effd7dd3c4aa061c48cc445c61f852bf11 100755 (executable)
@@ -12,6 +12,8 @@
 @echo off\r
 pushd .\r
 set SCRIPT_ERROR=0\r
+set PYTHON_VER_MAJOR=3\r
+set PYTHON_VER_MINOR=6\r
 \r
 @REM ##############################################################\r
 @REM # You should not have to modify anything below this line\r
@@ -304,17 +306,19 @@ goto check_build_environment
      )\r
   )\r
 \r
-:defined_python\r
+@REM Check Python environment\r
 \r
 if not defined PYTHON_COMMAND (\r
   set PYTHON_COMMAND=py -3\r
-  py -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1\r
-  setlocal enabledelayedexpansion\r
-  set /p PythonCheck=<"PythonCheck.txt"\r
-  del PythonCheck.txt\r
-  if "!PythonCheck!" NEQ "TRUE" (\r
+  py -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py %PYTHON_VER_MAJOR% %PYTHON_VER_MINOR% >NUL 2>NUL\r
+  if %ERRORLEVEL% EQU 1 (\r
+    echo.\r
+    echo !!! ERROR !!! Python %PYTHON_VER_MAJOR%.%PYTHON_VER_MINOR% or newer is required.\r
+    echo.\r
+    goto end\r
+  )\r
+  if %ERRORLEVEL% NEQ 0 (\r
     if not defined PYTHON_HOME if not defined PYTHONHOME (\r
-      endlocal\r
       set PYTHON_COMMAND=\r
       echo.\r
       echo !!! ERROR !!! Binary python tools are missing.\r
@@ -327,8 +331,6 @@ if not defined PYTHON_COMMAND (
   )\r
 )\r
 \r
-endlocal\r
-\r
 if defined PYTHON_HOME (\r
   if EXIST "%PYTHON_HOME%" (\r
     set PYTHON_COMMAND=%PYTHON_HOME%\python.exe\r
@@ -340,27 +342,30 @@ if defined PYTHON_HOME (
   )\r
 )\r
 \r
-%PYTHON_COMMAND% %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1\r
-  setlocal enabledelayedexpansion\r
-  set /p PythonCheck=<"PythonCheck.txt"\r
-  del PythonCheck.txt\r
-  if "!PythonCheck!" NEQ "TRUE" (\r
-    echo.\r
-    echo ! ERROR !  PYTHON_COMMAND="%PYTHON_COMMAND%" is not installed or added to environment variables\r
-    echo.\r
-    goto end\r
+%PYTHON_COMMAND% %BASE_TOOLS_PATH%\Tests\PythonTest.py %PYTHON_VER_MAJOR% %PYTHON_VER_MINOR% >NUL 2>NUL\r
+if %ERRORLEVEL% EQU 1 (\r
+  echo.\r
+  echo !!! ERROR !!! Python %PYTHON_VER_MAJOR%.%PYTHON_VER_MINOR% or newer is required.\r
+  echo.\r
+  goto end\r
+)\r
+if %ERRORLEVEL% NEQ 0 (\r
+  echo.\r
+  echo !!! ERROR !!!  PYTHON_COMMAND="%PYTHON_COMMAND%" does not exist or is not a Python interpreter.\r
+  echo.\r
+  goto end\r
 )\r
 \r
 endlocal\r
 \r
-  %PYTHON_COMMAND% -c "import edk2basetools" >NUL 2>NUL\r
-  if %ERRORLEVEL% EQU 0 (\r
-    goto use_pip_basetools\r
-  ) else (\r
-    REM reset ERRORLEVEL\r
-    type nul>nul\r
-    goto use_builtin_basetools\r
-  )\r
+%PYTHON_COMMAND% -c "import edk2basetools" >NUL 2>NUL\r
+if %ERRORLEVEL% EQU 0 (\r
+  goto use_pip_basetools\r
+) else (\r
+  REM reset ERRORLEVEL\r
+  type nul>nul\r
+  goto use_builtin_basetools\r
+)\r
 \r
 :use_builtin_basetools\r
   @echo Using EDK2 in-source Basetools\r
@@ -444,5 +449,7 @@ set VS2019=
 set VS2017=\r
 set VS2015=\r
 set VSTool=\r
+set PYTHON_VER_MAJOR=\r
+set PYTHON_VER_MINOR=\r
+set SCRIPT_ERROR=\r
 popd\r
-\r