Move setup main entry point to separate file to easily store logs.

This commit is contained in:
Marcel Pi 2025-02-25 16:20:51 +01:00
parent 8baf894f66
commit 3e99ab4beb
4 changed files with 298 additions and 276 deletions

View File

@ -1,137 +1,11 @@
@echo off
setlocal EnableDelayedExpansion
set skip_prerequisites=false
set launch=false
set interactive=false
set python_path=python
set python_root=
set timestamp=%date%-%time%
set setup_utils_folder=%cd%\Util\SetupUtils\
set setup_logs_folder=%SetupUtilsFolder%\SetupLogs\
rem -- PARSE COMMAND LINE ARGUMENTS --
:parse
if "%1"=="" (
goto main
)
if "%1"=="--interactive" (
set interactive=true
) else if "%1"=="-i" (
set interactive=true
) else if "%1"=="--skip-prerequisites" (
set skip_prerequisites=true
) else if "%1"=="-p" (
set skip_prerequisites=true
) else if "%1"=="--launch" (
set launch=true
) else if "%1"=="-l" (
set launch=true
) else (
echo %1 | findstr /B /C:"--python-root=" >nul
if not errorlevel 1 (
set python_root="%1"
set python_root="!python_root:--python-root=!"
) else if "%1"=="--python-root" (
set python_root=%2
shift
) else if "%1"=="-pyroot" (
set python_root=%2
shift
) else (
echo Unknown argument "%1"
exit /b
)
)
shift
goto parse
rem -- MAIN --
:main
if not "%python_root%"=="" (
set python_path=%python_root%\python
if not exist "%SetupLogsFolder%" (
mkdir "%SetupLogsFolder%"
)
rem -- PREREQUISITES INSTALL STEP --
if %skip_prerequisites%==false (
echo Installing prerequisites...
call Util/SetupUtils/InstallPrerequisites.bat --python-path=%python_path% || exit /b
) else (
echo Skipping prerequisites install step.
)
rem -- CLONE CONTENT --
if exist "%cd%\Unreal\CarlaUnreal\Content" (
echo Found CARLA content.
) else (
echo Could not find CARLA content. Downloading...
mkdir %cd%\Unreal\CarlaUnreal\Content
git ^
-C %cd%\Unreal\CarlaUnreal\Content ^
clone ^
-b ue5-dev ^
https://bitbucket.org/carla-simulator/carla-content.git ^
Carla ^
|| exit /b
)
rem Activate VS terminal development environment:
if exist "%PROGRAMFILES%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" (
echo Activating "x64 Native Tools Command Prompt" terminal environment.
call "%PROGRAMFILES%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" || exit /b
) else (
echo Could not find vcvarsall.bat, aborting setup...
exit 1
)
rem -- DOWNLOAD + BUILD UNREAL ENGINE --
if exist "%CARLA_UNREAL_ENGINE_PATH%" (
echo Found Unreal Engine 5 at "%CARLA_UNREAL_ENGINE_PATH%".
) else if exist ..\UnrealEngine5_carla (
echo Found CARLA Unreal Engine at %cd%/UnrealEngine5_carla. Assuming already built...
) else (
echo Could not find CARLA Unreal Engine, downloading...
pushd ..
git clone ^
-b ue5-dev-carla ^
https://github.com/CarlaUnreal/UnrealEngine.git ^
UnrealEngine5_carla || exit /b
pushd UnrealEngine5_carla
set CARLA_UNREAL_ENGINE_PATH=!cd!
setx CARLA_UNREAL_ENGINE_PATH !cd!
echo Running Unreal Engine pre-build steps...
call Setup.bat || exit /b
call GenerateProjectFiles.bat || exit /b
echo Building Unreal Engine 5...
msbuild ^
Engine\Intermediate\ProjectFiles\UE5.vcxproj ^
/property:Configuration="Development_Editor" ^
/property:Platform="x64" || exit /b
popd
popd
)
rem -- BUILD CARLA --
echo Configuring the CARLA CMake project...
cmake ^
-G Ninja ^
-S . ^
-B Build ^
--toolchain=CMake/Toolchain.cmake ^
-DPython_ROOT_DIR=%python_root% ^
-DPython3_ROOT_DIR=%python_root% ^
-DCMAKE_BUILD_TYPE=Release ^
-DCARLA_UNREAL_ENGINE_PATH=%CARLA_UNREAL_ENGINE_PATH% || exit /b
echo Building CARLA...
cmake --build Build || exit /b
echo Installing Python API...
cmake --build Build --target carla-python-api-install || exit /b
echo CARLA Python API build+install succeeded.
rem -- POST-BUILD STEPS --
if %launch%==true (
echo Launching Carla Unreal Editor...
cmake --build Build --target launch || exit /b
)
%SetupUtilsFolder%SetupMain.bat>%SetupLogsFolder%%timestamp%.log

151
CarlaSetup.sh Executable file → Normal file
View File

@ -1,148 +1,11 @@
#! /bin/bash
set -e
timestamp=$(date +%F_%T)
setup_utils_folder=%cd%/Util/SetupUtils/
setup_logs_folder=%SetupUtilsFolder%/SetupLogs/
interactive=0
skip_prerequisites=0
launch=0
python_root=
if not exist "%SetupLogsFolder%" (
mkdir "%SetupLogsFolder%"
)
workspace_path="$(dirname $(realpath "${BASH_SOURCE[-1]}"))"
echo "workspace_path=$workspace_path"
options=$(\
getopt \
-o "i,p,l,pyroot:" \
--long "interactive,skip-prerequisites,launch,python-root:" \
-n 'CarlaSetup.sh' -- "$@")
eval set -- "$options"
while true; do
case "$1" in
-i|--interactive)
interactive=1
shift
;;
-p|--skip-prerequisites)
skip_prerequisites=1
shift
;;
-l|--launch)
launch=1
shift
;;
-pyroot|--python-root)
python_root=$2
shift 2
;;
--)
shift
break
;;
*)
;;
esac
done
# Check for root privileges:
if [ -z "$EUID" ]; then
EUID=$(id -u)
fi
if [ "$EUID" -ne 0 ]; then
if [ $interactive -eq 0 ]; then
if [ $skip_prerequisites -eq 0 ]; then
echo "Please run this script as root. Otherwise pass --interactive to be prompted whenever root privileges or Git credentials are needed."
exit 1
fi
fi
fi
# Check for Git credentials:
if [ -z "$GIT_LOCAL_CREDENTIALS" ]; then
if [ $interactive -eq 1 ]; then
echo "Warning: git credentials are not set. You may be required to manually enter them later."
else
echo "Git credentials are not set, can not continue setup in unattended mode."
exit 1
fi
else
echo "Found git credentials."
fi
# -- PREREQUISITES INSTALL STEP --
if [ $skip_prerequisites -eq 0 ]; then
python_path=python3
if [ "$python_root" != "" ]; then
python_path=${python_root}/python3
fi
echo "Installing prerequisites..."
sudo -E bash -x Util/SetupUtils/InstallPrerequisites.sh --python-path=$python_path
else
echo "Skipping prerequisites install step."
fi
# -- CLONE CONTENT --
if [ -d $workspace_path/Unreal/CarlaUnreal/Content ]; then
echo "Found CARLA content."
else
echo "Could not find CARLA content. Downloading..."
mkdir -p $workspace_path/Unreal/CarlaUnreal/Content
git \
-C $workspace_path/Unreal/CarlaUnreal/Content \
clone \
-b ue5-dev \
https://bitbucket.org/carla-simulator/carla-content.git \
Carla
fi
# -- DOWNLOAD + BUILD UNREAL ENGINE --
if [ ! -z $CARLA_UNREAL_ENGINE_PATH ] && [ -d $CARLA_UNREAL_ENGINE_PATH ]; then
echo "Found CARLA Unreal Engine at $CARLA_UNREAL_ENGINE_PATH"
elif [ -d ../UnrealEngine5_carla ]; then
echo "Found CARLA Unreal Engine at $workspace_path/UnrealEngine5_carla. Assuming already built..."
else
echo "Could not find CARLA Unreal Engine, downloading..."
pushd ..
if [ -z "$GIT_LOCAL_CREDENTIALS" ]
then
UE5_URL=https://github.com/CarlaUnreal/UnrealEngine.git
else
GIT_CREDENTIALS_INFO=(${GIT_LOCAL_CREDENTIALS//@/ })
GIT_LOCAL_USER=${GIT_CREDENTIALS_INFO[0]}
GIT_LOCAL_TOKEN=${GIT_CREDENTIALS_INFO[1]}
UE5_URL=https://$GIT_LOCAL_USER:$GIT_LOCAL_TOKEN@github.com/CarlaUnreal/UnrealEngine.git
fi
git clone -b ue5-dev-carla $UE5_URL UnrealEngine5_carla
pushd UnrealEngine5_carla
echo -e '\n#CARLA UnrealEngine5\nexport CARLA_UNREAL_ENGINE_PATH='$PWD >> ~/.bashrc
export CARLA_UNREAL_ENGINE_PATH=$PWD
echo "Running Unreal Engine pre-build steps..."
bash -x Setup.sh
bash -x GenerateProjectFiles.sh
echo "Building Unreal Engine 5..."
make
popd
popd
fi
# -- BUILD CARLA --
echo "Configuring the CARLA CMake project..."
cmake -G Ninja -S . -B Build \
--toolchain=$PWD/CMake/Toolchain.cmake \
-DLAUNCH_ARGS="-prefernvidia" \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_ROS2=ON \
-DPython_ROOT_DIR=${python_root} \
-DPython3_ROOT_DIR=${python_root} \
-DCARLA_UNREAL_ENGINE_PATH=$CARLA_UNREAL_ENGINE_PATH
echo "Building CARLA..."
cmake --build Build
echo "Installing Python API..."
cmake --build Build --target carla-python-api-install
echo "CARLA Python API build+install succeeded."
# -- POST-BUILD STEPS --
if [ $launch -eq 1 ]; then
echo "Launching Carla - Unreal Editor..."
cmake --build Build --target launch
fi
$setup_utils_folder/SetupMain.bat>$setup_logs_folder$timestamp.log

View File

@ -0,0 +1,137 @@
@echo off
setlocal EnableDelayedExpansion
set skip_prerequisites=false
set launch=false
set interactive=false
set python_path=python
set python_root=
rem -- PARSE COMMAND LINE ARGUMENTS --
:parse
if "%1"=="" (
goto main
)
if "%1"=="--interactive" (
set interactive=true
) else if "%1"=="-i" (
set interactive=true
) else if "%1"=="--skip-prerequisites" (
set skip_prerequisites=true
) else if "%1"=="-p" (
set skip_prerequisites=true
) else if "%1"=="--launch" (
set launch=true
) else if "%1"=="-l" (
set launch=true
) else (
echo %1 | findstr /B /C:"--python-root=" >nul
if not errorlevel 1 (
set python_root="%1"
set python_root="!python_root:--python-root=!"
) else if "%1"=="--python-root" (
set python_root=%2
shift
) else if "%1"=="-pyroot" (
set python_root=%2
shift
) else (
echo Unknown argument "%1"
exit /b
)
)
shift
goto parse
rem -- MAIN --
:main
if not "%python_root%"=="" (
set python_path=%python_root%\python
)
rem -- PREREQUISITES INSTALL STEP --
if %skip_prerequisites%==false (
echo Installing prerequisites...
call Util/SetupUtils/InstallPrerequisites.bat --python-path=%python_path% || exit /b
) else (
echo Skipping prerequisites install step.
)
rem -- CLONE CONTENT --
if exist "%cd%\Unreal\CarlaUnreal\Content" (
echo Found CARLA content.
) else (
echo Could not find CARLA content. Downloading...
mkdir %cd%\Unreal\CarlaUnreal\Content
git ^
-C %cd%\Unreal\CarlaUnreal\Content ^
clone ^
-b ue5-dev ^
https://bitbucket.org/carla-simulator/carla-content.git ^
Carla ^
|| exit /b
)
rem Activate VS terminal development environment:
if exist "%PROGRAMFILES%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" (
echo Activating "x64 Native Tools Command Prompt" terminal environment.
call "%PROGRAMFILES%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" || exit /b
) else (
echo Could not find vcvarsall.bat, aborting setup...
exit 1
)
rem -- DOWNLOAD + BUILD UNREAL ENGINE --
if exist "%CARLA_UNREAL_ENGINE_PATH%" (
echo Found Unreal Engine 5 at "%CARLA_UNREAL_ENGINE_PATH%".
) else if exist ..\UnrealEngine5_carla (
echo Found CARLA Unreal Engine at %cd%/UnrealEngine5_carla. Assuming already built...
) else (
echo Could not find CARLA Unreal Engine, downloading...
pushd ..
git clone ^
-b ue5-dev-carla ^
https://github.com/CarlaUnreal/UnrealEngine.git ^
UnrealEngine5_carla || exit /b
pushd UnrealEngine5_carla
set CARLA_UNREAL_ENGINE_PATH=!cd!
setx CARLA_UNREAL_ENGINE_PATH !cd!
echo Running Unreal Engine pre-build steps...
call Setup.bat || exit /b
call GenerateProjectFiles.bat || exit /b
echo Building Unreal Engine 5...
msbuild ^
Engine\Intermediate\ProjectFiles\UE5.vcxproj ^
/property:Configuration="Development_Editor" ^
/property:Platform="x64" || exit /b
popd
popd
)
rem -- BUILD CARLA --
echo Configuring the CARLA CMake project...
cmake ^
-G Ninja ^
-S . ^
-B Build ^
--toolchain=CMake/Toolchain.cmake ^
-DPython_ROOT_DIR=%python_root% ^
-DPython3_ROOT_DIR=%python_root% ^
-DCMAKE_BUILD_TYPE=Release ^
-DCARLA_UNREAL_ENGINE_PATH=%CARLA_UNREAL_ENGINE_PATH% || exit /b
echo Building CARLA...
cmake --build Build || exit /b
echo Installing Python API...
cmake --build Build --target carla-python-api-install || exit /b
echo CARLA Python API build+install succeeded.
rem -- POST-BUILD STEPS --
if %launch%==true (
echo Launching Carla Unreal Editor...
cmake --build Build --target launch || exit /b
)

148
Util/SetupUtils/SetupMain.sh Executable file
View File

@ -0,0 +1,148 @@
#! /bin/bash
set -e
interactive=0
skip_prerequisites=0
launch=0
python_root=
workspace_path="$(dirname $(realpath "${BASH_SOURCE[-1]}"))"
echo "workspace_path=$workspace_path"
options=$(\
getopt \
-o "i,p,l,pyroot:" \
--long "interactive,skip-prerequisites,launch,python-root:" \
-n 'CarlaSetup.sh' -- "$@")
eval set -- "$options"
while true; do
case "$1" in
-i|--interactive)
interactive=1
shift
;;
-p|--skip-prerequisites)
skip_prerequisites=1
shift
;;
-l|--launch)
launch=1
shift
;;
-pyroot|--python-root)
python_root=$2
shift 2
;;
--)
shift
break
;;
*)
;;
esac
done
# Check for root privileges:
if [ -z "$EUID" ]; then
EUID=$(id -u)
fi
if [ "$EUID" -ne 0 ]; then
if [ $interactive -eq 0 ]; then
if [ $skip_prerequisites -eq 0 ]; then
echo "Please run this script as root. Otherwise pass --interactive to be prompted whenever root privileges or Git credentials are needed."
exit 1
fi
fi
fi
# Check for Git credentials:
if [ -z "$GIT_LOCAL_CREDENTIALS" ]; then
if [ $interactive -eq 1 ]; then
echo "Warning: git credentials are not set. You may be required to manually enter them later."
else
echo "Git credentials are not set, can not continue setup in unattended mode."
exit 1
fi
else
echo "Found git credentials."
fi
# -- PREREQUISITES INSTALL STEP --
if [ $skip_prerequisites -eq 0 ]; then
python_path=python3
if [ "$python_root" != "" ]; then
python_path=${python_root}/python3
fi
echo "Installing prerequisites..."
sudo -E bash -x Util/SetupUtils/InstallPrerequisites.sh --python-path=$python_path
else
echo "Skipping prerequisites install step."
fi
# -- CLONE CONTENT --
if [ -d $workspace_path/Unreal/CarlaUnreal/Content ]; then
echo "Found CARLA content."
else
echo "Could not find CARLA content. Downloading..."
mkdir -p $workspace_path/Unreal/CarlaUnreal/Content
git \
-C $workspace_path/Unreal/CarlaUnreal/Content \
clone \
-b ue5-dev \
https://bitbucket.org/carla-simulator/carla-content.git \
Carla
fi
# -- DOWNLOAD + BUILD UNREAL ENGINE --
if [ ! -z $CARLA_UNREAL_ENGINE_PATH ] && [ -d $CARLA_UNREAL_ENGINE_PATH ]; then
echo "Found CARLA Unreal Engine at $CARLA_UNREAL_ENGINE_PATH"
elif [ -d ../UnrealEngine5_carla ]; then
echo "Found CARLA Unreal Engine at $workspace_path/UnrealEngine5_carla. Assuming already built..."
else
echo "Could not find CARLA Unreal Engine, downloading..."
pushd ..
if [ -z "$GIT_LOCAL_CREDENTIALS" ]
then
UE5_URL=https://github.com/CarlaUnreal/UnrealEngine.git
else
GIT_CREDENTIALS_INFO=(${GIT_LOCAL_CREDENTIALS//@/ })
GIT_LOCAL_USER=${GIT_CREDENTIALS_INFO[0]}
GIT_LOCAL_TOKEN=${GIT_CREDENTIALS_INFO[1]}
UE5_URL=https://$GIT_LOCAL_USER:$GIT_LOCAL_TOKEN@github.com/CarlaUnreal/UnrealEngine.git
fi
git clone -b ue5-dev-carla $UE5_URL UnrealEngine5_carla
pushd UnrealEngine5_carla
echo -e '\n#CARLA UnrealEngine5\nexport CARLA_UNREAL_ENGINE_PATH='$PWD >> ~/.bashrc
export CARLA_UNREAL_ENGINE_PATH=$PWD
echo "Running Unreal Engine pre-build steps..."
bash -x Setup.sh
bash -x GenerateProjectFiles.sh
echo "Building Unreal Engine 5..."
make
popd
popd
fi
# -- BUILD CARLA --
echo "Configuring the CARLA CMake project..."
cmake -G Ninja -S . -B Build \
--toolchain=$PWD/CMake/Toolchain.cmake \
-DLAUNCH_ARGS="-prefernvidia" \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_ROS2=ON \
-DPython_ROOT_DIR=${python_root} \
-DPython3_ROOT_DIR=${python_root} \
-DCARLA_UNREAL_ENGINE_PATH=$CARLA_UNREAL_ENGINE_PATH
echo "Building CARLA..."
cmake --build Build
echo "Installing Python API..."
cmake --build Build --target carla-python-api-install
echo "CARLA Python API build+install succeeded."
# -- POST-BUILD STEPS --
if [ $launch -eq 1 ]; then
echo "Launching Carla - Unreal Editor..."
cmake --build Build --target launch
fi