|
| 1 | +@echo off |
| 2 | +setlocal |
| 3 | + |
| 4 | +rem BAT script that creates the client python api of LibCarla (carla.org). |
| 5 | +rem Run it through a cmd with the x64 Visual C++ Toolset enabled. |
| 6 | + |
| 7 | +set LOCAL_PATH=%~dp0 |
| 8 | +set FILE_N=-[%~n0]: |
| 9 | + |
| 10 | +rem Print batch params (debug purpose) |
| 11 | +echo %FILE_N% [Batch params]: %* |
| 12 | + |
| 13 | +rem ============================================================================ |
| 14 | +rem -- Parse arguments --------------------------------------------------------- |
| 15 | +rem ============================================================================ |
| 16 | + |
| 17 | +set DOC_STRING=Build and package CARLA Python API. |
| 18 | +set "USAGE_STRING=Usage: %FILE_N% [-h^|--help] [--rebuild] [--clean]" |
| 19 | + |
| 20 | +set REMOVE_INTERMEDIATE=false |
| 21 | +set BUILD_FOR_PYTHON2=false |
| 22 | +set BUILD_FOR_PYTHON3=false |
| 23 | + |
| 24 | +:arg-parse |
| 25 | +if not "%1"=="" ( |
| 26 | + if "%1"=="--rebuild" ( |
| 27 | + set REMOVE_INTERMEDIATE=true |
| 28 | + rem We don't provide support for py2 right now |
| 29 | + set BUILD_FOR_PYTHON2=false |
| 30 | + set BUILD_FOR_PYTHON3=true |
| 31 | + ) |
| 32 | + |
| 33 | + if "%1"=="--py2" ( |
| 34 | + set BUILD_FOR_PYTHON2=true |
| 35 | + ) |
| 36 | + |
| 37 | + if "%1"=="--py3" ( |
| 38 | + set BUILD_FOR_PYTHON3=true |
| 39 | + ) |
| 40 | + |
| 41 | + |
| 42 | + if "%1"=="--clean" ( |
| 43 | + set REMOVE_INTERMEDIATE=true |
| 44 | + ) |
| 45 | + |
| 46 | + if "%1"=="-h" ( |
| 47 | + echo %DOC_STRING% |
| 48 | + echo %USAGE_STRING% |
| 49 | + GOTO :eof |
| 50 | + ) |
| 51 | + |
| 52 | + if "%1"=="--help" ( |
| 53 | + echo %DOC_STRING% |
| 54 | + echo %USAGE_STRING% |
| 55 | + GOTO :eof |
| 56 | + ) |
| 57 | + |
| 58 | + shift |
| 59 | + goto :arg-parse |
| 60 | +) |
| 61 | + |
| 62 | +set PYTHON_LIB_PATH=%ROOT_PATH:/=\%PythonAPI\carla\ |
| 63 | + |
| 64 | +if %REMOVE_INTERMEDIATE% == false ( |
| 65 | + if %BUILD_FOR_PYTHON3% == false ( |
| 66 | + if %BUILD_FOR_PYTHON2% == false ( |
| 67 | + echo Nothing selected to be done. |
| 68 | + goto :eof |
| 69 | + ) |
| 70 | + ) |
| 71 | +) |
| 72 | + |
| 73 | +if %REMOVE_INTERMEDIATE% == true ( |
| 74 | + rem Remove directories |
| 75 | + for %%G in ( |
| 76 | + "%PYTHON_LIB_PATH%build", |
| 77 | + "%PYTHON_LIB_PATH%dist", |
| 78 | + "%PYTHON_LIB_PATH%source\carla.egg-info" |
| 79 | + ) do ( |
| 80 | + if exist %%G ( |
| 81 | + echo %FILE_N% Cleaning %%G |
| 82 | + rmdir /s/q %%G |
| 83 | + ) |
| 84 | + ) |
| 85 | + if %BUILD_FOR_PYTHON3% == false ( |
| 86 | + if %BUILD_FOR_PYTHON2% == false ( |
| 87 | + goto good_exit |
| 88 | + ) |
| 89 | + ) |
| 90 | +) |
| 91 | + |
| 92 | +cd "%PYTHON_LIB_PATH%" |
| 93 | +rem if exist "%PYTHON_LIB_PATH%dist" goto already_installed |
| 94 | + |
| 95 | +rem ============================================================================ |
| 96 | +rem -- Check for py ------------------------------------------------------------ |
| 97 | +rem ============================================================================ |
| 98 | + |
| 99 | +rem prefer invoking 'python' (for externally installed, eg conda) over 'py' (built in to Windows) |
| 100 | +rem |
| 101 | +set PYTHON_EXEC=python |
| 102 | + |
| 103 | +where %PYTHON_EXEC%>nul |
| 104 | +if %errorlevel% neq 0 set PYTHON_EXEC=py -3 |
| 105 | + |
| 106 | +where %PYTHON_EXEC%>nul |
| 107 | +if %errorlevel% neq 0 goto error_py |
| 108 | + |
| 109 | +rem Build for Python 2 |
| 110 | +rem |
| 111 | +if %BUILD_FOR_PYTHON2%==true ( |
| 112 | + goto py2_not_supported |
| 113 | +) |
| 114 | + |
| 115 | +rem Build for Python 3 |
| 116 | +rem |
| 117 | +if %BUILD_FOR_PYTHON3%==true ( |
| 118 | + echo Building Python API for Python 3. |
| 119 | + %PYTHON_EXEC% setup.py bdist_egg bdist_wheel |
| 120 | + if %errorlevel% neq 0 goto error_build_wheel |
| 121 | +) |
| 122 | + |
| 123 | +goto success |
| 124 | + |
| 125 | +rem ============================================================================ |
| 126 | +rem -- Messages and Errors ----------------------------------------------------- |
| 127 | +rem ============================================================================ |
| 128 | + |
| 129 | +:success |
| 130 | + echo. |
| 131 | + if %BUILD_FOR_PYTHON3%==true echo %FILE_N% Carla lib for python has been successfully installed in "%PYTHON_LIB_PATH%dist"! |
| 132 | + goto good_exit |
| 133 | + |
| 134 | +:already_installed |
| 135 | + echo. |
| 136 | + echo %FILE_N% [ERROR] Already installed in "%PYTHON_LIB_PATH%dist" |
| 137 | + goto good_exit |
| 138 | + |
| 139 | +:py2_not_supported |
| 140 | + echo. |
| 141 | + echo %FILE_N% [ERROR] Python 2 is not currently suported in Windows. |
| 142 | + goto bad_exit |
| 143 | + |
| 144 | +:error_py |
| 145 | + echo. |
| 146 | + echo %FILE_N% [ERROR] An error ocurred while executing the py. |
| 147 | + echo %FILE_N% [ERROR] Possible causes: |
| 148 | + echo %FILE_N% [ERROR] - Make sure "py" is installed. |
| 149 | + echo %FILE_N% [ERROR] - py = python launcher. This utility is bundled with Python installation but not installed by default. |
| 150 | + echo %FILE_N% [ERROR] - Make sure it is available on your Windows "py". |
| 151 | + goto bad_exit |
| 152 | + |
| 153 | +:error_build_wheel |
| 154 | + echo. |
| 155 | + echo %FILE_N% [ERROR] An error occurred while building the wheel file. |
| 156 | + goto bad_exit |
| 157 | + |
| 158 | +:good_exit |
| 159 | + endlocal |
| 160 | + exit /b 0 |
| 161 | + |
| 162 | +:bad_exit |
| 163 | + endlocal |
| 164 | + exit /b %errorlevel% |
| 165 | + |
0 commit comments