carla/Util/BuildTools/Package.bat

483 lines
16 KiB
Batchfile
Raw Normal View History

2018-08-01 22:34:17 +08:00
@echo off
setlocal enabledelayedexpansion
2018-08-01 22:34:17 +08:00
2020-12-11 02:51:27 +08:00
rem don't remove next two empty lines after next
set LF=^
2018-08-02 16:51:15 +08:00
rem Bat script that compiles and exports the carla project (carla.org)
rem Run it through a cmd with the x64 Visual C++ Toolset enabled.
2018-08-01 22:34:17 +08:00
rem https://wiki.unrealengine.com/How_to_package_your_game_with_commands
set LOCAL_PATH=%~dp0
set FILE_N=-[%~n0]:
2018-08-01 22:34:17 +08:00
2018-08-29 18:24:30 +08:00
rem Print batch params (debug purpose)
echo %FILE_N% [Batch params]: %*
2018-08-02 16:51:15 +08:00
rem ==============================================================================
rem -- Parse arguments -----------------------------------------------------------
rem ==============================================================================
set DOC_STRING="Makes a packaged version of CARLA for distribution."
2022-06-09 05:22:30 +08:00
set USAGE_STRING="Usage: %FILE_N% [-h|--help] [--config={Debug,Development,Shipping}] [--no-packaging] [--no-zip] [--clean] [--clean-intermediate] [--target-archive]"
2018-08-02 16:51:15 +08:00
set DO_PACKAGE=true
set DO_COPY_FILES=true
set DO_TARBALL=true
2018-08-24 20:57:29 +08:00
set DO_CLEAN=false
set PACKAGES=Carla
2022-06-09 05:22:30 +08:00
set PACKAGE_CONFIG=Shipping
set USE_CARSIM=false
set SINGLE_PACKAGE=false
2018-08-02 16:51:15 +08:00
:arg-parse
if not "%1"=="" (
2018-08-24 20:57:29 +08:00
if "%1"=="--clean" (
set DO_CLEAN=true
2020-04-17 22:57:03 +08:00
set DO_TARBALL=false
set DO_PACKAGE=false
set DO_COPY_FILES=false
2021-03-01 22:29:17 +08:00
)
2020-04-17 22:57:03 +08:00
2022-06-09 05:22:30 +08:00
if "%1"=="--config" (
set PACKAGE_CONFIG=%2
shift
)
2021-03-01 22:29:17 +08:00
if "%1"=="--clean-intermediate" (
set DO_CLEAN=true
2018-08-02 16:51:15 +08:00
)
if "%1"=="--no-zip" (
set DO_TARBALL=false
)
if "%1"=="--no-packaging" (
set DO_PACKAGE=false
)
if "%1"=="--packages" (
2020-04-17 22:57:03 +08:00
set DO_PACKAGE=false
set DO_COPY_FILES=false
2020-12-11 02:51:27 +08:00
set PACKAGES=%*
shift
)
if "%1"=="--target-archive" (
set SINGLE_PACKAGE=true
set TARGET_ARCHIVE=%2
shift
)
if "%1"=="--carsim" (
set USE_CARSIM=true
)
2018-08-02 16:51:15 +08:00
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
)
2018-08-01 22:34:17 +08:00
rem Get Unreal Engine root path
if not defined UE4_ROOT (
set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\EpicGames\Unreal Engine"
set VALUE_NAME=InstalledDirectory
for /f "usebackq tokens=1,2,*" %%A in (`reg query !KEY_NAME! /s /reg:64`) do (
if "%%A" == "!VALUE_NAME!" (
set UE4_ROOT=%%C
)
)
if not defined UE4_ROOT goto error_unreal_no_found
)
2018-08-01 22:34:17 +08:00
rem Set packaging paths
rem
for /f %%i in ('git describe --tags --dirty --always') do set CARLA_VERSION=%%i
if not defined CARLA_VERSION goto error_carla_version
2018-08-02 16:51:15 +08:00
set BUILD_FOLDER=%INSTALLATION_DIR%UE4Carla/%CARLA_VERSION%/
set DESTINATION_ZIP=%INSTALLATION_DIR%UE4Carla/CARLA_%CARLA_VERSION%.zip
set SOURCE=!BUILD_FOLDER!WindowsNoEditor/
2018-08-01 22:34:17 +08:00
rem ============================================================================
rem -- Create Carla package ----------------------------------------------------
rem ============================================================================
2018-08-02 16:51:15 +08:00
if %DO_PACKAGE%==true (
if %USE_CARSIM% == true (
2024-02-19 17:55:48 +08:00
python %ROOT_PATH%Util/BuildTools/enable_carsim_to_uproject.py -f="%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject" -e
echo CarSim ON > "%ROOT_PATH%Unreal/CarlaUE4/Config/CarSimConfig.ini"
) else (
2024-02-19 17:55:48 +08:00
python %ROOT_PATH%Util/BuildTools/enable_carsim_to_uproject.py -f="%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject"
echo CarSim OFF > "%ROOT_PATH%Unreal/CarlaUE4/Config/CarSimConfig.ini"
)
2020-04-17 22:57:03 +08:00
if not exist "!BUILD_FOLDER!" mkdir "!BUILD_FOLDER!"
2018-08-02 16:51:15 +08:00
call "%UE4_ROOT%\Engine\Build\BatchFiles\Build.bat"^
CarlaUE4Editor^
Win64^
Development^
-WaitMutex^
-FromMsBuild^
"%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject"
2018-08-24 20:57:29 +08:00
if errorlevel 1 goto error_build_editor
2022-06-09 05:22:30 +08:00
echo "%UE4_ROOT%\Engine\Build\BatchFiles\Build.bat"^
CarlaUE4^
Win64^
%PACKAGE_CONFIG%^
-WaitMutex^
-FromMsBuild^
"%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject"
2018-08-02 16:51:15 +08:00
call "%UE4_ROOT%\Engine\Build\BatchFiles\Build.bat"^
CarlaUE4^
Win64^
2022-06-09 05:22:30 +08:00
%PACKAGE_CONFIG%^
2018-08-02 16:51:15 +08:00
-WaitMutex^
-FromMsBuild^
"%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject"
2018-08-24 20:57:29 +08:00
if errorlevel 1 goto error_build
2022-06-09 05:22:30 +08:00
echo "%UE4_ROOT%\Engine\Build\BatchFiles\RunUAT.bat"^
BuildCookRun^
-nocompileeditor^
-TargetPlatform=Win64^
-Platform=Win64^
-installed^
-nop4^
-project="%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject"^
-cook^
-stage^
-build^
-archive^
-archivedirectory="!BUILD_FOLDER!"^
-package^
-clientconfig=%PACKAGE_CONFIG%
2018-08-02 16:51:15 +08:00
call "%UE4_ROOT%\Engine\Build\BatchFiles\RunUAT.bat"^
BuildCookRun^
-nocompileeditor^
-TargetPlatform=Win64^
-Platform=Win64^
-installed^
-nop4^
-project="%ROOT_PATH%Unreal/CarlaUE4/CarlaUE4.uproject"^
-cook^
-stage^
-build^
-archive^
-archivedirectory="!BUILD_FOLDER!"^
2018-08-02 16:51:15 +08:00
-package^
2022-06-09 05:22:30 +08:00
-clientconfig=%PACKAGE_CONFIG%
2018-08-24 20:57:29 +08:00
if errorlevel 1 goto error_runUAT
2018-08-02 16:51:15 +08:00
)
rem ==============================================================================
rem -- Adding extra files to package ---------------------------------------------
rem ==============================================================================
if %DO_COPY_FILES%==true (
echo "%FILE_N% Adding extra files to package..."
set XCOPY_FROM=%ROOT_PATH:/=\%
set XCOPY_TO=%SOURCE:/=\%
echo f | xcopy /y "!XCOPY_FROM!LICENSE" "!XCOPY_TO!LICENSE"
echo f | xcopy /y "!XCOPY_FROM!CHANGELOG.md" "!XCOPY_TO!CHANGELOG"
echo f | xcopy /y "!XCOPY_FROM!Docs\release_readme.md" "!XCOPY_TO!README"
echo f | xcopy /y "!XCOPY_FROM!Util\Docker\Release.Dockerfile" "!XCOPY_TO!Dockerfile"
echo f | xcopy /y "!XCOPY_FROM!PythonAPI\carla\dist\*.egg" "!XCOPY_TO!PythonAPI\carla\dist\"
2021-07-15 17:18:34 +08:00
echo f | xcopy /y "!XCOPY_FROM!PythonAPI\carla\dist\*.whl" "!XCOPY_TO!PythonAPI\carla\dist\"
2020-03-31 22:33:19 +08:00
echo d | xcopy /y /s "!XCOPY_FROM!Co-Simulation" "!XCOPY_TO!Co-Simulation"
echo d | xcopy /y /s "!XCOPY_FROM!PythonAPI\carla\agents" "!XCOPY_TO!PythonAPI\carla\agents"
echo f | xcopy /y "!XCOPY_FROM!PythonAPI\carla\scene_layout.py" "!XCOPY_TO!PythonAPI\carla\"
echo f | xcopy /y "!XCOPY_FROM!PythonAPI\carla\requirements.txt" "!XCOPY_TO!PythonAPI\carla\"
echo f | xcopy /y "!XCOPY_FROM!PythonAPI\examples\*.py" "!XCOPY_TO!PythonAPI\examples\"
echo f | xcopy /y "!XCOPY_FROM!PythonAPI\examples\requirements.txt" "!XCOPY_TO!PythonAPI\examples\"
echo f | xcopy /y "!XCOPY_FROM!PythonAPI\util\*.py" "!XCOPY_TO!PythonAPI\util\"
echo d | xcopy /y /s "!XCOPY_FROM!PythonAPI\util\opendrive" "!XCOPY_TO!PythonAPI\util\opendrive"
echo f | xcopy /y "!XCOPY_FROM!PythonAPI\util\requirements.txt" "!XCOPY_TO!PythonAPI\util\"
echo f | xcopy /y "!XCOPY_FROM!Unreal\CarlaUE4\Content\Carla\HDMaps\*.pcd" "!XCOPY_TO!HDMaps\"
echo f | xcopy /y "!XCOPY_FROM!Unreal\CarlaUE4\Content\Carla\HDMaps\Readme.md" "!XCOPY_TO!HDMaps\README"
if exist "!XCOPY_FROM!Plugins" (
echo d | xcopy /y /s "!XCOPY_FROM!Plugins" "!XCOPY_TO!Plugins"
)
)
2018-08-02 16:51:15 +08:00
rem ==============================================================================
rem -- Zip the project -----------------------------------------------------------
rem ==============================================================================
if %DO_PACKAGE%==true if %DO_TARBALL%==true (
set SRC_PATH=%SOURCE:/=\%
2018-08-02 16:51:15 +08:00
echo %FILE_N% Building package...
if exist "!SRC_PATH!Manifest_NonUFSFiles_Win64.txt" del /Q "!SRC_PATH!Manifest_NonUFSFiles_Win64.txt"
if exist "!SRC_PATH!Manifest_DebugFiles_Win64.txt" del /Q "!SRC_PATH!Manifest_DebugFiles_Win64.txt"
if exist "!SRC_PATH!Manifest_UFSFiles_Win64.txt" del /Q "!SRC_PATH!Manifest_UFSFiles_Win64.txt"
if exist "!SRC_PATH!CarlaUE4/Saved" rmdir /S /Q "!SRC_PATH!CarlaUE4/Saved"
if exist "!SRC_PATH!Engine/Saved" rmdir /S /Q "!SRC_PATH!Engine/Saved"
set DST_ZIP=%DESTINATION_ZIP:/=\%
if exist "%ProgramW6432%/7-Zip/7z.exe" (
"%ProgramW6432%/7-Zip/7z.exe" a "!DST_ZIP!" "!SRC_PATH!" -tzip -mmt -mx5
) else (
pushd "!SRC_PATH!"
rem https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.archive/compress-archive?view=powershell-6
powershell -command "& { Compress-Archive -Path * -CompressionLevel Fastest -DestinationPath '!DST_ZIP!' }"
popd
)
2018-08-02 16:51:15 +08:00
)
rem ==============================================================================
rem -- Remove intermediate files -------------------------------------------------
rem ==============================================================================
2018-08-24 20:57:29 +08:00
if %DO_CLEAN%==true (
2018-08-30 18:18:07 +08:00
echo %FILE_N% Removing intermediate build.
rmdir /S /Q "!BUILD_FOLDER!"
2018-08-02 16:51:15 +08:00
)
2018-08-01 22:34:17 +08:00
rem ==============================================================================
rem -- Cook other packages -------------------------------------------------------
rem ==============================================================================
rem Set some file locations
set CARLAUE4_ROOT_FOLDER=%ROOT_PATH%Unreal/CarlaUE4
set PACKAGE_PATH_FILE=%CARLAUE4_ROOT_FOLDER%/Content/PackagePath.txt
set MAP_LIST_FILE=%CARLAUE4_ROOT_FOLDER%/Content/MapPaths.txt
2020-12-11 02:51:27 +08:00
rem get the packages to cook from the arguments whole string
rem (to support multiple packages)
echo Parsing packages...
if not "%PACKAGES%" == "Carla" (
set ARGUMENTS=%PACKAGES:--=!LF!%
for /f "tokens=*" %%i in ("!ARGUMENTS!") do (
set a=%%i
if "!a:~0,9!" == "packages=" (
set RESULT=!a:~9!
) else (
if "!a:~0,9!" == "packages " (
set RESULT=!a:~9!
)
)
)
) else (
set RESULT=%PACKAGES%
)
rem through all maps to cook (parameter)
2020-12-11 02:51:27 +08:00
set PACKAGES=%RESULT:,=!LF!%
for /f "tokens=* delims=" %%i in ("!PACKAGES!") do (
2020-04-17 22:57:03 +08:00
set PACKAGE_NAME=%%i
2020-04-17 22:57:03 +08:00
if not !PACKAGE_NAME! == Carla (
echo Preparing environment for cooking '!PACKAGE_NAME!'.
2020-04-17 22:57:03 +08:00
set BUILD_FOLDER=%INSTALLATION_DIR%UE4Carla/!PACKAGE_NAME!_%CARLA_VERSION%\
set PACKAGE_PATH=%CARLAUE4_ROOT_FOLDER%/Content/!PACKAGE_NAME!
2020-04-17 22:57:03 +08:00
if not exist "!BUILD_FOLDER!" mkdir "!BUILD_FOLDER!"
2020-04-17 22:57:03 +08:00
echo Cooking package '!PACKAGE_NAME!'...
2020-04-17 22:57:03 +08:00
pushd "%CARLAUE4_ROOT_FOLDER%"
2021-03-01 22:29:17 +08:00
echo - prepare
2020-04-17 22:57:03 +08:00
REM # Prepare cooking of package
echo Prepare cooking of package: !PACKAGE_NAME!
2020-04-17 22:57:03 +08:00
call "%UE4_ROOT%/Engine/Binaries/Win64/UE4Editor.exe "^
"%CARLAUE4_ROOT_FOLDER%/CarlaUE4.uproject"^
-run=PrepareAssetsForCooking^
-PackageName=!PACKAGE_NAME!^
-OnlyPrepareMaps=false
2020-04-17 22:57:03 +08:00
set /p PACKAGE_FILE=<%PACKAGE_PATH_FILE%
set /p MAPS_TO_COOK=<%MAP_LIST_FILE%
2021-03-01 22:29:17 +08:00
echo - cook
for /f "tokens=*" %%a in (%MAP_LIST_FILE%) do (
REM # Cook maps
echo Cooking: %%a
call "%UE4_ROOT%/Engine/Binaries/Win64/UE4Editor.exe "^
"%CARLAUE4_ROOT_FOLDER%/CarlaUE4.uproject"^
-run=cook^
-map="%%a"^
-targetplatform="WindowsNoEditor"^
-OutputDir="!BUILD_FOLDER!"^
-iterate^
-cooksinglepackage^
)
2020-04-17 22:57:03 +08:00
REM remove the props folder if exist
set PROPS_MAP_FOLDER="%PACKAGE_PATH%/Maps/PropsMap"
if exist "%PROPS_MAP_FOLDER%" (
rmdir /S /Q "%PROPS_MAP_FOLDER%"
)
2020-04-17 22:57:03 +08:00
popd
2020-04-17 22:57:03 +08:00
echo Copying files to '!PACKAGE_NAME!'...
pushd "!BUILD_FOLDER!"
set SUBST_PATH=!BUILD_FOLDER!CarlaUE4
REM Copy the package config file to package
set TARGET="!SUBST_PATH!\Content\Carla\Config\"
mkdir !TARGET:/=\!
copy "!PACKAGE_FILE:/=\!" !TARGET:/=\!
REM Copy some files for each map to the package
REM MAPS_TO_COOK is read into an array as tokens separated by '+', we replace the '+' by a new line
REM We need the blank line after this line, don't remove it
set MAPS_TO_COOK=!MAPS_TO_COOK:+=^
!
set BASE_CONTENT=%INSTALLATION_DIR:/=\%..\Unreal\CarlaUE4\Content
for /f "tokens=1 delims=+" %%a in ("!MAPS_TO_COOK!") do (
REM Get path and name of map
for /f %%i in ("%%a") do (
set MAP_FOLDER=%%~pi
set MAP_NAME=%%~ni
REM Remove the '/Game' string
set MAP_FOLDER=!MAP_FOLDER:~5!
)
REM # copy the OpenDrive file
set SRC=!BASE_CONTENT!!MAP_FOLDER!\OpenDrive\!MAP_NAME!.xodr
set TRG=!BUILD_FOLDER!\CarlaUE4\Content\!MAP_FOLDER!\OpenDrive\
if exist "!SRC!" (
mkdir "!TRG!"
copy "!SRC!" "!TRG!"
)
REM # copy the navigation file
set SRC=!BASE_CONTENT!!MAP_FOLDER!\Nav\!MAP_NAME!.bin
set TRG=!BUILD_FOLDER!\CarlaUE4\Content\!MAP_FOLDER!\Nav\
if exist "!SRC!" (
mkdir "!TRG!"
copy "!SRC!" "!TRG!"
)
REM # copy the traffic manager map file
set SRC=!BASE_CONTENT!!MAP_FOLDER!\TM\!MAP_NAME!.bin
set TRG=!BUILD_FOLDER!\CarlaUE4\Content\!MAP_FOLDER!\TM\
if exist "!SRC!" (
mkdir "!TRG!"
copy "!SRC!" "!TRG!"
)
2020-04-17 22:57:03 +08:00
)
rmdir /S /Q "!BUILD_FOLDER!\CarlaUE4\Metadata"
rmdir /S /Q "!BUILD_FOLDER!\CarlaUE4\Plugins"
REM del "!BUILD_FOLDER!\CarlaUE4\Content\!PACKAGE_NAME!/Maps/!PROPS_MAP_NAME!"
del "!BUILD_FOLDER!\CarlaUE4\AssetRegistry.bin"
if %DO_TARBALL%==true (
if %SINGLE_PACKAGE%==true (
echo Packaging '%TARGET_ARCHIVE%'...
set DESTINATION_ZIP=%INSTALLATION_DIR%UE4Carla/%TARGET_ARCHIVE%_%CARLA_VERSION%.zip
) else (
echo Packaging '!PACKAGE_NAME!'...
set DESTINATION_ZIP=%INSTALLATION_DIR%UE4Carla/!PACKAGE_NAME!_%CARLA_VERSION%.zip
)
2020-04-17 22:57:03 +08:00
set SOURCE=!BUILD_FOLDER:/=\!\
set DST_ZIP=!DESTINATION_ZIP:/=\!
pushd "!SOURCE!"
if exist "%ProgramW6432%/7-Zip/7z.exe" (
"%ProgramW6432%/7-Zip/7z.exe" a "!DST_ZIP!" . -tzip -mmt -mx5
) else (
rem https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.archive/compress-archive?view=powershell-6
powershell -command "& { Compress-Archive -Update -Path * -CompressionLevel Fastest -DestinationPath '!DST_ZIP!' }"
2020-04-17 22:57:03 +08:00
)
popd
if errorlevel 1 goto bad_exit
echo ZIP created at !DST_ZIP!
)
2020-04-21 21:43:04 +08:00
2020-04-17 22:57:03 +08:00
popd
2020-04-17 22:57:03 +08:00
if %DO_CLEAN%==true (
echo %FILE_N% Removing intermediate build.
rmdir /S /Q "!BUILD_FOLDER!"
)
)
)
rem ============================================================================
2018-08-24 20:57:29 +08:00
goto success
2018-08-01 22:34:17 +08:00
rem ============================================================================
rem -- Messages and Errors -----------------------------------------------------
rem ============================================================================
:success
echo.
if %DO_PACKAGE%==true echo %FILE_N% Carla project successful exported to "%BUILD_FOLDER:/=\%"!
if %DO_TARBALL%==true echo %FILE_N% Compress carla project exported to "%DESTINATION_ZIP%"!
2018-08-01 22:34:17 +08:00
goto good_exit
:error_carla_version
echo.
2018-08-30 20:18:53 +08:00
echo %FILE_N% [ERROR] Carla Version is not set
2018-08-01 22:34:17 +08:00
goto bad_exit
:error_unreal_no_found
echo.
echo %FILE_N% [ERROR] Unreal Engine not detected
2018-08-01 22:34:17 +08:00
goto bad_exit
2018-08-24 20:57:29 +08:00
:error_build_editor
echo.
2018-08-30 20:18:53 +08:00
echo %FILE_N% [ERROR] There was a problem while building the CarlaUE4Editor.
echo [ERROR] Please read the screen log for more information.
2018-08-24 20:57:29 +08:00
goto bad_exit
:error_build
echo.
2018-08-30 20:18:53 +08:00
echo %FILE_N% [ERROR] There was a problem while building the CarlaUE4.
echo [ERROR] Please read the screen log for more information.
2018-08-24 20:57:29 +08:00
goto bad_exit
:error_runUAT
echo.
2018-08-30 20:18:53 +08:00
echo %FILE_N% [ERROR] There was a problem while packaging Unreal project.
echo [ERROR] Please read the screen log for more information.
2018-08-24 20:57:29 +08:00
goto bad_exit
2018-08-01 22:34:17 +08:00
:good_exit
endlocal
exit /b 0
:bad_exit
endlocal
exit /b 1