2018-07-04 17:59:59 +08:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- Parse arguments -----------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
DOC_STRING="Build and package CARLA Python API."
|
|
|
|
|
2021-07-15 17:18:34 +08:00
|
|
|
USAGE_STRING="Usage: $0 [-h|--help] [--rebuild] [--clean] [--python-version=VERSION] [--target-wheel-platform=PLATFORM]"
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
REMOVE_INTERMEDIATE=false
|
2019-06-03 19:01:53 +08:00
|
|
|
BUILD_RSS_VARIANT=false
|
2020-09-02 21:19:07 +08:00
|
|
|
BUILD_PYTHONAPI=true
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2021-07-15 17:18:34 +08:00
|
|
|
OPTS=`getopt -o h --long help,config:,rebuild,clean,rss,carsim,python-version:,target-wheel-platform:,packages:,clean-intermediate,all,xml,target-archive:, -n 'parse-options' -- "$@"`
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
eval set -- "$OPTS"
|
|
|
|
|
2020-10-01 22:12:15 +08:00
|
|
|
PY_VERSION_LIST=3
|
2021-07-15 17:18:34 +08:00
|
|
|
TARGET_WHEEL_PLATFORM=
|
2020-08-25 20:10:53 +08:00
|
|
|
|
2020-08-25 21:12:46 +08:00
|
|
|
while [[ $# -gt 0 ]]; do
|
2018-07-04 17:59:59 +08:00
|
|
|
case "$1" in
|
|
|
|
--rebuild )
|
|
|
|
REMOVE_INTERMEDIATE=true;
|
2020-09-02 21:19:07 +08:00
|
|
|
BUILD_PYTHONAPI=true;
|
2018-07-04 17:59:59 +08:00
|
|
|
shift ;;
|
2020-09-02 21:19:07 +08:00
|
|
|
--python-version )
|
2020-10-01 22:12:15 +08:00
|
|
|
PY_VERSION_LIST="$2"
|
2020-08-25 21:12:46 +08:00
|
|
|
shift 2 ;;
|
2021-07-15 17:18:34 +08:00
|
|
|
--target-wheel-platform )
|
|
|
|
TARGET_WHEEL_PLATFORM="$2"
|
|
|
|
shift 2 ;;
|
2019-06-03 19:01:53 +08:00
|
|
|
--rss )
|
|
|
|
BUILD_RSS_VARIANT=true;
|
|
|
|
shift ;;
|
2018-07-04 17:59:59 +08:00
|
|
|
--clean )
|
|
|
|
REMOVE_INTERMEDIATE=true;
|
2020-09-02 21:19:07 +08:00
|
|
|
BUILD_PYTHONAPI=false;
|
2018-07-04 17:59:59 +08:00
|
|
|
shift ;;
|
|
|
|
-h | --help )
|
|
|
|
echo "$DOC_STRING"
|
|
|
|
echo "$USAGE_STRING"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
* )
|
2020-08-25 21:12:46 +08:00
|
|
|
shift ;;
|
2018-07-04 17:59:59 +08:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2022-04-26 21:24:17 +08:00
|
|
|
|
2023-01-20 06:37:49 +08:00
|
|
|
export CC="$UE4_ROOT/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v17_clang-10.0.1-centos7/x86_64-unknown-linux-gnu/bin/clang"
|
|
|
|
export CXX="$UE4_ROOT/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v17_clang-10.0.1-centos7/x86_64-unknown-linux-gnu/bin/clang++"
|
|
|
|
export PATH="$UE4_ROOT/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v17_clang-10.0.1-centos7/x86_64-unknown-linux-gnu/bin:$PATH"
|
2022-04-22 20:56:44 +08:00
|
|
|
|
2020-12-17 17:53:03 +08:00
|
|
|
source $(dirname "$0")/Environment.sh
|
|
|
|
|
2020-09-02 21:19:07 +08:00
|
|
|
if ! { ${REMOVE_INTERMEDIATE} || ${BUILD_PYTHONAPI} ; }; then
|
2018-07-04 17:59:59 +08:00
|
|
|
fatal_error "Nothing selected to be done."
|
|
|
|
fi
|
|
|
|
|
2020-10-01 22:12:15 +08:00
|
|
|
# Convert comma-separated string to array of unique elements.
|
|
|
|
IFS="," read -r -a PY_VERSION_LIST <<< "${PY_VERSION_LIST}"
|
|
|
|
|
2019-03-29 01:35:31 +08:00
|
|
|
pushd "${CARLA_PYTHONAPI_SOURCE_FOLDER}" >/dev/null
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- Clean intermediate files --------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
if ${REMOVE_INTERMEDIATE} ; then
|
|
|
|
|
|
|
|
log "Cleaning intermediate files and folders."
|
|
|
|
|
2021-07-15 17:18:34 +08:00
|
|
|
rm -Rf build dist source/carla.egg-info
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
find source -name "*.so" -delete
|
|
|
|
find source -name "__pycache__" -type d -exec rm -r "{}" \;
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- Build API -----------------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
2019-06-03 19:01:53 +08:00
|
|
|
if ${BUILD_RSS_VARIANT} ; then
|
|
|
|
export BUILD_RSS_VARIANT=${BUILD_RSS_VARIANT}
|
|
|
|
fi
|
|
|
|
|
2020-09-02 21:19:07 +08:00
|
|
|
if ${BUILD_PYTHONAPI} ; then
|
2021-07-15 17:18:34 +08:00
|
|
|
# Add patchelf to the path. Auditwheel relies on patchelf to repair ELF files.
|
|
|
|
export PATH="${LIBCARLA_INSTALL_CLIENT_FOLDER}/bin:${PATH}"
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2021-07-21 22:53:42 +08:00
|
|
|
CODENAME=$(cat /etc/os-release | grep VERSION_CODENAME)
|
|
|
|
if [[ ! -z ${TARGET_WHEEL_PLATFORM} ]] && [[ ${CODENAME#*=} != "bionic" ]] ; then
|
2021-07-21 22:02:54 +08:00
|
|
|
log "A target platform has been specified but you are not using a compatible linux distribution. The wheel repair step will be skipped"
|
|
|
|
TARGET_WHEEL_PLATFORM=
|
|
|
|
fi
|
|
|
|
|
2020-10-01 22:12:15 +08:00
|
|
|
for PY_VERSION in ${PY_VERSION_LIST[@]} ; do
|
2020-10-08 17:29:25 +08:00
|
|
|
log "Building Python API for Python ${PY_VERSION}."
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2021-07-15 17:18:34 +08:00
|
|
|
if [[ -z ${TARGET_WHEEL_PLATFORM} ]] ; then
|
|
|
|
/usr/bin/env python${PY_VERSION} setup.py bdist_egg bdist_wheel --dist-dir dist/.tmp
|
|
|
|
cp dist/.tmp/$(ls dist/.tmp | grep .whl) dist
|
|
|
|
else
|
|
|
|
/usr/bin/env python${PY_VERSION} setup.py bdist_egg bdist_wheel --dist-dir dist/.tmp --plat ${TARGET_WHEEL_PLATFORM}
|
2024-05-16 16:28:36 +08:00
|
|
|
/usr/bin/env python${PY_VERSION} -m auditwheel repair --plat ${TARGET_WHEEL_PLATFORM} --wheel-dir dist dist/.tmp/$(ls dist/.tmp | grep .whl)
|
2021-07-15 17:18:34 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
rm -rf dist/.tmp
|
|
|
|
|
2020-10-01 22:12:15 +08:00
|
|
|
done
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- ...and we are done --------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
popd >/dev/null
|
|
|
|
|
|
|
|
log "Success!"
|