public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/6] edksetup.bat, BaseTools: Improve Windows environment setup and BaseTools C compilation
@ 2023-04-25 17:15 Rebecca Cran
  2023-04-25 17:15 ` [PATCH 1/6] BaseTools: Remove Python2/Python3 detection from toolset.bat Rebecca Cran
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Rebecca Cran @ 2023-04-25 17:15 UTC (permalink / raw)
  To: devel, Andrew Fish, Leif Lindholm, Michael D Kinney, Liming Gao,
	Bob Feng, Yuwei Chen
  Cc: Rebecca Cran

There are remnants of Python 2 support in BaseTools/toolsetup.bat that it's
probably time to remove since we only support Python 3.9 and newer these days.
So, remove the variables that enable Python3 support and simplify the batch
script. I've also seen errors where after running edksetup.bat the build
command isn't available because PYTHONPATH wasn't being set, so fix that
when the Pip BaseTools are being used.

At the same time, let's add a check that we meet the minimum version
requirement so we don't end up failing with an obscure error.

Building BaseTools causes a warning about threading.currentThread being
deprecated, so update code in NmakeSubdirs.py to switch to
threading.current_thread.

There needs to be further work, because if PYTHON_COMMAND isn't specified then
it defaults to "py -3", where py is C:\Windows\py.exe, which doesn't work if
you're using a virtualenv since it installs python.exe and pythonw.exe in
venv\Scripts. toolsetup.bat therefore fails to detect the Pip BaseTools and
uses the in-source Basetools.

GitHub PR: https://github.com/tianocore/edk2/pull/4302
GitHub branch: https://github.com/bcran/edk2/tree/py3

Rebecca Cran (6):
  BaseTools: Remove Python2/Python3 detection from toolset.bat
  BaseTools: use threading.current_thread in NmakeSubdirs.py
  edksetup.bat: if toolsetup.bat fails, just exit
  BaseTools: Update toolsetup.bat and Tests/PythonTest.py to check ver
  BaseTools: Update toolsetup.bat to not use BASETOOLS_PYTHON_SOURCE
  BaseTools: only print the environment once in toolsetup.bat

 BaseTools/Source/C/Makefiles/NmakeSubdirs.py |   2 +-
 BaseTools/Tests/PythonTest.py                |  21 ++-
 BaseTools/toolsetup.bat                      | 157 ++++++++------------
 edksetup.bat                                 |   1 +
 4 files changed, 85 insertions(+), 96 deletions(-)

-- 
2.40.0.windows.1


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

* [PATCH 1/6] BaseTools: Remove Python2/Python3 detection from toolset.bat
  2023-04-25 17:15 [PATCH 0/6] edksetup.bat, BaseTools: Improve Windows environment setup and BaseTools C compilation Rebecca Cran
@ 2023-04-25 17:15 ` Rebecca Cran
  2023-04-25 17:15 ` [PATCH 2/6] BaseTools: use threading.current_thread in NmakeSubdirs.py Rebecca Cran
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Rebecca Cran @ 2023-04-25 17:15 UTC (permalink / raw)
  To: devel, Andrew Fish, Leif Lindholm, Michael D Kinney, Liming Gao,
	Bob Feng, Yuwei Chen
  Cc: Rebecca Cran

Since Python3 is now required, we can remove the checks for PYTHON3_ENABLE
and PYTHON3 and simplify the code in toolsetup.bat. Also, remove the
leftover from when we supported freezing Python code.

While here, fix a couple of typos and improve error messages.

Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
---
 BaseTools/toolsetup.bat | 64 +++++---------------
 1 file changed, 16 insertions(+), 48 deletions(-)

diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat
index 58fd26a4b585..29a630b9035c 100755
--- a/BaseTools/toolsetup.bat
+++ b/BaseTools/toolsetup.bat
@@ -323,18 +323,8 @@ goto check_build_environment
   )
 
 :defined_python
-if defined PYTHON_COMMAND if not defined PYTHON3_ENABLE (
-  goto check_python_available
-)
-if defined PYTHON3_ENABLE (
-  if "%PYTHON3_ENABLE%" EQU "TRUE" (
-    set PYTHON_COMMAND=py -3
-    goto check_python_available
-  ) else (
-    goto check_python2
-  )
-)
-if not defined PYTHON_COMMAND if not defined PYTHON3_ENABLE (
+
+if not defined PYTHON_COMMAND (
   set PYTHON_COMMAND=py -3
   py -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1
   setlocal enabledelayedexpansion
@@ -346,56 +336,40 @@ if not defined PYTHON_COMMAND if not defined PYTHON3_ENABLE (
       set PYTHON_COMMAND=
       echo.
       echo !!! ERROR !!! Binary python tools are missing.
-      echo PYTHON_COMMAND, PYTHON3_ENABLE or PYTHON_HOME
-      echo Environment variable is not set successfully.
-      echo They is required to build or execute the python tools.
+      echo PYTHON_COMMAND or PYTHON_HOME
+      echo Environment variable is not set correctly.
+      echo They are required to build or execute the python tools.
       echo.
       goto end
-    ) else (
-      goto check_python2
     )
-  ) else (
-    goto check_freezer_path
   )
 )
 
-:check_python2
 endlocal
+
 if defined PYTHON_HOME (
   if EXIST "%PYTHON_HOME%" (
     set PYTHON_COMMAND=%PYTHON_HOME%\python.exe
-    goto check_python_available
+  ) else (
+    echo .
+    echo !!! ERROR !!!  PYTHON_HOME="%PYTHON_HOME%" does not exist.
+    echo .
+    goto end
   )
 )
-if defined PYTHONHOME (
-  if EXIST "%PYTHONHOME%" (
-    set PYTHON_HOME=%PYTHONHOME%
-    set PYTHON_COMMAND=%PYTHON_HOME%\python.exe
-    goto check_python_available
-  )
-)
-echo.
-echo !!! ERROR !!!  PYTHON_HOME is not defined or The value of this variable does not exist
-echo.
-goto end
-:check_python_available
+
 %PYTHON_COMMAND% %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1
   setlocal enabledelayedexpansion
   set /p PythonCheck=<"PythonCheck.txt"
   del PythonCheck.txt
   if "!PythonCheck!" NEQ "TRUE" (
     echo.
-    echo ! ERROR !  "%PYTHON_COMMAND%" is not installed or added to environment variables
+    echo ! ERROR !  PYTHON_COMMAND="%PYTHON_COMMAND%" is not installed or added to environment variables
     echo.
     goto end
-  ) else (
-    goto check_freezer_path
-  )
+)
 
-
-
-:check_freezer_path
-  endlocal
+endlocal
 
   %PYTHON_COMMAND% -c "import edk2basetools" >NUL 2>NUL
   if %ERRORLEVEL% EQU 0 (
@@ -422,13 +396,7 @@ goto end
 
 :print_python_info
   echo                PATH = %PATH%
-  if defined PYTHON3_ENABLE if "%PYTHON3_ENABLE%" EQU "TRUE" (
-    echo      PYTHON3_ENABLE = %PYTHON3_ENABLE%
-    echo             PYTHON3 = %PYTHON_COMMAND%
-  ) else (
-    echo      PYTHON3_ENABLE = FALSE
-    echo      PYTHON_COMMAND = %PYTHON_COMMAND%
-  )
+  echo      PYTHON_COMMAND = %PYTHON_COMMAND%
   echo          PYTHONPATH = %PYTHONPATH%
   echo.
 
-- 
2.40.0.windows.1


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

* [PATCH 2/6] BaseTools: use threading.current_thread in NmakeSubdirs.py
  2023-04-25 17:15 [PATCH 0/6] edksetup.bat, BaseTools: Improve Windows environment setup and BaseTools C compilation Rebecca Cran
  2023-04-25 17:15 ` [PATCH 1/6] BaseTools: Remove Python2/Python3 detection from toolset.bat Rebecca Cran
