Skip to content

Commit

Permalink
Upgrade Package.sh to be able to create content packages too
Browse files Browse the repository at this point in the history
  • Loading branch information
nsubiron committed Jul 9, 2019
1 parent b3537a5 commit 07a2083
Showing 1 changed file with 119 additions and 38 deletions.
157 changes: 119 additions & 38 deletions Util/BuildTools/Package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,31 @@ source $(dirname "$0")/Environment.sh
# -- Parse arguments -----------------------------------------------------------
# ==============================================================================

DOC_STRING="Makes a packaged version of CARLA for distribution."
DOC_STRING="Makes a packaged version of CARLA and other content packages ready for distribution."

USAGE_STRING="Usage: $0 [-h|--help] [--no-packaging] [--no-zip] [--clean-intermediate]"
USAGE_STRING="Usage: $0 [-h|--help] [--no-zip] [--clean-intermediate] [--packages=Name1,Name2,...]"

DO_PACKAGE=true
DO_COPY_FILES=true
PACKAGES="Carla"
DO_TARBALL=true
DO_CLEAN_INTERMEDIATE=false

OPTS=`getopt -o h --long help,no-packaging,no-zip,clean-intermediate -n 'parse-options' -- "$@"`
OPTS=`getopt -o h --long help,no-zip,clean-intermediate,packages: -n 'parse-options' -- "$@"`

if [ $? != 0 ] ; then echo "$USAGE_STRING" ; exit 2 ; fi

eval set -- "$OPTS"

while true; do
case "$1" in
--no-packaging )
DO_PACKAGE=false
shift ;;
--no-zip )
DO_TARBALL=false
shift ;;
--clean-intermediate )
DO_CLEAN_INTERMEDIATE=true
shift ;;
--packages )
PACKAGES="$2"
shift 2 ;;
-h | --help )
echo "$DOC_STRING"
echo "$USAGE_STRING"
Expand All @@ -43,56 +42,75 @@ while true; do
done

# ==============================================================================
# -- Package project -----------------------------------------------------------
# -- Prepare environment -------------------------------------------------------
# ==============================================================================

if [ ! -d "${UE4_ROOT}" ]; then
fatal_error "UE4_ROOT is not defined, or points to a non-existent directory, please set this environment variable."
fi

if [ ! -n "${PACKAGES}" ] ; then
fatal_error "Nothing to be done."
fi

# Convert comma-separated string to array of unique elements.
PACKAGES="$(echo "${PACKAGES}" | tr ',' '\n' | sort -u | tr '\n' ',')"
IFS=',' read -r -a PACKAGES <<< "${PACKAGES}"

# If contains an element called "Carla".
if [[ "${PACKAGES[@]}" =~ "Carla" ]] ; then
DO_CARLA_RELEASE=true
else
DO_CARLA_RELEASE=false
fi

REPOSITORY_TAG=$(get_git_repository_version)

BUILD_FOLDER=${CARLA_DIST_FOLDER}/${REPOSITORY_TAG}
RELEASE_BUILD_FOLDER=${CARLA_DIST_FOLDER}/CARLA_${REPOSITORY_TAG}

log "Packaging version '${REPOSITORY_TAG}'."

log "Packaging version '$REPOSITORY_TAG'."
# ==============================================================================
# -- Cook CARLA project --------------------------------------------------------
# ==============================================================================

if $DO_PACKAGE ; then
if ${DO_CARLA_RELEASE} ; then

pushd "${CARLAUE4_ROOT_FOLDER}" >/dev/null

log "Packaging the project."

if [ ! -d "${UE4_ROOT}" ]; then
fatal_error "UE4_ROOT is not defined, or points to a non-existant directory, please set this environment variable."
fi
log "Cooking CARLA project."

rm -Rf ${BUILD_FOLDER}
mkdir -p ${BUILD_FOLDER}
rm -Rf ${RELEASE_BUILD_FOLDER}
mkdir -p ${RELEASE_BUILD_FOLDER}

${UE4_ROOT}/Engine/Build/BatchFiles/RunUAT.sh BuildCookRun \
-project="${PWD}/CarlaUE4.uproject" \
-nocompileeditor -nop4 -cook -stage -archive -package \
-clientconfig=Shipping -ue4exe=UE4Editor \
-prereqs -targetplatform=Linux -build -utf8output \
-archivedirectory="${BUILD_FOLDER}"
-archivedirectory="${RELEASE_BUILD_FOLDER}"

popd >/dev/null

fi
if [[ ! -d ${RELEASE_BUILD_FOLDER}/LinuxNoEditor ]] ; then
fatal_error "Failed to cook the project!"
fi

if [[ ! -d ${BUILD_FOLDER}/LinuxNoEditor ]] ; then
fatal_error "Failed to package the project!"
fi

# ==============================================================================
# -- Copy files (Python API, README, etc) --------------------------------------
# ==============================================================================

