Python/xenia-build/xb fixes

Use variable for Python version to make upgrading easier.
xb.bat:
 Update copyright date.
 Add candidate paths.
xb.ps1
 Properly use found python executable.
 More consistency with .bat.
 Don't spew unnecessary errors, etc.
 EOF newline.
This commit is contained in:
Margen67 2022-03-09 07:07:46 -08:00 committed by Rick Gibbed
parent 6ff312afb1
commit 74d83e4af8
3 changed files with 28 additions and 20 deletions

19
xb.bat
View File

@ -1,5 +1,5 @@
@ECHO OFF
REM Copyright 2015 Ben Vanik. All Rights Reserved.
REM Copyright 2022 Ben Vanik. All Rights Reserved.
SET "DIR=%~dp0"
@ -7,10 +7,12 @@ REM ============================================================================
REM Environment Validation
REM ============================================================================
SET "PYTHON_MINIMUM_VERSION[0]=3"
SET "PYTHON_MINIMUM_VERSION[1]=6"
CALL :check_python
IF %_RESULT% NEQ 0 (
ECHO.
ECHO Python 3.6+ must be installed and on PATH:
ECHO Python %PYTHON_MINIMUM_VERSION[0]%.%PYTHON_MINIMUM_VERSION[1]%+ must be installed and on PATH:
ECHO https://www.python.org/
GOTO :eof
)
@ -33,9 +35,12 @@ SETLOCAL ENABLEDELAYEDEXPANSION
SET FOUND_PATH=""
SET "CANDIDATE_PATHS[0]=C:\python37\python.exe"
SET "CANDIDATE_PATHS[1]=C:\python36\python.exe"
SET OUTPUT_INDEX=2
SET "CANDIDATE_PATHS[0]=C:\python310\python.exe"
SET "CANDIDATE_PATHS[1]=C:\python39\python.exe"
SET "CANDIDATE_PATHS[2]=C:\python38\python.exe"
SET "CANDIDATE_PATHS[3]=C:\python37\python.exe"
SET "CANDIDATE_PATHS[4]=C:\python%PYTHON_MINIMUM_VERSION[0]%%PYTHON_MINIMUM_VERSION[1]%\python.exe"
SET OUTPUT_INDEX=5
FOR /F "usebackq delims=" %%L IN (`2^>NUL where python3`) DO (
IF %%~zL NEQ 0 (
@ -70,9 +75,9 @@ IF "%FOUND_PATH%"=="" (
GOTO :eof
)
CMD /C ""%FOUND_PATH%" -c "import sys; sys.exit(1 if not sys.version_info[:2] ^>= (3, 6) else 0)"
CMD /C ""%FOUND_PATH%" -c "import sys; sys.exit(1 if not sys.version_info[:2] ^>= (%PYTHON_MINIMUM_VERSION[0]%, %PYTHON_MINIMUM_VERSION[1]%) else 0)"
IF %ERRORLEVEL% NEQ 0 (
ECHO ERROR: Python version mismatch, not at least 3.6.
ECHO ERROR: Python version mismatch, not at least %PYTHON_MINIMUM_VERSION[0]%.%PYTHON_MINIMUM_VERSION[1]%.
ECHO Found Python executable was "%FOUND_PATH%".
ENDLOCAL & SET _RESULT=1
GOTO :eof

23
xb.ps1
View File

@ -5,20 +5,23 @@ function Write-FatalError($message) {
Exit 1
}
$pythonPath = Get-Command python | Select-Object -ExpandProperty Definition
# Check for 'python3' if 'python' isn't found
if ([string]::IsNullOrEmpty($pythonPath)) {
$pythonPath = Get-Command python3 | Select-Object -ExpandProperty Definition
$pythonExecutables = 'python', 'python3'
foreach ($pythonExecutable in $pythonExecutables) {
if (!$pythonPath) {
$pythonPath = powershell -NoLogo -NonInteractive "(Get-Command -ErrorAction SilentlyContinue $pythonexecutable).Definition" # Hack to not give command suggestion
} else {
break
}
}
# Neither found, error and exit
if ([string]::IsNullOrEmpty($pythonPath)) {
Write-FatalError "ERROR: no Python executable found on PATH.`nMake sure you can run 'python' or 'python3' in a Command Prompt."
$pythonMinimumVer = 3,6
if (!$pythonPath) {
Write-FatalError "ERROR: Python $($pythonMinimumVer[0]).$($pythonMinimumVer[1])+ must be installed and on PATH:`nhttps://www.python.org/"
}
python -c "import sys; sys.exit(1 if not sys.version_info[:2] >= (3, 4) else 0)"
& $pythonPath -c "import sys; sys.exit(1 if not sys.version_info[:2] >= ($($pythonMinimumVer[0]), $($pythonMinimumVer[1])) else 0)"
if ($LASTEXITCODE -gt 0) {
Write-FatalError "ERROR: Python version mismatch, not at least 3.4.`nFound Python executable was $($pythonPath)"
Write-FatalError "ERROR: Python version mismatch, not at least $($pythonMinimumVer[0]).$($pythonMinimumVer[1]).`nFound Python executable was `"$($pythonPath)`"."
}
python "$($PSScriptRoot)/xenia-build" $args
& $pythonPath "$($PSScriptRoot)/xenia-build" $args

View File

@ -134,8 +134,9 @@ def main():
print('')
# Check python version.
if not sys.version_info[:2] >= (3, 6):
print('ERROR: Python 3.6+ must be installed and on PATH')
python_minimum_ver=3,6
if not sys.version_info[:2] >= (python_minimum_ver[0], python_minimum_ver[1]):
print('ERROR: Python ', python_minimum_ver[0], '.', python_minimum_ver[1], '+ must be installed and on PATH', sep='')
sys.exit(1)
# Grab Visual Studio version and execute shell to set up environment.
@ -1830,4 +1831,3 @@ class DevenvCommand(Command):
if __name__ == '__main__':
main()