@ 2023-04-25 17:15 ` Rebecca Cran
  2023-04-25 17:15 ` [PATCH 3/6] edksetup.bat: if toolsetup.bat fails, just exit Rebecca Cran
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Rebecca Cran @ 2023-04-25 17:15 UTC (permalink / raw)
  To: devel, Andrew Fish, Leif Lindholm, Michael D Kinney, Liming Gao,
	Bob Feng, Yuwei Chen
  Cc: Rebecca Cran

threading.currentThread is a deprecated alias for
threading.current_thread, and causes a warning to be displayed when it's
called. Update NmakeSubdirs.py to use the latter method instead.

Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
---
 BaseTools/Source/C/Makefiles/NmakeSubdirs.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Source/C/Makefiles/NmakeSubdirs.py b/BaseTools/Source/C/Makefiles/NmakeSubdirs.py
index 1f4a45004f4b..7860c040afa0 100644
--- a/BaseTools/Source/C/Makefiles/NmakeSubdirs.py
+++ b/BaseTools/Source/C/Makefiles/NmakeSubdirs.py
@@ -132,7 +132,7 @@ class ThreadControl(object):
                 break
 
         self.runningLock.acquire(True)
-        self.running.remove(threading.currentThread())
+        self.running.remove(threading.current_thread())
         self.runningLock.release()
 
 def Run():