if $DO_COPY_FILES ; then
if ${DO_CARLA_RELEASE} ; then

DESTINATION=${BUILD_FOLDER}/LinuxNoEditor
DESTINATION=${RELEASE_BUILD_FOLDER}/LinuxNoEditor

log "Adding extra files to package."
log "Adding extra files to CARLA package."

pushd ${CARLA_ROOT_FOLDER} >/dev/null

mkdir -p "${DESTINATION}/ExportedAssets"
mkdir -p "${DESTINATION}/Import"

echo "${REPOSITORY_TAG}" > ${DESTINATION}/VERSION

Expand Down Expand Up @@ -125,14 +143,14 @@ fi
# -- Zip the project -----------------------------------------------------------
# ==============================================================================

if $DO_TARBALL ; then
if ${DO_CARLA_RELEASE} && ${DO_TARBALL} ; then

DESTINATION=${CARLA_DIST_FOLDER}/CARLA_${REPOSITORY_TAG}.tar.gz
SOURCE=${BUILD_FOLDER}/LinuxNoEditor
SOURCE=${RELEASE_BUILD_FOLDER}/LinuxNoEditor

pushd "${SOURCE}" >/dev/null

log "Packaging build."
log "Packaging CARLA release."

rm -f ./Manifest_NonUFSFiles_Linux.txt
rm -f ./Manifest_UFSFiles_Linux.txt
Expand All @@ -149,23 +167,86 @@ fi
# -- Remove intermediate files -------------------------------------------------
# ==============================================================================

if $DO_CLEAN_INTERMEDIATE ; then
if ${DO_CARLA_RELEASE} && ${DO_CLEAN_INTERMEDIATE} ; then

log "Removing intermediate build."

rm -Rf ${BUILD_FOLDER}
rm -Rf ${RELEASE_BUILD_FOLDER}

fi

# ==============================================================================
# -- ...and we are done --------------------------------------------------------
# -- Cook other packages -------------------------------------------------------
# ==============================================================================

if $DO_TARBALL ; then
FINAL_PACKAGE=${CARLA_DIST_FOLDER}/CARLA_${REPOSITORY_TAG}.tar.gz
else
FINAL_PACKAGE=${BUILD_FOLDER}
for PACKAGE_NAME in "${PACKAGES[@]}" ; do if [[ ${PACKAGE_NAME} != "Carla" ]] ; then

BUILD_FOLDER=${CARLA_DIST_FOLDER}/${PACKAGE_NAME}_${REPOSITORY_TAG}

DESTINATION=${BUILD_FOLDER}.tar.gz

mkdir -p ${BUILD_FOLDER}

log "Preparing environment for cooking '${PACKAGE_NAME}'."

fatal_error "TODO: Call command-let here."

pushd "${CARLAUE4_ROOT_FOLDER}" > /dev/null

log "Cooking '${PACKAGE_NAME}'."

${UE4_ROOT}/Engine/Binaries/Linux/UE4Editor "${PWD}/CarlaUE4.uproject" \
-run=cook -cooksinglepackage -targetplatform="LinuxNoEditor" \
-OutputDir="${BUILD_FOLDER}" \
-Map=${MAP_TO_COOK}

popd >/dev/null

if ${DO_TARBALL} ; then

pushd "${BUILD_FOLDER}" > /dev/null

log "Packaging '${PACKAGE_NAME}'."

rm -Rf ./CarlaUE4/Metadata
rm -Rf ./CarlaUE4/Plugins
rm ./CarlaUE4/AssetRegistry.bin

fatal_error "TODO: Remove intermediate maps here."

tar -czvf ${DESTINATION} *

popd >/dev/null

fi

if ${DO_CLEAN_INTERMEDIATE} ; then
log "Removing intermediate build."
rm -Rf ${BUILD_FOLDER}
fi

fi ; done

# ==============================================================================
# -- Log paths of generated packages -------------------------------------------
# ==============================================================================

for PACKAGE_NAME in "${PACKAGES[@]}" ; do if [[ ${PACKAGE_NAME} != "Carla" ]] ; then
FINAL_PACKAGE=${CARLA_DIST_FOLDER}/${PACKAGE_NAME}_${REPOSITORY_TAG}.tar.gz
log "Package '${PACKAGE_NAME}' created at ${FINAL_PACKAGE}"
fi ; done

if ${DO_CARLA_RELEASE} ; then
if ${DO_TARBALL} ; then
FINAL_PACKAGE=${CARLA_DIST_FOLDER}/CARLA_${REPOSITORY_TAG}.tar.gz
else
FINAL_PACKAGE=${RELEASE_BUILD_FOLDER}
fi
log "CARLA release created at ${FINAL_PACKAGE}"
fi

log "Packaged version created at ${FINAL_PACKAGE}"
# ==============================================================================
# -- ...and we are done --------------------------------------------------------
# ==============================================================================

log "Success!"

0 comments on commit 07a2083

Please sign in to comment.