From a9e1a6b829cece9fddc0674f48a928f0f414a07b Mon Sep 17 00:00:00 2001 From: Tristan Laurent <tristan.laurent@cs-soprasteria.com> Date: Fri, 17 Jan 2025 17:03:07 +0100 Subject: [PATCH 1/4] BUG: fix empty OS variable, fix osgeo finding on rhel-based OS --- Packaging/Files/otbenv.profile | 8 ++++---- Packaging/Files/post_install.sh.in | 25 ++++++++++++++----------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Packaging/Files/otbenv.profile b/Packaging/Files/otbenv.profile index c40c49a2c7..bc934b99df 100644 --- a/Packaging/Files/otbenv.profile +++ b/Packaging/Files/otbenv.profile @@ -42,7 +42,7 @@ OS="$(lsb_release -is)" # path may differ if [ -n "${BASH}" ]; then # dirname does not exists on RH-based OS - if [ $OS = "RedHatEnterprise" ] || [ $OS = "Fedora" ] || [ $OS = "RockyLinux" ]; then + if [ "$OS" = "RedHatEnterprise" ] || [ "$OS" = "Fedora" ] || [ "$OS" = "RockyLinux" ]; then OTB_INSTALL_DIR="$(realpath $(dirname "${BASH_SOURCE[0]}"))" elif [ -n "${BASH}" ]; then OTB_INSTALL_DIR="$( dirname -- "$( readlink -f -- "${BASH_SOURCE[0]}"; )"; )" @@ -51,7 +51,7 @@ else # non-bash shell OTB_INSTALL_DIR="$( dirname -- "$( readlink -f -- "$0"; )"; )" fi -CMAKE_PREFIX_PATH=$OTB_INSTALL_DIR +CMAKE_PREFIX_PATH="$OTB_INSTALL_DIR" export CMAKE_PREFIX_PATH # check and set OTB_APPLICATION_PATH @@ -62,7 +62,7 @@ PATH=$(cat_path "$OTB_INSTALL_DIR/bin" "$PATH") # export PYTHONPATH to import otbApplication.py PYTHONPATH=$(cat_path "$OTB_INSTALL_DIR/lib/otb/python" "$PYTHONPATH") -if [ $OS = "RedHatEnterprise" ] || [ $OS = "Fedora" ] || [ $OS = "RockyLinux" ]; then +if [ "$OS" = "RedHatEnterprise" ] || [ "$OS" = "Fedora" ] || [ "$OS" = "RockyLinux" ]; then PYTHONPATH=$(cat_path "$OTB_INSTALL_DIR/lib/python3.8/site-packages" "$PYTHONPATH") else PYTHONPATH=$(cat_path "$OTB_INSTALL_DIR/lib/python3/dist-packages" "$PYTHONPATH") @@ -76,7 +76,7 @@ GDAL_DATA="$OTB_INSTALL_DIR/share/gdal" PROJ_LIB="$OTB_INSTALL_DIR/share/proj" -export GDAL_DRIVER_PATH=disable +export GDAL_DRIVER_PATH="disable" export LD_LIBRARY_PATH="$OTB_INSTALL_DIR/lib:$LD_LIBRARY_PATH" diff --git a/Packaging/Files/post_install.sh.in b/Packaging/Files/post_install.sh.in index e14909d8fc..7734a39a2d 100644 --- a/Packaging/Files/post_install.sh.in +++ b/Packaging/Files/post_install.sh.in @@ -33,25 +33,28 @@ 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 -pyversion="$(python3 -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]*\).*/\1\2/')" +concatpyversion="$(python3 -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]*\).*/\1\2/')" ostype="$(lsb_release -is)" -# Recompile OTB Python bindings -if [ "$pyversion" -ne "310" ] && [ $ostype != "RedHatEnterprise" ] ; then +# 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 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 -python_distpackage_path="$OTB_INSTALL_DIR/lib/python3/dist-packages/osgeo/" -gdal_python_found="$(find $python_distpackage_path -name "*$pyversion-x86_64-linux*")" +# 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 - echo "***** Python $pyversion detected, downloading gdal bindings compiled for this Python version *****" - HTTP_STATUS=$(curl -s -o "$OTB_INSTALL_DIR"/tools/gdal-py$pyversion.tar.gz -w "%{response_code}\n" https://www.orfeo-toolbox.org/packages/archives/OTB/OTB-$OTB_SHORT_VERSION-GDAL-bindings-py$pyversion.tar.gz) + 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$pyversion.tar.gz -C $python_distpackage_path - rm "$OTB_INSTALL_DIR"/tools/gdal-py$pyversion.tar.gz - echo "***** GDAL bindings for python $pyversion successfully installed *****" + 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$pyversion.tar.gz" + 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 -- GitLab From adf84d03b110bcb0229778a5c425c9f64560f403 Mon Sep 17 00:00:00 2001 From: Tristan Laurent <tristan.laurent@cs-soprasteria.com> Date: Mon, 20 Jan 2025 11:06:24 +0100 Subject: [PATCH 2/4] STYLE: Make build_gdal_bindings.sh works independently from python version --- Packaging/Files/build_gdal_bindings.sh | 20 ++++++------ Packaging/Files/post_install.sh.in | 44 +++++++++++++++----------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/Packaging/Files/build_gdal_bindings.sh b/Packaging/Files/build_gdal_bindings.sh index d8fd70d8a3..affc3451aa 100644 --- a/Packaging/Files/build_gdal_bindings.sh +++ b/Packaging/Files/build_gdal_bindings.sh @@ -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 - diff --git a/Packaging/Files/post_install.sh.in b/Packaging/Files/post_install.sh.in index 7734a39a2d..8ff82bedf3 100644 --- a/Packaging/Files/post_install.sh.in +++ b/Packaging/Files/post_install.sh.in @@ -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 -- GitLab From 9d83cbe4ae1b184df65ebe137e9a944c47843276 Mon Sep 17 00:00:00 2001 From: Tristan Laurent <tristan.laurent@cs-soprasteria.com> Date: Wed, 22 Jan 2025 16:39:57 +0100 Subject: [PATCH 3/4] FEAT: add a copyright update script --- Utilities/Maintenance/update_copyright_date.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 Utilities/Maintenance/update_copyright_date.sh diff --git a/Utilities/Maintenance/update_copyright_date.sh b/Utilities/Maintenance/update_copyright_date.sh new file mode 100755 index 0000000000..9cc9bb5efc --- /dev/null +++ b/Utilities/Maintenance/update_copyright_date.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +tmp_file_name="_tmp_file_list.txt" +# get all files +find . -type f > $tmp_file_name +current_year=$(date -u | egrep -o "[0-9]{4}") + +# for all files, update the year to current +while IFS= read -r f_path; do + # except for this current script + if [ "$f_path" != $0 ]; then + sed -i "s/Copyright (C) 2005-20../Copyright (C) 2005-$current_year/g" "$line" + fi +done < "$tmp_file_name" + +rm $tmp_file_name -- GitLab From 7415935b329d1881acf148472e2a62f536341bf7 Mon Sep 17 00:00:00 2001 From: Tristan Laurent <tristan.laurent@cs-soprasteria.com> Date: Thu, 30 Jan 2025 16:10:33 +0100 Subject: [PATCH 4/4] ENH: do not recompile bindings already compiled with good python version --- CMakeLists.txt | 19 +++++++++++++++++ Packaging/Files/post_install.sh.in | 6 +++--- .../Maintenance/update_copyright_date.sh | 21 +++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 473055c2bb..98c6cfed6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -436,6 +436,25 @@ if(UNIX) DESTINATION . COMPONENT Core ) + # output of python3 --version is "Python XX.XX.XX", notice the space that + # is used + execute_process( + COMMAND python3 --version + RESULT_VARIABLE CMD_RES + OUTPUT_VARIABLE PYTHON_VERSION_DURING_BUILD + ) + # Get the first two digit and concatenate them + string(REGEX MATCH " ([0-9]+)\.([0-9]+)" TMP_VAR "${PYTHON_VERSION_DURING_BUILD}") + + if (${CMAKE_MATCH_COUNT} EQUAL 2) + # CMAKE_MATCH_0 is the entire match + #Â See https://cmake.org/cmake/help/latest/variable/CMAKE_MATCH_n.html + set(PYTHON_VERSION_DURING_BUILD "${CMAKE_MATCH_1}${CMAKE_MATCH_2}") + else() + # set default version + set(PYTHON_VERSION_DURING_BUILD "310") + endif() + configure_file(${OTB_SOURCE_DIR}/Packaging/Files/post_install.sh.in ${CMAKE_BINARY_DIR}/post_install.sh @ONLY) install( PROGRAMS diff --git a/Packaging/Files/post_install.sh.in b/Packaging/Files/post_install.sh.in index 8ff82bedf3..7e935214d0 100644 --- a/Packaging/Files/post_install.sh.in +++ b/Packaging/Files/post_install.sh.in @@ -37,9 +37,9 @@ ostype="$(lsb_release -is)" 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 + # Compare the concat version with the version used to build this OTB package + #Â The python build version is filled by cmake + if [ "$concatpyversion" -ne "@PYTHON_VERSION_DURING_BUILD@" ]; then sh "$OTB_INSTALL_DIR"/recompile_bindings.sh fi # Check python version, if python 3.12 (ubuntu 24 and debian > 12) download diff --git a/Utilities/Maintenance/update_copyright_date.sh b/Utilities/Maintenance/update_copyright_date.sh index 9cc9bb5efc..9b2f36a0df 100755 --- a/Utilities/Maintenance/update_copyright_date.sh +++ b/Utilities/Maintenance/update_copyright_date.sh @@ -1,4 +1,25 @@ #!/bin/bash +# +# Copyright (C) 2005-2025 Centre National d'Etudes Spatiales (CNES) +# +# This file is part of Orfeo Toolbox +# +# https://www.orfeo-toolbox.org/ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Change the copyright date of all files (recursively) where this script is executed tmp_file_name="_tmp_file_list.txt" # get all files -- GitLab