-- 
2.40.0.windows.1


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

* [PATCH 3/6] edksetup.bat: if toolsetup.bat fails, just exit
  2023-04-25 17:15 [PATCH 0/6] edksetup.bat, BaseTools: Improve Windows environment setup and BaseTools C compilation Rebecca Cran
  2023-04-25 17:15 ` [PATCH 1/6] BaseTools: Remove Python2/Python3 detection from toolset.bat Rebecca Cran
  2023-04-25 17:15 ` [PATCH 2/6] BaseTools: use threading.current_thread in NmakeSubdirs.py Rebecca Cran
@ 2023-04-25 17:15 ` Rebecca Cran
  2023-04-25 17:15 ` [PATCH 4/6] BaseTools: Update toolsetup.bat and Tests/PythonTest.py to check ver Rebecca Cran
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Rebecca Cran @ 2023-04-25 17:15 UTC (permalink / raw)
  To: devel, Andrew Fish, Leif Lindholm, Michael D Kinney, Liming Gao,
	Bob Feng, Yuwei Chen
  Cc: Rebecca Cran

If toolsetup.bat fails (i.e. exits with a non-zero %ERRORLEVEL%), don't
try and carry on but just quit.

Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
---
 edksetup.bat | 1 +
 1 file changed, 1 insertion(+)

diff --git a/edksetup.bat b/edksetup.bat
index 7ad137bb3e9b..b63b57fc873e 100755
--- a/edksetup.bat
+++ b/edksetup.bat
@@ -86,6 +86,7 @@ if exist %EDK_TOOLS_PATH%\Source set BASE_TOOLS_PATH=%EDK_TOOLS_PATH%
 :checkBaseTools
 IF NOT EXIST "%EDK_TOOLS_PATH%\toolsetup.bat" goto BadBaseTools
 call %EDK_TOOLS_PATH%\toolsetup.bat %*
+if %ERRORLEVEL% NEQ 0 goto end
 if /I "%1"=="Reconfig" shift
 goto check_NASM
 goto check_cygwin
-- 
2.40.0.windows.1


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

* [PATCH 4/6] BaseTools: Update toolsetup.bat and Tests/PythonTest.py to check ver
  2023-04-25 17:15 [PATCH 0/6] edksetup.bat, BaseTools: Improve Windows environment setup and BaseTools C compilation Rebecca Cran
                   ` (2 preceding siblings ...)
  2023-04-25 17:15 ` [PATCH 3/6] edksetup.bat: if toolsetup.bat fails, just exit Rebecca Cran
@ 2023-04-25 17:15 ` Rebecca Cran
  2023-04-27  3:11   ` 回复: [edk2-devel] " gaoliming
  2023-04-25 17:15 ` [PATCH 5/6] BaseTools: Update toolsetup.bat to not use BASETOOLS_PYTHON_SOURCE Rebecca Cran
  2023-04-25 17:15 ` [PATCH 6/6] BaseTools: only print the environment once in toolsetup.bat Rebecca Cran
  5 siblings, 1 reply; 8+ messages in thread
From: Rebecca Cran @ 2023-04-25 17:15 UTC (permalink / raw)
  To: devel, Andrew Fish, Leif Lindholm, Michael D Kinney, Liming Gao,
	Bob Feng, Yuwei Chen
  Cc: Rebecca Cran

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.

Since edk2-pytool-extensions
(https://pypi.org/project/edk2-pytool-extensions/) requires Python 3.9
or newer, set that as the minimum version EDK2 requires.

Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
---
 BaseTools/Tests/PythonTest.py | 21 ++++++-
 BaseTools/toolsetup.bat       | 61 +++++++++++---------
 2 files changed, 53 insertions(+), 29 deletions(-)

diff --git a/BaseTools/Tests/PythonTest.py b/BaseTools/Tests/PythonTest.py
index ec44c7947086..1716f78b5217 100644
--- a/BaseTools/Tests/PythonTest.py
+++ b/BaseTools/Tests/PythonTest.py
@@ -1,9 +1,26 @@
 ## @file
-# Test whether PYTHON_COMMAND is available
+# Test whether PYTHON_COMMAND is available and the
+# minimum Python version is installed.
 #
 # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 
+import sys
+
 if __name__ == '__main__':
-    print('TRUE')
+    # Check if the major and minor versions required were specified.
+    if len(sys.argv) >= 3:
+        req_major_version = int(sys.argv[1])
+        req_minor_version = int(sys.argv[2])
+    else:
+        # If the minimum version wasn't specified on the command line,
+        # default to 3.9 which was the minimum required on 2023-04-24.
+        req_major_version = 3
+        req_minor_version = 9
+
+    if sys.version_info.major == req_major_version and \
+       sys.version_info.minor >= req_minor_version:
+        sys.exit(0)
+    else:
+        sys.exit(1)
diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat
index 29a630b9035c..66df628eac5f 100755
--- a/BaseTools/toolsetup.bat
+++ b/BaseTools/toolsetup.bat
@@ -12,6 +12,8 @@
 @echo off
 pushd .
 set SCRIPT_ERROR=0
+set PYTHON_VER_MAJOR=3
+set PYTHON_VER_MINOR=9
 
 @REM ##############################################################
 @REM # You should not have to modify anything below this line
@@ -322,17 +324,19 @@ goto check_build_environment
      )
   )
 
