Skip to content
Snippets Groups Projects
Commit adf84d03 authored by Tristan Laurent's avatar Tristan Laurent
Browse files

STYLE: Make build_gdal_bindings.sh works independently from python version

parent a9e1a6b8
No related branches found
No related tags found
1 merge request!1054BUG: fix empty OS variable, fix osgeo finding on rhel-based OS
Pipeline #16397 passed
......@@ -25,18 +25,20 @@ if [ "$#" -ne 3 ]; then
exit
fi
SOURCEDIR=$1
WORKDIR=$2
INSTALLDIR=$WORKDIR/gdal_bindings_otb-$3-py312
SOURCEDIR="$1"
WORKDIR="$2"
concatpyversion="$(python3 -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]*\).*/\1\2/')"
INSTALLDIR="$WORKDIR/gdal_bindings_otb-$3-py$concatpyversion"
echo "*** Checking out branch release-$3 ***"
cd $SOURCEDIR
cd "$SOURCEDIR"
git checkout origin/release-$3
pyversion="$(python3 -V 2>&1)"
echo "*** Building GDAL bindings with $pyversion for otb $3 ***"
mkdir $WORKDIR/gdal_build_otb-$3 && cd $WORKDIR/gdal_build_otb-$3
cmake $SOURCEDIR/SuperBuild -DCMAKE_INSTALL_PREFIX=$INSTALLDIR -DDOWNLOAD_LOCATION=$WORKDIR/superbuild-archives
echo "*** Building GDAL bindings with $concatpyversion for otb $3 ***"
mkdir "$WORKDIR/gdal_build_otb-$3" && cd "$WORKDIR/gdal_build_otb-$3"
cmake "$SOURCEDIR/SuperBuild" -DCMAKE_INSTALL_PREFIX="$INSTALLDIR" -DDOWNLOAD_LOCATION="$WORKDIR/superbuild-archives"
make -j16 GDAL
echo "*** Creating a tar gz of the gdal bindings in the directory $INSTALLDIR ***"
find $INSTALLDIR/lib/python3/dist-packages/osgeo/ -type f -name "*.so" -printf "%P\n" | tar -czf $INSTALLDIR/OTB-$3-GDAL-bindings-py312.tar.gz --no-recursion -C $INSTALLDIR/lib/python3/dist-packages/osgeo -T -
osgeopython=$(find "$INSTALLDIR/lib" -mindepth 3 -maxdepth 3 -type d -name "osgeo")
find "$osgeopython" -type f -name "*.so" -printf "%P\n" | tar -czf "$INSTALLDIR/OTB-$3-GDAL-bindings-py$concatpyversion.tar.gz" --no-recursion -C "$osgeopython" -T -
......@@ -33,30 +33,36 @@ sed -i "s/\/builds\/otb\/xdk/\$OTB_INSTALL_DIR/g" "$OTB_INSTALL_DIR"/bin/gdal-co
sed -i "s/\/builds\/otb\/xdk/\$OTB_INSTALL_DIR/g" "$OTB_INSTALL_DIR"/bin/curl-config
sh "$OTB_INSTALL_DIR"/tools/sanitize_rpath.sh
concatpyversion="$(python3 -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]*\).*/\1\2/')"
ostype="$(lsb_release -is)"
# Recompile OTB Python bindings. By default on non RHEL OS, the packaged
# bindings are compiled for version 3.10
if [ "$concatpyversion" -ne "310" ] && [ $ostype != "RedHatEnterprise" ] ; then
if [ "$ostype" != "RedHatEnterprise" ] ; then
concatpyversion="$(python3 -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]*\).*/\1\2/')"
# Recompile OTB Python bindings. By default on non RHEL OS, the packaged
# bindings are compiled for version 3.10
if [ "$concatpyversion" -ne "310" ]; then
sh "$OTB_INSTALL_DIR"/recompile_bindings.sh
fi
# Check python version, if python 3.12 (ubuntu 24 and debian > 12) download and extract the gdal bindings for python 3.12
# In case your install is from compiled code, the gdal bindings will be already there in the installation
# Note that the install path differs from RHEL to debian based OS. To handle it,
# check before the folder name (always prefixed of python3)
osgeo_pkg_path=$(find "$OTB_INSTALL_DIR/lib" -mindepth 3 -maxdepth 3 -type d -name "osgeo")
gdal_python_found="$(find $osgeo_pkg_path -name "*$concatpyversion-x86_64-linux*")"
if [ -z "$gdal_python_found" ]; then
fi
# Check python version, if python 3.12 (ubuntu 24 and debian > 12) download
# and extract the gdal bindings for python 3.12
# In case your install is from compiled code, the gdal bindings will be
# already there in the installation
# Note that the install path differs from OS. To handle it,
# check before the folder name (always prefixed of python3)
osgeo_pkg_path=$(find "$OTB_INSTALL_DIR/lib" -mindepth 3 -maxdepth 3 -type d -name "osgeo")
gdal_python_found="$(find $osgeo_pkg_path -name "*$concatpyversion-x86_64-linux*")"
if [ -z "$gdal_python_found" ]; then
echo "***** Python $concatpyversion detected, downloading gdal bindings compiled for this Python version *****"
HTTP_STATUS=$(curl -s -o "$OTB_INSTALL_DIR"/tools/gdal-py$concatpyversion.tar.gz -w "%{response_code}\n" https://www.orfeo-toolbox.org/packages/archives/OTB/OTB-$OTB_SHORT_VERSION-GDAL-bindings-py$concatpyversion.tar.gz)
if [ $HTTP_STATUS -eq 200 ]; then
tar -xf "$OTB_INSTALL_DIR"/tools/gdal-py$concatpyversion.tar.gz -C $python_distpackage_path
rm "$OTB_INSTALL_DIR"/tools/gdal-py$concatpyversion.tar.gz
echo "***** GDAL bindings for python $concatpyversion successfully installed *****"
if [ "$HTTP_STATUS" -eq 200 ]; then
tar -xf "$OTB_INSTALL_DIR"/tools/gdal-py$concatpyversion.tar.gz -C $python_distpackage_path
rm "$OTB_INSTALL_DIR"/tools/gdal-py$concatpyversion.tar.gz
echo "***** GDAL bindings for python $concatpyversion successfully installed *****"
else
echo "Can not find GDAL bindings at https://www.orfeo-toolbox.org/packages/archives/OTB/OTB-$OTB_SHORT_VERSION-GDAL-bindings-py$concatpyversion.tar.gz"
return -1
echo "Can not find GDAL bindings at https://www.orfeo-toolbox.org/packages/archives/OTB/OTB-$OTB_SHORT_VERSION-GDAL-bindings-py$concatpyversion.tar.gz"
return -1
fi
fi
fi
echo "***** OTB Environment and Python bindings setup complete *****"
echo "OK" > "$OTB_INSTALL_DIR"/tools/install_done.txt
\ No newline at end of file
echo "OK" > "$OTB_INSTALL_DIR"/tools/install_done.txt
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment