Fix handling of paths to Python with spaces in xb.bat.

This commit is contained in:
gibbed 2019-08-23 10:39:03 -05:00 committed by Rick Gibbed
parent 24321dbcd9
commit 16bbfdbb3c
1 changed files with 23 additions and 29 deletions

48
xb.bat
View File

@ -1,7 +1,7 @@
@ECHO OFF @ECHO OFF
REM Copyright 2015 Ben Vanik. All Rights Reserved. REM Copyright 2015 Ben Vanik. All Rights Reserved.
SET DIR=%~dp0 SET "DIR=%~dp0"
REM ============================================================================ REM ============================================================================
REM Environment Validation REM Environment Validation
@ -20,7 +20,7 @@ REM ============================================================================
REM Trampoline into xenia-build REM Trampoline into xenia-build
REM ============================================================================ REM ============================================================================
"%PYTHON_EXE%" xenia-build %* "%PYTHON_EXE%" "%DIR%\xenia-build" %*
EXIT /b %ERRORLEVEL% EXIT /b %ERRORLEVEL%
@ -33,19 +33,23 @@ SETLOCAL ENABLEDELAYEDEXPANSION
SET FOUND_PATH="" SET FOUND_PATH=""
SET CANDIDATE_PATHS[0]=C:\python37\python.exe SET "CANDIDATE_PATHS[0]=C:\python37\python.exe"
SET CANDIDATE_PATHS[1]=C:\python36\python.exe SET "CANDIDATE_PATHS[1]=C:\python36\python.exe"
SET CANDIDATE_PATHS[2]=C:\python35\python.exe SET "CANDIDATE_PATHS[2]=C:\python35\python.exe"
SET CANDIDATE_PATHS[3]=C:\python34\python.exe SET "CANDIDATE_PATHS[3]=C:\python34\python.exe"
SET OUTPUT_INDEX=4 SET OUTPUT_INDEX=4
FOR /F "usebackq" %%l IN (`2^>NUL where python3`) DO ( FOR /F "usebackq delims=" %%L IN (`2^>NUL where python3`) DO (
SET CANDIDATE_PATHS[!OUTPUT_INDEX!]=%%l IF %%~zL NEQ 0 (
SET "CANDIDATE_PATHS[!OUTPUT_INDEX!]=%%L"
SET /A OUTPUT_INDEX+=1 SET /A OUTPUT_INDEX+=1
)
) )
FOR /F "usebackq" %%l IN (`2^>NUL where python`) DO ( FOR /F "usebackq delims=" %%L IN (`2^>NUL where python`) DO (
SET CANDIDATE_PATHS[!OUTPUT_INDEX!]=%%l IF %%~zL NEQ 0 (
SET "CANDIDATE_PATHS[!OUTPUT_INDEX!]=%%L"
SET /A OUTPUT_INDEX+=1 SET /A OUTPUT_INDEX+=1
)
) )
SET CANDIDATE_INDEX=0 SET CANDIDATE_INDEX=0
@ -54,40 +58,30 @@ IF NOT DEFINED CANDIDATE_PATHS[%CANDIDATE_INDEX%] (
GOTO :found_python GOTO :found_python
) )
CALL SET CANDIDATE_PATH=%%CANDIDATE_PATHS[%CANDIDATE_INDEX%]%% CALL SET CANDIDATE_PATH=%%CANDIDATE_PATHS[%CANDIDATE_INDEX%]%%
IF NOT EXIST %CANDIDATE_PATH% ( IF NOT EXIST "%CANDIDATE_PATH%" (
SET /A CANDIDATE_INDEX+=1 SET /A CANDIDATE_INDEX+=1
GOTO :check_candidate_loop GOTO :check_candidate_loop
) )
CALL :get_size %CANDIDATE_PATH% SET "FOUND_PATH=%CANDIDATE_PATH%"
IF %_SIZE% NEQ 0 (
SET FOUND_PATH=%CANDIDATE_PATH%
GOTO :found_python
)
SET /A CANDIDATE_INDEX+=1
GOTO :check_candidate_loop
:found_python :found_python
IF %FOUND_PATH%=="" ( IF "%FOUND_PATH%"=="" (
ECHO ERROR: no Python executable found on PATH. ECHO ERROR: no Python executable found on PATH.
ECHO Make sure you can run 'python' or 'python3' in a Command Prompt. ECHO Make sure you can run 'python' or 'python3' in a Command Prompt.
ENDLOCAL & SET _RESULT=1 ENDLOCAL & SET _RESULT=1
GOTO :eof GOTO :eof
) )
CMD /C %FOUND_PATH% -c "import sys; sys.exit(1 if not sys.version_info[:2] >= (3, 4) else 0)" CMD /C ""%FOUND_PATH%" -c "import sys; sys.exit(1 if not sys.version_info[:2] ^>= (3, 4) else 0)"
IF %ERRORLEVEL% NEQ 0 ( IF %ERRORLEVEL% NEQ 0 (
ECHO ERROR: Python version mismatch - not 3.4+ ECHO ERROR: Python version mismatch, not at least 3.4.
ECHO Found Python executable was '%FOUND_PATH%'. ECHO Found Python executable was "%FOUND_PATH%".
ENDLOCAL & SET _RESULT=1 ENDLOCAL & SET _RESULT=1
GOTO :eof GOTO :eof
) )
ENDLOCAL & ( ENDLOCAL & (
SET _RESULT=0 SET _RESULT=0
SET PYTHON_EXE=%FOUND_PATH% SET "PYTHON_EXE=%FOUND_PATH%"
) )
GOTO :eof GOTO :eof
:get_size
SET _SIZE=%~z1
goto :eof