-:defined_python
+@REM Check Python environment
 
 if not defined PYTHON_COMMAND (
   set PYTHON_COMMAND=py -3
-  py -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1
-  setlocal enabledelayedexpansion
-  set /p PythonCheck=<"PythonCheck.txt"
-  del PythonCheck.txt
-  if "!PythonCheck!" NEQ "TRUE" (
+  py -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py %PYTHON_VER_MAJOR% %PYTHON_VER_MINOR% >NUL 2>NUL
+  if %ERRORLEVEL% EQU 1 (
+    echo.
+    echo !!! ERROR !!! Python %PYTHON_VER_MAJOR%.%PYTHON_VER_MINOR% or newer is required.
+    echo.
+    goto end
+  )
+  if %ERRORLEVEL% NEQ 0 (
     if not defined PYTHON_HOME if not defined PYTHONHOME (
-      endlocal
       set PYTHON_COMMAND=
       echo.
       echo !!! ERROR !!! Binary python tools are missing.
@@ -345,8 +349,6 @@ if not defined PYTHON_COMMAND (
   )
 )
 
-endlocal
-
 if defined PYTHON_HOME (
   if EXIST "%PYTHON_HOME%" (
     set PYTHON_COMMAND=%PYTHON_HOME%\python.exe
@@ -358,27 +360,30 @@ if defined PYTHON_HOME (
   )
 )
 
-%PYTHON_COMMAND% %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1
-  setlocal enabledelayedexpansion
-  set /p PythonCheck=<"PythonCheck.txt"
-  del PythonCheck.txt
-  if "!PythonCheck!" NEQ "TRUE" (
-    echo.
-    echo ! ERROR !  PYTHON_COMMAND="%PYTHON_COMMAND%" is not installed or added to environment variables
-    echo.
-    goto end
+%PYTHON_COMMAND% %BASE_TOOLS_PATH%\Tests\PythonTest.py %PYTHON_VER_MAJOR% %PYTHON_VER_MINOR% >NUL 2>NUL
+if %ERRORLEVEL% EQU 1 (
+  echo.
+  echo !!! ERROR !!! Python %PYTHON_VER_MAJOR%.%PYTHON_VER_MINOR% or newer is required.
+  echo.
+  goto end
+)
+if %ERRORLEVEL% NEQ 0 (
+  echo.
+  echo !!! ERROR !!!  PYTHON_COMMAND="%PYTHON_COMMAND%" does not exist or is not a Python interpreter.
+  echo.
+  goto end
 )
 
 endlocal
 
-  %PYTHON_COMMAND% -c "import edk2basetools" >NUL 2>NUL
-  if %ERRORLEVEL% EQU 0 (
-    goto use_pip_basetools
-  ) else (
-    REM reset ERRORLEVEL
-    type nul>nul
-    goto use_builtin_basetools
-  )
+%PYTHON_COMMAND% -c "import edk2basetools" >NUL 2>NUL
+if %ERRORLEVEL% EQU 0 (
+  goto use_pip_basetools
+) else (
+  REM reset ERRORLEVEL
+  type nul>nul
+  goto use_builtin_basetools
+)
 
 :use_builtin_basetools
   @echo Using EDK2 in-source Basetools
@@ -466,5 +471,7 @@ set VS2015=
 set VS2013=
 set VS2012=
 set VSTool=
+set PYTHON_VER_MAJOR=
+set PYTHON_VER_MINOR=
+set SCRIPT_ERROR=
 popd
-
-- 
2.40.0.windows.1


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

* [PATCH 5/6] BaseTools: Update toolsetup.bat to not use BASETOOLS_PYTHON_SOURCE
  2023-04-25 17:15 [PATCH 0/6] edksetup.bat, BaseTools: Improve Windows environment setup and BaseTools C compilation Rebecca Cran
                   ` (3 preceding siblings ...)
  2023-04-25 17:15 ` [PATCH 4/6] BaseTools: Update toolsetup.bat and Tests/PythonTest.py to check ver Rebecca Cran
@ 2023-04-25 17:15 ` Rebecca Cran
  2023-04-25 17:15 ` [PATCH 6/6] BaseTools: only print the environment once in toolsetup.bat Rebecca Cran
  5 siblings, 0 replies; 8+ messages in thread
From: Rebecca Cran @ 2023-04-25 17:15 UTC (permalink / raw)
  To: devel, Andrew Fish, Leif Lindholm, Michael D Kinney, Liming Gao,
	Bob Feng, Yuwei Chen
  Cc: Rebecca Cran

The BASETOOLS_PYTHON_SOURCE environment variable is only used temporarily to
set PYTHONPATH. Since it doesn't help improve clarity, remove it.

While here, make sure we set PYTHONPATH when we're using Pip BaseTools
so that build etc. can be found.

Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
---
 BaseTools/toolsetup.bat | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat
index 66df628eac5f..80aa2992ba80 100755
--- a/BaseTools/toolsetup.bat
+++ b/BaseTools/toolsetup.bat
@@ -389,14 +389,13 @@ if %ERRORLEVEL% EQU 0 (
   @echo Using EDK2 in-source Basetools
   if defined BASETOOLS_PYTHON_SOURCE goto print_python_info
   set "PATH=%BASE_TOOLS_PATH%\BinWrappers\WindowsLike;%PATH%"
-  set BASETOOLS_PYTHON_SOURCE=%BASE_TOOLS_PATH%\Source\Python
-  set PYTHONPATH=%BASETOOLS_PYTHON_SOURCE%;%PYTHONPATH%
+  set PYTHONPATH=%BASE_TOOLS_PATH%\Source\Python;%PYTHONPATH%
   goto print_python_info
 
 :use_pip_basetools
   @echo Using Pip Basetools
   set "PATH=%BASE_TOOLS_PATH%\BinPipWrappers\WindowsLike;%PATH%"
-  set BASETOOLS_PYTHON_SOURCE=edk2basetools
+  set PYTHONPATH=%BASE_TOOLS_PATH%\Source\Python;%PYTHONPATH%
   goto print_python_info
 
 :print_python_info
-- 
2.40.0.windows.1


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

* [PATCH 6/6] BaseTools: only print the environment once in toolsetup.bat
  2023-04-25 17:15 [PATCH 0/6] edksetup.bat, BaseTools: Improve Windows environment setup and BaseTools C compilation Rebecca Cran
                   ` (4 preceding siblings ...)
  2023-04-25 17:15 ` [PATCH 5/6] BaseTools: Update toolsetup.bat to not use BASETOOLS_PYTHON_SOURCE Rebecca Cran
@ 2023-04-25 17:15 ` Rebecca Cran
  5 siblings, 0 replies; 8+ messages in thread
From: Rebecca Cran @ 2023-04-25 17:15 UTC (permalink / raw)
  To: devel, Andrew Fish, Leif Lindholm, Michael D Kinney, Liming Gao,
	Bob Feng, Yuwei Chen
  Cc: Rebecca Cran

Avoid printing %PATH% twice: move the printing of the environment down
to print_python_info.

Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
---
 BaseTools/toolsetup.bat | 35 +++++++++-----------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat
index 80aa2992ba80..6edfa3074f80 100755
--- a/BaseTools/toolsetup.bat
+++ b/BaseTools/toolsetup.bat
@@ -268,24 +268,6 @@ if NOT exist %CONF_PATH%\build_rule.txt (
   if defined RECONFIG copy /Y %EDK_TOOLS_PATH%\Conf\build_rule.template %CONF_PATH%\build_rule.txt > nul
 )
 
-echo           PATH      = %PATH%
-echo.
-if defined WORKSPACE (
-  echo      WORKSPACE      = %WORKSPACE%
-)
-if defined PACKAGES_PATH (
-  echo  PACKAGES_PATH      = %PACKAGES_PATH%
-)
-echo EDK_TOOLS_PATH      = %EDK_TOOLS_PATH%
-if defined BASE_TOOLS_PATH (
-  echo BASE_TOOLS_PATH     = %BASE_TOOLS_PATH%
-)
-if defined EDK_TOOLS_BIN (
-  echo  EDK_TOOLS_BIN      = %EDK_TOOLS_BIN%
-)
-echo      CONF_PATH      = %CONF_PATH%
-echo.
-
 :skip_reconfig
 
 @REM
@@ -399,7 +381,22 @@ if %ERRORLEVEL% EQU 0 (
   goto print_python_info
 
 :print_python_info
-  echo                PATH = %PATH%
+  echo           PATH      = %PATH%
+  echo.
+  if defined WORKSPACE (
+    echo      WORKSPACE      = %WORKSPACE%
+  )
+  if defined PACKAGES_PATH (
+    echo  PACKAGES_PATH      = %PACKAGES_PATH%
+  )
+  echo EDK_TOOLS_PATH      = %EDK_TOOLS_PATH%
+  if defined BASE_TOOLS_PATH (
+    echo BASE_TOOLS_PATH     = %BASE_TOOLS_PATH%
+  )
+  if defined EDK_TOOLS_BIN (
+    echo  EDK_TOOLS_BIN      = %EDK_TOOLS_BIN%
+  )
+  echo      CONF_PATH      = %CONF_PATH%
   echo      PYTHON_COMMAND = %PYTHON_COMMAND%
   echo          PYTHONPATH = %PYTHONPATH%
   echo.
-- 
2.40.0.windows.1


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

* 回复: [edk2-devel] [PATCH 4/6] BaseTools: Update toolsetup.bat and Tests/PythonTest.py to check ver
  2023-04-25 17:15 ` [PATCH 4/6] BaseTools: Update toolsetup.bat and Tests/PythonTest.py to check ver Rebecca Cran
@ 2023-04-27  3:11   ` gaoliming
  0 siblings, 0 replies; 8+ messages in thread
From: gaoliming @ 2023-04-27  3:11 UTC (permalink / raw)
  To: devel, rebecca, 'Andrew Fish', 'Leif Lindholm',
	'Michael D Kinney', 'Bob Feng',
	'Yuwei Chen'

Rebecca:
  This change will break some development machines those have not installed
Python 3.9 or above. Now, those machines can still work.
  
  I suggest to report warning message first if the python version doesn't
match.

Thanks
Liming
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Rebecca Cran
> 发送时间: 2023年4月26日 1:15
> 收件人: devel@edk2.groups.io; Andrew Fish <afish@apple.com>; Leif
> Lindholm <quic_llindhol@quicinc.com>; Michael D Kinney
> <michael.d.kinney@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>;
> Bob Feng <bob.c.feng@intel.com>; Yuwei Chen <yuwei.chen@intel.com>
> 抄送: Rebecca Cran <rebecca@bsdio.com>
> 主题: [edk2-devel] [PATCH 4/6] BaseTools: Update toolsetup.bat and
> Tests/PythonTest.py to check ver
> 
> 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.
> 
> Since edk2-pytool-extensions
> (https://pypi.org/project/edk2-pytool-extensions/) requires Python 3.9
> or newer, set that as the minimum version EDK2 requires.
> 
> Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
> ---
>  BaseTools/Tests/PythonTest.py | 21 ++++++-
>  BaseTools/toolsetup.bat       | 61 +++++++++++---------
>  2 files changed, 53 insertions(+), 29 deletions(-)
> 
> diff --git a/BaseTools/Tests/PythonTest.py b/BaseTools/Tests/PythonTest.py
> index ec44c7947086..1716f78b5217 100644
> --- a/BaseTools/Tests/PythonTest.py
> +++ b/BaseTools/Tests/PythonTest.py
> @@ -1,9 +1,26 @@
>  ## @file
> -# Test whether PYTHON_COMMAND is available
> +# Test whether PYTHON_COMMAND is available and the
> +# minimum Python version is installed.
>  #
>  # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
>  # SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
> 
> +import sys
> +
>  if __name__ == '__main__':
> -    print('TRUE')
> +    # Check if the major and minor versions required were specified.
> +    if len(sys.argv) >= 3:
> +        req_major_version = int(sys.argv[1])
> +        req_minor_version = int(sys.argv[2])
> +    else:
> +        # If the minimum version wasn't specified on the command line,
> +        # default to 3.9 which was the minimum required on 2023-04-24.
> +        req_major_version = 3
> +        req_minor_version = 9
> +
> +    if sys.version_info.major == req_major_version and \
> +       sys.version_info.minor >= req_minor_version:
> +        sys.exit(0)
> +    else:
> +        sys.exit(1)
> diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat
> index 29a630b9035c..66df628eac5f 100755
> --- a/BaseTools/toolsetup.bat
> +++ b/BaseTools/toolsetup.bat
> @@ -12,6 +12,8 @@
>  @echo off
>  pushd .
>  set SCRIPT_ERROR=0
> +set PYTHON_VER_MAJOR=3
> +set PYTHON_VER_MINOR=9
> 
>  @REM
> ##############################################################
>  @REM # You should not have to modify anything below this line
> @@ -322,17 +324,19 @@ goto check_build_environment
>       )
>    )
> 
> -:defined_python
> +@REM Check Python environment
> 
>  if not defined PYTHON_COMMAND (
>    set PYTHON_COMMAND=py -3
> -  py -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1
> -  setlocal enabledelayedexpansion
> -  set /p PythonCheck=<"PythonCheck.txt"
> -  del PythonCheck.txt
> -  if "!PythonCheck!" NEQ "TRUE" (
> +  py
> -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py %PYTHON_VER_MAJOR% %P
> YTHON_VER_MINOR% >NUL 2>NUL
> +  if %ERRORLEVEL% EQU 1 (
> +    echo.
> +    echo !!! ERROR !!!
> Python %PYTHON_VER_MAJOR%.%PYTHON_VER_MINOR% or newer is
> required.
> +    echo.
> +    goto end
> +  )
> +  if %ERRORLEVEL% NEQ 0 (
>      if not defined PYTHON_HOME if not defined PYTHONHOME (
> -      endlocal
>        set PYTHON_COMMAND=
>        echo.
>        echo !!! ERROR !!! Binary python tools are missing.
> @@ -345,8 +349,6 @@ if not defined PYTHON_COMMAND (
>    )
>  )
> 
> -endlocal
> -
>  if defined PYTHON_HOME (
>    if EXIST "%PYTHON_HOME%" (
>      set PYTHON_COMMAND=%PYTHON_HOME%\python.exe
> @@ -358,27 +360,30 @@ if defined PYTHON_HOME (
>    )
>  )
> 
> -%PYTHON_COMMAND% %BASE_TOOLS_PATH%\Tests\PythonTest.py >Pyth
> onCheck.txt 2>&1
> -  setlocal enabledelayedexpansion
> -  set /p PythonCheck=<"PythonCheck.txt"
> -  del PythonCheck.txt
> -  if "!PythonCheck!" NEQ "TRUE" (
> -    echo.
> -    echo ! ERROR !  PYTHON_COMMAND="%PYTHON_COMMAND%" is
> not installed or added to environment variables
> -    echo.
> -    goto end
> +%PYTHON_COMMAND% %BASE_TOOLS_PATH%\Tests\PythonTest.py %PYT
> HON_VER_MAJOR% %PYTHON_VER_MINOR% >NUL 2>NUL
> +if %ERRORLEVEL% EQU 1 (
> +  echo.
> +  echo !!! ERROR !!!
> Python %PYTHON_VER_MAJOR%.%PYTHON_VER_MINOR% or newer is
> required.
> +  echo.
> +  goto end
> +)
> +if %ERRORLEVEL% NEQ 0 (
> +  echo.
> +  echo !!! ERROR !!!  PYTHON_COMMAND="%PYTHON_COMMAND%"
> does not exist or is not a Python interpreter.
> +  echo.
> +  goto end
>  )
> 
>  endlocal
> 
> -  %PYTHON_COMMAND% -c "import edk2basetools" >NUL 2>NUL
> -  if %ERRORLEVEL% EQU 0 (
> -    goto use_pip_basetools
> -  ) else (
> -    REM reset ERRORLEVEL
> -    type nul>nul
> -    goto use_builtin_basetools
> -  )
> +%PYTHON_COMMAND% -c "import edk2basetools" >NUL 2>NUL
> +if %ERRORLEVEL% EQU 0 (
> +  goto use_pip_basetools
> +) else (
> +  REM reset ERRORLEVEL
> +  type nul>nul
> +  goto use_builtin_basetools
> +)
> 
>  :use_builtin_basetools
>    @echo Using EDK2 in-source Basetools
> @@ -466,5 +471,7 @@ set VS2015=
>  set VS2013=
>  set VS2012=
>  set VSTool=
> +set PYTHON_VER_MAJOR=
> +set PYTHON_VER_MINOR=
> +set SCRIPT_ERROR=
>  popd
> -
> --
> 2.40.0.windows.1
> 
> 
> 
> 
> 




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

end of thread, other threads:[~2023-04-27  3:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-25 17:15 [PATCH 0/6] edksetup.bat, BaseTools: Improve Windows environment setup and BaseTools C compilation Rebecca Cran
2023-04-25 17:15 ` [PATCH 1/6] BaseTools: Remove Python2/Python3 detection from toolset.bat Rebecca Cran
2023-04-25 17:15 ` [PATCH 2/6] BaseTools: use threading.current_thread in NmakeSubdirs.py Rebecca Cran
2023-04-25 17:15 ` [PATCH 3/6] edksetup.bat: if toolsetup.bat fails, just exit Rebecca Cran
2023-04-25 17:15 ` [PATCH 4/6] BaseTools: Update toolsetup.bat and Tests/PythonTest.py to check ver Rebecca Cran
2023-04-27  3:11   ` 回复: [edk2-devel] " gaoliming
2023-04-25 17:15 ` [PATCH 5/6] BaseTools: Update toolsetup.bat to not use BASETOOLS_PYTHON_SOURCE Rebecca Cran
2023-04-25 17:15 ` [PATCH 6/6] BaseTools: only print the environment once in toolsetup.bat Rebecca Cran

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