From nobody Fri Dec 19 17:36:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+104198+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104198+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1683393870; cv=none; d=zohomail.com; s=zohoarc; b=aOsZ7701bd3cKOAcQV/ygfD/rtaYwdN25GiiCa7JdCfgvlWQgkDPFSg+GHk9Zl4lDGo/4s8YqfvdUDhRrjECOI8UqpDT+FTwgjxswxYahECGg1lARZhJyl6RKiKa3tjqqtE5hdC9tdtMR6Rm92jbsf0ixrgZHiPspD3nvJ810P0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683393870; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=uUsVf6HAZKLpnbWa4rNx1j1Z7unb2zHXurMY0K6oJzk=; b=a7A9Bnt6+391/ukrgkTSYWlEJTCXIjfWjXEFgkwm8SlXFlkPo6EjhTkXbCuT1W326UAAXAWfbVohPYJiOPlBccsHxNtgttv6+iIqoj08OHDQsguAd80xtj1vwXST779kTAUI26cVnnDIg4ScufTcUVmvhnyw3Hsq8cSGIkfA5X4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104198+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1683393870105777.2286934054944; Sat, 6 May 2023 10:24:30 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id NS8SYY1788612xJQFcMmuoU2; Sat, 06 May 2023 10:24:29 -0700 X-Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by mx.groups.io with SMTP id smtpd.web10.38460.1683393869066005517 for ; Sat, 06 May 2023 10:24:29 -0700 X-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 65FE35C0253; Sat, 6 May 2023 13:24:28 -0400 (EDT) X-Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sat, 06 May 2023 13:24:28 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeefgedgkeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfgvsggv tggtrgcuvehrrghnuceorhgvsggvtggtrgessghsughiohdrtghomheqnecuggftrfgrth htvghrnhephfdttdehhfejudefvedtueehuddvueetgfeiueefjefghfdvtdelfeetuddt gffgnecuffhomhgrihhnpehphihthhhonhdrohhrghenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrvggsvggttggrsegsshguihhordgtohhm X-ME-Proxy: Feedback-ID: i5b994698:Fastmail X-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 6 May 2023 13:24:27 -0400 (EDT) From: "Rebecca Cran" To: devel@edk2.groups.io, Andrew Fish , Leif Lindholm , Michael D Kinney , Liming Gao , Bob Feng , Yuwei Chen Cc: Rebecca Cran Subject: [edk2-devel] [PATCH v2 7/7] BaseTools: Update toolsetup.bat and Tests/PythonTest.py to check ver Date: Sat, 6 May 2023 11:24:02 -0600 Message-Id: <20230506172402.116-8-rebecca@bsdio.com> In-Reply-To: <20230506172402.116-1-rebecca@bsdio.com> References: <20230506172402.116-1-rebecca@bsdio.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,rebecca@bsdio.com X-Gm-Message-State: ZWP2fHHlzgOn7etCygIZgGlnx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683393869; bh=d5OagIm7Tfr2c4dCmbX6snkAPNcO0m8xNRXCzJRc4pI=; h=Cc:Date:From:Reply-To:Subject:To; b=nskm2xb34TEKVJFswR5HdgRQG93MNQGStv5ZwA0AqoLtlwRDS3nBP2GEQGyHLlAbH7l s24N20xif09GAe0NhD9CVZ+85BBjf80IOVahKcwoEYHu6fvE3AZQq5rFe57wiRoGlAemh 9Hftt9AS2nsRVLwzmpaBkwqNA5yukcvjhyk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683393871113100029 Content-Type: text/plain; charset="utf-8" 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 --- BaseTools/Tests/PythonTest.py | 22 ++++++- BaseTools/toolsetup.bat | 61 +++++++++++--------- 2 files changed, 54 insertions(+), 29 deletions(-) diff --git a/BaseTools/Tests/PythonTest.py b/BaseTools/Tests/PythonTest.py index ec44c7947086..b87c78570eae 100644 --- a/BaseTools/Tests/PythonTest.py +++ b/BaseTools/Tests/PythonTest.py @@ -1,9 +1,27 @@ ## @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.
# SPDX-License-Identifier: BSD-2-Clause-Patent # =20 +import sys + if __name__ =3D=3D '__main__': - print('TRUE') + # Check if the major and minor versions required were specified. + if len(sys.argv) >=3D 3: + req_major_version =3D int(sys.argv[1]) + req_minor_version =3D int(sys.argv[2]) + else: + # If the minimum version wasn't specified on the command line, + # default to 3.6 because BaseTools uses syntax from PEP 526 + # (https://peps.python.org/pep-0526/) + req_major_version =3D 3 + req_minor_version =3D 6 + + if sys.version_info.major =3D=3D req_major_version and \ + sys.version_info.minor >=3D req_minor_version: + sys.exit(0) + else: + sys.exit(1) diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat index 3d13e9fad286..dc6288effd7d 100755 --- a/BaseTools/toolsetup.bat +++ b/BaseTools/toolsetup.bat @@ -12,6 +12,8 @@ @echo off pushd . set SCRIPT_ERROR=3D0 +set PYTHON_VER_MAJOR=3D3 +set PYTHON_VER_MINOR=3D6 =20 @REM ############################################################## @REM # You should not have to modify anything below this line @@ -304,17 +306,19 @@ goto check_build_environment ) ) =20 -:defined_python +@REM Check Python environment =20 if not defined PYTHON_COMMAND ( set PYTHON_COMMAND=3Dpy -3 - py -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1 - setlocal enabledelayedexpansion - set /p PythonCheck=3D<"PythonCheck.txt" - del PythonCheck.txt - if "!PythonCheck!" NEQ "TRUE" ( + py -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py %PYTHON_VER_MAJOR% %PYTHON_V= ER_MINOR% >NUL 2>NUL + if %ERRORLEVEL% EQU 1 ( + echo. + echo !!! ERROR !!! Python %PYTHON_VER_MAJOR%.%PYTHON_VER_MINOR% or new= er is required. + echo. + goto end + ) + if %ERRORLEVEL% NEQ 0 ( if not defined PYTHON_HOME if not defined PYTHONHOME ( - endlocal set PYTHON_COMMAND=3D echo. echo !!! ERROR !!! Binary python tools are missing. @@ -327,8 +331,6 @@ if not defined PYTHON_COMMAND ( ) ) =20 -endlocal - if defined PYTHON_HOME ( if EXIST "%PYTHON_HOME%" ( set PYTHON_COMMAND=3D%PYTHON_HOME%\python.exe @@ -340,27 +342,30 @@ if defined PYTHON_HOME ( ) ) =20 -%PYTHON_COMMAND% %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>= &1 - setlocal enabledelayedexpansion - set /p PythonCheck=3D<"PythonCheck.txt" - del PythonCheck.txt - if "!PythonCheck!" NEQ "TRUE" ( - echo. - echo ! ERROR ! PYTHON_COMMAND=3D"%PYTHON_COMMAND%" is not installed o= r 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=3D"%PYTHON_COMMAND%" does not exist o= r is not a Python interpreter. + echo. + goto end ) =20 endlocal =20 - %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 +) =20 :use_builtin_basetools @echo Using EDK2 in-source Basetools @@ -444,5 +449,7 @@ set VS2019=3D set VS2017=3D set VS2015=3D set VSTool=3D +set PYTHON_VER_MAJOR=3D +set PYTHON_VER_MINOR=3D +set SCRIPT_ERROR=3D popd - --=20 2.40.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#104198): https://edk2.groups.io/g/devel/message/104198 Mute This Topic: https://groups.io/mt/98728632/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-