## @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
@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
)\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
)\r
)\r
\r
-endlocal\r
-\r
if defined PYTHON_HOME (\r
if EXIST "%PYTHON_HOME%" (\r
set PYTHON_COMMAND=%PYTHON_HOME%\python.exe\r
)\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
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