2018-07-30 22:52:29 +08:00
|
|
|
@echo off
|
|
|
|
setlocal
|
|
|
|
|
2018-07-31 22:35:02 +08:00
|
|
|
rem BAT script that creates the client python api of LibCarla (carla.org).
|
|
|
|
rem Run it through a cmd with the x64 Visual C++ Toolset enabled.
|
|
|
|
|
2018-07-30 22:52:29 +08:00
|
|
|
set LOCAL_PATH=%~dp0
|
2018-07-31 22:35:02 +08:00
|
|
|
set "FILE_N=-[%~n0]:"
|
|
|
|
|
2018-08-29 18:24:30 +08:00
|
|
|
rem Print batch params (debug purpose)
|
|
|
|
echo %FILE_N% [Batch params]: %*
|
|
|
|
|
2018-07-31 22:35:02 +08:00
|
|
|
rem ============================================================================
|
|
|
|
rem -- Parse arguments ---------------------------------------------------------
|
|
|
|
rem ============================================================================
|
2018-07-30 22:52:29 +08:00
|
|
|
|
|
|
|
set DOC_STRING=Build and package CARLA Python API.
|
|
|
|
set "USAGE_STRING=Usage: %FILE_N% [-h^|--help] [--rebuild] [--clean]"
|
|
|
|
|
|
|
|
set REMOVE_INTERMEDIATE=false
|
|
|
|
set BUILD_FOR_PYTHON2=false
|
|
|
|
set BUILD_FOR_PYTHON3=false
|
|
|
|
|
|
|
|
:arg-parse
|
|
|
|
if not "%1"=="" (
|
|
|
|
if "%1"=="--rebuild" (
|
|
|
|
set REMOVE_INTERMEDIATE=true
|
|
|
|
set BUILD_FOR_PYTHON2=true
|
|
|
|
set BUILD_FOR_PYTHON3=true
|
|
|
|
)
|
|
|
|
|
|
|
|
if "%1"=="--py2" (
|
|
|
|
set BUILD_FOR_PYTHON2=true
|
|
|
|
)
|
|
|
|
|
|
|
|
if "%1"=="--py3" (
|
|
|
|
set BUILD_FOR_PYTHON3=true
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if "%1"=="--clean" (
|
|
|
|
set REMOVE_INTERMEDIATE=true
|
|
|
|
)
|
|
|
|
|
|
|
|
if "%1"=="-h" (
|
|
|
|
echo %DOC_STRING%
|
|
|
|
echo %USAGE_STRING%
|
|
|
|
GOTO :eof
|
|
|
|
)
|
|
|
|
|
|
|
|
if "%1"=="--help" (
|
|
|
|
echo %DOC_STRING%
|
|
|
|
echo %USAGE_STRING%
|
|
|
|
GOTO :eof
|
|
|
|
)
|
|
|
|
|
|
|
|
shift
|
|
|
|
goto :arg-parse
|
|
|
|
)
|
|
|
|
|
|
|
|
set PYTHON_LIB_PATH=%ROOT_PATH%PythonAPI\
|
2018-08-01 22:34:17 +08:00
|
|
|
set PYTHON_LIB_BUILD=%PYTHON_LIB_PATH%build\
|
|
|
|
set PYTHON_LIB_DEPENDENCIES=%PYTHON_LIB_PATH%dependencies\
|
2018-07-30 22:52:29 +08:00
|
|
|
|
|
|
|
if %REMOVE_INTERMEDIATE% == false (
|
|
|
|
if %BUILD_FOR_PYTHON3% == false (
|
|
|
|
if %BUILD_FOR_PYTHON2% == false (
|
|
|
|
echo Nothing selected to be done.
|
|
|
|
goto :eof
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
if %REMOVE_INTERMEDIATE% == true (
|
2019-02-08 21:38:12 +08:00
|
|
|
for %%G in (
|
|
|
|
"%PYTHON_LIB_BUILD:/=\%",
|
|
|
|
"%PYTHON_LIB_DEPENDENCIES:/=\%",
|
|
|
|
"%PYTHON_LIB_PATH:/=\%dist",
|
|
|
|
) do (
|
|
|
|
if exist %%G (
|
|
|
|
echo %FILE_N% Cleaning %%G
|
|
|
|
rmdir /s/q %%G
|
|
|
|
)
|
|
|
|
)
|
|
|
|
goto good_exit
|
2018-07-30 22:52:29 +08:00
|
|
|
)
|
|
|
|
|
2018-07-31 22:35:02 +08:00
|
|
|
cd "%PYTHON_LIB_PATH%"
|
2018-09-06 18:40:23 +08:00
|
|
|
rem if exist "%PYTHON_LIB_PATH%dist" goto already_installed
|
2018-07-31 22:35:02 +08:00
|
|
|
|
|
|
|
rem ============================================================================
|
|
|
|
rem -- Check for py ------------------------------------------------------------
|
|
|
|
rem ============================================================================
|
|
|
|
|
|
|
|
where py 1>nul
|
|
|
|
if %errorlevel% neq 0 goto error_py
|
|
|
|
|
|
|
|
rem Build for Python 2
|
|
|
|
rem
|
2018-07-30 22:52:29 +08:00
|
|
|
if %BUILD_FOR_PYTHON2%==true (
|
2018-07-31 22:35:02 +08:00
|
|
|
goto py2_not_supported
|
2018-07-30 22:52:29 +08:00
|
|
|
)
|
|
|
|
|
2018-07-31 22:35:02 +08:00
|
|
|
rem Build for Python 2
|
|
|
|
rem
|
2018-07-30 22:52:29 +08:00
|
|
|
if %BUILD_FOR_PYTHON3%==true (
|
|
|
|
echo Building Python API for Python 3.
|
2019-02-08 21:38:12 +08:00
|
|
|
py -3 setup.py bdist_egg
|
2018-08-20 17:26:09 +08:00
|
|
|
if %errorlevel% neq 0 goto error_build_egg
|
2018-07-30 22:52:29 +08:00
|
|
|
)
|
|
|
|
|
2018-07-31 22:35:02 +08:00
|
|
|
goto success
|
|
|
|
|
|
|
|
rem ============================================================================
|
|
|
|
rem -- Messages and Errors -----------------------------------------------------
|
|
|
|
rem ============================================================================
|
|
|
|
|
|
|
|
:success
|
|
|
|
echo.
|
2018-08-01 22:34:17 +08:00
|
|
|
if %BUILD_FOR_PYTHON3%==true echo %FILE_N% Carla lib for python has been successfully installed in "%PYTHON_LIB_PATH%dist"!
|
|
|
|
goto good_exit
|
|
|
|
|
|
|
|
:already_installed
|
|
|
|
echo.
|
2018-08-30 20:18:53 +08:00
|
|
|
echo %FILE_N% [ERROR] Already installed in "%PYTHON_LIB_PATH%dist"
|
2018-07-31 22:35:02 +08:00
|
|
|
goto good_exit
|
|
|
|
|
|
|
|
:py2_not_supported
|
|
|
|
echo.
|
2018-08-30 20:18:53 +08:00
|
|
|
echo %FILE_N% [ERROR] Python 2 is not currently suported in Windows.
|
2018-07-31 22:35:02 +08:00
|
|
|
goto bad_exit
|
|
|
|
|
|
|
|
:error_py
|
|
|
|
echo.
|
2018-08-30 20:18:53 +08:00
|
|
|
echo %FILE_N% [ERROR] An error ocurred while executing the py.
|
|
|
|
echo %FILE_N% [ERROR] Possible causes:
|
|
|
|
echo %FILE_N% [ERROR] - Make sure "py" is installed.
|
|
|
|
echo %FILE_N% [ERROR] - Make sure it is available on your Windows "py".
|
2018-07-31 22:35:02 +08:00
|
|
|
goto bad_exit
|
|
|
|
|
2018-08-20 17:26:09 +08:00
|
|
|
:error_build_egg
|
|
|
|
echo.
|
2018-08-30 20:18:53 +08:00
|
|
|
echo %FILE_N% [ERROR] An error occurred while building the egg file.
|
2018-08-20 17:26:09 +08:00
|
|
|
goto bad_exit
|
|
|
|
|
2018-07-31 22:35:02 +08:00
|
|
|
:good_exit
|
|
|
|
endlocal
|
|
|
|
exit /b 0
|
|
|
|
|
|
|
|
:bad_exit
|
|
|
|
endlocal
|
|
|
|
exit /b %errorlevel%
|